blob: 95e304eb44d9af645acce0dfe9d24ce9dfc7b2c1 [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;
Sean Huntc3021132010-05-05 15:23:54 +000099
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 }
Sean Huntc3021132010-05-05 15:23:54 +0000184
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.
Sean Huntc3021132010-05-05 15:23:54 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
Douglas Gregor124b8782010-02-16 19:09:40 +0000205 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 ///
Sean Huntc3021132010-05-05 15:23:54 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +0000212 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.
Sean Huntc3021132010-05-05 15:23:54 +0000246 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
247 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 ///
Sean Huntc3021132010-05-05 15:23:54 +0000253 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000254 /// 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.
Sean Huntc3021132010-05-05 15:23:54 +0000259 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
260 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000261 }
Sean Huntc3021132010-05-05 15:23:54 +0000262
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
Sean Huntc3021132010-05-05 15:23:54 +0000333 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +0000334 QualType ObjectType);
John McCall85737a72009-10-30 00:06:24 +0000335
Sean Huntc3021132010-05-05 15:23:54 +0000336 QualType
Douglas Gregordd62b152009-10-19 22:04:39 +0000337 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);
Zhongxing Xud8383d42010-04-21 06:32:25 +0000341 OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000342
Douglas Gregor43959a92009-08-20 07:17:43 +0000343#define STMT(Node, Parent) \
344 OwningStmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000345#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +0000346 OwningExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000347#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000348#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000349
Douglas Gregor577f75a2009-08-04 16:50:30 +0000350 /// \brief Build a new pointer type given its pointee type.
351 ///
352 /// By default, performs semantic analysis when building the pointer type.
353 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000354 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000355
356 /// \brief Build a new block pointer type given its pointee type.
357 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000358 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000359 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000360 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000361
John McCall85737a72009-10-30 00:06:24 +0000362 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000363 ///
John McCall85737a72009-10-30 00:06:24 +0000364 /// By default, performs semantic analysis when building the
365 /// reference type. Subclasses may override this routine to provide
366 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000367 ///
John McCall85737a72009-10-30 00:06:24 +0000368 /// \param LValue whether the type was written with an lvalue sigil
369 /// or an rvalue sigil.
370 QualType RebuildReferenceType(QualType ReferentType,
371 bool LValue,
372 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000373
Douglas Gregor577f75a2009-08-04 16:50:30 +0000374 /// \brief Build a new member pointer type given the pointee type and the
375 /// class type it refers into.
376 ///
377 /// By default, performs semantic analysis when building the member pointer
378 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000379 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
380 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000381
Douglas Gregor577f75a2009-08-04 16:50:30 +0000382 /// \brief Build a new array type given the element type, size
383 /// modifier, size of the array (if known), size expression, and index type
384 /// qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000388 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000389 QualType RebuildArrayType(QualType ElementType,
390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt *Size,
392 Expr *SizeExpr,
393 unsigned IndexTypeQuals,
394 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000395
Douglas Gregor577f75a2009-08-04 16:50:30 +0000396 /// \brief Build a new constant array type given the element type, size
397 /// modifier, (known) size of the array, and index type qualifiers.
398 ///
399 /// By default, performs semantic analysis when building the array type.
400 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000401 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
403 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000404 unsigned IndexTypeQuals,
405 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000406
Douglas Gregor577f75a2009-08-04 16:50:30 +0000407 /// \brief Build a new incomplete array type given the element type, size
408 /// modifier, and index type qualifiers.
409 ///
410 /// By default, performs semantic analysis when building the array type.
411 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000412 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000413 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000416
Mike Stump1eb44332009-09-09 15:08:12 +0000417 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000418 /// size modifier, size expression, and index type qualifiers.
419 ///
420 /// By default, performs semantic analysis when building the array type.
421 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000422 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000424 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
Mike Stump1eb44332009-09-09 15:08:12 +0000428 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000429 /// size modifier, size expression, and index type qualifiers.
430 ///
431 /// By default, performs semantic analysis when building the array type.
432 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000433 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000434 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000435 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000436 unsigned IndexTypeQuals,
437 SourceRange BracketsRange);
438
439 /// \brief Build a new vector type given the element type and
440 /// number of elements.
441 ///
442 /// By default, performs semantic analysis when building the vector type.
443 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000444 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Chris Lattner788b0fd2010-06-23 06:00:24 +0000445 VectorType::AltiVecSpecific AltiVecSpec);
Mike Stump1eb44332009-09-09 15:08:12 +0000446
Douglas Gregor577f75a2009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000461 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000463
Douglas Gregor577f75a2009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
471 bool Variadic, unsigned Quals);
Mike Stump1eb44332009-09-09 15:08:12 +0000472
John McCalla2becad2009-10-21 00:40:46 +0000473 /// \brief Build a new unprototyped function type.
474 QualType RebuildFunctionNoProtoType(QualType ResultType);
475
John McCalled976492009-12-04 22:46:56 +0000476 /// \brief Rebuild an unresolved typename type, given the decl that
477 /// the UnresolvedUsingTypenameDecl was transformed to.
478 QualType RebuildUnresolvedUsingType(Decl *D);
479
Douglas Gregor577f75a2009-08-04 16:50:30 +0000480 /// \brief Build a new typedef type.
481 QualType RebuildTypedefType(TypedefDecl *Typedef) {
482 return SemaRef.Context.getTypeDeclType(Typedef);
483 }
484
485 /// \brief Build a new class/struct/union type.
486 QualType RebuildRecordType(RecordDecl *Record) {
487 return SemaRef.Context.getTypeDeclType(Record);
488 }
489
490 /// \brief Build a new Enum type.
491 QualType RebuildEnumType(EnumDecl *Enum) {
492 return SemaRef.Context.getTypeDeclType(Enum);
493 }
John McCall7da24312009-09-05 00:15:47 +0000494
Mike Stump1eb44332009-09-09 15:08:12 +0000495 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000496 ///
497 /// By default, performs semantic analysis when building the typeof type.
498 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000499 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000500
Mike Stump1eb44332009-09-09 15:08:12 +0000501 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000502 ///
503 /// By default, builds a new TypeOfType with the given underlying type.
504 QualType RebuildTypeOfType(QualType Underlying);
505
Mike Stump1eb44332009-09-09 15:08:12 +0000506 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000507 ///
508 /// By default, performs semantic analysis when building the decltype type.
509 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000510 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump1eb44332009-09-09 15:08:12 +0000511
Douglas Gregor577f75a2009-08-04 16:50:30 +0000512 /// \brief Build a new template specialization type.
513 ///
514 /// By default, performs semantic analysis when building the template
515 /// specialization type. Subclasses may override this routine to provide
516 /// different behavior.
517 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000518 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000519 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000520
Douglas Gregor577f75a2009-08-04 16:50:30 +0000521 /// \brief Build a new qualified name type.
522 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000523 /// By default, builds a new ElaboratedType type from the keyword,
524 /// the nested-name-specifier and the named type.
525 /// Subclasses may override this routine to provide different behavior.
526 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
527 NestedNameSpecifier *NNS, QualType Named) {
528 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000529 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000530
531 /// \brief Build a new typename type that refers to a template-id.
532 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000533 /// By default, builds a new DependentNameType type from the
534 /// nested-name-specifier and the given type. Subclasses may override
535 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000536 QualType RebuildDependentTemplateSpecializationType(
537 ElaboratedTypeKeyword Keyword,
538 NestedNameSpecifier *NNS,
539 const IdentifierInfo *Name,
540 SourceLocation NameLoc,
541 const TemplateArgumentListInfo &Args) {
542 // Rebuild the template name.
543 // TODO: avoid TemplateName abstraction
544 TemplateName InstName =
545 getDerived().RebuildTemplateName(NNS, *Name, QualType());
546
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000547 if (InstName.isNull())
548 return QualType();
549
John McCall33500952010-06-11 00:33:02 +0000550 // If it's still dependent, make a dependent specialization.
551 if (InstName.getAsDependentTemplateName())
552 return SemaRef.Context.getDependentTemplateSpecializationType(
553 Keyword, NNS, Name, Args);
554
555 // Otherwise, make an elaborated type wrapping a non-dependent
556 // specialization.
557 QualType T =
558 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
559 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000560
561 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000562 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000563
564 /// \brief Build a new typename type that refers to an identifier.
565 ///
566 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000567 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000568 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000569 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000570 NestedNameSpecifier *NNS,
571 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000572 SourceLocation KeywordLoc,
573 SourceRange NNSRange,
574 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000575 CXXScopeSpec SS;
576 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000577 SS.setRange(NNSRange);
578
Douglas Gregor40336422010-03-31 22:19:08 +0000579 if (NNS->isDependent()) {
580 // If the name is still dependent, just build a new dependent name type.
581 if (!SemaRef.computeDeclContext(SS))
582 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
583 }
584
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000585 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000586 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
587 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000588
589 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
590
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000591 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000592 // into a non-dependent elaborated-type-specifier. Find the tag we're
593 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000594 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000595 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
596 if (!DC)
597 return QualType();
598
John McCall56138762010-05-27 06:40:31 +0000599 if (SemaRef.RequireCompleteDeclContext(SS, DC))
600 return QualType();
601
Douglas Gregor40336422010-03-31 22:19:08 +0000602 TagDecl *Tag = 0;
603 SemaRef.LookupQualifiedName(Result, DC);
604 switch (Result.getResultKind()) {
605 case LookupResult::NotFound:
606 case LookupResult::NotFoundInCurrentInstantiation:
607 break;
Sean Huntc3021132010-05-05 15:23:54 +0000608
Douglas Gregor40336422010-03-31 22:19:08 +0000609 case LookupResult::Found:
610 Tag = Result.getAsSingle<TagDecl>();
611 break;
Sean Huntc3021132010-05-05 15:23:54 +0000612
Douglas Gregor40336422010-03-31 22:19:08 +0000613 case LookupResult::FoundOverloaded:
614 case LookupResult::FoundUnresolvedValue:
615 llvm_unreachable("Tag lookup cannot find non-tags");
616 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000617
Douglas Gregor40336422010-03-31 22:19:08 +0000618 case LookupResult::Ambiguous:
619 // Let the LookupResult structure handle ambiguities.
620 return QualType();
621 }
622
623 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000624 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000625 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000626 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000627 return QualType();
628 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000629
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000630 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
631 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000632 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
633 return QualType();
634 }
635
636 // Build the elaborated-type-specifier type.
637 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000638 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000639 }
Mike Stump1eb44332009-09-09 15:08:12 +0000640
Douglas Gregordcee1a12009-08-06 05:28:30 +0000641 /// \brief Build a new nested-name-specifier given the prefix and an
642 /// identifier that names the next step in the nested-name-specifier.
643 ///
644 /// By default, performs semantic analysis when building the new
645 /// nested-name-specifier. Subclasses may override this routine to provide
646 /// different behavior.
647 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
648 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000649 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000650 QualType ObjectType,
651 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000652
653 /// \brief Build a new nested-name-specifier given the prefix and the
654 /// namespace named in the next step in the nested-name-specifier.
655 ///
656 /// By default, performs semantic analysis when building the new
657 /// nested-name-specifier. Subclasses may override this routine to provide
658 /// different behavior.
659 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
660 SourceRange Range,
661 NamespaceDecl *NS);
662
663 /// \brief Build a new nested-name-specifier given the prefix and the
664 /// type named in the next step in the nested-name-specifier.
665 ///
666 /// By default, performs semantic analysis when building the new
667 /// nested-name-specifier. Subclasses may override this routine to provide
668 /// different behavior.
669 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
670 SourceRange Range,
671 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000672 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000673
674 /// \brief Build a new template name given a nested name specifier, a flag
675 /// indicating whether the "template" keyword was provided, and the template
676 /// that the template name refers to.
677 ///
678 /// By default, builds the new template name directly. Subclasses may override
679 /// this routine to provide different behavior.
680 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
681 bool TemplateKW,
682 TemplateDecl *Template);
683
Douglas Gregord1067e52009-08-06 06:41:21 +0000684 /// \brief Build a new template name given a nested name specifier and the
685 /// name that is referred to as a template.
686 ///
687 /// By default, performs semantic analysis to determine whether the name can
688 /// be resolved to a specific template, then builds the appropriate kind of
689 /// template name. Subclasses may override this routine to provide different
690 /// behavior.
691 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000692 const IdentifierInfo &II,
693 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000694
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000695 /// \brief Build a new template name given a nested name specifier and the
696 /// overloaded operator name that is referred to as a template.
697 ///
698 /// By default, performs semantic analysis to determine whether the name can
699 /// be resolved to a specific template, then builds the appropriate kind of
700 /// template name. Subclasses may override this routine to provide different
701 /// behavior.
702 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
703 OverloadedOperatorKind Operator,
704 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000705
Douglas Gregor43959a92009-08-20 07:17:43 +0000706 /// \brief Build a new compound statement.
707 ///
708 /// By default, performs semantic analysis to build the new statement.
709 /// Subclasses may override this routine to provide different behavior.
710 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
711 MultiStmtArg Statements,
712 SourceLocation RBraceLoc,
713 bool IsStmtExpr) {
714 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
715 IsStmtExpr);
716 }
717
718 /// \brief Build a new case statement.
719 ///
720 /// By default, performs semantic analysis to build the new statement.
721 /// Subclasses may override this routine to provide different behavior.
722 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
723 ExprArg LHS,
724 SourceLocation EllipsisLoc,
725 ExprArg RHS,
726 SourceLocation ColonLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000727 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregor43959a92009-08-20 07:17:43 +0000728 ColonLoc);
729 }
Mike Stump1eb44332009-09-09 15:08:12 +0000730
Douglas Gregor43959a92009-08-20 07:17:43 +0000731 /// \brief Attach the body to a new case statement.
732 ///
733 /// By default, performs semantic analysis to build the new statement.
734 /// Subclasses may override this routine to provide different behavior.
735 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
736 getSema().ActOnCaseStmtBody(S.get(), move(Body));
737 return move(S);
738 }
Mike Stump1eb44332009-09-09 15:08:12 +0000739
Douglas Gregor43959a92009-08-20 07:17:43 +0000740 /// \brief Build a new default statement.
741 ///
742 /// By default, performs semantic analysis to build the new statement.
743 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000744 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000745 SourceLocation ColonLoc,
746 StmtArg SubStmt) {
Mike Stump1eb44332009-09-09 15:08:12 +0000747 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregor43959a92009-08-20 07:17:43 +0000748 /*CurScope=*/0);
749 }
Mike Stump1eb44332009-09-09 15:08:12 +0000750
Douglas Gregor43959a92009-08-20 07:17:43 +0000751 /// \brief Build a new label statement.
752 ///
753 /// By default, performs semantic analysis to build the new statement.
754 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000755 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000756 IdentifierInfo *Id,
757 SourceLocation ColonLoc,
758 StmtArg SubStmt) {
759 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
760 }
Mike Stump1eb44332009-09-09 15:08:12 +0000761
Douglas Gregor43959a92009-08-20 07:17:43 +0000762 /// \brief Build a new "if" statement.
763 ///
764 /// By default, performs semantic analysis to build the new statement.
765 /// Subclasses may override this routine to provide different behavior.
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000766 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Sean Huntc3021132010-05-05 15:23:54 +0000767 VarDecl *CondVar, StmtArg Then,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000768 SourceLocation ElseLoc, StmtArg Else) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000769 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000770 move(Then), ElseLoc, move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +0000771 }
Mike Stump1eb44332009-09-09 15:08:12 +0000772
Douglas Gregor43959a92009-08-20 07:17:43 +0000773 /// \brief Start building a new switch statement.
774 ///
775 /// By default, performs semantic analysis to build the new statement.
776 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor586596f2010-05-06 17:25:47 +0000777 OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
778 Sema::ExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000779 VarDecl *CondVar) {
Douglas Gregor586596f2010-05-06 17:25:47 +0000780 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond),
781 DeclPtrTy::make(CondVar));
Douglas Gregor43959a92009-08-20 07:17:43 +0000782 }
Mike Stump1eb44332009-09-09 15:08:12 +0000783
Douglas Gregor43959a92009-08-20 07:17:43 +0000784 /// \brief Attach the body to the switch statement.
785 ///
786 /// By default, performs semantic analysis to build the new statement.
787 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000788 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000789 StmtArg Switch, StmtArg Body) {
790 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
791 move(Body));
792 }
793
794 /// \brief Build a new while statement.
795 ///
796 /// By default, performs semantic analysis to build the new statement.
797 /// Subclasses may override this routine to provide different behavior.
798 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000799 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000800 VarDecl *CondVar,
Douglas Gregor43959a92009-08-20 07:17:43 +0000801 StmtArg Body) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000802 return getSema().ActOnWhileStmt(WhileLoc, Cond,
Douglas Gregor586596f2010-05-06 17:25:47 +0000803 DeclPtrTy::make(CondVar), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000804 }
Mike Stump1eb44332009-09-09 15:08:12 +0000805
Douglas Gregor43959a92009-08-20 07:17:43 +0000806 /// \brief Build a new do-while statement.
807 ///
808 /// By default, performs semantic analysis to build the new statement.
809 /// Subclasses may override this routine to provide different behavior.
810 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
811 SourceLocation WhileLoc,
812 SourceLocation LParenLoc,
813 ExprArg Cond,
814 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000815 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000816 move(Cond), RParenLoc);
817 }
818
819 /// \brief Build a new for statement.
820 ///
821 /// By default, performs semantic analysis to build the new statement.
822 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000823 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000824 SourceLocation LParenLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000825 StmtArg Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000826 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000827 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000828 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000829 DeclPtrTy::make(CondVar),
830 Inc, RParenLoc, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000831 }
Mike Stump1eb44332009-09-09 15:08:12 +0000832
Douglas Gregor43959a92009-08-20 07:17:43 +0000833 /// \brief Build a new goto statement.
834 ///
835 /// By default, performs semantic analysis to build the new statement.
836 /// Subclasses may override this routine to provide different behavior.
837 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
838 SourceLocation LabelLoc,
839 LabelStmt *Label) {
840 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
841 }
842
843 /// \brief Build a new indirect goto statement.
844 ///
845 /// By default, performs semantic analysis to build the new statement.
846 /// Subclasses may override this routine to provide different behavior.
847 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
848 SourceLocation StarLoc,
849 ExprArg Target) {
850 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
851 }
Mike Stump1eb44332009-09-09 15:08:12 +0000852
Douglas Gregor43959a92009-08-20 07:17:43 +0000853 /// \brief Build a new return statement.
854 ///
855 /// By default, performs semantic analysis to build the new statement.
856 /// Subclasses may override this routine to provide different behavior.
857 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
858 ExprArg Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000859
Douglas Gregor43959a92009-08-20 07:17:43 +0000860 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
861 }
Mike Stump1eb44332009-09-09 15:08:12 +0000862
Douglas Gregor43959a92009-08-20 07:17:43 +0000863 /// \brief Build a new declaration statement.
864 ///
865 /// By default, performs semantic analysis to build the new statement.
866 /// Subclasses may override this routine to provide different behavior.
867 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000868 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000869 SourceLocation EndLoc) {
870 return getSema().Owned(
871 new (getSema().Context) DeclStmt(
872 DeclGroupRef::Create(getSema().Context,
873 Decls, NumDecls),
874 StartLoc, EndLoc));
875 }
Mike Stump1eb44332009-09-09 15:08:12 +0000876
Anders Carlsson703e3942010-01-24 05:50:09 +0000877 /// \brief Build a new inline asm statement.
878 ///
879 /// By default, performs semantic analysis to build the new statement.
880 /// Subclasses may override this routine to provide different behavior.
881 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
882 bool IsSimple,
883 bool IsVolatile,
884 unsigned NumOutputs,
885 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000886 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000887 MultiExprArg Constraints,
888 MultiExprArg Exprs,
889 ExprArg AsmString,
890 MultiExprArg Clobbers,
891 SourceLocation RParenLoc,
892 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000893 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000894 NumInputs, Names, move(Constraints),
895 move(Exprs), move(AsmString), move(Clobbers),
896 RParenLoc, MSAsm);
897 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000898
899 /// \brief Build a new Objective-C @try statement.
900 ///
901 /// By default, performs semantic analysis to build the new statement.
902 /// Subclasses may override this routine to provide different behavior.
903 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
904 StmtArg TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000905 MultiStmtArg CatchStmts,
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000906 StmtArg Finally) {
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000907 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000908 move(Finally));
909 }
910
Douglas Gregorbe270a02010-04-26 17:57:08 +0000911 /// \brief Rebuild an Objective-C exception declaration.
912 ///
913 /// By default, performs semantic analysis to build the new declaration.
914 /// Subclasses may override this routine to provide different behavior.
915 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
916 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +0000917 return getSema().BuildObjCExceptionDecl(TInfo, T,
918 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +0000919 ExceptionDecl->getLocation());
920 }
Sean Huntc3021132010-05-05 15:23:54 +0000921
Douglas Gregorbe270a02010-04-26 17:57:08 +0000922 /// \brief Build a new Objective-C @catch statement.
923 ///
924 /// By default, performs semantic analysis to build the new statement.
925 /// Subclasses may override this routine to provide different behavior.
926 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
927 SourceLocation RParenLoc,
928 VarDecl *Var,
929 StmtArg Body) {
930 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
931 Sema::DeclPtrTy::make(Var),
932 move(Body));
933 }
Sean Huntc3021132010-05-05 15:23:54 +0000934
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000935 /// \brief Build a new Objective-C @finally statement.
936 ///
937 /// By default, performs semantic analysis to build the new statement.
938 /// Subclasses may override this routine to provide different behavior.
939 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
940 StmtArg Body) {
941 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
942 }
Sean Huntc3021132010-05-05 15:23:54 +0000943
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000944 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +0000945 ///
946 /// By default, performs semantic analysis to build the new statement.
947 /// Subclasses may override this routine to provide different behavior.
948 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
949 ExprArg Operand) {
950 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
951 }
Sean Huntc3021132010-05-05 15:23:54 +0000952
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000953 /// \brief Build a new Objective-C @synchronized statement.
954 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000955 /// By default, performs semantic analysis to build the new statement.
956 /// Subclasses may override this routine to provide different behavior.
957 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
958 ExprArg Object,
959 StmtArg Body) {
960 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
961 move(Body));
962 }
Douglas Gregorc3203e72010-04-22 23:10:45 +0000963
964 /// \brief Build a new Objective-C fast enumeration statement.
965 ///
966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
968 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
969 SourceLocation LParenLoc,
970 StmtArg Element,
971 ExprArg Collection,
972 SourceLocation RParenLoc,
973 StmtArg Body) {
974 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
Sean Huntc3021132010-05-05 15:23:54 +0000975 move(Element),
Douglas Gregorc3203e72010-04-22 23:10:45 +0000976 move(Collection),
977 RParenLoc,
978 move(Body));
979 }
Sean Huntc3021132010-05-05 15:23:54 +0000980
Douglas Gregor43959a92009-08-20 07:17:43 +0000981 /// \brief Build a new C++ exception declaration.
982 ///
983 /// By default, performs semantic analysis to build the new decaration.
984 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000985 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000986 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000987 IdentifierInfo *Name,
988 SourceLocation Loc,
989 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000990 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000991 TypeRange);
992 }
993
994 /// \brief Build a new C++ catch statement.
995 ///
996 /// By default, performs semantic analysis to build the new statement.
997 /// Subclasses may override this routine to provide different behavior.
998 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
999 VarDecl *ExceptionDecl,
1000 StmtArg Handler) {
1001 return getSema().Owned(
Mike Stump1eb44332009-09-09 15:08:12 +00001002 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 Handler.takeAs<Stmt>()));
1004 }
Mike Stump1eb44332009-09-09 15:08:12 +00001005
Douglas Gregor43959a92009-08-20 07:17:43 +00001006 /// \brief Build a new C++ try statement.
1007 ///
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
1010 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1011 StmtArg TryBlock,
1012 MultiStmtArg Handlers) {
1013 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
1014 }
Mike Stump1eb44332009-09-09 15:08:12 +00001015
Douglas Gregorb98b1992009-08-11 05:31:07 +00001016 /// \brief Build a new expression that references a declaration.
1017 ///
1018 /// By default, performs semantic analysis to build the new expression.
1019 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001020 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1021 LookupResult &R,
1022 bool RequiresADL) {
1023 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1024 }
1025
1026
1027 /// \brief Build a new expression that references a declaration.
1028 ///
1029 /// By default, performs semantic analysis to build the new expression.
1030 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora2813ce2009-10-23 18:54:35 +00001031 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1032 SourceRange QualifierRange,
John McCalldbd872f2009-12-08 09:08:17 +00001033 ValueDecl *VD, SourceLocation Loc,
1034 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001035 CXXScopeSpec SS;
1036 SS.setScopeRep(Qualifier);
1037 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001038
1039 // FIXME: loses template args.
Sean Huntc3021132010-05-05 15:23:54 +00001040
John McCalldbd872f2009-12-08 09:08:17 +00001041 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001042 }
Mike Stump1eb44332009-09-09 15:08:12 +00001043
Douglas Gregorb98b1992009-08-11 05:31:07 +00001044 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001045 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001046 /// By default, performs semantic analysis to build the new expression.
1047 /// Subclasses may override this routine to provide different behavior.
1048 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1049 SourceLocation RParen) {
1050 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1051 }
1052
Douglas Gregora71d8192009-09-04 17:36:40 +00001053 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001054 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001055 /// By default, performs semantic analysis to build the new expression.
1056 /// Subclasses may override this routine to provide different behavior.
1057 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1058 SourceLocation OperatorLoc,
1059 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001060 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001061 SourceRange QualifierRange,
1062 TypeSourceInfo *ScopeType,
1063 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001064 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001065 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001066
Douglas Gregorb98b1992009-08-11 05:31:07 +00001067 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001068 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001069 /// By default, performs semantic analysis to build the new expression.
1070 /// Subclasses may override this routine to provide different behavior.
1071 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1072 UnaryOperator::Opcode Opc,
1073 ExprArg SubExpr) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001074 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001075 }
Mike Stump1eb44332009-09-09 15:08:12 +00001076
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001077 /// \brief Build a new builtin offsetof expression.
1078 ///
1079 /// By default, performs semantic analysis to build the new expression.
1080 /// Subclasses may override this routine to provide different behavior.
1081 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1082 TypeSourceInfo *Type,
1083 Action::OffsetOfComponent *Components,
1084 unsigned NumComponents,
1085 SourceLocation RParenLoc) {
1086 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1087 NumComponents, RParenLoc);
1088 }
Sean Huntc3021132010-05-05 15:23:54 +00001089
Douglas Gregorb98b1992009-08-11 05:31:07 +00001090 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001091 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001092 /// By default, performs semantic analysis to build the new expression.
1093 /// Subclasses may override this routine to provide different behavior.
John McCalla93c9342009-12-07 02:54:59 +00001094 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001095 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001096 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001097 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001098 }
1099
Mike Stump1eb44332009-09-09 15:08:12 +00001100 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001101 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001102 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001103 /// By default, performs semantic analysis to build the new expression.
1104 /// Subclasses may override this routine to provide different behavior.
1105 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1106 bool isSizeOf, SourceRange R) {
Mike Stump1eb44332009-09-09 15:08:12 +00001107 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001108 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1109 OpLoc, isSizeOf, R);
1110 if (Result.isInvalid())
1111 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001112
Douglas Gregorb98b1992009-08-11 05:31:07 +00001113 SubExpr.release();
1114 return move(Result);
1115 }
Mike Stump1eb44332009-09-09 15:08:12 +00001116
Douglas Gregorb98b1992009-08-11 05:31:07 +00001117 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001118 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001119 /// By default, performs semantic analysis to build the new expression.
1120 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001121 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001122 SourceLocation LBracketLoc,
1123 ExprArg RHS,
1124 SourceLocation RBracketLoc) {
1125 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump1eb44332009-09-09 15:08:12 +00001126 LBracketLoc, move(RHS),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001127 RBracketLoc);
1128 }
1129
1130 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001131 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001132 /// By default, performs semantic analysis to build the new expression.
1133 /// Subclasses may override this routine to provide different behavior.
1134 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1135 MultiExprArg Args,
1136 SourceLocation *CommaLocs,
1137 SourceLocation RParenLoc) {
1138 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1139 move(Args), CommaLocs, RParenLoc);
1140 }
1141
1142 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001143 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001144 /// By default, performs semantic analysis to build the new expression.
1145 /// Subclasses may override this routine to provide different behavior.
1146 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001147 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001148 NestedNameSpecifier *Qualifier,
1149 SourceRange QualifierRange,
1150 SourceLocation MemberLoc,
Eli Friedmanf595cc42009-12-04 06:40:45 +00001151 ValueDecl *Member,
John McCall6bb80172010-03-30 21:47:33 +00001152 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001153 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +00001154 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001155 if (!Member->getDeclName()) {
1156 // We have a reference to an unnamed field.
1157 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +00001158
Douglas Gregor83a56c42009-12-24 20:02:50 +00001159 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall6bb80172010-03-30 21:47:33 +00001160 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1161 FoundDecl, Member))
Douglas Gregor83a56c42009-12-24 20:02:50 +00001162 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001163
Mike Stump1eb44332009-09-09 15:08:12 +00001164 MemberExpr *ME =
Douglas Gregor83a56c42009-12-24 20:02:50 +00001165 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlssond8b285f2009-09-01 04:26:58 +00001166 Member, MemberLoc,
1167 cast<FieldDecl>(Member)->getType());
1168 return getSema().Owned(ME);
1169 }
Mike Stump1eb44332009-09-09 15:08:12 +00001170
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001171 CXXScopeSpec SS;
1172 if (Qualifier) {
1173 SS.setRange(QualifierRange);
1174 SS.setScopeRep(Qualifier);
1175 }
1176
Douglas Gregor83c9abc2010-06-22 02:41:05 +00001177 Expr *BaseExpr = Base.takeAs<Expr>();
1178 getSema().DefaultFunctionArrayConversion(BaseExpr);
1179 QualType BaseType = BaseExpr->getType();
John McCallaa81e162009-12-01 22:10:20 +00001180
John McCall6bb80172010-03-30 21:47:33 +00001181 // FIXME: this involves duplicating earlier analysis in a lot of
1182 // cases; we should avoid this when possible.
John McCallc2233c52010-01-15 08:34:02 +00001183 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1184 Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001185 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001186 R.resolveKind();
1187
Douglas Gregor83c9abc2010-06-22 02:41:05 +00001188 return getSema().BuildMemberReferenceExpr(getSema().Owned(BaseExpr),
1189 BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001190 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001191 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001192 }
Mike Stump1eb44332009-09-09 15:08:12 +00001193
Douglas Gregorb98b1992009-08-11 05:31:07 +00001194 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001195 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001196 /// By default, performs semantic analysis to build the new expression.
1197 /// Subclasses may override this routine to provide different behavior.
1198 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1199 BinaryOperator::Opcode Opc,
1200 ExprArg LHS, ExprArg RHS) {
Sean Huntc3021132010-05-05 15:23:54 +00001201 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001202 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregorb98b1992009-08-11 05:31:07 +00001203 }
1204
1205 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001206 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001207 /// By default, performs semantic analysis to build the new expression.
1208 /// Subclasses may override this routine to provide different behavior.
1209 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1210 SourceLocation QuestionLoc,
1211 ExprArg LHS,
1212 SourceLocation ColonLoc,
1213 ExprArg RHS) {
Mike Stump1eb44332009-09-09 15:08:12 +00001214 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001215 move(LHS), move(RHS));
1216 }
1217
Douglas Gregorb98b1992009-08-11 05:31:07 +00001218 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001219 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001220 /// By default, performs semantic analysis to build the new expression.
1221 /// Subclasses may override this routine to provide different behavior.
John McCall9d125032010-01-15 18:39:57 +00001222 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1223 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001224 SourceLocation RParenLoc,
1225 ExprArg SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001226 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1227 move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001228 }
Mike Stump1eb44332009-09-09 15:08:12 +00001229
Douglas Gregorb98b1992009-08-11 05:31:07 +00001230 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001231 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001232 /// By default, performs semantic analysis to build the new expression.
1233 /// Subclasses may override this routine to provide different behavior.
1234 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001235 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001236 SourceLocation RParenLoc,
1237 ExprArg Init) {
John McCall42f56b52010-01-18 19:35:47 +00001238 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1239 move(Init));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001240 }
Mike Stump1eb44332009-09-09 15:08:12 +00001241
Douglas Gregorb98b1992009-08-11 05:31:07 +00001242 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001243 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001244 /// By default, performs semantic analysis to build the new expression.
1245 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001246 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001247 SourceLocation OpLoc,
1248 SourceLocation AccessorLoc,
1249 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001250
John McCall129e2df2009-11-30 22:42:35 +00001251 CXXScopeSpec SS;
John McCallaa81e162009-12-01 22:10:20 +00001252 QualType BaseType = ((Expr*) Base.get())->getType();
1253 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001254 OpLoc, /*IsArrow*/ false,
1255 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor2d1c2142009-11-03 19:44:04 +00001256 DeclarationName(&Accessor),
John McCall129e2df2009-11-30 22:42:35 +00001257 AccessorLoc,
1258 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001259 }
Mike Stump1eb44332009-09-09 15:08:12 +00001260
Douglas Gregorb98b1992009-08-11 05:31:07 +00001261 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001262 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001263 /// By default, performs semantic analysis to build the new expression.
1264 /// Subclasses may override this routine to provide different behavior.
1265 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1266 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001267 SourceLocation RBraceLoc,
1268 QualType ResultTy) {
1269 OwningExprResult Result
1270 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1271 if (Result.isInvalid() || ResultTy->isDependentType())
1272 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001273
Douglas Gregore48319a2009-11-09 17:16:50 +00001274 // Patch in the result type we were given, which may have been computed
1275 // when the initial InitListExpr was built.
1276 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1277 ILE->setType(ResultTy);
1278 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001279 }
Mike Stump1eb44332009-09-09 15:08:12 +00001280
Douglas Gregorb98b1992009-08-11 05:31:07 +00001281 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001282 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001283 /// By default, performs semantic analysis to build the new expression.
1284 /// Subclasses may override this routine to provide different behavior.
1285 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1286 MultiExprArg ArrayExprs,
1287 SourceLocation EqualOrColonLoc,
1288 bool GNUSyntax,
1289 ExprArg Init) {
1290 OwningExprResult Result
1291 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1292 move(Init));
1293 if (Result.isInvalid())
1294 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001295
Douglas Gregorb98b1992009-08-11 05:31:07 +00001296 ArrayExprs.release();
1297 return move(Result);
1298 }
Mike Stump1eb44332009-09-09 15:08:12 +00001299
Douglas Gregorb98b1992009-08-11 05:31:07 +00001300 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001301 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001302 /// By default, builds the implicit value initialization without performing
1303 /// any semantic analysis. Subclasses may override this routine to provide
1304 /// different behavior.
1305 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1306 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1307 }
Mike Stump1eb44332009-09-09 15:08:12 +00001308
Douglas Gregorb98b1992009-08-11 05:31:07 +00001309 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001310 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001311 /// By default, performs semantic analysis to build the new expression.
1312 /// Subclasses may override this routine to provide different behavior.
1313 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1314 QualType T, SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001315 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001316 RParenLoc);
1317 }
1318
1319 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001320 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
1323 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1324 MultiExprArg SubExprs,
1325 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001326 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001327 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001328 }
Mike Stump1eb44332009-09-09 15:08:12 +00001329
Douglas Gregorb98b1992009-08-11 05:31:07 +00001330 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001331 ///
1332 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001333 /// rather than attempting to map the label statement itself.
1334 /// Subclasses may override this routine to provide different behavior.
1335 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1336 SourceLocation LabelLoc,
1337 LabelStmt *Label) {
1338 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1339 }
Mike Stump1eb44332009-09-09 15:08:12 +00001340
Douglas Gregorb98b1992009-08-11 05:31:07 +00001341 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001342 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001343 /// By default, performs semantic analysis to build the new expression.
1344 /// Subclasses may override this routine to provide different behavior.
1345 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1346 StmtArg SubStmt,
1347 SourceLocation RParenLoc) {
1348 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1349 }
Mike Stump1eb44332009-09-09 15:08:12 +00001350
Douglas Gregorb98b1992009-08-11 05:31:07 +00001351 /// \brief Build a new __builtin_types_compatible_p expression.
1352 ///
1353 /// By default, performs semantic analysis to build the new expression.
1354 /// Subclasses may override this routine to provide different behavior.
1355 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1356 QualType T1, QualType T2,
1357 SourceLocation RParenLoc) {
1358 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1359 T1.getAsOpaquePtr(),
1360 T2.getAsOpaquePtr(),
1361 RParenLoc);
1362 }
Mike Stump1eb44332009-09-09 15:08:12 +00001363
Douglas Gregorb98b1992009-08-11 05:31:07 +00001364 /// \brief Build a new __builtin_choose_expr expression.
1365 ///
1366 /// By default, performs semantic analysis to build the new expression.
1367 /// Subclasses may override this routine to provide different behavior.
1368 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1369 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1370 SourceLocation RParenLoc) {
1371 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1372 move(Cond), move(LHS), move(RHS),
1373 RParenLoc);
1374 }
Mike Stump1eb44332009-09-09 15:08:12 +00001375
Douglas Gregorb98b1992009-08-11 05:31:07 +00001376 /// \brief Build a new overloaded operator call expression.
1377 ///
1378 /// By default, performs semantic analysis to build the new expression.
1379 /// The semantic analysis provides the behavior of template instantiation,
1380 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001381 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001382 /// argument-dependent lookup, etc. Subclasses may override this routine to
1383 /// provide different behavior.
1384 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1385 SourceLocation OpLoc,
1386 ExprArg Callee,
1387 ExprArg First,
1388 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001389
1390 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001391 /// reinterpret_cast.
1392 ///
1393 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001394 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001395 /// Subclasses may override this routine to provide different behavior.
1396 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1397 Stmt::StmtClass Class,
1398 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001399 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 SourceLocation RAngleLoc,
1401 SourceLocation LParenLoc,
1402 ExprArg SubExpr,
1403 SourceLocation RParenLoc) {
1404 switch (Class) {
1405 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001406 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001407 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001408 move(SubExpr), RParenLoc);
1409
1410 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001411 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001412 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001413 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001414
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001416 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001417 RAngleLoc, LParenLoc,
1418 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001419 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001420
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001422 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001423 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001424 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001425
Douglas Gregorb98b1992009-08-11 05:31:07 +00001426 default:
1427 assert(false && "Invalid C++ named cast");
1428 break;
1429 }
Mike Stump1eb44332009-09-09 15:08:12 +00001430
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 return getSema().ExprError();
1432 }
Mike Stump1eb44332009-09-09 15:08:12 +00001433
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 /// \brief Build a new C++ static_cast expression.
1435 ///
1436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
1438 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1439 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001440 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001441 SourceLocation RAngleLoc,
1442 SourceLocation LParenLoc,
1443 ExprArg SubExpr,
1444 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001445 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1446 TInfo, move(SubExpr),
1447 SourceRange(LAngleLoc, RAngleLoc),
1448 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001449 }
1450
1451 /// \brief Build a new C++ dynamic_cast expression.
1452 ///
1453 /// By default, performs semantic analysis to build the new expression.
1454 /// Subclasses may override this routine to provide different behavior.
1455 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1456 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001457 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001458 SourceLocation RAngleLoc,
1459 SourceLocation LParenLoc,
1460 ExprArg SubExpr,
1461 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001462 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1463 TInfo, move(SubExpr),
1464 SourceRange(LAngleLoc, RAngleLoc),
1465 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001466 }
1467
1468 /// \brief Build a new C++ reinterpret_cast expression.
1469 ///
1470 /// By default, performs semantic analysis to build the new expression.
1471 /// Subclasses may override this routine to provide different behavior.
1472 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1473 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001474 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 SourceLocation RAngleLoc,
1476 SourceLocation LParenLoc,
1477 ExprArg SubExpr,
1478 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001479 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1480 TInfo, move(SubExpr),
1481 SourceRange(LAngleLoc, RAngleLoc),
1482 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 }
1484
1485 /// \brief Build a new C++ const_cast expression.
1486 ///
1487 /// By default, performs semantic analysis to build the new expression.
1488 /// Subclasses may override this routine to provide different behavior.
1489 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1490 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001491 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 SourceLocation RAngleLoc,
1493 SourceLocation LParenLoc,
1494 ExprArg SubExpr,
1495 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001496 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1497 TInfo, move(SubExpr),
1498 SourceRange(LAngleLoc, RAngleLoc),
1499 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 }
Mike Stump1eb44332009-09-09 15:08:12 +00001501
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 /// \brief Build a new C++ functional-style cast expression.
1503 ///
1504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
1506 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001507 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001508 SourceLocation LParenLoc,
1509 ExprArg SubExpr,
1510 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001511 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001513 TInfo->getType().getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001515 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001516 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 RParenLoc);
1518 }
Mike Stump1eb44332009-09-09 15:08:12 +00001519
Douglas Gregorb98b1992009-08-11 05:31:07 +00001520 /// \brief Build a new C++ typeid(type) expression.
1521 ///
1522 /// By default, performs semantic analysis to build the new expression.
1523 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001524 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1525 SourceLocation TypeidLoc,
1526 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001527 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001528 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001529 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001530 }
Mike Stump1eb44332009-09-09 15:08:12 +00001531
Douglas Gregorb98b1992009-08-11 05:31:07 +00001532 /// \brief Build a new C++ typeid(expr) expression.
1533 ///
1534 /// By default, performs semantic analysis to build the new expression.
1535 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001536 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1537 SourceLocation TypeidLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001538 ExprArg Operand,
1539 SourceLocation RParenLoc) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001540 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1541 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001542 }
1543
Douglas Gregorb98b1992009-08-11 05:31:07 +00001544 /// \brief Build a new C++ "this" expression.
1545 ///
1546 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001547 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001548 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001549 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001550 QualType ThisType,
1551 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001552 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001553 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1554 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 }
1556
1557 /// \brief Build a new C++ throw expression.
1558 ///
1559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
1561 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1562 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1563 }
1564
1565 /// \brief Build a new C++ default-argument expression.
1566 ///
1567 /// By default, builds a new default-argument expression, which does not
1568 /// require any semantic analysis. Subclasses may override this routine to
1569 /// provide different behavior.
Sean Huntc3021132010-05-05 15:23:54 +00001570 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001571 ParmVarDecl *Param) {
1572 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1573 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001574 }
1575
1576 /// \brief Build a new C++ zero-initialization expression.
1577 ///
1578 /// By default, performs semantic analysis to build the new expression.
1579 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor016a4a92010-07-07 22:43:56 +00001580 OwningExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 SourceLocation LParenLoc,
1582 QualType T,
1583 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001584 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1585 T.getAsOpaquePtr(), LParenLoc,
1586 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001587 0, RParenLoc);
1588 }
Mike Stump1eb44332009-09-09 15:08:12 +00001589
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 /// \brief Build a new C++ "new" expression.
1591 ///
1592 /// By default, performs semantic analysis to build the new expression.
1593 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001594 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 bool UseGlobal,
1596 SourceLocation PlacementLParen,
1597 MultiExprArg PlacementArgs,
1598 SourceLocation PlacementRParen,
Mike Stump1eb44332009-09-09 15:08:12 +00001599 bool ParenTypeId,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 QualType AllocType,
1601 SourceLocation TypeLoc,
1602 SourceRange TypeRange,
1603 ExprArg ArraySize,
1604 SourceLocation ConstructorLParen,
1605 MultiExprArg ConstructorArgs,
1606 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001607 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 PlacementLParen,
1609 move(PlacementArgs),
1610 PlacementRParen,
1611 ParenTypeId,
1612 AllocType,
1613 TypeLoc,
1614 TypeRange,
1615 move(ArraySize),
1616 ConstructorLParen,
1617 move(ConstructorArgs),
1618 ConstructorRParen);
1619 }
Mike Stump1eb44332009-09-09 15:08:12 +00001620
Douglas Gregorb98b1992009-08-11 05:31:07 +00001621 /// \brief Build a new C++ "delete" expression.
1622 ///
1623 /// By default, performs semantic analysis to build the new expression.
1624 /// Subclasses may override this routine to provide different behavior.
1625 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1626 bool IsGlobalDelete,
1627 bool IsArrayForm,
1628 ExprArg Operand) {
1629 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1630 move(Operand));
1631 }
Mike Stump1eb44332009-09-09 15:08:12 +00001632
Douglas Gregorb98b1992009-08-11 05:31:07 +00001633 /// \brief Build a new unary type trait expression.
1634 ///
1635 /// By default, performs semantic analysis to build the new expression.
1636 /// Subclasses may override this routine to provide different behavior.
1637 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1638 SourceLocation StartLoc,
1639 SourceLocation LParenLoc,
1640 QualType T,
1641 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001642 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001643 T.getAsOpaquePtr(), RParenLoc);
1644 }
1645
Mike Stump1eb44332009-09-09 15:08:12 +00001646 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647 /// expression.
1648 ///
1649 /// By default, performs semantic analysis to build the new expression.
1650 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001651 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 SourceRange QualifierRange,
1653 DeclarationName Name,
1654 SourceLocation Location,
John McCallf7a1a742009-11-24 19:00:30 +00001655 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 CXXScopeSpec SS;
1657 SS.setRange(QualifierRange);
1658 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001659
1660 if (TemplateArgs)
1661 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1662 *TemplateArgs);
1663
1664 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001665 }
1666
1667 /// \brief Build a new template-id expression.
1668 ///
1669 /// By default, performs semantic analysis to build the new expression.
1670 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001671 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1672 LookupResult &R,
1673 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001674 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001675 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 }
1677
1678 /// \brief Build a new object-construction expression.
1679 ///
1680 /// By default, performs semantic analysis to build the new expression.
1681 /// Subclasses may override this routine to provide different behavior.
1682 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001683 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001684 CXXConstructorDecl *Constructor,
1685 bool IsElidable,
1686 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001687 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001688 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001689 ConvertedArgs))
1690 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001691
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001692 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1693 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 }
1695
1696 /// \brief Build a new object-construction expression.
1697 ///
1698 /// By default, performs semantic analysis to build the new expression.
1699 /// Subclasses may override this routine to provide different behavior.
1700 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1701 QualType T,
1702 SourceLocation LParenLoc,
1703 MultiExprArg Args,
1704 SourceLocation *Commas,
1705 SourceLocation RParenLoc) {
1706 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1707 T.getAsOpaquePtr(),
1708 LParenLoc,
1709 move(Args),
1710 Commas,
1711 RParenLoc);
1712 }
1713
1714 /// \brief Build a new object-construction expression.
1715 ///
1716 /// By default, performs semantic analysis to build the new expression.
1717 /// Subclasses may override this routine to provide different behavior.
1718 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1719 QualType T,
1720 SourceLocation LParenLoc,
1721 MultiExprArg Args,
1722 SourceLocation *Commas,
1723 SourceLocation RParenLoc) {
1724 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1725 /*FIXME*/LParenLoc),
1726 T.getAsOpaquePtr(),
1727 LParenLoc,
1728 move(Args),
1729 Commas,
1730 RParenLoc);
1731 }
Mike Stump1eb44332009-09-09 15:08:12 +00001732
Douglas Gregorb98b1992009-08-11 05:31:07 +00001733 /// \brief Build a new member reference expression.
1734 ///
1735 /// By default, performs semantic analysis to build the new expression.
1736 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001737 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001738 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001739 bool IsArrow,
1740 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001741 NestedNameSpecifier *Qualifier,
1742 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001743 NamedDecl *FirstQualifierInScope,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001744 DeclarationName Name,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001745 SourceLocation MemberLoc,
John McCall129e2df2009-11-30 22:42:35 +00001746 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001747 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001748 SS.setRange(QualifierRange);
1749 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001750
John McCallaa81e162009-12-01 22:10:20 +00001751 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1752 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001753 SS, FirstQualifierInScope,
1754 Name, MemberLoc, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 }
1756
John McCall129e2df2009-11-30 22:42:35 +00001757 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001758 ///
1759 /// By default, performs semantic analysis to build the new expression.
1760 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001761 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001762 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001763 SourceLocation OperatorLoc,
1764 bool IsArrow,
1765 NestedNameSpecifier *Qualifier,
1766 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001767 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001768 LookupResult &R,
1769 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001770 CXXScopeSpec SS;
1771 SS.setRange(QualifierRange);
1772 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001773
John McCallaa81e162009-12-01 22:10:20 +00001774 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1775 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001776 SS, FirstQualifierInScope,
1777 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001778 }
Mike Stump1eb44332009-09-09 15:08:12 +00001779
Douglas Gregorb98b1992009-08-11 05:31:07 +00001780 /// \brief Build a new Objective-C @encode expression.
1781 ///
1782 /// By default, performs semantic analysis to build the new expression.
1783 /// Subclasses may override this routine to provide different behavior.
1784 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001785 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001786 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001787 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001788 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001789 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001790
Douglas Gregor92e986e2010-04-22 16:44:27 +00001791 /// \brief Build a new Objective-C class message.
1792 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1793 Selector Sel,
1794 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001795 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001796 MultiExprArg Args,
1797 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001798 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1799 ReceiverTypeInfo->getType(),
1800 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001801 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001802 move(Args));
1803 }
1804
1805 /// \brief Build a new Objective-C instance message.
1806 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1807 Selector Sel,
1808 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001809 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001810 MultiExprArg Args,
1811 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001812 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1813 return SemaRef.BuildInstanceMessage(move(Receiver),
1814 ReceiverType,
1815 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001816 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001817 move(Args));
1818 }
1819
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001820 /// \brief Build a new Objective-C ivar reference expression.
1821 ///
1822 /// By default, performs semantic analysis to build the new expression.
1823 /// Subclasses may override this routine to provide different behavior.
1824 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1825 SourceLocation IvarLoc,
1826 bool IsArrow, bool IsFreeIvar) {
1827 // FIXME: We lose track of the IsFreeIvar bit.
1828 CXXScopeSpec SS;
1829 Expr *Base = BaseArg.takeAs<Expr>();
1830 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1831 Sema::LookupMemberName);
1832 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1833 /*FIME:*/IvarLoc,
John McCallad00b772010-06-16 08:42:20 +00001834 SS, DeclPtrTy(),
1835 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001836 if (Result.isInvalid())
1837 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001838
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001839 if (Result.get())
1840 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001841
1842 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001843 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001844 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001845 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001846 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001847 /*TemplateArgs=*/0);
1848 }
Douglas Gregore3303542010-04-26 20:47:02 +00001849
1850 /// \brief Build a new Objective-C property reference expression.
1851 ///
1852 /// By default, performs semantic analysis to build the new expression.
1853 /// Subclasses may override this routine to provide different behavior.
Sean Huntc3021132010-05-05 15:23:54 +00001854 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001855 ObjCPropertyDecl *Property,
1856 SourceLocation PropertyLoc) {
1857 CXXScopeSpec SS;
1858 Expr *Base = BaseArg.takeAs<Expr>();
1859 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1860 Sema::LookupMemberName);
1861 bool IsArrow = false;
1862 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1863 /*FIME:*/PropertyLoc,
John McCallad00b772010-06-16 08:42:20 +00001864 SS, DeclPtrTy(),
1865 false);
Douglas Gregore3303542010-04-26 20:47:02 +00001866 if (Result.isInvalid())
1867 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001868
Douglas Gregore3303542010-04-26 20:47:02 +00001869 if (Result.get())
1870 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001871
1872 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregore3303542010-04-26 20:47:02 +00001873 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001874 /*FIXME:*/PropertyLoc, IsArrow,
1875 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001876 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001877 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001878 /*TemplateArgs=*/0);
1879 }
Sean Huntc3021132010-05-05 15:23:54 +00001880
1881 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001882 /// expression.
1883 ///
1884 /// By default, performs semantic analysis to build the new expression.
Sean Huntc3021132010-05-05 15:23:54 +00001885 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001886 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1887 ObjCMethodDecl *Getter,
1888 QualType T,
1889 ObjCMethodDecl *Setter,
1890 SourceLocation NameLoc,
1891 ExprArg Base) {
1892 // Since these expressions can only be value-dependent, we do not need to
1893 // perform semantic analysis again.
1894 return getSema().Owned(
1895 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1896 Setter,
1897 NameLoc,
1898 Base.takeAs<Expr>()));
1899 }
1900
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001901 /// \brief Build a new Objective-C "isa" expression.
1902 ///
1903 /// By default, performs semantic analysis to build the new expression.
1904 /// Subclasses may override this routine to provide different behavior.
1905 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1906 bool IsArrow) {
1907 CXXScopeSpec SS;
1908 Expr *Base = BaseArg.takeAs<Expr>();
1909 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1910 Sema::LookupMemberName);
1911 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1912 /*FIME:*/IsaLoc,
John McCallad00b772010-06-16 08:42:20 +00001913 SS, DeclPtrTy(),
1914 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001915 if (Result.isInvalid())
1916 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001917
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001918 if (Result.get())
1919 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001920
1921 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001922 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001923 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001924 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001925 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001926 /*TemplateArgs=*/0);
1927 }
Sean Huntc3021132010-05-05 15:23:54 +00001928
Douglas Gregorb98b1992009-08-11 05:31:07 +00001929 /// \brief Build a new shuffle vector expression.
1930 ///
1931 /// By default, performs semantic analysis to build the new expression.
1932 /// Subclasses may override this routine to provide different behavior.
1933 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1934 MultiExprArg SubExprs,
1935 SourceLocation RParenLoc) {
1936 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001937 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1939 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1940 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1941 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001942
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 // Build a reference to the __builtin_shufflevector builtin
1944 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001945 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001947 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001948 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001949
1950 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001951 unsigned NumSubExprs = SubExprs.size();
1952 Expr **Subs = (Expr **)SubExprs.release();
1953 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1954 Subs, NumSubExprs,
1955 Builtin->getResultType(),
1956 RParenLoc);
1957 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001958
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 // Type-check the __builtin_shufflevector expression.
1960 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1961 if (Result.isInvalid())
1962 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001963
Douglas Gregorb98b1992009-08-11 05:31:07 +00001964 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001965 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001966 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001967};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001968
Douglas Gregor43959a92009-08-20 07:17:43 +00001969template<typename Derived>
1970Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1971 if (!S)
1972 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001973
Douglas Gregor43959a92009-08-20 07:17:43 +00001974 switch (S->getStmtClass()) {
1975 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001976
Douglas Gregor43959a92009-08-20 07:17:43 +00001977 // Transform individual statement nodes
1978#define STMT(Node, Parent) \
1979 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1980#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00001981#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001982
Douglas Gregor43959a92009-08-20 07:17:43 +00001983 // Transform expressions by calling TransformExpr.
1984#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00001985#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00001986#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00001987#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00001988 {
1989 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1990 if (E.isInvalid())
1991 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001992
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001993 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001994 }
Mike Stump1eb44332009-09-09 15:08:12 +00001995 }
1996
Douglas Gregor43959a92009-08-20 07:17:43 +00001997 return SemaRef.Owned(S->Retain());
1998}
Mike Stump1eb44332009-09-09 15:08:12 +00001999
2000
Douglas Gregor670444e2009-08-04 22:27:00 +00002001template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00002002Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002003 if (!E)
2004 return SemaRef.Owned(E);
2005
2006 switch (E->getStmtClass()) {
2007 case Stmt::NoStmtClass: break;
2008#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002009#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002010#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002011 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002012#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002013 }
2014
Douglas Gregorb98b1992009-08-11 05:31:07 +00002015 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002016}
2017
2018template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002019NestedNameSpecifier *
2020TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002021 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002022 QualType ObjectType,
2023 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00002024 if (!NNS)
2025 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002026
Douglas Gregor43959a92009-08-20 07:17:43 +00002027 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002028 NestedNameSpecifier *Prefix = NNS->getPrefix();
2029 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002030 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002031 ObjectType,
2032 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002033 if (!Prefix)
2034 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002035
2036 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00002037 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00002038 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00002039 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002040 }
Mike Stump1eb44332009-09-09 15:08:12 +00002041
Douglas Gregordcee1a12009-08-06 05:28:30 +00002042 switch (NNS->getKind()) {
2043 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00002044 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002045 "Identifier nested-name-specifier with no prefix or object type");
2046 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2047 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002048 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002049
2050 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002051 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002052 ObjectType,
2053 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002054
Douglas Gregordcee1a12009-08-06 05:28:30 +00002055 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002056 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002057 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002058 getDerived().TransformDecl(Range.getBegin(),
2059 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002060 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002061 Prefix == NNS->getPrefix() &&
2062 NS == NNS->getAsNamespace())
2063 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002064
Douglas Gregordcee1a12009-08-06 05:28:30 +00002065 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2066 }
Mike Stump1eb44332009-09-09 15:08:12 +00002067
Douglas Gregordcee1a12009-08-06 05:28:30 +00002068 case NestedNameSpecifier::Global:
2069 // There is no meaningful transformation that one could perform on the
2070 // global scope.
2071 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002072
Douglas Gregordcee1a12009-08-06 05:28:30 +00002073 case NestedNameSpecifier::TypeSpecWithTemplate:
2074 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002075 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00002076 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2077 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002078 if (T.isNull())
2079 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002080
Douglas Gregordcee1a12009-08-06 05:28:30 +00002081 if (!getDerived().AlwaysRebuild() &&
2082 Prefix == NNS->getPrefix() &&
2083 T == QualType(NNS->getAsType(), 0))
2084 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002085
2086 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2087 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002088 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002089 }
2090 }
Mike Stump1eb44332009-09-09 15:08:12 +00002091
Douglas Gregordcee1a12009-08-06 05:28:30 +00002092 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002093 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002094}
2095
2096template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002097DeclarationName
Douglas Gregor81499bb2009-09-03 22:13:48 +00002098TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +00002099 SourceLocation Loc,
2100 QualType ObjectType) {
Douglas Gregor81499bb2009-09-03 22:13:48 +00002101 if (!Name)
2102 return Name;
2103
2104 switch (Name.getNameKind()) {
2105 case DeclarationName::Identifier:
2106 case DeclarationName::ObjCZeroArgSelector:
2107 case DeclarationName::ObjCOneArgSelector:
2108 case DeclarationName::ObjCMultiArgSelector:
2109 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002110 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002111 case DeclarationName::CXXUsingDirective:
2112 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002113
Douglas Gregor81499bb2009-09-03 22:13:48 +00002114 case DeclarationName::CXXConstructorName:
2115 case DeclarationName::CXXDestructorName:
2116 case DeclarationName::CXXConversionFunctionName: {
2117 TemporaryBase Rebase(*this, Loc, Name);
Sean Huntc3021132010-05-05 15:23:54 +00002118 QualType T = getDerived().TransformType(Name.getCXXNameType(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002119 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00002120 if (T.isNull())
2121 return DeclarationName();
Mike Stump1eb44332009-09-09 15:08:12 +00002122
Douglas Gregor81499bb2009-09-03 22:13:48 +00002123 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump1eb44332009-09-09 15:08:12 +00002124 Name.getNameKind(),
Douglas Gregor81499bb2009-09-03 22:13:48 +00002125 SemaRef.Context.getCanonicalType(T));
Douglas Gregor81499bb2009-09-03 22:13:48 +00002126 }
Mike Stump1eb44332009-09-09 15:08:12 +00002127 }
2128
Douglas Gregor81499bb2009-09-03 22:13:48 +00002129 return DeclarationName();
2130}
2131
2132template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002133TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002134TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2135 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002136 SourceLocation Loc = getDerived().getBaseLocation();
2137
Douglas Gregord1067e52009-08-06 06:41:21 +00002138 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002139 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002140 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002141 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2142 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002143 if (!NNS)
2144 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002145
Douglas Gregord1067e52009-08-06 06:41:21 +00002146 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002147 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002148 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002149 if (!TransTemplate)
2150 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002151
Douglas Gregord1067e52009-08-06 06:41:21 +00002152 if (!getDerived().AlwaysRebuild() &&
2153 NNS == QTN->getQualifier() &&
2154 TransTemplate == Template)
2155 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002156
Douglas Gregord1067e52009-08-06 06:41:21 +00002157 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2158 TransTemplate);
2159 }
Mike Stump1eb44332009-09-09 15:08:12 +00002160
John McCallf7a1a742009-11-24 19:00:30 +00002161 // These should be getting filtered out before they make it into the AST.
2162 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002163 }
Mike Stump1eb44332009-09-09 15:08:12 +00002164
Douglas Gregord1067e52009-08-06 06:41:21 +00002165 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002166 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002167 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002168 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2169 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002170 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00002171 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002172
Douglas Gregord1067e52009-08-06 06:41:21 +00002173 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002174 NNS == DTN->getQualifier() &&
2175 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002176 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002177
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002178 if (DTN->isIdentifier())
Sean Huntc3021132010-05-05 15:23:54 +00002179 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002180 ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +00002181
2182 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002183 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002184 }
Mike Stump1eb44332009-09-09 15:08:12 +00002185
Douglas Gregord1067e52009-08-06 06:41:21 +00002186 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002187 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002188 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002189 if (!TransTemplate)
2190 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002191
Douglas Gregord1067e52009-08-06 06:41:21 +00002192 if (!getDerived().AlwaysRebuild() &&
2193 TransTemplate == Template)
2194 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002195
Douglas Gregord1067e52009-08-06 06:41:21 +00002196 return TemplateName(TransTemplate);
2197 }
Mike Stump1eb44332009-09-09 15:08:12 +00002198
John McCallf7a1a742009-11-24 19:00:30 +00002199 // These should be getting filtered out before they reach the AST.
2200 assert(false && "overloaded function decl survived to here");
2201 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002202}
2203
2204template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002205void TreeTransform<Derived>::InventTemplateArgumentLoc(
2206 const TemplateArgument &Arg,
2207 TemplateArgumentLoc &Output) {
2208 SourceLocation Loc = getDerived().getBaseLocation();
2209 switch (Arg.getKind()) {
2210 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002211 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002212 break;
2213
2214 case TemplateArgument::Type:
2215 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002216 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002217
John McCall833ca992009-10-29 08:12:44 +00002218 break;
2219
Douglas Gregor788cd062009-11-11 01:00:40 +00002220 case TemplateArgument::Template:
2221 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2222 break;
Sean Huntc3021132010-05-05 15:23:54 +00002223
John McCall833ca992009-10-29 08:12:44 +00002224 case TemplateArgument::Expression:
2225 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2226 break;
2227
2228 case TemplateArgument::Declaration:
2229 case TemplateArgument::Integral:
2230 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002231 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002232 break;
2233 }
2234}
2235
2236template<typename Derived>
2237bool TreeTransform<Derived>::TransformTemplateArgument(
2238 const TemplateArgumentLoc &Input,
2239 TemplateArgumentLoc &Output) {
2240 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002241 switch (Arg.getKind()) {
2242 case TemplateArgument::Null:
2243 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002244 Output = Input;
2245 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002246
Douglas Gregor670444e2009-08-04 22:27:00 +00002247 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002248 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002249 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002250 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002251
2252 DI = getDerived().TransformType(DI);
2253 if (!DI) return true;
2254
2255 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2256 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002257 }
Mike Stump1eb44332009-09-09 15:08:12 +00002258
Douglas Gregor670444e2009-08-04 22:27:00 +00002259 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002260 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002261 DeclarationName Name;
2262 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2263 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002264 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002265 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002266 if (!D) return true;
2267
John McCall828bff22009-10-29 18:45:58 +00002268 Expr *SourceExpr = Input.getSourceDeclExpression();
2269 if (SourceExpr) {
2270 EnterExpressionEvaluationContext Unevaluated(getSema(),
2271 Action::Unevaluated);
2272 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2273 if (E.isInvalid())
2274 SourceExpr = NULL;
2275 else {
2276 SourceExpr = E.takeAs<Expr>();
2277 SourceExpr->Retain();
2278 }
2279 }
2280
2281 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002282 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002283 }
Mike Stump1eb44332009-09-09 15:08:12 +00002284
Douglas Gregor788cd062009-11-11 01:00:40 +00002285 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002286 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002287 TemplateName Template
2288 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2289 if (Template.isNull())
2290 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002291
Douglas Gregor788cd062009-11-11 01:00:40 +00002292 Output = TemplateArgumentLoc(TemplateArgument(Template),
2293 Input.getTemplateQualifierRange(),
2294 Input.getTemplateNameLoc());
2295 return false;
2296 }
Sean Huntc3021132010-05-05 15:23:54 +00002297
Douglas Gregor670444e2009-08-04 22:27:00 +00002298 case TemplateArgument::Expression: {
2299 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002300 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002301 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002302
John McCall833ca992009-10-29 08:12:44 +00002303 Expr *InputExpr = Input.getSourceExpression();
2304 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2305
2306 Sema::OwningExprResult E
2307 = getDerived().TransformExpr(InputExpr);
2308 if (E.isInvalid()) return true;
2309
2310 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00002311 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00002312 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2313 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002314 }
Mike Stump1eb44332009-09-09 15:08:12 +00002315
Douglas Gregor670444e2009-08-04 22:27:00 +00002316 case TemplateArgument::Pack: {
2317 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2318 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002319 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002320 AEnd = Arg.pack_end();
2321 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002322
John McCall833ca992009-10-29 08:12:44 +00002323 // FIXME: preserve source information here when we start
2324 // caring about parameter packs.
2325
John McCall828bff22009-10-29 18:45:58 +00002326 TemplateArgumentLoc InputArg;
2327 TemplateArgumentLoc OutputArg;
2328 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2329 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002330 return true;
2331
John McCall828bff22009-10-29 18:45:58 +00002332 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002333 }
2334 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002335 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002336 true);
John McCall828bff22009-10-29 18:45:58 +00002337 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002338 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002339 }
2340 }
Mike Stump1eb44332009-09-09 15:08:12 +00002341
Douglas Gregor670444e2009-08-04 22:27:00 +00002342 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002343 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002344}
2345
Douglas Gregor577f75a2009-08-04 16:50:30 +00002346//===----------------------------------------------------------------------===//
2347// Type transformation
2348//===----------------------------------------------------------------------===//
2349
2350template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00002351QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregor124b8782010-02-16 19:09:40 +00002352 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002353 if (getDerived().AlreadyTransformed(T))
2354 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002355
John McCalla2becad2009-10-21 00:40:46 +00002356 // Temporary workaround. All of these transformations should
2357 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002358 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002359 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002360
Douglas Gregor124b8782010-02-16 19:09:40 +00002361 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002362
John McCalla2becad2009-10-21 00:40:46 +00002363 if (!NewDI)
2364 return QualType();
2365
2366 return NewDI->getType();
2367}
2368
2369template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002370TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2371 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002372 if (getDerived().AlreadyTransformed(DI->getType()))
2373 return DI;
2374
2375 TypeLocBuilder TLB;
2376
2377 TypeLoc TL = DI->getTypeLoc();
2378 TLB.reserve(TL.getFullDataSize());
2379
Douglas Gregor124b8782010-02-16 19:09:40 +00002380 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002381 if (Result.isNull())
2382 return 0;
2383
John McCalla93c9342009-12-07 02:54:59 +00002384 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002385}
2386
2387template<typename Derived>
2388QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002389TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2390 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002391 switch (T.getTypeLocClass()) {
2392#define ABSTRACT_TYPELOC(CLASS, PARENT)
2393#define TYPELOC(CLASS, PARENT) \
2394 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002395 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2396 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002397#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002398 }
Mike Stump1eb44332009-09-09 15:08:12 +00002399
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002400 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002401 return QualType();
2402}
2403
2404/// FIXME: By default, this routine adds type qualifiers only to types
2405/// that can have qualifiers, and silently suppresses those qualifiers
2406/// that are not permitted (e.g., qualifiers on reference or function
2407/// types). This is the right thing for template instantiation, but
2408/// probably not for other clients.
2409template<typename Derived>
2410QualType
2411TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002412 QualifiedTypeLoc T,
2413 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002414 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002415
Douglas Gregor124b8782010-02-16 19:09:40 +00002416 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2417 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002418 if (Result.isNull())
2419 return QualType();
2420
2421 // Silently suppress qualifiers if the result type can't be qualified.
2422 // FIXME: this is the right thing for template instantiation, but
2423 // probably not for other clients.
2424 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002425 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002426
John McCall28654742010-06-05 06:41:15 +00002427 if (!Quals.empty()) {
2428 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2429 TLB.push<QualifiedTypeLoc>(Result);
2430 // No location information to preserve.
2431 }
John McCalla2becad2009-10-21 00:40:46 +00002432
2433 return Result;
2434}
2435
2436template <class TyLoc> static inline
2437QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2438 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2439 NewT.setNameLoc(T.getNameLoc());
2440 return T.getType();
2441}
2442
John McCalla2becad2009-10-21 00:40:46 +00002443template<typename Derived>
2444QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002445 BuiltinTypeLoc T,
2446 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002447 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2448 NewT.setBuiltinLoc(T.getBuiltinLoc());
2449 if (T.needsExtraLocalData())
2450 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2451 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002452}
Mike Stump1eb44332009-09-09 15:08:12 +00002453
Douglas Gregor577f75a2009-08-04 16:50:30 +00002454template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002455QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002456 ComplexTypeLoc T,
2457 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002458 // FIXME: recurse?
2459 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002460}
Mike Stump1eb44332009-09-09 15:08:12 +00002461
Douglas Gregor577f75a2009-08-04 16:50:30 +00002462template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002463QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Sean Huntc3021132010-05-05 15:23:54 +00002464 PointerTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00002465 QualType ObjectType) {
Sean Huntc3021132010-05-05 15:23:54 +00002466 QualType PointeeType
2467 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002468 if (PointeeType.isNull())
2469 return QualType();
2470
2471 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002472 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002473 // A dependent pointer type 'T *' has is being transformed such
2474 // that an Objective-C class type is being replaced for 'T'. The
2475 // resulting pointer type is an ObjCObjectPointerType, not a
2476 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002477 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002478
John McCallc12c5bb2010-05-15 11:32:37 +00002479 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2480 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002481 return Result;
2482 }
Sean Huntc3021132010-05-05 15:23:54 +00002483
Douglas Gregor92e986e2010-04-22 16:44:27 +00002484 if (getDerived().AlwaysRebuild() ||
2485 PointeeType != TL.getPointeeLoc().getType()) {
2486 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2487 if (Result.isNull())
2488 return QualType();
2489 }
Sean Huntc3021132010-05-05 15:23:54 +00002490
Douglas Gregor92e986e2010-04-22 16:44:27 +00002491 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2492 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002493 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002494}
Mike Stump1eb44332009-09-09 15:08:12 +00002495
2496template<typename Derived>
2497QualType
John McCalla2becad2009-10-21 00:40:46 +00002498TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002499 BlockPointerTypeLoc TL,
2500 QualType ObjectType) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002501 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002502 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2503 if (PointeeType.isNull())
2504 return QualType();
2505
2506 QualType Result = TL.getType();
2507 if (getDerived().AlwaysRebuild() ||
2508 PointeeType != TL.getPointeeLoc().getType()) {
2509 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002510 TL.getSigilLoc());
2511 if (Result.isNull())
2512 return QualType();
2513 }
2514
Douglas Gregor39968ad2010-04-22 16:50:51 +00002515 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002516 NewT.setSigilLoc(TL.getSigilLoc());
2517 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002518}
2519
John McCall85737a72009-10-30 00:06:24 +00002520/// Transforms a reference type. Note that somewhat paradoxically we
2521/// don't care whether the type itself is an l-value type or an r-value
2522/// type; we only care if the type was *written* as an l-value type
2523/// or an r-value type.
2524template<typename Derived>
2525QualType
2526TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002527 ReferenceTypeLoc TL,
2528 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002529 const ReferenceType *T = TL.getTypePtr();
2530
2531 // Note that this works with the pointee-as-written.
2532 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2533 if (PointeeType.isNull())
2534 return QualType();
2535
2536 QualType Result = TL.getType();
2537 if (getDerived().AlwaysRebuild() ||
2538 PointeeType != T->getPointeeTypeAsWritten()) {
2539 Result = getDerived().RebuildReferenceType(PointeeType,
2540 T->isSpelledAsLValue(),
2541 TL.getSigilLoc());
2542 if (Result.isNull())
2543 return QualType();
2544 }
2545
2546 // r-value references can be rebuilt as l-value references.
2547 ReferenceTypeLoc NewTL;
2548 if (isa<LValueReferenceType>(Result))
2549 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2550 else
2551 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2552 NewTL.setSigilLoc(TL.getSigilLoc());
2553
2554 return Result;
2555}
2556
Mike Stump1eb44332009-09-09 15:08:12 +00002557template<typename Derived>
2558QualType
John McCalla2becad2009-10-21 00:40:46 +00002559TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002560 LValueReferenceTypeLoc TL,
2561 QualType ObjectType) {
2562 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002563}
2564
Mike Stump1eb44332009-09-09 15:08:12 +00002565template<typename Derived>
2566QualType
John McCalla2becad2009-10-21 00:40:46 +00002567TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002568 RValueReferenceTypeLoc TL,
2569 QualType ObjectType) {
2570 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002571}
Mike Stump1eb44332009-09-09 15:08:12 +00002572
Douglas Gregor577f75a2009-08-04 16:50:30 +00002573template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002574QualType
John McCalla2becad2009-10-21 00:40:46 +00002575TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002576 MemberPointerTypeLoc TL,
2577 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002578 MemberPointerType *T = TL.getTypePtr();
2579
2580 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002581 if (PointeeType.isNull())
2582 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002583
John McCalla2becad2009-10-21 00:40:46 +00002584 // TODO: preserve source information for this.
2585 QualType ClassType
2586 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002587 if (ClassType.isNull())
2588 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002589
John McCalla2becad2009-10-21 00:40:46 +00002590 QualType Result = TL.getType();
2591 if (getDerived().AlwaysRebuild() ||
2592 PointeeType != T->getPointeeType() ||
2593 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002594 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2595 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002596 if (Result.isNull())
2597 return QualType();
2598 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002599
John McCalla2becad2009-10-21 00:40:46 +00002600 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2601 NewTL.setSigilLoc(TL.getSigilLoc());
2602
2603 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002604}
2605
Mike Stump1eb44332009-09-09 15:08:12 +00002606template<typename Derived>
2607QualType
John McCalla2becad2009-10-21 00:40:46 +00002608TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002609 ConstantArrayTypeLoc TL,
2610 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002611 ConstantArrayType *T = TL.getTypePtr();
2612 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002613 if (ElementType.isNull())
2614 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002615
John McCalla2becad2009-10-21 00:40:46 +00002616 QualType Result = TL.getType();
2617 if (getDerived().AlwaysRebuild() ||
2618 ElementType != T->getElementType()) {
2619 Result = getDerived().RebuildConstantArrayType(ElementType,
2620 T->getSizeModifier(),
2621 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002622 T->getIndexTypeCVRQualifiers(),
2623 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002624 if (Result.isNull())
2625 return QualType();
2626 }
Sean Huntc3021132010-05-05 15:23:54 +00002627
John McCalla2becad2009-10-21 00:40:46 +00002628 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2629 NewTL.setLBracketLoc(TL.getLBracketLoc());
2630 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002631
John McCalla2becad2009-10-21 00:40:46 +00002632 Expr *Size = TL.getSizeExpr();
2633 if (Size) {
2634 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2635 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2636 }
2637 NewTL.setSizeExpr(Size);
2638
2639 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002640}
Mike Stump1eb44332009-09-09 15:08:12 +00002641
Douglas Gregor577f75a2009-08-04 16:50:30 +00002642template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002643QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002644 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002645 IncompleteArrayTypeLoc TL,
2646 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002647 IncompleteArrayType *T = TL.getTypePtr();
2648 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002649 if (ElementType.isNull())
2650 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002651
John McCalla2becad2009-10-21 00:40:46 +00002652 QualType Result = TL.getType();
2653 if (getDerived().AlwaysRebuild() ||
2654 ElementType != T->getElementType()) {
2655 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002656 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002657 T->getIndexTypeCVRQualifiers(),
2658 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002659 if (Result.isNull())
2660 return QualType();
2661 }
Sean Huntc3021132010-05-05 15:23:54 +00002662
John McCalla2becad2009-10-21 00:40:46 +00002663 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2664 NewTL.setLBracketLoc(TL.getLBracketLoc());
2665 NewTL.setRBracketLoc(TL.getRBracketLoc());
2666 NewTL.setSizeExpr(0);
2667
2668 return Result;
2669}
2670
2671template<typename Derived>
2672QualType
2673TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002674 VariableArrayTypeLoc TL,
2675 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002676 VariableArrayType *T = TL.getTypePtr();
2677 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2678 if (ElementType.isNull())
2679 return QualType();
2680
2681 // Array bounds are not potentially evaluated contexts
2682 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2683
2684 Sema::OwningExprResult SizeResult
2685 = getDerived().TransformExpr(T->getSizeExpr());
2686 if (SizeResult.isInvalid())
2687 return QualType();
2688
2689 Expr *Size = static_cast<Expr*>(SizeResult.get());
2690
2691 QualType Result = TL.getType();
2692 if (getDerived().AlwaysRebuild() ||
2693 ElementType != T->getElementType() ||
2694 Size != T->getSizeExpr()) {
2695 Result = getDerived().RebuildVariableArrayType(ElementType,
2696 T->getSizeModifier(),
2697 move(SizeResult),
2698 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002699 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002700 if (Result.isNull())
2701 return QualType();
2702 }
2703 else SizeResult.take();
Sean Huntc3021132010-05-05 15:23:54 +00002704
John McCalla2becad2009-10-21 00:40:46 +00002705 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2706 NewTL.setLBracketLoc(TL.getLBracketLoc());
2707 NewTL.setRBracketLoc(TL.getRBracketLoc());
2708 NewTL.setSizeExpr(Size);
2709
2710 return Result;
2711}
2712
2713template<typename Derived>
2714QualType
2715TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002716 DependentSizedArrayTypeLoc TL,
2717 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002718 DependentSizedArrayType *T = TL.getTypePtr();
2719 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2720 if (ElementType.isNull())
2721 return QualType();
2722
2723 // Array bounds are not potentially evaluated contexts
2724 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2725
2726 Sema::OwningExprResult SizeResult
2727 = getDerived().TransformExpr(T->getSizeExpr());
2728 if (SizeResult.isInvalid())
2729 return QualType();
2730
2731 Expr *Size = static_cast<Expr*>(SizeResult.get());
2732
2733 QualType Result = TL.getType();
2734 if (getDerived().AlwaysRebuild() ||
2735 ElementType != T->getElementType() ||
2736 Size != T->getSizeExpr()) {
2737 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2738 T->getSizeModifier(),
2739 move(SizeResult),
2740 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002741 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002742 if (Result.isNull())
2743 return QualType();
2744 }
2745 else SizeResult.take();
2746
2747 // We might have any sort of array type now, but fortunately they
2748 // all have the same location layout.
2749 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2750 NewTL.setLBracketLoc(TL.getLBracketLoc());
2751 NewTL.setRBracketLoc(TL.getRBracketLoc());
2752 NewTL.setSizeExpr(Size);
2753
2754 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002755}
Mike Stump1eb44332009-09-09 15:08:12 +00002756
2757template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002758QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002759 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002760 DependentSizedExtVectorTypeLoc TL,
2761 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002762 DependentSizedExtVectorType *T = TL.getTypePtr();
2763
2764 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002765 QualType ElementType = getDerived().TransformType(T->getElementType());
2766 if (ElementType.isNull())
2767 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002768
Douglas Gregor670444e2009-08-04 22:27:00 +00002769 // Vector sizes are not potentially evaluated contexts
2770 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2771
Douglas Gregor577f75a2009-08-04 16:50:30 +00002772 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2773 if (Size.isInvalid())
2774 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002775
John McCalla2becad2009-10-21 00:40:46 +00002776 QualType Result = TL.getType();
2777 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002778 ElementType != T->getElementType() ||
2779 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002780 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002781 move(Size),
2782 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002783 if (Result.isNull())
2784 return QualType();
2785 }
2786 else Size.take();
2787
2788 // Result might be dependent or not.
2789 if (isa<DependentSizedExtVectorType>(Result)) {
2790 DependentSizedExtVectorTypeLoc NewTL
2791 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2792 NewTL.setNameLoc(TL.getNameLoc());
2793 } else {
2794 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2795 NewTL.setNameLoc(TL.getNameLoc());
2796 }
2797
2798 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002799}
Mike Stump1eb44332009-09-09 15:08:12 +00002800
2801template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002802QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002803 VectorTypeLoc TL,
2804 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002805 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002806 QualType ElementType = getDerived().TransformType(T->getElementType());
2807 if (ElementType.isNull())
2808 return QualType();
2809
John McCalla2becad2009-10-21 00:40:46 +00002810 QualType Result = TL.getType();
2811 if (getDerived().AlwaysRebuild() ||
2812 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002813 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner788b0fd2010-06-23 06:00:24 +00002814 T->getAltiVecSpecific());
John McCalla2becad2009-10-21 00:40:46 +00002815 if (Result.isNull())
2816 return QualType();
2817 }
Sean Huntc3021132010-05-05 15:23:54 +00002818
John McCalla2becad2009-10-21 00:40:46 +00002819 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2820 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002821
John McCalla2becad2009-10-21 00:40:46 +00002822 return Result;
2823}
2824
2825template<typename Derived>
2826QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002827 ExtVectorTypeLoc TL,
2828 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002829 VectorType *T = TL.getTypePtr();
2830 QualType ElementType = getDerived().TransformType(T->getElementType());
2831 if (ElementType.isNull())
2832 return QualType();
2833
2834 QualType Result = TL.getType();
2835 if (getDerived().AlwaysRebuild() ||
2836 ElementType != T->getElementType()) {
2837 Result = getDerived().RebuildExtVectorType(ElementType,
2838 T->getNumElements(),
2839 /*FIXME*/ SourceLocation());
2840 if (Result.isNull())
2841 return QualType();
2842 }
Sean Huntc3021132010-05-05 15:23:54 +00002843
John McCalla2becad2009-10-21 00:40:46 +00002844 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2845 NewTL.setNameLoc(TL.getNameLoc());
2846
2847 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002848}
Mike Stump1eb44332009-09-09 15:08:12 +00002849
2850template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002851ParmVarDecl *
2852TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2853 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2854 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2855 if (!NewDI)
2856 return 0;
2857
2858 if (NewDI == OldDI)
2859 return OldParm;
2860 else
2861 return ParmVarDecl::Create(SemaRef.Context,
2862 OldParm->getDeclContext(),
2863 OldParm->getLocation(),
2864 OldParm->getIdentifier(),
2865 NewDI->getType(),
2866 NewDI,
2867 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002868 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002869 /* DefArg */ NULL);
2870}
2871
2872template<typename Derived>
2873bool TreeTransform<Derived>::
2874 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2875 llvm::SmallVectorImpl<QualType> &PTypes,
2876 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2877 FunctionProtoType *T = TL.getTypePtr();
2878
2879 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2880 ParmVarDecl *OldParm = TL.getArg(i);
2881
2882 QualType NewType;
2883 ParmVarDecl *NewParm;
2884
2885 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002886 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2887 if (!NewParm)
2888 return true;
2889 NewType = NewParm->getType();
2890
2891 // Deal with the possibility that we don't have a parameter
2892 // declaration for this parameter.
2893 } else {
2894 NewParm = 0;
2895
2896 QualType OldType = T->getArgType(i);
2897 NewType = getDerived().TransformType(OldType);
2898 if (NewType.isNull())
2899 return true;
2900 }
2901
2902 PTypes.push_back(NewType);
2903 PVars.push_back(NewParm);
2904 }
2905
2906 return false;
2907}
2908
2909template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002910QualType
John McCalla2becad2009-10-21 00:40:46 +00002911TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002912 FunctionProtoTypeLoc TL,
2913 QualType ObjectType) {
Douglas Gregor895162d2010-04-30 18:55:50 +00002914 // Transform the parameters. We do this first for the benefit of template
2915 // instantiations, so that the ParmVarDecls get/ placed into the template
2916 // instantiation scope before we transform the function type.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002917 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002918 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall21ef0fa2010-03-11 09:03:00 +00002919 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2920 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002921
Douglas Gregor895162d2010-04-30 18:55:50 +00002922 FunctionProtoType *T = TL.getTypePtr();
2923 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2924 if (ResultType.isNull())
2925 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002926
John McCalla2becad2009-10-21 00:40:46 +00002927 QualType Result = TL.getType();
2928 if (getDerived().AlwaysRebuild() ||
2929 ResultType != T->getResultType() ||
2930 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2931 Result = getDerived().RebuildFunctionProtoType(ResultType,
2932 ParamTypes.data(),
2933 ParamTypes.size(),
2934 T->isVariadic(),
2935 T->getTypeQuals());
2936 if (Result.isNull())
2937 return QualType();
2938 }
Mike Stump1eb44332009-09-09 15:08:12 +00002939
John McCalla2becad2009-10-21 00:40:46 +00002940 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2941 NewTL.setLParenLoc(TL.getLParenLoc());
2942 NewTL.setRParenLoc(TL.getRParenLoc());
2943 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2944 NewTL.setArg(i, ParamDecls[i]);
2945
2946 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002947}
Mike Stump1eb44332009-09-09 15:08:12 +00002948
Douglas Gregor577f75a2009-08-04 16:50:30 +00002949template<typename Derived>
2950QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002951 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002952 FunctionNoProtoTypeLoc TL,
2953 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002954 FunctionNoProtoType *T = TL.getTypePtr();
2955 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2956 if (ResultType.isNull())
2957 return QualType();
2958
2959 QualType Result = TL.getType();
2960 if (getDerived().AlwaysRebuild() ||
2961 ResultType != T->getResultType())
2962 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2963
2964 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2965 NewTL.setLParenLoc(TL.getLParenLoc());
2966 NewTL.setRParenLoc(TL.getRParenLoc());
2967
2968 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002969}
Mike Stump1eb44332009-09-09 15:08:12 +00002970
John McCalled976492009-12-04 22:46:56 +00002971template<typename Derived> QualType
2972TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002973 UnresolvedUsingTypeLoc TL,
2974 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00002975 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002976 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00002977 if (!D)
2978 return QualType();
2979
2980 QualType Result = TL.getType();
2981 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2982 Result = getDerived().RebuildUnresolvedUsingType(D);
2983 if (Result.isNull())
2984 return QualType();
2985 }
2986
2987 // We might get an arbitrary type spec type back. We should at
2988 // least always get a type spec type, though.
2989 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2990 NewTL.setNameLoc(TL.getNameLoc());
2991
2992 return Result;
2993}
2994
Douglas Gregor577f75a2009-08-04 16:50:30 +00002995template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002996QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002997 TypedefTypeLoc TL,
2998 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002999 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003000 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003001 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3002 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003003 if (!Typedef)
3004 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003005
John McCalla2becad2009-10-21 00:40:46 +00003006 QualType Result = TL.getType();
3007 if (getDerived().AlwaysRebuild() ||
3008 Typedef != T->getDecl()) {
3009 Result = getDerived().RebuildTypedefType(Typedef);
3010 if (Result.isNull())
3011 return QualType();
3012 }
Mike Stump1eb44332009-09-09 15:08:12 +00003013
John McCalla2becad2009-10-21 00:40:46 +00003014 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3015 NewTL.setNameLoc(TL.getNameLoc());
3016
3017 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003018}
Mike Stump1eb44332009-09-09 15:08:12 +00003019
Douglas Gregor577f75a2009-08-04 16:50:30 +00003020template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003021QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003022 TypeOfExprTypeLoc TL,
3023 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003024 // typeof expressions are not potentially evaluated contexts
3025 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003026
John McCallcfb708c2010-01-13 20:03:27 +00003027 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003028 if (E.isInvalid())
3029 return QualType();
3030
John McCalla2becad2009-10-21 00:40:46 +00003031 QualType Result = TL.getType();
3032 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003033 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003034 Result = getDerived().RebuildTypeOfExprType(move(E));
3035 if (Result.isNull())
3036 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003037 }
John McCalla2becad2009-10-21 00:40:46 +00003038 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003039
John McCalla2becad2009-10-21 00:40:46 +00003040 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003041 NewTL.setTypeofLoc(TL.getTypeofLoc());
3042 NewTL.setLParenLoc(TL.getLParenLoc());
3043 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003044
3045 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003046}
Mike Stump1eb44332009-09-09 15:08:12 +00003047
3048template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003049QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003050 TypeOfTypeLoc TL,
3051 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00003052 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3053 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3054 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003055 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003056
John McCalla2becad2009-10-21 00:40:46 +00003057 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003058 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3059 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003060 if (Result.isNull())
3061 return QualType();
3062 }
Mike Stump1eb44332009-09-09 15:08:12 +00003063
John McCalla2becad2009-10-21 00:40:46 +00003064 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003065 NewTL.setTypeofLoc(TL.getTypeofLoc());
3066 NewTL.setLParenLoc(TL.getLParenLoc());
3067 NewTL.setRParenLoc(TL.getRParenLoc());
3068 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003069
3070 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003071}
Mike Stump1eb44332009-09-09 15:08:12 +00003072
3073template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003074QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003075 DecltypeTypeLoc TL,
3076 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003077 DecltypeType *T = TL.getTypePtr();
3078
Douglas Gregor670444e2009-08-04 22:27:00 +00003079 // decltype expressions are not potentially evaluated contexts
3080 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003081
Douglas Gregor577f75a2009-08-04 16:50:30 +00003082 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3083 if (E.isInvalid())
3084 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003085
John McCalla2becad2009-10-21 00:40:46 +00003086 QualType Result = TL.getType();
3087 if (getDerived().AlwaysRebuild() ||
3088 E.get() != T->getUnderlyingExpr()) {
3089 Result = getDerived().RebuildDecltypeType(move(E));
3090 if (Result.isNull())
3091 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003092 }
John McCalla2becad2009-10-21 00:40:46 +00003093 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003094
John McCalla2becad2009-10-21 00:40:46 +00003095 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3096 NewTL.setNameLoc(TL.getNameLoc());
3097
3098 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003099}
3100
3101template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003102QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003103 RecordTypeLoc TL,
3104 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003105 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003106 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003107 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3108 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003109 if (!Record)
3110 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003111
John McCalla2becad2009-10-21 00:40:46 +00003112 QualType Result = TL.getType();
3113 if (getDerived().AlwaysRebuild() ||
3114 Record != T->getDecl()) {
3115 Result = getDerived().RebuildRecordType(Record);
3116 if (Result.isNull())
3117 return QualType();
3118 }
Mike Stump1eb44332009-09-09 15:08:12 +00003119
John McCalla2becad2009-10-21 00:40:46 +00003120 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3121 NewTL.setNameLoc(TL.getNameLoc());
3122
3123 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003124}
Mike Stump1eb44332009-09-09 15:08:12 +00003125
3126template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003127QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003128 EnumTypeLoc TL,
3129 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003130 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003131 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003132 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3133 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003134 if (!Enum)
3135 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003136
John McCalla2becad2009-10-21 00:40:46 +00003137 QualType Result = TL.getType();
3138 if (getDerived().AlwaysRebuild() ||
3139 Enum != T->getDecl()) {
3140 Result = getDerived().RebuildEnumType(Enum);
3141 if (Result.isNull())
3142 return QualType();
3143 }
Mike Stump1eb44332009-09-09 15:08:12 +00003144
John McCalla2becad2009-10-21 00:40:46 +00003145 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3146 NewTL.setNameLoc(TL.getNameLoc());
3147
3148 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003149}
John McCall7da24312009-09-05 00:15:47 +00003150
John McCall3cb0ebd2010-03-10 03:28:59 +00003151template<typename Derived>
3152QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3153 TypeLocBuilder &TLB,
3154 InjectedClassNameTypeLoc TL,
3155 QualType ObjectType) {
3156 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3157 TL.getTypePtr()->getDecl());
3158 if (!D) return QualType();
3159
3160 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3161 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3162 return T;
3163}
3164
Mike Stump1eb44332009-09-09 15:08:12 +00003165
Douglas Gregor577f75a2009-08-04 16:50:30 +00003166template<typename Derived>
3167QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003168 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003169 TemplateTypeParmTypeLoc TL,
3170 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003171 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003172}
3173
Mike Stump1eb44332009-09-09 15:08:12 +00003174template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003175QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003176 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003177 SubstTemplateTypeParmTypeLoc TL,
3178 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003179 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003180}
3181
3182template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003183QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3184 const TemplateSpecializationType *TST,
3185 QualType ObjectType) {
3186 // FIXME: this entire method is a temporary workaround; callers
3187 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00003188
John McCall833ca992009-10-29 08:12:44 +00003189 // Fake up a TemplateSpecializationTypeLoc.
3190 TypeLocBuilder TLB;
3191 TemplateSpecializationTypeLoc TL
3192 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3193
John McCall828bff22009-10-29 18:45:58 +00003194 SourceLocation BaseLoc = getDerived().getBaseLocation();
3195
3196 TL.setTemplateNameLoc(BaseLoc);
3197 TL.setLAngleLoc(BaseLoc);
3198 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00003199 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3200 const TemplateArgument &TA = TST->getArg(i);
3201 TemplateArgumentLoc TAL;
3202 getDerived().InventTemplateArgumentLoc(TA, TAL);
3203 TL.setArgLocInfo(i, TAL.getLocInfo());
3204 }
3205
3206 TypeLocBuilder IgnoredTLB;
3207 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00003208}
Sean Huntc3021132010-05-05 15:23:54 +00003209
Douglas Gregordd62b152009-10-19 22:04:39 +00003210template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003211QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003212 TypeLocBuilder &TLB,
3213 TemplateSpecializationTypeLoc TL,
3214 QualType ObjectType) {
3215 const TemplateSpecializationType *T = TL.getTypePtr();
3216
Mike Stump1eb44332009-09-09 15:08:12 +00003217 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00003218 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003219 if (Template.isNull())
3220 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003221
John McCalld5532b62009-11-23 01:53:49 +00003222 TemplateArgumentListInfo NewTemplateArgs;
3223 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3224 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3225
3226 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3227 TemplateArgumentLoc Loc;
3228 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003229 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003230 NewTemplateArgs.addArgument(Loc);
3231 }
Mike Stump1eb44332009-09-09 15:08:12 +00003232
John McCall833ca992009-10-29 08:12:44 +00003233 // FIXME: maybe don't rebuild if all the template arguments are the same.
3234
3235 QualType Result =
3236 getDerived().RebuildTemplateSpecializationType(Template,
3237 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003238 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003239
3240 if (!Result.isNull()) {
3241 TemplateSpecializationTypeLoc NewTL
3242 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3243 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3244 NewTL.setLAngleLoc(TL.getLAngleLoc());
3245 NewTL.setRAngleLoc(TL.getRAngleLoc());
3246 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3247 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003248 }
Mike Stump1eb44332009-09-09 15:08:12 +00003249
John McCall833ca992009-10-29 08:12:44 +00003250 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003251}
Mike Stump1eb44332009-09-09 15:08:12 +00003252
3253template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003254QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003255TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3256 ElaboratedTypeLoc TL,
3257 QualType ObjectType) {
3258 ElaboratedType *T = TL.getTypePtr();
3259
3260 NestedNameSpecifier *NNS = 0;
3261 // NOTE: the qualifier in an ElaboratedType is optional.
3262 if (T->getQualifier() != 0) {
3263 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003264 TL.getQualifierRange(),
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003265 ObjectType);
3266 if (!NNS)
3267 return QualType();
3268 }
Mike Stump1eb44332009-09-09 15:08:12 +00003269
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003270 QualType NamedT;
3271 // FIXME: this test is meant to workaround a problem (failing assertion)
3272 // occurring if directly executing the code in the else branch.
3273 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3274 TemplateSpecializationTypeLoc OldNamedTL
3275 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3276 const TemplateSpecializationType* OldTST
Jim Grosbach9cbb4d82010-05-19 23:53:08 +00003277 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003278 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3279 if (NamedT.isNull())
3280 return QualType();
3281 TemplateSpecializationTypeLoc NewNamedTL
3282 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3283 NewNamedTL.copy(OldNamedTL);
3284 }
3285 else {
3286 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3287 if (NamedT.isNull())
3288 return QualType();
3289 }
Daniel Dunbara63db842010-05-14 16:34:09 +00003290
John McCalla2becad2009-10-21 00:40:46 +00003291 QualType Result = TL.getType();
3292 if (getDerived().AlwaysRebuild() ||
3293 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003294 NamedT != T->getNamedType()) {
3295 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003296 if (Result.isNull())
3297 return QualType();
3298 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003299
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003300 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003301 NewTL.setKeywordLoc(TL.getKeywordLoc());
3302 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003303
3304 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003305}
Mike Stump1eb44332009-09-09 15:08:12 +00003306
3307template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003308QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3309 DependentNameTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00003310 QualType ObjectType) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003311 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003312
Douglas Gregor577f75a2009-08-04 16:50:30 +00003313 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003314 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3315 TL.getQualifierRange(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003316 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003317 if (!NNS)
3318 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003319
John McCall33500952010-06-11 00:33:02 +00003320 QualType Result
3321 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3322 T->getIdentifier(),
3323 TL.getKeywordLoc(),
3324 TL.getQualifierRange(),
3325 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003326 if (Result.isNull())
3327 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003328
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003329 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3330 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003331 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3332
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003333 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3334 NewTL.setKeywordLoc(TL.getKeywordLoc());
3335 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003336 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003337 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3338 NewTL.setKeywordLoc(TL.getKeywordLoc());
3339 NewTL.setQualifierRange(TL.getQualifierRange());
3340 NewTL.setNameLoc(TL.getNameLoc());
3341 }
John McCalla2becad2009-10-21 00:40:46 +00003342 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003343}
Mike Stump1eb44332009-09-09 15:08:12 +00003344
Douglas Gregor577f75a2009-08-04 16:50:30 +00003345template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003346QualType TreeTransform<Derived>::
3347 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3348 DependentTemplateSpecializationTypeLoc TL,
3349 QualType ObjectType) {
3350 DependentTemplateSpecializationType *T = TL.getTypePtr();
3351
3352 NestedNameSpecifier *NNS
3353 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3354 TL.getQualifierRange(),
3355 ObjectType);
3356 if (!NNS)
3357 return QualType();
3358
3359 TemplateArgumentListInfo NewTemplateArgs;
3360 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3361 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3362
3363 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3364 TemplateArgumentLoc Loc;
3365 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3366 return QualType();
3367 NewTemplateArgs.addArgument(Loc);
3368 }
3369
3370 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3371 T->getKeyword(),
3372 NNS,
3373 T->getIdentifier(),
3374 TL.getNameLoc(),
3375 NewTemplateArgs);
3376 if (Result.isNull())
3377 return QualType();
3378
3379 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3380 QualType NamedT = ElabT->getNamedType();
3381
3382 // Copy information relevant to the template specialization.
3383 TemplateSpecializationTypeLoc NamedTL
3384 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3385 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3386 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3387 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3388 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3389
3390 // Copy information relevant to the elaborated type.
3391 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3392 NewTL.setKeywordLoc(TL.getKeywordLoc());
3393 NewTL.setQualifierRange(TL.getQualifierRange());
3394 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003395 TypeLoc NewTL(Result, TL.getOpaqueData());
3396 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003397 }
3398 return Result;
3399}
3400
3401template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003402QualType
3403TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003404 ObjCInterfaceTypeLoc TL,
3405 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003406 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003407 TLB.pushFullCopy(TL);
3408 return TL.getType();
3409}
3410
3411template<typename Derived>
3412QualType
3413TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3414 ObjCObjectTypeLoc TL,
3415 QualType ObjectType) {
3416 // ObjCObjectType is never dependent.
3417 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003418 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003419}
Mike Stump1eb44332009-09-09 15:08:12 +00003420
3421template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003422QualType
3423TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003424 ObjCObjectPointerTypeLoc TL,
3425 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003426 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003427 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003428 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003429}
3430
Douglas Gregor577f75a2009-08-04 16:50:30 +00003431//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003432// Statement transformation
3433//===----------------------------------------------------------------------===//
3434template<typename Derived>
3435Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003436TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3437 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003438}
3439
3440template<typename Derived>
3441Sema::OwningStmtResult
3442TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3443 return getDerived().TransformCompoundStmt(S, false);
3444}
3445
3446template<typename Derived>
3447Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003448TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003449 bool IsStmtExpr) {
3450 bool SubStmtChanged = false;
3451 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3452 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3453 B != BEnd; ++B) {
3454 OwningStmtResult Result = getDerived().TransformStmt(*B);
3455 if (Result.isInvalid())
3456 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003457
Douglas Gregor43959a92009-08-20 07:17:43 +00003458 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3459 Statements.push_back(Result.takeAs<Stmt>());
3460 }
Mike Stump1eb44332009-09-09 15:08:12 +00003461
Douglas Gregor43959a92009-08-20 07:17:43 +00003462 if (!getDerived().AlwaysRebuild() &&
3463 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003464 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003465
3466 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3467 move_arg(Statements),
3468 S->getRBracLoc(),
3469 IsStmtExpr);
3470}
Mike Stump1eb44332009-09-09 15:08:12 +00003471
Douglas Gregor43959a92009-08-20 07:17:43 +00003472template<typename Derived>
3473Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003474TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00003475 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3476 {
3477 // The case value expressions are not potentially evaluated.
3478 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003479
Eli Friedman264c1f82009-11-19 03:14:00 +00003480 // Transform the left-hand case value.
3481 LHS = getDerived().TransformExpr(S->getLHS());
3482 if (LHS.isInvalid())
3483 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003484
Eli Friedman264c1f82009-11-19 03:14:00 +00003485 // Transform the right-hand case value (for the GNU case-range extension).
3486 RHS = getDerived().TransformExpr(S->getRHS());
3487 if (RHS.isInvalid())
3488 return SemaRef.StmtError();
3489 }
Mike Stump1eb44332009-09-09 15:08:12 +00003490
Douglas Gregor43959a92009-08-20 07:17:43 +00003491 // Build the case statement.
3492 // Case statements are always rebuilt so that they will attached to their
3493 // transformed switch statement.
3494 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3495 move(LHS),
3496 S->getEllipsisLoc(),
3497 move(RHS),
3498 S->getColonLoc());
3499 if (Case.isInvalid())
3500 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003501
Douglas Gregor43959a92009-08-20 07:17:43 +00003502 // Transform the statement following the case
3503 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3504 if (SubStmt.isInvalid())
3505 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003506
Douglas Gregor43959a92009-08-20 07:17:43 +00003507 // Attach the body to the case statement
3508 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3509}
3510
3511template<typename Derived>
3512Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003513TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003514 // Transform the statement following the default case
3515 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3516 if (SubStmt.isInvalid())
3517 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003518
Douglas Gregor43959a92009-08-20 07:17:43 +00003519 // Default statements are always rebuilt
3520 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3521 move(SubStmt));
3522}
Mike Stump1eb44332009-09-09 15:08:12 +00003523
Douglas Gregor43959a92009-08-20 07:17:43 +00003524template<typename Derived>
3525Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003526TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003527 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3528 if (SubStmt.isInvalid())
3529 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003530
Douglas Gregor43959a92009-08-20 07:17:43 +00003531 // FIXME: Pass the real colon location in.
3532 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3533 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3534 move(SubStmt));
3535}
Mike Stump1eb44332009-09-09 15:08:12 +00003536
Douglas Gregor43959a92009-08-20 07:17:43 +00003537template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003538Sema::OwningStmtResult
3539TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003540 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003541 OwningExprResult Cond(SemaRef);
3542 VarDecl *ConditionVar = 0;
3543 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003544 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003545 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003546 getDerived().TransformDefinition(
3547 S->getConditionVariable()->getLocation(),
3548 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003549 if (!ConditionVar)
3550 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003551 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003552 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003553
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003554 if (Cond.isInvalid())
3555 return SemaRef.StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003556
3557 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003558 if (S->getCond()) {
3559 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3560 S->getIfLoc(),
3561 move(Cond));
3562 if (CondE.isInvalid())
3563 return getSema().StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003564
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003565 Cond = move(CondE);
3566 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003567 }
Sean Huntc3021132010-05-05 15:23:54 +00003568
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003569 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3570 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3571 return SemaRef.StmtError();
3572
Douglas Gregor43959a92009-08-20 07:17:43 +00003573 // Transform the "then" branch.
3574 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3575 if (Then.isInvalid())
3576 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003577
Douglas Gregor43959a92009-08-20 07:17:43 +00003578 // Transform the "else" branch.
3579 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3580 if (Else.isInvalid())
3581 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003582
Douglas Gregor43959a92009-08-20 07:17:43 +00003583 if (!getDerived().AlwaysRebuild() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003584 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003585 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003586 Then.get() == S->getThen() &&
3587 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003588 return SemaRef.Owned(S->Retain());
3589
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003590 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003591 move(Then),
Mike Stump1eb44332009-09-09 15:08:12 +00003592 S->getElseLoc(), move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +00003593}
3594
3595template<typename Derived>
3596Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003597TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003598 // Transform the condition.
Douglas Gregord3d53012009-11-24 17:07:59 +00003599 OwningExprResult Cond(SemaRef);
3600 VarDecl *ConditionVar = 0;
3601 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003602 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003603 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003604 getDerived().TransformDefinition(
3605 S->getConditionVariable()->getLocation(),
3606 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003607 if (!ConditionVar)
3608 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003609 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003610 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003611
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003612 if (Cond.isInvalid())
3613 return SemaRef.StmtError();
3614 }
Mike Stump1eb44332009-09-09 15:08:12 +00003615
Douglas Gregor43959a92009-08-20 07:17:43 +00003616 // Rebuild the switch statement.
Douglas Gregor586596f2010-05-06 17:25:47 +00003617 OwningStmtResult Switch
3618 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3619 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003620 if (Switch.isInvalid())
3621 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003622
Douglas Gregor43959a92009-08-20 07:17:43 +00003623 // Transform the body of the switch statement.
3624 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3625 if (Body.isInvalid())
3626 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003627
Douglas Gregor43959a92009-08-20 07:17:43 +00003628 // Complete the switch statement.
3629 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3630 move(Body));
3631}
Mike Stump1eb44332009-09-09 15:08:12 +00003632
Douglas Gregor43959a92009-08-20 07:17:43 +00003633template<typename Derived>
3634Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003635TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003636 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003637 OwningExprResult Cond(SemaRef);
3638 VarDecl *ConditionVar = 0;
3639 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003640 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003641 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003642 getDerived().TransformDefinition(
3643 S->getConditionVariable()->getLocation(),
3644 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003645 if (!ConditionVar)
3646 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003647 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003648 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003649
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003650 if (Cond.isInvalid())
3651 return SemaRef.StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003652
3653 if (S->getCond()) {
3654 // Convert the condition to a boolean value.
3655 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003656 S->getWhileLoc(),
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003657 move(Cond));
3658 if (CondE.isInvalid())
3659 return getSema().StmtError();
3660 Cond = move(CondE);
3661 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003662 }
Mike Stump1eb44332009-09-09 15:08:12 +00003663
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003664 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3665 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3666 return SemaRef.StmtError();
3667
Douglas Gregor43959a92009-08-20 07:17:43 +00003668 // Transform the body
3669 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3670 if (Body.isInvalid())
3671 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003672
Douglas Gregor43959a92009-08-20 07:17:43 +00003673 if (!getDerived().AlwaysRebuild() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003674 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003675 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003676 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003677 return SemaRef.Owned(S->Retain());
3678
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003679 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregor586596f2010-05-06 17:25:47 +00003680 ConditionVar, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003681}
Mike Stump1eb44332009-09-09 15:08:12 +00003682
Douglas Gregor43959a92009-08-20 07:17:43 +00003683template<typename Derived>
3684Sema::OwningStmtResult
3685TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003686 // Transform the body
3687 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3688 if (Body.isInvalid())
3689 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003690
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003691 // Transform the condition
3692 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3693 if (Cond.isInvalid())
3694 return SemaRef.StmtError();
3695
Douglas Gregor43959a92009-08-20 07:17:43 +00003696 if (!getDerived().AlwaysRebuild() &&
3697 Cond.get() == S->getCond() &&
3698 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003699 return SemaRef.Owned(S->Retain());
3700
Douglas Gregor43959a92009-08-20 07:17:43 +00003701 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3702 /*FIXME:*/S->getWhileLoc(), move(Cond),
3703 S->getRParenLoc());
3704}
Mike Stump1eb44332009-09-09 15:08:12 +00003705
Douglas Gregor43959a92009-08-20 07:17:43 +00003706template<typename Derived>
3707Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003708TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003709 // Transform the initialization statement
3710 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3711 if (Init.isInvalid())
3712 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003713
Douglas Gregor43959a92009-08-20 07:17:43 +00003714 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003715 OwningExprResult Cond(SemaRef);
3716 VarDecl *ConditionVar = 0;
3717 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003718 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003719 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003720 getDerived().TransformDefinition(
3721 S->getConditionVariable()->getLocation(),
3722 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003723 if (!ConditionVar)
3724 return SemaRef.StmtError();
3725 } else {
3726 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003727
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003728 if (Cond.isInvalid())
3729 return SemaRef.StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003730
3731 if (S->getCond()) {
3732 // Convert the condition to a boolean value.
3733 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3734 S->getForLoc(),
3735 move(Cond));
3736 if (CondE.isInvalid())
3737 return getSema().StmtError();
3738
3739 Cond = move(CondE);
3740 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003741 }
Mike Stump1eb44332009-09-09 15:08:12 +00003742
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003743 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3744 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3745 return SemaRef.StmtError();
3746
Douglas Gregor43959a92009-08-20 07:17:43 +00003747 // Transform the increment
3748 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3749 if (Inc.isInvalid())
3750 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003751
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003752 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3753 if (S->getInc() && !FullInc->get())
3754 return SemaRef.StmtError();
3755
Douglas Gregor43959a92009-08-20 07:17:43 +00003756 // Transform the body
3757 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3758 if (Body.isInvalid())
3759 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003760
Douglas Gregor43959a92009-08-20 07:17:43 +00003761 if (!getDerived().AlwaysRebuild() &&
3762 Init.get() == S->getInit() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003763 FullCond->get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003764 Inc.get() == S->getInc() &&
3765 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003766 return SemaRef.Owned(S->Retain());
3767
Douglas Gregor43959a92009-08-20 07:17:43 +00003768 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003769 move(Init), FullCond, ConditionVar,
3770 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003771}
3772
3773template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003774Sema::OwningStmtResult
3775TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003776 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003777 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003778 S->getLabel());
3779}
3780
3781template<typename Derived>
3782Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003783TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003784 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3785 if (Target.isInvalid())
3786 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003787
Douglas Gregor43959a92009-08-20 07:17:43 +00003788 if (!getDerived().AlwaysRebuild() &&
3789 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003790 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003791
3792 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3793 move(Target));
3794}
3795
3796template<typename Derived>
3797Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003798TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3799 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003800}
Mike Stump1eb44332009-09-09 15:08:12 +00003801
Douglas Gregor43959a92009-08-20 07:17:43 +00003802template<typename Derived>
3803Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003804TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3805 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003806}
Mike Stump1eb44332009-09-09 15:08:12 +00003807
Douglas Gregor43959a92009-08-20 07:17:43 +00003808template<typename Derived>
3809Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003810TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003811 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3812 if (Result.isInvalid())
3813 return SemaRef.StmtError();
3814
Mike Stump1eb44332009-09-09 15:08:12 +00003815 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003816 // to tell whether the return type of the function has changed.
3817 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3818}
Mike Stump1eb44332009-09-09 15:08:12 +00003819
Douglas Gregor43959a92009-08-20 07:17:43 +00003820template<typename Derived>
3821Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003822TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003823 bool DeclChanged = false;
3824 llvm::SmallVector<Decl *, 4> Decls;
3825 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3826 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003827 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3828 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003829 if (!Transformed)
3830 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003831
Douglas Gregor43959a92009-08-20 07:17:43 +00003832 if (Transformed != *D)
3833 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003834
Douglas Gregor43959a92009-08-20 07:17:43 +00003835 Decls.push_back(Transformed);
3836 }
Mike Stump1eb44332009-09-09 15:08:12 +00003837
Douglas Gregor43959a92009-08-20 07:17:43 +00003838 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003839 return SemaRef.Owned(S->Retain());
3840
3841 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003842 S->getStartLoc(), S->getEndLoc());
3843}
Mike Stump1eb44332009-09-09 15:08:12 +00003844
Douglas Gregor43959a92009-08-20 07:17:43 +00003845template<typename Derived>
3846Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003847TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003848 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003849 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003850}
3851
3852template<typename Derived>
3853Sema::OwningStmtResult
3854TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003855
Anders Carlsson703e3942010-01-24 05:50:09 +00003856 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3857 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003858 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003859
Anders Carlsson703e3942010-01-24 05:50:09 +00003860 OwningExprResult AsmString(SemaRef);
3861 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3862
3863 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003864
Anders Carlsson703e3942010-01-24 05:50:09 +00003865 // Go through the outputs.
3866 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003867 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003868
Anders Carlsson703e3942010-01-24 05:50:09 +00003869 // No need to transform the constraint literal.
3870 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003871
Anders Carlsson703e3942010-01-24 05:50:09 +00003872 // Transform the output expr.
3873 Expr *OutputExpr = S->getOutputExpr(I);
3874 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3875 if (Result.isInvalid())
3876 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003877
Anders Carlsson703e3942010-01-24 05:50:09 +00003878 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003879
Anders Carlsson703e3942010-01-24 05:50:09 +00003880 Exprs.push_back(Result.takeAs<Expr>());
3881 }
Sean Huntc3021132010-05-05 15:23:54 +00003882
Anders Carlsson703e3942010-01-24 05:50:09 +00003883 // Go through the inputs.
3884 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003885 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003886
Anders Carlsson703e3942010-01-24 05:50:09 +00003887 // No need to transform the constraint literal.
3888 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003889
Anders Carlsson703e3942010-01-24 05:50:09 +00003890 // Transform the input expr.
3891 Expr *InputExpr = S->getInputExpr(I);
3892 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3893 if (Result.isInvalid())
3894 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003895
Anders Carlsson703e3942010-01-24 05:50:09 +00003896 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003897
Anders Carlsson703e3942010-01-24 05:50:09 +00003898 Exprs.push_back(Result.takeAs<Expr>());
3899 }
Sean Huntc3021132010-05-05 15:23:54 +00003900
Anders Carlsson703e3942010-01-24 05:50:09 +00003901 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3902 return SemaRef.Owned(S->Retain());
3903
3904 // Go through the clobbers.
3905 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3906 Clobbers.push_back(S->getClobber(I)->Retain());
3907
3908 // No need to transform the asm string literal.
3909 AsmString = SemaRef.Owned(S->getAsmString());
3910
3911 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3912 S->isSimple(),
3913 S->isVolatile(),
3914 S->getNumOutputs(),
3915 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003916 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003917 move_arg(Constraints),
3918 move_arg(Exprs),
3919 move(AsmString),
3920 move_arg(Clobbers),
3921 S->getRParenLoc(),
3922 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003923}
3924
3925
3926template<typename Derived>
3927Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003928TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003929 // Transform the body of the @try.
3930 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3931 if (TryBody.isInvalid())
3932 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003933
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003934 // Transform the @catch statements (if present).
3935 bool AnyCatchChanged = false;
3936 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3937 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3938 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003939 if (Catch.isInvalid())
3940 return SemaRef.StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003941 if (Catch.get() != S->getCatchStmt(I))
3942 AnyCatchChanged = true;
3943 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003944 }
Sean Huntc3021132010-05-05 15:23:54 +00003945
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003946 // Transform the @finally statement (if present).
3947 OwningStmtResult Finally(SemaRef);
3948 if (S->getFinallyStmt()) {
3949 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3950 if (Finally.isInvalid())
3951 return SemaRef.StmtError();
3952 }
3953
3954 // If nothing changed, just retain this statement.
3955 if (!getDerived().AlwaysRebuild() &&
3956 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003957 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003958 Finally.get() == S->getFinallyStmt())
3959 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003960
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003961 // Build a new statement.
3962 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003963 move_arg(CatchStmts), move(Finally));
Douglas Gregor43959a92009-08-20 07:17:43 +00003964}
Mike Stump1eb44332009-09-09 15:08:12 +00003965
Douglas Gregor43959a92009-08-20 07:17:43 +00003966template<typename Derived>
3967Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003968TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00003969 // Transform the @catch parameter, if there is one.
3970 VarDecl *Var = 0;
3971 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3972 TypeSourceInfo *TSInfo = 0;
3973 if (FromVar->getTypeSourceInfo()) {
3974 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3975 if (!TSInfo)
3976 return SemaRef.StmtError();
3977 }
Sean Huntc3021132010-05-05 15:23:54 +00003978
Douglas Gregorbe270a02010-04-26 17:57:08 +00003979 QualType T;
3980 if (TSInfo)
3981 T = TSInfo->getType();
3982 else {
3983 T = getDerived().TransformType(FromVar->getType());
3984 if (T.isNull())
Sean Huntc3021132010-05-05 15:23:54 +00003985 return SemaRef.StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00003986 }
Sean Huntc3021132010-05-05 15:23:54 +00003987
Douglas Gregorbe270a02010-04-26 17:57:08 +00003988 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3989 if (!Var)
3990 return SemaRef.StmtError();
3991 }
Sean Huntc3021132010-05-05 15:23:54 +00003992
Douglas Gregorbe270a02010-04-26 17:57:08 +00003993 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3994 if (Body.isInvalid())
3995 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003996
3997 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00003998 S->getRParenLoc(),
3999 Var, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004000}
Mike Stump1eb44332009-09-09 15:08:12 +00004001
Douglas Gregor43959a92009-08-20 07:17:43 +00004002template<typename Derived>
4003Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004004TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004005 // Transform the body.
4006 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
4007 if (Body.isInvalid())
4008 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004009
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004010 // If nothing changed, just retain this statement.
4011 if (!getDerived().AlwaysRebuild() &&
4012 Body.get() == S->getFinallyBody())
4013 return SemaRef.Owned(S->Retain());
4014
4015 // Build a new statement.
4016 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
4017 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004018}
Mike Stump1eb44332009-09-09 15:08:12 +00004019
Douglas Gregor43959a92009-08-20 07:17:43 +00004020template<typename Derived>
4021Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004022TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregord1377b22010-04-22 21:44:01 +00004023 OwningExprResult Operand(SemaRef);
4024 if (S->getThrowExpr()) {
4025 Operand = getDerived().TransformExpr(S->getThrowExpr());
4026 if (Operand.isInvalid())
4027 return getSema().StmtError();
4028 }
Sean Huntc3021132010-05-05 15:23:54 +00004029
Douglas Gregord1377b22010-04-22 21:44:01 +00004030 if (!getDerived().AlwaysRebuild() &&
4031 Operand.get() == S->getThrowExpr())
4032 return getSema().Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004033
Douglas Gregord1377b22010-04-22 21:44:01 +00004034 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregor43959a92009-08-20 07:17:43 +00004035}
Mike Stump1eb44332009-09-09 15:08:12 +00004036
Douglas Gregor43959a92009-08-20 07:17:43 +00004037template<typename Derived>
4038Sema::OwningStmtResult
4039TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004040 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004041 // Transform the object we are locking.
4042 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
4043 if (Object.isInvalid())
4044 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004045
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004046 // Transform the body.
4047 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
4048 if (Body.isInvalid())
4049 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004050
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004051 // If nothing change, just retain the current statement.
4052 if (!getDerived().AlwaysRebuild() &&
4053 Object.get() == S->getSynchExpr() &&
4054 Body.get() == S->getSynchBody())
4055 return SemaRef.Owned(S->Retain());
4056
4057 // Build a new statement.
4058 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
4059 move(Object), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004060}
4061
4062template<typename Derived>
4063Sema::OwningStmtResult
4064TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004065 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004066 // Transform the element statement.
4067 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
4068 if (Element.isInvalid())
4069 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004070
Douglas Gregorc3203e72010-04-22 23:10:45 +00004071 // Transform the collection expression.
4072 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
4073 if (Collection.isInvalid())
4074 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004075
Douglas Gregorc3203e72010-04-22 23:10:45 +00004076 // Transform the body.
4077 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
4078 if (Body.isInvalid())
4079 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004080
Douglas Gregorc3203e72010-04-22 23:10:45 +00004081 // If nothing changed, just retain this statement.
4082 if (!getDerived().AlwaysRebuild() &&
4083 Element.get() == S->getElement() &&
4084 Collection.get() == S->getCollection() &&
4085 Body.get() == S->getBody())
4086 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004087
Douglas Gregorc3203e72010-04-22 23:10:45 +00004088 // Build a new statement.
4089 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4090 /*FIXME:*/S->getForLoc(),
4091 move(Element),
4092 move(Collection),
4093 S->getRParenLoc(),
4094 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004095}
4096
4097
4098template<typename Derived>
4099Sema::OwningStmtResult
4100TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4101 // Transform the exception declaration, if any.
4102 VarDecl *Var = 0;
4103 if (S->getExceptionDecl()) {
4104 VarDecl *ExceptionDecl = S->getExceptionDecl();
4105 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4106 ExceptionDecl->getDeclName());
4107
4108 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4109 if (T.isNull())
4110 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004111
Douglas Gregor43959a92009-08-20 07:17:43 +00004112 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4113 T,
John McCalla93c9342009-12-07 02:54:59 +00004114 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004115 ExceptionDecl->getIdentifier(),
4116 ExceptionDecl->getLocation(),
4117 /*FIXME: Inaccurate*/
4118 SourceRange(ExceptionDecl->getLocation()));
4119 if (!Var || Var->isInvalidDecl()) {
4120 if (Var)
4121 Var->Destroy(SemaRef.Context);
4122 return SemaRef.StmtError();
4123 }
4124 }
Mike Stump1eb44332009-09-09 15:08:12 +00004125
Douglas Gregor43959a92009-08-20 07:17:43 +00004126 // Transform the actual exception handler.
4127 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4128 if (Handler.isInvalid()) {
4129 if (Var)
4130 Var->Destroy(SemaRef.Context);
4131 return SemaRef.StmtError();
4132 }
Mike Stump1eb44332009-09-09 15:08:12 +00004133
Douglas Gregor43959a92009-08-20 07:17:43 +00004134 if (!getDerived().AlwaysRebuild() &&
4135 !Var &&
4136 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00004137 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004138
4139 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4140 Var,
4141 move(Handler));
4142}
Mike Stump1eb44332009-09-09 15:08:12 +00004143
Douglas Gregor43959a92009-08-20 07:17:43 +00004144template<typename Derived>
4145Sema::OwningStmtResult
4146TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4147 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00004148 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004149 = getDerived().TransformCompoundStmt(S->getTryBlock());
4150 if (TryBlock.isInvalid())
4151 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004152
Douglas Gregor43959a92009-08-20 07:17:43 +00004153 // Transform the handlers.
4154 bool HandlerChanged = false;
4155 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4156 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00004157 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004158 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4159 if (Handler.isInvalid())
4160 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004161
Douglas Gregor43959a92009-08-20 07:17:43 +00004162 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4163 Handlers.push_back(Handler.takeAs<Stmt>());
4164 }
Mike Stump1eb44332009-09-09 15:08:12 +00004165
Douglas Gregor43959a92009-08-20 07:17:43 +00004166 if (!getDerived().AlwaysRebuild() &&
4167 TryBlock.get() == S->getTryBlock() &&
4168 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004169 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004170
4171 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00004172 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004173}
Mike Stump1eb44332009-09-09 15:08:12 +00004174
Douglas Gregor43959a92009-08-20 07:17:43 +00004175//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004176// Expression transformation
4177//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004178template<typename Derived>
4179Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004180TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004181 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004182}
Mike Stump1eb44332009-09-09 15:08:12 +00004183
4184template<typename Derived>
4185Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004186TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004187 NestedNameSpecifier *Qualifier = 0;
4188 if (E->getQualifier()) {
4189 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004190 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004191 if (!Qualifier)
4192 return SemaRef.ExprError();
4193 }
John McCalldbd872f2009-12-08 09:08:17 +00004194
4195 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004196 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4197 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004198 if (!ND)
4199 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004200
Sean Huntc3021132010-05-05 15:23:54 +00004201 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004202 Qualifier == E->getQualifier() &&
4203 ND == E->getDecl() &&
John McCalldbd872f2009-12-08 09:08:17 +00004204 !E->hasExplicitTemplateArgumentList()) {
4205
4206 // Mark it referenced in the new context regardless.
4207 // FIXME: this is a bit instantiation-specific.
4208 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4209
Mike Stump1eb44332009-09-09 15:08:12 +00004210 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004211 }
John McCalldbd872f2009-12-08 09:08:17 +00004212
4213 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4214 if (E->hasExplicitTemplateArgumentList()) {
4215 TemplateArgs = &TransArgs;
4216 TransArgs.setLAngleLoc(E->getLAngleLoc());
4217 TransArgs.setRAngleLoc(E->getRAngleLoc());
4218 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4219 TemplateArgumentLoc Loc;
4220 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4221 return SemaRef.ExprError();
4222 TransArgs.addArgument(Loc);
4223 }
4224 }
4225
Douglas Gregora2813ce2009-10-23 18:54:35 +00004226 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCalldbd872f2009-12-08 09:08:17 +00004227 ND, E->getLocation(), TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004228}
Mike Stump1eb44332009-09-09 15:08:12 +00004229
Douglas Gregorb98b1992009-08-11 05:31:07 +00004230template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004231Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004232TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004233 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004234}
Mike Stump1eb44332009-09-09 15:08:12 +00004235
Douglas Gregorb98b1992009-08-11 05:31:07 +00004236template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004237Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004238TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004239 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004240}
Mike Stump1eb44332009-09-09 15:08:12 +00004241
Douglas Gregorb98b1992009-08-11 05:31:07 +00004242template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004243Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004244TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004245 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004246}
Mike Stump1eb44332009-09-09 15:08:12 +00004247
Douglas Gregorb98b1992009-08-11 05:31:07 +00004248template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004249Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004250TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004251 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004252}
Mike Stump1eb44332009-09-09 15:08:12 +00004253
Douglas Gregorb98b1992009-08-11 05:31:07 +00004254template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004255Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004256TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004257 return SemaRef.Owned(E->Retain());
4258}
4259
4260template<typename Derived>
4261Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004262TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004263 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4264 if (SubExpr.isInvalid())
4265 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004266
Douglas Gregorb98b1992009-08-11 05:31:07 +00004267 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004268 return SemaRef.Owned(E->Retain());
4269
4270 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004271 E->getRParen());
4272}
4273
Mike Stump1eb44332009-09-09 15:08:12 +00004274template<typename Derived>
4275Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004276TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4277 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004278 if (SubExpr.isInvalid())
4279 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004280
Douglas Gregorb98b1992009-08-11 05:31:07 +00004281 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004282 return SemaRef.Owned(E->Retain());
4283
Douglas Gregorb98b1992009-08-11 05:31:07 +00004284 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4285 E->getOpcode(),
4286 move(SubExpr));
4287}
Mike Stump1eb44332009-09-09 15:08:12 +00004288
Douglas Gregorb98b1992009-08-11 05:31:07 +00004289template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004290Sema::OwningExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004291TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4292 // Transform the type.
4293 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4294 if (!Type)
4295 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004296
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004297 // Transform all of the components into components similar to what the
4298 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004299 // FIXME: It would be slightly more efficient in the non-dependent case to
4300 // just map FieldDecls, rather than requiring the rebuilder to look for
4301 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004302 // template code that we don't care.
4303 bool ExprChanged = false;
4304 typedef Action::OffsetOfComponent Component;
4305 typedef OffsetOfExpr::OffsetOfNode Node;
4306 llvm::SmallVector<Component, 4> Components;
4307 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4308 const Node &ON = E->getComponent(I);
4309 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004310 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004311 Comp.LocStart = ON.getRange().getBegin();
4312 Comp.LocEnd = ON.getRange().getEnd();
4313 switch (ON.getKind()) {
4314 case Node::Array: {
4315 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4316 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4317 if (Index.isInvalid())
4318 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004319
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004320 ExprChanged = ExprChanged || Index.get() != FromIndex;
4321 Comp.isBrackets = true;
4322 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4323 break;
4324 }
Sean Huntc3021132010-05-05 15:23:54 +00004325
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004326 case Node::Field:
4327 case Node::Identifier:
4328 Comp.isBrackets = false;
4329 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004330 if (!Comp.U.IdentInfo)
4331 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004332
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004333 break;
Sean Huntc3021132010-05-05 15:23:54 +00004334
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004335 case Node::Base:
4336 // Will be recomputed during the rebuild.
4337 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004338 }
Sean Huntc3021132010-05-05 15:23:54 +00004339
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004340 Components.push_back(Comp);
4341 }
Sean Huntc3021132010-05-05 15:23:54 +00004342
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004343 // If nothing changed, retain the existing expression.
4344 if (!getDerived().AlwaysRebuild() &&
4345 Type == E->getTypeSourceInfo() &&
4346 !ExprChanged)
4347 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004348
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004349 // Build a new offsetof expression.
4350 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4351 Components.data(), Components.size(),
4352 E->getRParenLoc());
4353}
4354
4355template<typename Derived>
4356Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004357TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004358 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004359 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004360
John McCalla93c9342009-12-07 02:54:59 +00004361 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004362 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004363 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004364
John McCall5ab75172009-11-04 07:28:41 +00004365 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004366 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004367
John McCall5ab75172009-11-04 07:28:41 +00004368 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004369 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004370 E->getSourceRange());
4371 }
Mike Stump1eb44332009-09-09 15:08:12 +00004372
Douglas Gregorb98b1992009-08-11 05:31:07 +00004373 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00004374 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004375 // C++0x [expr.sizeof]p1:
4376 // The operand is either an expression, which is an unevaluated operand
4377 // [...]
4378 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004379
Douglas Gregorb98b1992009-08-11 05:31:07 +00004380 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4381 if (SubExpr.isInvalid())
4382 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004383
Douglas Gregorb98b1992009-08-11 05:31:07 +00004384 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4385 return SemaRef.Owned(E->Retain());
4386 }
Mike Stump1eb44332009-09-09 15:08:12 +00004387
Douglas Gregorb98b1992009-08-11 05:31:07 +00004388 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4389 E->isSizeOf(),
4390 E->getSourceRange());
4391}
Mike Stump1eb44332009-09-09 15:08:12 +00004392
Douglas Gregorb98b1992009-08-11 05:31:07 +00004393template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004394Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004395TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004396 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4397 if (LHS.isInvalid())
4398 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004399
Douglas Gregorb98b1992009-08-11 05:31:07 +00004400 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4401 if (RHS.isInvalid())
4402 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004403
4404
Douglas Gregorb98b1992009-08-11 05:31:07 +00004405 if (!getDerived().AlwaysRebuild() &&
4406 LHS.get() == E->getLHS() &&
4407 RHS.get() == E->getRHS())
4408 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004409
Douglas Gregorb98b1992009-08-11 05:31:07 +00004410 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4411 /*FIXME:*/E->getLHS()->getLocStart(),
4412 move(RHS),
4413 E->getRBracketLoc());
4414}
Mike Stump1eb44332009-09-09 15:08:12 +00004415
4416template<typename Derived>
4417Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004418TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004419 // Transform the callee.
4420 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4421 if (Callee.isInvalid())
4422 return SemaRef.ExprError();
4423
4424 // Transform arguments.
4425 bool ArgChanged = false;
4426 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4427 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4428 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4429 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4430 if (Arg.isInvalid())
4431 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004432
Douglas Gregorb98b1992009-08-11 05:31:07 +00004433 // FIXME: Wrong source location information for the ','.
4434 FakeCommaLocs.push_back(
4435 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00004436
4437 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004438 Args.push_back(Arg.takeAs<Expr>());
4439 }
Mike Stump1eb44332009-09-09 15:08:12 +00004440
Douglas Gregorb98b1992009-08-11 05:31:07 +00004441 if (!getDerived().AlwaysRebuild() &&
4442 Callee.get() == E->getCallee() &&
4443 !ArgChanged)
4444 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004445
Douglas Gregorb98b1992009-08-11 05:31:07 +00004446 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004447 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004448 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4449 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4450 move_arg(Args),
4451 FakeCommaLocs.data(),
4452 E->getRParenLoc());
4453}
Mike Stump1eb44332009-09-09 15:08:12 +00004454
4455template<typename Derived>
4456Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004457TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004458 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4459 if (Base.isInvalid())
4460 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004461
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004462 NestedNameSpecifier *Qualifier = 0;
4463 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004464 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004465 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004466 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004467 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004468 return SemaRef.ExprError();
4469 }
Mike Stump1eb44332009-09-09 15:08:12 +00004470
Eli Friedmanf595cc42009-12-04 06:40:45 +00004471 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004472 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4473 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004474 if (!Member)
4475 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004476
John McCall6bb80172010-03-30 21:47:33 +00004477 NamedDecl *FoundDecl = E->getFoundDecl();
4478 if (FoundDecl == E->getMemberDecl()) {
4479 FoundDecl = Member;
4480 } else {
4481 FoundDecl = cast_or_null<NamedDecl>(
4482 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4483 if (!FoundDecl)
4484 return SemaRef.ExprError();
4485 }
4486
Douglas Gregorb98b1992009-08-11 05:31:07 +00004487 if (!getDerived().AlwaysRebuild() &&
4488 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004489 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004490 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004491 FoundDecl == E->getFoundDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00004492 !E->hasExplicitTemplateArgumentList()) {
Sean Huntc3021132010-05-05 15:23:54 +00004493
Anders Carlsson1f240322009-12-22 05:24:09 +00004494 // Mark it referenced in the new context regardless.
4495 // FIXME: this is a bit instantiation-specific.
4496 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00004497 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00004498 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004499
John McCalld5532b62009-11-23 01:53:49 +00004500 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004501 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00004502 TransArgs.setLAngleLoc(E->getLAngleLoc());
4503 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004504 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004505 TemplateArgumentLoc Loc;
4506 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004507 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004508 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004509 }
4510 }
Sean Huntc3021132010-05-05 15:23:54 +00004511
Douglas Gregorb98b1992009-08-11 05:31:07 +00004512 // FIXME: Bogus source location for the operator
4513 SourceLocation FakeOperatorLoc
4514 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4515
John McCallc2233c52010-01-15 08:34:02 +00004516 // FIXME: to do this check properly, we will need to preserve the
4517 // first-qualifier-in-scope here, just in case we had a dependent
4518 // base (and therefore couldn't do the check) and a
4519 // nested-name-qualifier (and therefore could do the lookup).
4520 NamedDecl *FirstQualifierInScope = 0;
4521
Douglas Gregorb98b1992009-08-11 05:31:07 +00004522 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4523 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004524 Qualifier,
4525 E->getQualifierRange(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004526 E->getMemberLoc(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004527 Member,
John McCall6bb80172010-03-30 21:47:33 +00004528 FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00004529 (E->hasExplicitTemplateArgumentList()
4530 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004531 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004532}
Mike Stump1eb44332009-09-09 15:08:12 +00004533
Douglas Gregorb98b1992009-08-11 05:31:07 +00004534template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004535Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004536TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004537 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4538 if (LHS.isInvalid())
4539 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004540
Douglas Gregorb98b1992009-08-11 05:31:07 +00004541 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4542 if (RHS.isInvalid())
4543 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004544
Douglas Gregorb98b1992009-08-11 05:31:07 +00004545 if (!getDerived().AlwaysRebuild() &&
4546 LHS.get() == E->getLHS() &&
4547 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004548 return SemaRef.Owned(E->Retain());
4549
Douglas Gregorb98b1992009-08-11 05:31:07 +00004550 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4551 move(LHS), move(RHS));
4552}
4553
Mike Stump1eb44332009-09-09 15:08:12 +00004554template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004555Sema::OwningExprResult
4556TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004557 CompoundAssignOperator *E) {
4558 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004559}
Mike Stump1eb44332009-09-09 15:08:12 +00004560
Douglas Gregorb98b1992009-08-11 05:31:07 +00004561template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004562Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004563TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004564 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4565 if (Cond.isInvalid())
4566 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004567
Douglas Gregorb98b1992009-08-11 05:31:07 +00004568 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4569 if (LHS.isInvalid())
4570 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004571
Douglas Gregorb98b1992009-08-11 05:31:07 +00004572 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4573 if (RHS.isInvalid())
4574 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004575
Douglas Gregorb98b1992009-08-11 05:31:07 +00004576 if (!getDerived().AlwaysRebuild() &&
4577 Cond.get() == E->getCond() &&
4578 LHS.get() == E->getLHS() &&
4579 RHS.get() == E->getRHS())
4580 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004581
4582 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004583 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004584 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004585 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004586 move(RHS));
4587}
Mike Stump1eb44332009-09-09 15:08:12 +00004588
4589template<typename Derived>
4590Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004591TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004592 // Implicit casts are eliminated during transformation, since they
4593 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004594 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004595}
Mike Stump1eb44332009-09-09 15:08:12 +00004596
Douglas Gregorb98b1992009-08-11 05:31:07 +00004597template<typename Derived>
4598Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004599TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004600 TypeSourceInfo *OldT;
4601 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004602 {
4603 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004604 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004605 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4606 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004607
John McCall9d125032010-01-15 18:39:57 +00004608 OldT = E->getTypeInfoAsWritten();
4609 NewT = getDerived().TransformType(OldT);
4610 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004611 return SemaRef.ExprError();
4612 }
Mike Stump1eb44332009-09-09 15:08:12 +00004613
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004614 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004615 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004616 if (SubExpr.isInvalid())
4617 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004618
Douglas Gregorb98b1992009-08-11 05:31:07 +00004619 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004620 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004621 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004622 return SemaRef.Owned(E->Retain());
4623
John McCall9d125032010-01-15 18:39:57 +00004624 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4625 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004626 E->getRParenLoc(),
4627 move(SubExpr));
4628}
Mike Stump1eb44332009-09-09 15:08:12 +00004629
Douglas Gregorb98b1992009-08-11 05:31:07 +00004630template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004631Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004632TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004633 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4634 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4635 if (!NewT)
4636 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004637
Douglas Gregorb98b1992009-08-11 05:31:07 +00004638 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4639 if (Init.isInvalid())
4640 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004641
Douglas Gregorb98b1992009-08-11 05:31:07 +00004642 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004643 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004644 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00004645 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004646
John McCall1d7d8d62010-01-19 22:33:45 +00004647 // Note: the expression type doesn't necessarily match the
4648 // type-as-written, but that's okay, because it should always be
4649 // derivable from the initializer.
4650
John McCall42f56b52010-01-18 19:35:47 +00004651 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004652 /*FIXME:*/E->getInitializer()->getLocEnd(),
4653 move(Init));
4654}
Mike Stump1eb44332009-09-09 15:08:12 +00004655
Douglas Gregorb98b1992009-08-11 05:31:07 +00004656template<typename Derived>
4657Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004658TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004659 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4660 if (Base.isInvalid())
4661 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004662
Douglas Gregorb98b1992009-08-11 05:31:07 +00004663 if (!getDerived().AlwaysRebuild() &&
4664 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00004665 return SemaRef.Owned(E->Retain());
4666
Douglas Gregorb98b1992009-08-11 05:31:07 +00004667 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004668 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004669 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4670 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4671 E->getAccessorLoc(),
4672 E->getAccessor());
4673}
Mike Stump1eb44332009-09-09 15:08:12 +00004674
Douglas Gregorb98b1992009-08-11 05:31:07 +00004675template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004676Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004677TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004678 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004679
Douglas Gregorb98b1992009-08-11 05:31:07 +00004680 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4681 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4682 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4683 if (Init.isInvalid())
4684 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004685
Douglas Gregorb98b1992009-08-11 05:31:07 +00004686 InitChanged = InitChanged || Init.get() != E->getInit(I);
4687 Inits.push_back(Init.takeAs<Expr>());
4688 }
Mike Stump1eb44332009-09-09 15:08:12 +00004689
Douglas Gregorb98b1992009-08-11 05:31:07 +00004690 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004691 return SemaRef.Owned(E->Retain());
4692
Douglas Gregorb98b1992009-08-11 05:31:07 +00004693 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004694 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004695}
Mike Stump1eb44332009-09-09 15:08:12 +00004696
Douglas Gregorb98b1992009-08-11 05:31:07 +00004697template<typename Derived>
4698Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004699TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004700 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004701
Douglas Gregor43959a92009-08-20 07:17:43 +00004702 // transform the initializer value
Douglas Gregorb98b1992009-08-11 05:31:07 +00004703 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4704 if (Init.isInvalid())
4705 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004706
Douglas Gregor43959a92009-08-20 07:17:43 +00004707 // transform the designators.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004708 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4709 bool ExprChanged = false;
4710 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4711 DEnd = E->designators_end();
4712 D != DEnd; ++D) {
4713 if (D->isFieldDesignator()) {
4714 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4715 D->getDotLoc(),
4716 D->getFieldLoc()));
4717 continue;
4718 }
Mike Stump1eb44332009-09-09 15:08:12 +00004719
Douglas Gregorb98b1992009-08-11 05:31:07 +00004720 if (D->isArrayDesignator()) {
4721 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4722 if (Index.isInvalid())
4723 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004724
4725 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004726 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004727
Douglas Gregorb98b1992009-08-11 05:31:07 +00004728 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4729 ArrayExprs.push_back(Index.release());
4730 continue;
4731 }
Mike Stump1eb44332009-09-09 15:08:12 +00004732
Douglas Gregorb98b1992009-08-11 05:31:07 +00004733 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump1eb44332009-09-09 15:08:12 +00004734 OwningExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004735 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4736 if (Start.isInvalid())
4737 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004738
Douglas Gregorb98b1992009-08-11 05:31:07 +00004739 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4740 if (End.isInvalid())
4741 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004742
4743 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004744 End.get(),
4745 D->getLBracketLoc(),
4746 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004747
Douglas Gregorb98b1992009-08-11 05:31:07 +00004748 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4749 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004750
Douglas Gregorb98b1992009-08-11 05:31:07 +00004751 ArrayExprs.push_back(Start.release());
4752 ArrayExprs.push_back(End.release());
4753 }
Mike Stump1eb44332009-09-09 15:08:12 +00004754
Douglas Gregorb98b1992009-08-11 05:31:07 +00004755 if (!getDerived().AlwaysRebuild() &&
4756 Init.get() == E->getInit() &&
4757 !ExprChanged)
4758 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004759
Douglas Gregorb98b1992009-08-11 05:31:07 +00004760 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4761 E->getEqualOrColonLoc(),
4762 E->usesGNUSyntax(), move(Init));
4763}
Mike Stump1eb44332009-09-09 15:08:12 +00004764
Douglas Gregorb98b1992009-08-11 05:31:07 +00004765template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004766Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004767TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004768 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004769 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004770
Douglas Gregor5557b252009-10-28 00:29:27 +00004771 // FIXME: Will we ever have proper type location here? Will we actually
4772 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004773 QualType T = getDerived().TransformType(E->getType());
4774 if (T.isNull())
4775 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004776
Douglas Gregorb98b1992009-08-11 05:31:07 +00004777 if (!getDerived().AlwaysRebuild() &&
4778 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004779 return SemaRef.Owned(E->Retain());
4780
Douglas Gregorb98b1992009-08-11 05:31:07 +00004781 return getDerived().RebuildImplicitValueInitExpr(T);
4782}
Mike Stump1eb44332009-09-09 15:08:12 +00004783
Douglas Gregorb98b1992009-08-11 05:31:07 +00004784template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004785Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004786TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004787 // FIXME: Do we want the type as written?
4788 QualType T;
Mike Stump1eb44332009-09-09 15:08:12 +00004789
Douglas Gregorb98b1992009-08-11 05:31:07 +00004790 {
4791 // FIXME: Source location isn't quite accurate.
4792 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4793 T = getDerived().TransformType(E->getType());
4794 if (T.isNull())
4795 return SemaRef.ExprError();
4796 }
Mike Stump1eb44332009-09-09 15:08:12 +00004797
Douglas Gregorb98b1992009-08-11 05:31:07 +00004798 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4799 if (SubExpr.isInvalid())
4800 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004801
Douglas Gregorb98b1992009-08-11 05:31:07 +00004802 if (!getDerived().AlwaysRebuild() &&
4803 T == E->getType() &&
4804 SubExpr.get() == E->getSubExpr())
4805 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004806
Douglas Gregorb98b1992009-08-11 05:31:07 +00004807 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4808 T, E->getRParenLoc());
4809}
4810
4811template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004812Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004813TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004814 bool ArgumentChanged = false;
4815 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4816 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4817 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4818 if (Init.isInvalid())
4819 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004820
Douglas Gregorb98b1992009-08-11 05:31:07 +00004821 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4822 Inits.push_back(Init.takeAs<Expr>());
4823 }
Mike Stump1eb44332009-09-09 15:08:12 +00004824
Douglas Gregorb98b1992009-08-11 05:31:07 +00004825 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4826 move_arg(Inits),
4827 E->getRParenLoc());
4828}
Mike Stump1eb44332009-09-09 15:08:12 +00004829
Douglas Gregorb98b1992009-08-11 05:31:07 +00004830/// \brief Transform an address-of-label expression.
4831///
4832/// By default, the transformation of an address-of-label expression always
4833/// rebuilds the expression, so that the label identifier can be resolved to
4834/// the corresponding label statement by semantic analysis.
4835template<typename Derived>
4836Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004837TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004838 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4839 E->getLabel());
4840}
Mike Stump1eb44332009-09-09 15:08:12 +00004841
4842template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00004843Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004844TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004845 OwningStmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004846 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4847 if (SubStmt.isInvalid())
4848 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004849
Douglas Gregorb98b1992009-08-11 05:31:07 +00004850 if (!getDerived().AlwaysRebuild() &&
4851 SubStmt.get() == E->getSubStmt())
4852 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004853
4854 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004855 move(SubStmt),
4856 E->getRParenLoc());
4857}
Mike Stump1eb44332009-09-09 15:08:12 +00004858
Douglas Gregorb98b1992009-08-11 05:31:07 +00004859template<typename Derived>
4860Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004861TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004862 QualType T1, T2;
4863 {
4864 // FIXME: Source location isn't quite accurate.
4865 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004866
Douglas Gregorb98b1992009-08-11 05:31:07 +00004867 T1 = getDerived().TransformType(E->getArgType1());
4868 if (T1.isNull())
4869 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004870
Douglas Gregorb98b1992009-08-11 05:31:07 +00004871 T2 = getDerived().TransformType(E->getArgType2());
4872 if (T2.isNull())
4873 return SemaRef.ExprError();
4874 }
4875
4876 if (!getDerived().AlwaysRebuild() &&
4877 T1 == E->getArgType1() &&
4878 T2 == E->getArgType2())
Mike Stump1eb44332009-09-09 15:08:12 +00004879 return SemaRef.Owned(E->Retain());
4880
Douglas Gregorb98b1992009-08-11 05:31:07 +00004881 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4882 T1, T2, E->getRParenLoc());
4883}
Mike Stump1eb44332009-09-09 15:08:12 +00004884
Douglas Gregorb98b1992009-08-11 05:31:07 +00004885template<typename Derived>
4886Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004887TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004888 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4889 if (Cond.isInvalid())
4890 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004891
Douglas Gregorb98b1992009-08-11 05:31:07 +00004892 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4893 if (LHS.isInvalid())
4894 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004895
Douglas Gregorb98b1992009-08-11 05:31:07 +00004896 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4897 if (RHS.isInvalid())
4898 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004899
Douglas Gregorb98b1992009-08-11 05:31:07 +00004900 if (!getDerived().AlwaysRebuild() &&
4901 Cond.get() == E->getCond() &&
4902 LHS.get() == E->getLHS() &&
4903 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004904 return SemaRef.Owned(E->Retain());
4905
Douglas Gregorb98b1992009-08-11 05:31:07 +00004906 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4907 move(Cond), move(LHS), move(RHS),
4908 E->getRParenLoc());
4909}
Mike Stump1eb44332009-09-09 15:08:12 +00004910
Douglas Gregorb98b1992009-08-11 05:31:07 +00004911template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004912Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004913TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004914 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004915}
4916
4917template<typename Derived>
4918Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004919TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004920 switch (E->getOperator()) {
4921 case OO_New:
4922 case OO_Delete:
4923 case OO_Array_New:
4924 case OO_Array_Delete:
4925 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4926 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004927
Douglas Gregor668d6d92009-12-13 20:44:55 +00004928 case OO_Call: {
4929 // This is a call to an object's operator().
4930 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4931
4932 // Transform the object itself.
4933 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4934 if (Object.isInvalid())
4935 return SemaRef.ExprError();
4936
4937 // FIXME: Poor location information
4938 SourceLocation FakeLParenLoc
4939 = SemaRef.PP.getLocForEndOfToken(
4940 static_cast<Expr *>(Object.get())->getLocEnd());
4941
4942 // Transform the call arguments.
4943 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4944 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4945 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004946 if (getDerived().DropCallArgument(E->getArg(I)))
4947 break;
Sean Huntc3021132010-05-05 15:23:54 +00004948
Douglas Gregor668d6d92009-12-13 20:44:55 +00004949 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4950 if (Arg.isInvalid())
4951 return SemaRef.ExprError();
4952
4953 // FIXME: Poor source location information.
4954 SourceLocation FakeCommaLoc
4955 = SemaRef.PP.getLocForEndOfToken(
4956 static_cast<Expr *>(Arg.get())->getLocEnd());
4957 FakeCommaLocs.push_back(FakeCommaLoc);
4958 Args.push_back(Arg.release());
4959 }
4960
4961 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4962 move_arg(Args),
4963 FakeCommaLocs.data(),
4964 E->getLocEnd());
4965 }
4966
4967#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4968 case OO_##Name:
4969#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4970#include "clang/Basic/OperatorKinds.def"
4971 case OO_Subscript:
4972 // Handled below.
4973 break;
4974
4975 case OO_Conditional:
4976 llvm_unreachable("conditional operator is not actually overloadable");
4977 return SemaRef.ExprError();
4978
4979 case OO_None:
4980 case NUM_OVERLOADED_OPERATORS:
4981 llvm_unreachable("not an overloaded operator?");
4982 return SemaRef.ExprError();
4983 }
4984
Douglas Gregorb98b1992009-08-11 05:31:07 +00004985 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4986 if (Callee.isInvalid())
4987 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004988
John McCall454feb92009-12-08 09:21:05 +00004989 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004990 if (First.isInvalid())
4991 return SemaRef.ExprError();
4992
4993 OwningExprResult Second(SemaRef);
4994 if (E->getNumArgs() == 2) {
4995 Second = getDerived().TransformExpr(E->getArg(1));
4996 if (Second.isInvalid())
4997 return SemaRef.ExprError();
4998 }
Mike Stump1eb44332009-09-09 15:08:12 +00004999
Douglas Gregorb98b1992009-08-11 05:31:07 +00005000 if (!getDerived().AlwaysRebuild() &&
5001 Callee.get() == E->getCallee() &&
5002 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005003 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5004 return SemaRef.Owned(E->Retain());
5005
Douglas Gregorb98b1992009-08-11 05:31:07 +00005006 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5007 E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005008 move(Callee),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005009 move(First),
5010 move(Second));
5011}
Mike Stump1eb44332009-09-09 15:08:12 +00005012
Douglas Gregorb98b1992009-08-11 05:31:07 +00005013template<typename Derived>
5014Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005015TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5016 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005017}
Mike Stump1eb44332009-09-09 15:08:12 +00005018
Douglas Gregorb98b1992009-08-11 05:31:07 +00005019template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005020Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005021TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00005022 TypeSourceInfo *OldT;
5023 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005024 {
5025 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00005026 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005027 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5028 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005029
John McCall9d125032010-01-15 18:39:57 +00005030 OldT = E->getTypeInfoAsWritten();
5031 NewT = getDerived().TransformType(OldT);
5032 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005033 return SemaRef.ExprError();
5034 }
Mike Stump1eb44332009-09-09 15:08:12 +00005035
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005036 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005037 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005038 if (SubExpr.isInvalid())
5039 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005040
Douglas Gregorb98b1992009-08-11 05:31:07 +00005041 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00005042 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005043 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005044 return SemaRef.Owned(E->Retain());
5045
Douglas Gregorb98b1992009-08-11 05:31:07 +00005046 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005047 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005048 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5049 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5050 SourceLocation FakeRParenLoc
5051 = SemaRef.PP.getLocForEndOfToken(
5052 E->getSubExpr()->getSourceRange().getEnd());
5053 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005054 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005055 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00005056 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005057 FakeRAngleLoc,
5058 FakeRAngleLoc,
5059 move(SubExpr),
5060 FakeRParenLoc);
5061}
Mike Stump1eb44332009-09-09 15:08:12 +00005062
Douglas Gregorb98b1992009-08-11 05:31:07 +00005063template<typename Derived>
5064Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005065TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5066 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005067}
Mike Stump1eb44332009-09-09 15:08:12 +00005068
5069template<typename Derived>
5070Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005071TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5072 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005073}
5074
Douglas Gregorb98b1992009-08-11 05:31:07 +00005075template<typename Derived>
5076Sema::OwningExprResult
5077TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005078 CXXReinterpretCastExpr *E) {
5079 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005080}
Mike Stump1eb44332009-09-09 15:08:12 +00005081
Douglas Gregorb98b1992009-08-11 05:31:07 +00005082template<typename Derived>
5083Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005084TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5085 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005086}
Mike Stump1eb44332009-09-09 15:08:12 +00005087
Douglas Gregorb98b1992009-08-11 05:31:07 +00005088template<typename Derived>
5089Sema::OwningExprResult
5090TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005091 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00005092 TypeSourceInfo *OldT;
5093 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005094 {
5095 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005096
John McCall9d125032010-01-15 18:39:57 +00005097 OldT = E->getTypeInfoAsWritten();
5098 NewT = getDerived().TransformType(OldT);
5099 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005100 return SemaRef.ExprError();
5101 }
Mike Stump1eb44332009-09-09 15:08:12 +00005102
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005103 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005104 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005105 if (SubExpr.isInvalid())
5106 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005107
Douglas Gregorb98b1992009-08-11 05:31:07 +00005108 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00005109 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005110 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005111 return SemaRef.Owned(E->Retain());
5112
Douglas Gregorb98b1992009-08-11 05:31:07 +00005113 // FIXME: The end of the type's source range is wrong
5114 return getDerived().RebuildCXXFunctionalCastExpr(
5115 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall9d125032010-01-15 18:39:57 +00005116 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005117 /*FIXME:*/E->getSubExpr()->getLocStart(),
5118 move(SubExpr),
5119 E->getRParenLoc());
5120}
Mike Stump1eb44332009-09-09 15:08:12 +00005121
Douglas Gregorb98b1992009-08-11 05:31:07 +00005122template<typename Derived>
5123Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005124TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005125 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005126 TypeSourceInfo *TInfo
5127 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5128 if (!TInfo)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005129 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005130
Douglas Gregorb98b1992009-08-11 05:31:07 +00005131 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005132 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005133 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005134
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005135 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5136 E->getLocStart(),
5137 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005138 E->getLocEnd());
5139 }
Mike Stump1eb44332009-09-09 15:08:12 +00005140
Douglas Gregorb98b1992009-08-11 05:31:07 +00005141 // We don't know whether the expression is potentially evaluated until
5142 // after we perform semantic analysis, so the expression is potentially
5143 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005144 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005145 Action::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005146
Douglas Gregorb98b1992009-08-11 05:31:07 +00005147 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5148 if (SubExpr.isInvalid())
5149 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005150
Douglas Gregorb98b1992009-08-11 05:31:07 +00005151 if (!getDerived().AlwaysRebuild() &&
5152 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00005153 return SemaRef.Owned(E->Retain());
5154
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005155 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5156 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005157 move(SubExpr),
5158 E->getLocEnd());
5159}
5160
5161template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005162Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005163TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005164 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005165}
Mike Stump1eb44332009-09-09 15:08:12 +00005166
Douglas Gregorb98b1992009-08-11 05:31:07 +00005167template<typename Derived>
5168Sema::OwningExprResult
5169TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005170 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005171 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005172}
Mike Stump1eb44332009-09-09 15:08:12 +00005173
Douglas Gregorb98b1992009-08-11 05:31:07 +00005174template<typename Derived>
5175Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005176TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005177 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005178
Douglas Gregorb98b1992009-08-11 05:31:07 +00005179 QualType T = getDerived().TransformType(E->getType());
5180 if (T.isNull())
5181 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005182
Douglas Gregorb98b1992009-08-11 05:31:07 +00005183 if (!getDerived().AlwaysRebuild() &&
5184 T == E->getType())
5185 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005186
Douglas Gregor828a1972010-01-07 23:12:05 +00005187 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005188}
Mike Stump1eb44332009-09-09 15:08:12 +00005189
Douglas Gregorb98b1992009-08-11 05:31:07 +00005190template<typename Derived>
5191Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005192TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005193 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5194 if (SubExpr.isInvalid())
5195 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005196
Douglas Gregorb98b1992009-08-11 05:31:07 +00005197 if (!getDerived().AlwaysRebuild() &&
5198 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005199 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005200
5201 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5202}
Mike Stump1eb44332009-09-09 15:08:12 +00005203
Douglas Gregorb98b1992009-08-11 05:31:07 +00005204template<typename Derived>
5205Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005206TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005207 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005208 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5209 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005210 if (!Param)
5211 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005212
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005213 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005214 Param == E->getParam())
5215 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005216
Douglas Gregor036aed12009-12-23 23:03:06 +00005217 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005218}
Mike Stump1eb44332009-09-09 15:08:12 +00005219
Douglas Gregorb98b1992009-08-11 05:31:07 +00005220template<typename Derived>
5221Sema::OwningExprResult
Douglas Gregor016a4a92010-07-07 22:43:56 +00005222TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005223 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5224
5225 QualType T = getDerived().TransformType(E->getType());
5226 if (T.isNull())
5227 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005228
Douglas Gregorb98b1992009-08-11 05:31:07 +00005229 if (!getDerived().AlwaysRebuild() &&
5230 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00005231 return SemaRef.Owned(E->Retain());
5232
Douglas Gregor016a4a92010-07-07 22:43:56 +00005233 return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
5234 /*FIXME:*/E->getTypeBeginLoc(),
5235 T,
5236 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005237}
Mike Stump1eb44332009-09-09 15:08:12 +00005238
Douglas Gregorb98b1992009-08-11 05:31:07 +00005239template<typename Derived>
5240Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005241TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005242 // Transform the type that we're allocating
5243 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5244 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5245 if (AllocType.isNull())
5246 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005247
Douglas Gregorb98b1992009-08-11 05:31:07 +00005248 // Transform the size of the array we're allocating (if any).
5249 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5250 if (ArraySize.isInvalid())
5251 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005252
Douglas Gregorb98b1992009-08-11 05:31:07 +00005253 // Transform the placement arguments (if any).
5254 bool ArgumentChanged = false;
5255 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5256 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5257 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5258 if (Arg.isInvalid())
5259 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005260
Douglas Gregorb98b1992009-08-11 05:31:07 +00005261 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5262 PlacementArgs.push_back(Arg.take());
5263 }
Mike Stump1eb44332009-09-09 15:08:12 +00005264
Douglas Gregor43959a92009-08-20 07:17:43 +00005265 // transform the constructor arguments (if any).
Douglas Gregorb98b1992009-08-11 05:31:07 +00005266 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5267 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005268 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5269 break;
5270
Douglas Gregorb98b1992009-08-11 05:31:07 +00005271 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5272 if (Arg.isInvalid())
5273 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005274
Douglas Gregorb98b1992009-08-11 05:31:07 +00005275 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5276 ConstructorArgs.push_back(Arg.take());
5277 }
Mike Stump1eb44332009-09-09 15:08:12 +00005278
Douglas Gregor1af74512010-02-26 00:38:10 +00005279 // Transform constructor, new operator, and delete operator.
5280 CXXConstructorDecl *Constructor = 0;
5281 if (E->getConstructor()) {
5282 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005283 getDerived().TransformDecl(E->getLocStart(),
5284 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005285 if (!Constructor)
5286 return SemaRef.ExprError();
5287 }
5288
5289 FunctionDecl *OperatorNew = 0;
5290 if (E->getOperatorNew()) {
5291 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005292 getDerived().TransformDecl(E->getLocStart(),
5293 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005294 if (!OperatorNew)
5295 return SemaRef.ExprError();
5296 }
5297
5298 FunctionDecl *OperatorDelete = 0;
5299 if (E->getOperatorDelete()) {
5300 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005301 getDerived().TransformDecl(E->getLocStart(),
5302 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005303 if (!OperatorDelete)
5304 return SemaRef.ExprError();
5305 }
Sean Huntc3021132010-05-05 15:23:54 +00005306
Douglas Gregorb98b1992009-08-11 05:31:07 +00005307 if (!getDerived().AlwaysRebuild() &&
5308 AllocType == E->getAllocatedType() &&
5309 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005310 Constructor == E->getConstructor() &&
5311 OperatorNew == E->getOperatorNew() &&
5312 OperatorDelete == E->getOperatorDelete() &&
5313 !ArgumentChanged) {
5314 // Mark any declarations we need as referenced.
5315 // FIXME: instantiation-specific.
5316 if (Constructor)
5317 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5318 if (OperatorNew)
5319 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5320 if (OperatorDelete)
5321 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005322 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005323 }
Mike Stump1eb44332009-09-09 15:08:12 +00005324
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005325 if (!ArraySize.get()) {
5326 // If no array size was specified, but the new expression was
5327 // instantiated with an array type (e.g., "new T" where T is
5328 // instantiated with "int[4]"), extract the outer bound from the
5329 // array type as our array size. We do this with constant and
5330 // dependently-sized array types.
5331 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5332 if (!ArrayT) {
5333 // Do nothing
5334 } else if (const ConstantArrayType *ConsArrayT
5335 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005336 ArraySize
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005337 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Sean Huntc3021132010-05-05 15:23:54 +00005338 ConsArrayT->getSize(),
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005339 SemaRef.Context.getSizeType(),
5340 /*FIXME:*/E->getLocStart()));
5341 AllocType = ConsArrayT->getElementType();
5342 } else if (const DependentSizedArrayType *DepArrayT
5343 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5344 if (DepArrayT->getSizeExpr()) {
5345 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5346 AllocType = DepArrayT->getElementType();
5347 }
5348 }
5349 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005350 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5351 E->isGlobalNew(),
5352 /*FIXME:*/E->getLocStart(),
5353 move_arg(PlacementArgs),
5354 /*FIXME:*/E->getLocStart(),
5355 E->isParenTypeId(),
5356 AllocType,
5357 /*FIXME:*/E->getLocStart(),
5358 /*FIXME:*/SourceRange(),
5359 move(ArraySize),
5360 /*FIXME:*/E->getLocStart(),
5361 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005362 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005363}
Mike Stump1eb44332009-09-09 15:08:12 +00005364
Douglas Gregorb98b1992009-08-11 05:31:07 +00005365template<typename Derived>
5366Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005367TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005368 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5369 if (Operand.isInvalid())
5370 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005371
Douglas Gregor1af74512010-02-26 00:38:10 +00005372 // Transform the delete operator, if known.
5373 FunctionDecl *OperatorDelete = 0;
5374 if (E->getOperatorDelete()) {
5375 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005376 getDerived().TransformDecl(E->getLocStart(),
5377 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005378 if (!OperatorDelete)
5379 return SemaRef.ExprError();
5380 }
Sean Huntc3021132010-05-05 15:23:54 +00005381
Douglas Gregorb98b1992009-08-11 05:31:07 +00005382 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005383 Operand.get() == E->getArgument() &&
5384 OperatorDelete == E->getOperatorDelete()) {
5385 // Mark any declarations we need as referenced.
5386 // FIXME: instantiation-specific.
5387 if (OperatorDelete)
5388 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005389 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005390 }
Mike Stump1eb44332009-09-09 15:08:12 +00005391
Douglas Gregorb98b1992009-08-11 05:31:07 +00005392 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5393 E->isGlobalDelete(),
5394 E->isArrayForm(),
5395 move(Operand));
5396}
Mike Stump1eb44332009-09-09 15:08:12 +00005397
Douglas Gregorb98b1992009-08-11 05:31:07 +00005398template<typename Derived>
5399Sema::OwningExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005400TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005401 CXXPseudoDestructorExpr *E) {
Douglas Gregora71d8192009-09-04 17:36:40 +00005402 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5403 if (Base.isInvalid())
5404 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005405
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005406 Sema::TypeTy *ObjectTypePtr = 0;
5407 bool MayBePseudoDestructor = false;
Sean Huntc3021132010-05-05 15:23:54 +00005408 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005409 E->getOperatorLoc(),
5410 E->isArrow()? tok::arrow : tok::period,
5411 ObjectTypePtr,
5412 MayBePseudoDestructor);
5413 if (Base.isInvalid())
5414 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005415
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005416 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregora71d8192009-09-04 17:36:40 +00005417 NestedNameSpecifier *Qualifier
5418 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00005419 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005420 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00005421 if (E->getQualifier() && !Qualifier)
5422 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005423
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005424 PseudoDestructorTypeStorage Destroyed;
5425 if (E->getDestroyedTypeInfo()) {
5426 TypeSourceInfo *DestroyedTypeInfo
5427 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5428 if (!DestroyedTypeInfo)
5429 return SemaRef.ExprError();
5430 Destroyed = DestroyedTypeInfo;
5431 } else if (ObjectType->isDependentType()) {
5432 // We aren't likely to be able to resolve the identifier down to a type
5433 // now anyway, so just retain the identifier.
5434 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5435 E->getDestroyedTypeLoc());
5436 } else {
5437 // Look for a destructor known with the given name.
5438 CXXScopeSpec SS;
5439 if (Qualifier) {
5440 SS.setScopeRep(Qualifier);
5441 SS.setRange(E->getQualifierRange());
5442 }
Sean Huntc3021132010-05-05 15:23:54 +00005443
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005444 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5445 *E->getDestroyedTypeIdentifier(),
5446 E->getDestroyedTypeLoc(),
5447 /*Scope=*/0,
5448 SS, ObjectTypePtr,
5449 false);
5450 if (!T)
5451 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005452
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005453 Destroyed
5454 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5455 E->getDestroyedTypeLoc());
5456 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005457
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005458 TypeSourceInfo *ScopeTypeInfo = 0;
5459 if (E->getScopeTypeInfo()) {
Sean Huntc3021132010-05-05 15:23:54 +00005460 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005461 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005462 if (!ScopeTypeInfo)
Douglas Gregora71d8192009-09-04 17:36:40 +00005463 return SemaRef.ExprError();
5464 }
Sean Huntc3021132010-05-05 15:23:54 +00005465
Douglas Gregora71d8192009-09-04 17:36:40 +00005466 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5467 E->getOperatorLoc(),
5468 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005469 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005470 E->getQualifierRange(),
5471 ScopeTypeInfo,
5472 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005473 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005474 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005475}
Mike Stump1eb44332009-09-09 15:08:12 +00005476
Douglas Gregora71d8192009-09-04 17:36:40 +00005477template<typename Derived>
5478Sema::OwningExprResult
John McCallba135432009-11-21 08:51:07 +00005479TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005480 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005481 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5482
5483 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5484 Sema::LookupOrdinaryName);
5485
5486 // Transform all the decls.
5487 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5488 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005489 NamedDecl *InstD = static_cast<NamedDecl*>(
5490 getDerived().TransformDecl(Old->getNameLoc(),
5491 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005492 if (!InstD) {
5493 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5494 // This can happen because of dependent hiding.
5495 if (isa<UsingShadowDecl>(*I))
5496 continue;
5497 else
5498 return SemaRef.ExprError();
5499 }
John McCallf7a1a742009-11-24 19:00:30 +00005500
5501 // Expand using declarations.
5502 if (isa<UsingDecl>(InstD)) {
5503 UsingDecl *UD = cast<UsingDecl>(InstD);
5504 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5505 E = UD->shadow_end(); I != E; ++I)
5506 R.addDecl(*I);
5507 continue;
5508 }
5509
5510 R.addDecl(InstD);
5511 }
5512
5513 // Resolve a kind, but don't do any further analysis. If it's
5514 // ambiguous, the callee needs to deal with it.
5515 R.resolveKind();
5516
5517 // Rebuild the nested-name qualifier, if present.
5518 CXXScopeSpec SS;
5519 NestedNameSpecifier *Qualifier = 0;
5520 if (Old->getQualifier()) {
5521 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005522 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005523 if (!Qualifier)
5524 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005525
John McCallf7a1a742009-11-24 19:00:30 +00005526 SS.setScopeRep(Qualifier);
5527 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005528 }
5529
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005530 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005531 CXXRecordDecl *NamingClass
5532 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5533 Old->getNameLoc(),
5534 Old->getNamingClass()));
5535 if (!NamingClass)
5536 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005537
Douglas Gregor66c45152010-04-27 16:10:10 +00005538 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005539 }
5540
5541 // If we have no template arguments, it's a normal declaration name.
5542 if (!Old->hasExplicitTemplateArgs())
5543 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5544
5545 // If we have template arguments, rebuild them, then rebuild the
5546 // templateid expression.
5547 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5548 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5549 TemplateArgumentLoc Loc;
5550 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5551 return SemaRef.ExprError();
5552 TransArgs.addArgument(Loc);
5553 }
5554
5555 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5556 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005557}
Mike Stump1eb44332009-09-09 15:08:12 +00005558
Douglas Gregorb98b1992009-08-11 05:31:07 +00005559template<typename Derived>
5560Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005561TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005562 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005563
Douglas Gregorb98b1992009-08-11 05:31:07 +00005564 QualType T = getDerived().TransformType(E->getQueriedType());
5565 if (T.isNull())
5566 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005567
Douglas Gregorb98b1992009-08-11 05:31:07 +00005568 if (!getDerived().AlwaysRebuild() &&
5569 T == E->getQueriedType())
5570 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005571
Douglas Gregorb98b1992009-08-11 05:31:07 +00005572 // FIXME: Bad location information
5573 SourceLocation FakeLParenLoc
5574 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00005575
5576 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005577 E->getLocStart(),
5578 /*FIXME:*/FakeLParenLoc,
5579 T,
5580 E->getLocEnd());
5581}
Mike Stump1eb44332009-09-09 15:08:12 +00005582
Douglas Gregorb98b1992009-08-11 05:31:07 +00005583template<typename Derived>
5584Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005585TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005586 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005587 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005588 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005589 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005590 if (!NNS)
5591 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005592
5593 DeclarationName Name
Douglas Gregor81499bb2009-09-03 22:13:48 +00005594 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5595 if (!Name)
5596 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005597
John McCallf7a1a742009-11-24 19:00:30 +00005598 if (!E->hasExplicitTemplateArgs()) {
5599 if (!getDerived().AlwaysRebuild() &&
5600 NNS == E->getQualifier() &&
5601 Name == E->getDeclName())
5602 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005603
John McCallf7a1a742009-11-24 19:00:30 +00005604 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5605 E->getQualifierRange(),
5606 Name, E->getLocation(),
5607 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005608 }
John McCalld5532b62009-11-23 01:53:49 +00005609
5610 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005611 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005612 TemplateArgumentLoc Loc;
5613 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb98b1992009-08-11 05:31:07 +00005614 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005615 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005616 }
5617
John McCallf7a1a742009-11-24 19:00:30 +00005618 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5619 E->getQualifierRange(),
5620 Name, E->getLocation(),
5621 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005622}
5623
5624template<typename Derived>
5625Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005626TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005627 // CXXConstructExprs are always implicit, so when we have a
5628 // 1-argument construction we just transform that argument.
5629 if (E->getNumArgs() == 1 ||
5630 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5631 return getDerived().TransformExpr(E->getArg(0));
5632
Douglas Gregorb98b1992009-08-11 05:31:07 +00005633 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5634
5635 QualType T = getDerived().TransformType(E->getType());
5636 if (T.isNull())
5637 return SemaRef.ExprError();
5638
5639 CXXConstructorDecl *Constructor
5640 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005641 getDerived().TransformDecl(E->getLocStart(),
5642 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005643 if (!Constructor)
5644 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005645
Douglas Gregorb98b1992009-08-11 05:31:07 +00005646 bool ArgumentChanged = false;
5647 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005648 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005649 ArgEnd = E->arg_end();
5650 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005651 if (getDerived().DropCallArgument(*Arg)) {
5652 ArgumentChanged = true;
5653 break;
5654 }
5655
Douglas Gregorb98b1992009-08-11 05:31:07 +00005656 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5657 if (TransArg.isInvalid())
5658 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005659
Douglas Gregorb98b1992009-08-11 05:31:07 +00005660 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5661 Args.push_back(TransArg.takeAs<Expr>());
5662 }
5663
5664 if (!getDerived().AlwaysRebuild() &&
5665 T == E->getType() &&
5666 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005667 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005668 // Mark the constructor as referenced.
5669 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005670 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005671 return SemaRef.Owned(E->Retain());
Douglas Gregorc845aad2010-02-26 00:01:57 +00005672 }
Mike Stump1eb44332009-09-09 15:08:12 +00005673
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005674 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5675 Constructor, E->isElidable(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005676 move_arg(Args));
5677}
Mike Stump1eb44332009-09-09 15:08:12 +00005678
Douglas Gregorb98b1992009-08-11 05:31:07 +00005679/// \brief Transform a C++ temporary-binding expression.
5680///
Douglas Gregor51326552009-12-24 18:51:59 +00005681/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5682/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005683template<typename Derived>
5684Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005685TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005686 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005687}
Mike Stump1eb44332009-09-09 15:08:12 +00005688
Anders Carlssoneb60edf2010-01-29 02:39:32 +00005689/// \brief Transform a C++ reference-binding expression.
5690///
5691/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5692/// transform the subexpression and return that.
5693template<typename Derived>
5694Sema::OwningExprResult
5695TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5696 return getDerived().TransformExpr(E->getSubExpr());
5697}
5698
Mike Stump1eb44332009-09-09 15:08:12 +00005699/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005700/// be destroyed after the expression is evaluated.
5701///
Douglas Gregor51326552009-12-24 18:51:59 +00005702/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5703/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005704template<typename Derived>
5705Sema::OwningExprResult
5706TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005707 CXXExprWithTemporaries *E) {
5708 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005709}
Mike Stump1eb44332009-09-09 15:08:12 +00005710
Douglas Gregorb98b1992009-08-11 05:31:07 +00005711template<typename Derived>
5712Sema::OwningExprResult
5713TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00005714 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005715 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5716 QualType T = getDerived().TransformType(E->getType());
5717 if (T.isNull())
5718 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005719
Douglas Gregorb98b1992009-08-11 05:31:07 +00005720 CXXConstructorDecl *Constructor
5721 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005722 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005723 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005724 if (!Constructor)
5725 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005726
Douglas Gregorb98b1992009-08-11 05:31:07 +00005727 bool ArgumentChanged = false;
5728 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5729 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005730 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005731 ArgEnd = E->arg_end();
5732 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005733 if (getDerived().DropCallArgument(*Arg)) {
5734 ArgumentChanged = true;
5735 break;
5736 }
5737
Douglas Gregorb98b1992009-08-11 05:31:07 +00005738 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5739 if (TransArg.isInvalid())
5740 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005741
Douglas Gregorb98b1992009-08-11 05:31:07 +00005742 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5743 Args.push_back((Expr *)TransArg.release());
5744 }
Mike Stump1eb44332009-09-09 15:08:12 +00005745
Douglas Gregorb98b1992009-08-11 05:31:07 +00005746 if (!getDerived().AlwaysRebuild() &&
5747 T == E->getType() &&
5748 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005749 !ArgumentChanged) {
5750 // FIXME: Instantiation-specific
5751 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carrutha3ce8ae2010-03-31 18:34:58 +00005752 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor91be6f52010-03-02 17:18:33 +00005753 }
Mike Stump1eb44332009-09-09 15:08:12 +00005754
Douglas Gregorb98b1992009-08-11 05:31:07 +00005755 // FIXME: Bogus location information
5756 SourceLocation CommaLoc;
5757 if (Args.size() > 1) {
5758 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00005759 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005760 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5761 }
5762 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5763 T,
5764 /*FIXME:*/E->getTypeBeginLoc(),
5765 move_arg(Args),
5766 &CommaLoc,
5767 E->getLocEnd());
5768}
Mike Stump1eb44332009-09-09 15:08:12 +00005769
Douglas Gregorb98b1992009-08-11 05:31:07 +00005770template<typename Derived>
5771Sema::OwningExprResult
5772TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005773 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005774 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5775 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5776 if (T.isNull())
5777 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005778
Douglas Gregorb98b1992009-08-11 05:31:07 +00005779 bool ArgumentChanged = false;
5780 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5781 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5782 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5783 ArgEnd = E->arg_end();
5784 Arg != ArgEnd; ++Arg) {
5785 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5786 if (TransArg.isInvalid())
5787 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005788
Douglas Gregorb98b1992009-08-11 05:31:07 +00005789 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5790 FakeCommaLocs.push_back(
5791 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5792 Args.push_back(TransArg.takeAs<Expr>());
5793 }
Mike Stump1eb44332009-09-09 15:08:12 +00005794
Douglas Gregorb98b1992009-08-11 05:31:07 +00005795 if (!getDerived().AlwaysRebuild() &&
5796 T == E->getTypeAsWritten() &&
5797 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005798 return SemaRef.Owned(E->Retain());
5799
Douglas Gregorb98b1992009-08-11 05:31:07 +00005800 // FIXME: we're faking the locations of the commas
5801 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5802 T,
5803 E->getLParenLoc(),
5804 move_arg(Args),
5805 FakeCommaLocs.data(),
5806 E->getRParenLoc());
5807}
Mike Stump1eb44332009-09-09 15:08:12 +00005808
Douglas Gregorb98b1992009-08-11 05:31:07 +00005809template<typename Derived>
5810Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005811TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall454feb92009-12-08 09:21:05 +00005812 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005813 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005814 OwningExprResult Base(SemaRef, (Expr*) 0);
5815 Expr *OldBase;
5816 QualType BaseType;
5817 QualType ObjectType;
5818 if (!E->isImplicitAccess()) {
5819 OldBase = E->getBase();
5820 Base = getDerived().TransformExpr(OldBase);
5821 if (Base.isInvalid())
5822 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005823
John McCallaa81e162009-12-01 22:10:20 +00005824 // Start the member reference and compute the object's type.
5825 Sema::TypeTy *ObjectTy = 0;
Douglas Gregord4dca082010-02-24 18:44:31 +00005826 bool MayBePseudoDestructor = false;
John McCallaa81e162009-12-01 22:10:20 +00005827 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5828 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005829 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005830 ObjectTy,
5831 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005832 if (Base.isInvalid())
5833 return SemaRef.ExprError();
5834
5835 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5836 BaseType = ((Expr*) Base.get())->getType();
5837 } else {
5838 OldBase = 0;
5839 BaseType = getDerived().TransformType(E->getBaseType());
5840 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5841 }
Mike Stump1eb44332009-09-09 15:08:12 +00005842
Douglas Gregor6cd21982009-10-20 05:58:46 +00005843 // Transform the first part of the nested-name-specifier that qualifies
5844 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005845 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005846 = getDerived().TransformFirstQualifierInScope(
5847 E->getFirstQualifierFoundInScope(),
5848 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005849
Douglas Gregora38c6872009-09-03 16:14:30 +00005850 NestedNameSpecifier *Qualifier = 0;
5851 if (E->getQualifier()) {
5852 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5853 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005854 ObjectType,
5855 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005856 if (!Qualifier)
5857 return SemaRef.ExprError();
5858 }
Mike Stump1eb44332009-09-09 15:08:12 +00005859
5860 DeclarationName Name
Douglas Gregordd62b152009-10-19 22:04:39 +00005861 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCallaa81e162009-12-01 22:10:20 +00005862 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00005863 if (!Name)
5864 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005865
John McCallaa81e162009-12-01 22:10:20 +00005866 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005867 // This is a reference to a member without an explicitly-specified
5868 // template argument list. Optimize for this common case.
5869 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005870 Base.get() == OldBase &&
5871 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005872 Qualifier == E->getQualifier() &&
5873 Name == E->getMember() &&
5874 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005875 return SemaRef.Owned(E->Retain());
5876
John McCall865d4472009-11-19 22:55:06 +00005877 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005878 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005879 E->isArrow(),
5880 E->getOperatorLoc(),
5881 Qualifier,
5882 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005883 FirstQualifierInScope,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005884 Name,
5885 E->getMemberLoc(),
John McCall129e2df2009-11-30 22:42:35 +00005886 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005887 }
5888
John McCalld5532b62009-11-23 01:53:49 +00005889 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005890 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005891 TemplateArgumentLoc Loc;
5892 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005893 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005894 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005895 }
Mike Stump1eb44332009-09-09 15:08:12 +00005896
John McCall865d4472009-11-19 22:55:06 +00005897 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005898 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005899 E->isArrow(),
5900 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005901 Qualifier,
5902 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005903 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005904 Name,
5905 E->getMemberLoc(),
5906 &TransArgs);
5907}
5908
5909template<typename Derived>
5910Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005911TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005912 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005913 OwningExprResult Base(SemaRef, (Expr*) 0);
5914 QualType BaseType;
5915 if (!Old->isImplicitAccess()) {
5916 Base = getDerived().TransformExpr(Old->getBase());
5917 if (Base.isInvalid())
5918 return SemaRef.ExprError();
5919 BaseType = ((Expr*) Base.get())->getType();
5920 } else {
5921 BaseType = getDerived().TransformType(Old->getBaseType());
5922 }
John McCall129e2df2009-11-30 22:42:35 +00005923
5924 NestedNameSpecifier *Qualifier = 0;
5925 if (Old->getQualifier()) {
5926 Qualifier
5927 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005928 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005929 if (Qualifier == 0)
5930 return SemaRef.ExprError();
5931 }
5932
5933 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5934 Sema::LookupOrdinaryName);
5935
5936 // Transform all the decls.
5937 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5938 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005939 NamedDecl *InstD = static_cast<NamedDecl*>(
5940 getDerived().TransformDecl(Old->getMemberLoc(),
5941 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005942 if (!InstD) {
5943 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5944 // This can happen because of dependent hiding.
5945 if (isa<UsingShadowDecl>(*I))
5946 continue;
5947 else
5948 return SemaRef.ExprError();
5949 }
John McCall129e2df2009-11-30 22:42:35 +00005950
5951 // Expand using declarations.
5952 if (isa<UsingDecl>(InstD)) {
5953 UsingDecl *UD = cast<UsingDecl>(InstD);
5954 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5955 E = UD->shadow_end(); I != E; ++I)
5956 R.addDecl(*I);
5957 continue;
5958 }
5959
5960 R.addDecl(InstD);
5961 }
5962
5963 R.resolveKind();
5964
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005965 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00005966 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00005967 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005968 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00005969 Old->getMemberLoc(),
5970 Old->getNamingClass()));
5971 if (!NamingClass)
5972 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005973
Douglas Gregor66c45152010-04-27 16:10:10 +00005974 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005975 }
Sean Huntc3021132010-05-05 15:23:54 +00005976
John McCall129e2df2009-11-30 22:42:35 +00005977 TemplateArgumentListInfo TransArgs;
5978 if (Old->hasExplicitTemplateArgs()) {
5979 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5980 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5981 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5982 TemplateArgumentLoc Loc;
5983 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5984 Loc))
5985 return SemaRef.ExprError();
5986 TransArgs.addArgument(Loc);
5987 }
5988 }
John McCallc2233c52010-01-15 08:34:02 +00005989
5990 // FIXME: to do this check properly, we will need to preserve the
5991 // first-qualifier-in-scope here, just in case we had a dependent
5992 // base (and therefore couldn't do the check) and a
5993 // nested-name-qualifier (and therefore could do the lookup).
5994 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00005995
John McCall129e2df2009-11-30 22:42:35 +00005996 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005997 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005998 Old->getOperatorLoc(),
5999 Old->isArrow(),
6000 Qualifier,
6001 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006002 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006003 R,
6004 (Old->hasExplicitTemplateArgs()
6005 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006006}
6007
6008template<typename Derived>
6009Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006010TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006011 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006012}
6013
Mike Stump1eb44332009-09-09 15:08:12 +00006014template<typename Derived>
6015Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006016TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006017 TypeSourceInfo *EncodedTypeInfo
6018 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6019 if (!EncodedTypeInfo)
Douglas Gregorb98b1992009-08-11 05:31:07 +00006020 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006021
Douglas Gregorb98b1992009-08-11 05:31:07 +00006022 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006023 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00006024 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006025
6026 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006027 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006028 E->getRParenLoc());
6029}
Mike Stump1eb44332009-09-09 15:08:12 +00006030
Douglas Gregorb98b1992009-08-11 05:31:07 +00006031template<typename Derived>
6032Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006033TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006034 // Transform arguments.
6035 bool ArgChanged = false;
6036 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
6037 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
6038 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
6039 if (Arg.isInvalid())
6040 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006041
Douglas Gregor92e986e2010-04-22 16:44:27 +00006042 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
6043 Args.push_back(Arg.takeAs<Expr>());
6044 }
6045
6046 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6047 // Class message: transform the receiver type.
6048 TypeSourceInfo *ReceiverTypeInfo
6049 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6050 if (!ReceiverTypeInfo)
6051 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006052
Douglas Gregor92e986e2010-04-22 16:44:27 +00006053 // If nothing changed, just retain the existing message send.
6054 if (!getDerived().AlwaysRebuild() &&
6055 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6056 return SemaRef.Owned(E->Retain());
6057
6058 // Build a new class message send.
6059 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6060 E->getSelector(),
6061 E->getMethodDecl(),
6062 E->getLeftLoc(),
6063 move_arg(Args),
6064 E->getRightLoc());
6065 }
6066
6067 // Instance message: transform the receiver
6068 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6069 "Only class and instance messages may be instantiated");
6070 OwningExprResult Receiver
6071 = getDerived().TransformExpr(E->getInstanceReceiver());
6072 if (Receiver.isInvalid())
6073 return SemaRef.ExprError();
6074
6075 // If nothing changed, just retain the existing message send.
6076 if (!getDerived().AlwaysRebuild() &&
6077 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6078 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006079
Douglas Gregor92e986e2010-04-22 16:44:27 +00006080 // Build a new instance message send.
6081 return getDerived().RebuildObjCMessageExpr(move(Receiver),
6082 E->getSelector(),
6083 E->getMethodDecl(),
6084 E->getLeftLoc(),
6085 move_arg(Args),
6086 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006087}
6088
Mike Stump1eb44332009-09-09 15:08:12 +00006089template<typename Derived>
6090Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006091TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006092 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006093}
6094
Mike Stump1eb44332009-09-09 15:08:12 +00006095template<typename Derived>
6096Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006097TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006098 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006099}
6100
Mike Stump1eb44332009-09-09 15:08:12 +00006101template<typename Derived>
6102Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006103TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006104 // Transform the base expression.
6105 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6106 if (Base.isInvalid())
6107 return SemaRef.ExprError();
6108
6109 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006110
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006111 // If nothing changed, just retain the existing expression.
6112 if (!getDerived().AlwaysRebuild() &&
6113 Base.get() == E->getBase())
6114 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006115
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006116 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6117 E->getLocation(),
6118 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006119}
6120
Mike Stump1eb44332009-09-09 15:08:12 +00006121template<typename Derived>
6122Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006123TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregore3303542010-04-26 20:47:02 +00006124 // Transform the base expression.
6125 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6126 if (Base.isInvalid())
6127 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006128
Douglas Gregore3303542010-04-26 20:47:02 +00006129 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006130
Douglas Gregore3303542010-04-26 20:47:02 +00006131 // If nothing changed, just retain the existing expression.
6132 if (!getDerived().AlwaysRebuild() &&
6133 Base.get() == E->getBase())
6134 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006135
Douglas Gregore3303542010-04-26 20:47:02 +00006136 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6137 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006138}
6139
Mike Stump1eb44332009-09-09 15:08:12 +00006140template<typename Derived>
6141Sema::OwningExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00006142TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00006143 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006144 // If this implicit setter/getter refers to class methods, it cannot have any
6145 // dependent parts. Just retain the existing declaration.
6146 if (E->getInterfaceDecl())
6147 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006148
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006149 // Transform the base expression.
6150 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6151 if (Base.isInvalid())
6152 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006153
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006154 // We don't need to transform the getters/setters; they will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006155
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006156 // If nothing changed, just retain the existing expression.
6157 if (!getDerived().AlwaysRebuild() &&
6158 Base.get() == E->getBase())
6159 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006160
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006161 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6162 E->getGetterMethod(),
6163 E->getType(),
6164 E->getSetterMethod(),
6165 E->getLocation(),
6166 move(Base));
Sean Huntc3021132010-05-05 15:23:54 +00006167
Douglas Gregorb98b1992009-08-11 05:31:07 +00006168}
6169
Mike Stump1eb44332009-09-09 15:08:12 +00006170template<typename Derived>
6171Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006172TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006173 // Can never occur in a dependent context.
Mike Stump1eb44332009-09-09 15:08:12 +00006174 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006175}
6176
Mike Stump1eb44332009-09-09 15:08:12 +00006177template<typename Derived>
6178Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006179TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006180 // Transform the base expression.
6181 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6182 if (Base.isInvalid())
6183 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006184
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006185 // If nothing changed, just retain the existing expression.
6186 if (!getDerived().AlwaysRebuild() &&
6187 Base.get() == E->getBase())
6188 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006189
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006190 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6191 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006192}
6193
Mike Stump1eb44332009-09-09 15:08:12 +00006194template<typename Derived>
6195Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006196TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006197 bool ArgumentChanged = false;
6198 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6199 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6200 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6201 if (SubExpr.isInvalid())
6202 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006203
Douglas Gregorb98b1992009-08-11 05:31:07 +00006204 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6205 SubExprs.push_back(SubExpr.takeAs<Expr>());
6206 }
Mike Stump1eb44332009-09-09 15:08:12 +00006207
Douglas Gregorb98b1992009-08-11 05:31:07 +00006208 if (!getDerived().AlwaysRebuild() &&
6209 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00006210 return SemaRef.Owned(E->Retain());
6211
Douglas Gregorb98b1992009-08-11 05:31:07 +00006212 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6213 move_arg(SubExprs),
6214 E->getRParenLoc());
6215}
6216
Mike Stump1eb44332009-09-09 15:08:12 +00006217template<typename Derived>
6218Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006219TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006220 // FIXME: Implement this!
6221 assert(false && "Cannot transform block expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00006222 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006223}
6224
Mike Stump1eb44332009-09-09 15:08:12 +00006225template<typename Derived>
6226Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006227TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006228 // FIXME: Implement this!
6229 assert(false && "Cannot transform block-related expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00006230 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006231}
Mike Stump1eb44332009-09-09 15:08:12 +00006232
Douglas Gregorb98b1992009-08-11 05:31:07 +00006233//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006234// Type reconstruction
6235//===----------------------------------------------------------------------===//
6236
Mike Stump1eb44332009-09-09 15:08:12 +00006237template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006238QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6239 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006240 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006241 getDerived().getBaseEntity());
6242}
6243
Mike Stump1eb44332009-09-09 15:08:12 +00006244template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006245QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6246 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006247 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006248 getDerived().getBaseEntity());
6249}
6250
Mike Stump1eb44332009-09-09 15:08:12 +00006251template<typename Derived>
6252QualType
John McCall85737a72009-10-30 00:06:24 +00006253TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6254 bool WrittenAsLValue,
6255 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006256 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006257 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006258}
6259
6260template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006261QualType
John McCall85737a72009-10-30 00:06:24 +00006262TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6263 QualType ClassType,
6264 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006265 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006266 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006267}
6268
6269template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006270QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006271TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6272 ArrayType::ArraySizeModifier SizeMod,
6273 const llvm::APInt *Size,
6274 Expr *SizeExpr,
6275 unsigned IndexTypeQuals,
6276 SourceRange BracketsRange) {
6277 if (SizeExpr || !Size)
6278 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6279 IndexTypeQuals, BracketsRange,
6280 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006281
6282 QualType Types[] = {
6283 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6284 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6285 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006286 };
6287 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6288 QualType SizeType;
6289 for (unsigned I = 0; I != NumTypes; ++I)
6290 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6291 SizeType = Types[I];
6292 break;
6293 }
Mike Stump1eb44332009-09-09 15:08:12 +00006294
Douglas Gregor577f75a2009-08-04 16:50:30 +00006295 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006296 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006297 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006298 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006299}
Mike Stump1eb44332009-09-09 15:08:12 +00006300
Douglas Gregor577f75a2009-08-04 16:50:30 +00006301template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006302QualType
6303TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006304 ArrayType::ArraySizeModifier SizeMod,
6305 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006306 unsigned IndexTypeQuals,
6307 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006308 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006309 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006310}
6311
6312template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006313QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006314TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006315 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006316 unsigned IndexTypeQuals,
6317 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006318 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006319 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006320}
Mike Stump1eb44332009-09-09 15:08:12 +00006321
Douglas Gregor577f75a2009-08-04 16:50:30 +00006322template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006323QualType
6324TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006325 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006326 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006327 unsigned IndexTypeQuals,
6328 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006329 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006330 SizeExpr.takeAs<Expr>(),
6331 IndexTypeQuals, BracketsRange);
6332}
6333
6334template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006335QualType
6336TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006337 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006338 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006339 unsigned IndexTypeQuals,
6340 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006341 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006342 SizeExpr.takeAs<Expr>(),
6343 IndexTypeQuals, BracketsRange);
6344}
6345
6346template<typename Derived>
6347QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner788b0fd2010-06-23 06:00:24 +00006348 unsigned NumElements,
6349 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006350 // FIXME: semantic checking!
Chris Lattner788b0fd2010-06-23 06:00:24 +00006351 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006352}
Mike Stump1eb44332009-09-09 15:08:12 +00006353
Douglas Gregor577f75a2009-08-04 16:50:30 +00006354template<typename Derived>
6355QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6356 unsigned NumElements,
6357 SourceLocation AttributeLoc) {
6358 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6359 NumElements, true);
6360 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00006361 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006362 AttributeLoc);
6363 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6364 AttributeLoc);
6365}
Mike Stump1eb44332009-09-09 15:08:12 +00006366
Douglas Gregor577f75a2009-08-04 16:50:30 +00006367template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006368QualType
6369TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006370 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006371 SourceLocation AttributeLoc) {
6372 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6373}
Mike Stump1eb44332009-09-09 15:08:12 +00006374
Douglas Gregor577f75a2009-08-04 16:50:30 +00006375template<typename Derived>
6376QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006377 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006378 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006379 bool Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006380 unsigned Quals) {
Mike Stump1eb44332009-09-09 15:08:12 +00006381 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006382 Quals,
6383 getDerived().getBaseLocation(),
6384 getDerived().getBaseEntity());
6385}
Mike Stump1eb44332009-09-09 15:08:12 +00006386
Douglas Gregor577f75a2009-08-04 16:50:30 +00006387template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006388QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6389 return SemaRef.Context.getFunctionNoProtoType(T);
6390}
6391
6392template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006393QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6394 assert(D && "no decl found");
6395 if (D->isInvalidDecl()) return QualType();
6396
Douglas Gregor92e986e2010-04-22 16:44:27 +00006397 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006398 TypeDecl *Ty;
6399 if (isa<UsingDecl>(D)) {
6400 UsingDecl *Using = cast<UsingDecl>(D);
6401 assert(Using->isTypeName() &&
6402 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6403
6404 // A valid resolved using typename decl points to exactly one type decl.
6405 assert(++Using->shadow_begin() == Using->shadow_end());
6406 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006407
John McCalled976492009-12-04 22:46:56 +00006408 } else {
6409 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6410 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6411 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6412 }
6413
6414 return SemaRef.Context.getTypeDeclType(Ty);
6415}
6416
6417template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00006418QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006419 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6420}
6421
6422template<typename Derived>
6423QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6424 return SemaRef.Context.getTypeOfType(Underlying);
6425}
6426
6427template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00006428QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006429 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6430}
6431
6432template<typename Derived>
6433QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006434 TemplateName Template,
6435 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006436 const TemplateArgumentListInfo &TemplateArgs) {
6437 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006438}
Mike Stump1eb44332009-09-09 15:08:12 +00006439
Douglas Gregordcee1a12009-08-06 05:28:30 +00006440template<typename Derived>
6441NestedNameSpecifier *
6442TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6443 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006444 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006445 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006446 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006447 CXXScopeSpec SS;
6448 // FIXME: The source location information is all wrong.
6449 SS.setRange(Range);
6450 SS.setScopeRep(Prefix);
6451 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006452 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006453 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006454 ObjectType,
6455 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006456 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006457}
6458
6459template<typename Derived>
6460NestedNameSpecifier *
6461TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6462 SourceRange Range,
6463 NamespaceDecl *NS) {
6464 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6465}
6466
6467template<typename Derived>
6468NestedNameSpecifier *
6469TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6470 SourceRange Range,
6471 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006472 QualType T) {
6473 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006474 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006475 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006476 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6477 T.getTypePtr());
6478 }
Mike Stump1eb44332009-09-09 15:08:12 +00006479
Douglas Gregordcee1a12009-08-06 05:28:30 +00006480 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6481 return 0;
6482}
Mike Stump1eb44332009-09-09 15:08:12 +00006483
Douglas Gregord1067e52009-08-06 06:41:21 +00006484template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006485TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006486TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6487 bool TemplateKW,
6488 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006489 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006490 Template);
6491}
6492
6493template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006494TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006495TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006496 const IdentifierInfo &II,
6497 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006498 CXXScopeSpec SS;
6499 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00006500 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006501 UnqualifiedId Name;
6502 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00006503 Sema::TemplateTy Template;
6504 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6505 /*FIXME:*/getDerived().getBaseLocation(),
6506 SS,
6507 Name,
6508 ObjectType.getAsOpaquePtr(),
6509 /*EnteringContext=*/false,
6510 Template);
6511 return Template.template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00006512}
Mike Stump1eb44332009-09-09 15:08:12 +00006513
Douglas Gregorb98b1992009-08-11 05:31:07 +00006514template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006515TemplateName
6516TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6517 OverloadedOperatorKind Operator,
6518 QualType ObjectType) {
6519 CXXScopeSpec SS;
6520 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6521 SS.setScopeRep(Qualifier);
6522 UnqualifiedId Name;
6523 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6524 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6525 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00006526 Sema::TemplateTy Template;
6527 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006528 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006529 SS,
6530 Name,
6531 ObjectType.getAsOpaquePtr(),
6532 /*EnteringContext=*/false,
6533 Template);
6534 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006535}
Sean Huntc3021132010-05-05 15:23:54 +00006536
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006537template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006538Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6540 SourceLocation OpLoc,
6541 ExprArg Callee,
6542 ExprArg First,
6543 ExprArg Second) {
6544 Expr *FirstExpr = (Expr *)First.get();
6545 Expr *SecondExpr = (Expr *)Second.get();
John McCallba135432009-11-21 08:51:07 +00006546 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006547 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006548
Douglas Gregorb98b1992009-08-11 05:31:07 +00006549 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006550 if (Op == OO_Subscript) {
6551 if (!FirstExpr->getType()->isOverloadableType() &&
6552 !SecondExpr->getType()->isOverloadableType())
6553 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCallba135432009-11-21 08:51:07 +00006554 CalleeExpr->getLocStart(),
Sebastian Redlf322ed62009-10-29 20:17:01 +00006555 move(Second), OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006556 } else if (Op == OO_Arrow) {
6557 // -> is never a builtin operation.
6558 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006559 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006560 if (!FirstExpr->getType()->isOverloadableType()) {
6561 // The argument is not of overloadable type, so try to create a
6562 // built-in unary operation.
Mike Stump1eb44332009-09-09 15:08:12 +00006563 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006564 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006565
Douglas Gregorb98b1992009-08-11 05:31:07 +00006566 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6567 }
6568 } else {
Mike Stump1eb44332009-09-09 15:08:12 +00006569 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006570 !SecondExpr->getType()->isOverloadableType()) {
6571 // Neither of the arguments is an overloadable type, so try to
6572 // create a built-in binary operation.
6573 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00006574 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006575 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6576 if (Result.isInvalid())
6577 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006578
Douglas Gregorb98b1992009-08-11 05:31:07 +00006579 First.release();
6580 Second.release();
6581 return move(Result);
6582 }
6583 }
Mike Stump1eb44332009-09-09 15:08:12 +00006584
6585 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006586 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006587 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006588
John McCallba135432009-11-21 08:51:07 +00006589 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6590 assert(ULE->requiresADL());
6591
6592 // FIXME: Do we have to check
6593 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006594 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006595 } else {
John McCall6e266892010-01-26 03:27:55 +00006596 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006597 }
Mike Stump1eb44332009-09-09 15:08:12 +00006598
Douglas Gregorb98b1992009-08-11 05:31:07 +00006599 // Add any functions found via argument-dependent lookup.
6600 Expr *Args[2] = { FirstExpr, SecondExpr };
6601 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006602
Douglas Gregorb98b1992009-08-11 05:31:07 +00006603 // Create the overloaded operator invocation for unary operators.
6604 if (NumArgs == 1 || isPostIncDec) {
Mike Stump1eb44332009-09-09 15:08:12 +00006605 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6607 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6608 }
Mike Stump1eb44332009-09-09 15:08:12 +00006609
Sebastian Redlf322ed62009-10-29 20:17:01 +00006610 if (Op == OO_Subscript)
John McCallba135432009-11-21 08:51:07 +00006611 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6612 OpLoc,
6613 move(First),
6614 move(Second));
Sebastian Redlf322ed62009-10-29 20:17:01 +00006615
Douglas Gregorb98b1992009-08-11 05:31:07 +00006616 // Create the overloaded operator invocation for binary operators.
Mike Stump1eb44332009-09-09 15:08:12 +00006617 BinaryOperator::Opcode Opc =
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00006619 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6621 if (Result.isInvalid())
6622 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006623
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624 First.release();
6625 Second.release();
Mike Stump1eb44332009-09-09 15:08:12 +00006626 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627}
Mike Stump1eb44332009-09-09 15:08:12 +00006628
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006629template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00006630Sema::OwningExprResult
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006631TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6632 SourceLocation OperatorLoc,
6633 bool isArrow,
6634 NestedNameSpecifier *Qualifier,
6635 SourceRange QualifierRange,
6636 TypeSourceInfo *ScopeType,
6637 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006638 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006639 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006640 CXXScopeSpec SS;
6641 if (Qualifier) {
6642 SS.setRange(QualifierRange);
6643 SS.setScopeRep(Qualifier);
6644 }
6645
6646 Expr *BaseE = (Expr *)Base.get();
6647 QualType BaseType = BaseE->getType();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006648 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006649 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006650 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006651 !BaseType->getAs<PointerType>()->getPointeeType()
6652 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006653 // This pseudo-destructor expression is still a pseudo-destructor.
6654 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6655 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006656 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006657 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006658 /*FIXME?*/true);
6659 }
Sean Huntc3021132010-05-05 15:23:54 +00006660
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006661 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006662 DeclarationName Name
6663 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6664 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
Sean Huntc3021132010-05-05 15:23:54 +00006665
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006666 // FIXME: the ScopeType should be tacked onto SS.
Sean Huntc3021132010-05-05 15:23:54 +00006667
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006668 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6669 OperatorLoc, isArrow,
6670 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006671 Name, Destroyed.getLocation(),
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006672 /*TemplateArgs*/ 0);
6673}
6674
Douglas Gregor577f75a2009-08-04 16:50:30 +00006675} // end namespace clang
6676
6677#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H