blob: 26caaadd499196e5f8e0fb3440d459898cf9ec30 [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,
445 bool IsAltiVec, bool IsPixel);
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.
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000536 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
537 NestedNameSpecifier *NNS, QualType T) {
Douglas Gregorae628892010-02-13 06:05:33 +0000538 if (NNS->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000539 // If the name is still dependent, just build a new dependent name type.
Douglas Gregorae628892010-02-13 06:05:33 +0000540 CXXScopeSpec SS;
541 SS.setScopeRep(NNS);
542 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000543 return SemaRef.Context.getDependentNameType(Keyword, NNS,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000544 cast<TemplateSpecializationType>(T));
Douglas Gregorae628892010-02-13 06:05:33 +0000545 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000546
547 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000548 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000549
550 /// \brief Build a new typename type that refers to an identifier.
551 ///
552 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000553 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000554 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000555 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000556 NestedNameSpecifier *NNS,
557 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000558 SourceLocation KeywordLoc,
559 SourceRange NNSRange,
560 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000561 CXXScopeSpec SS;
562 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000563 SS.setRange(NNSRange);
564
Douglas Gregor40336422010-03-31 22:19:08 +0000565 if (NNS->isDependent()) {
566 // If the name is still dependent, just build a new dependent name type.
567 if (!SemaRef.computeDeclContext(SS))
568 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
569 }
570
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000571 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000572 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
573 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000574
575 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
576
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000577 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000578 // into a non-dependent elaborated-type-specifier. Find the tag we're
579 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000580 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000581 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
582 if (!DC)
583 return QualType();
584
John McCall56138762010-05-27 06:40:31 +0000585 if (SemaRef.RequireCompleteDeclContext(SS, DC))
586 return QualType();
587
Douglas Gregor40336422010-03-31 22:19:08 +0000588 TagDecl *Tag = 0;
589 SemaRef.LookupQualifiedName(Result, DC);
590 switch (Result.getResultKind()) {
591 case LookupResult::NotFound:
592 case LookupResult::NotFoundInCurrentInstantiation:
593 break;
Sean Huntc3021132010-05-05 15:23:54 +0000594
Douglas Gregor40336422010-03-31 22:19:08 +0000595 case LookupResult::Found:
596 Tag = Result.getAsSingle<TagDecl>();
597 break;
Sean Huntc3021132010-05-05 15:23:54 +0000598
Douglas Gregor40336422010-03-31 22:19:08 +0000599 case LookupResult::FoundOverloaded:
600 case LookupResult::FoundUnresolvedValue:
601 llvm_unreachable("Tag lookup cannot find non-tags");
602 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000603
Douglas Gregor40336422010-03-31 22:19:08 +0000604 case LookupResult::Ambiguous:
605 // Let the LookupResult structure handle ambiguities.
606 return QualType();
607 }
608
609 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000610 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000611 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000612 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000613 return QualType();
614 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000615
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000616 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
617 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000618 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
619 return QualType();
620 }
621
622 // Build the elaborated-type-specifier type.
623 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000624 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000625 }
Mike Stump1eb44332009-09-09 15:08:12 +0000626
Douglas Gregordcee1a12009-08-06 05:28:30 +0000627 /// \brief Build a new nested-name-specifier given the prefix and an
628 /// identifier that names the next step in the nested-name-specifier.
629 ///
630 /// By default, performs semantic analysis when building the new
631 /// nested-name-specifier. Subclasses may override this routine to provide
632 /// different behavior.
633 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
634 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000635 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000636 QualType ObjectType,
637 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000638
639 /// \brief Build a new nested-name-specifier given the prefix and the
640 /// namespace named in the next step in the nested-name-specifier.
641 ///
642 /// By default, performs semantic analysis when building the new
643 /// nested-name-specifier. Subclasses may override this routine to provide
644 /// different behavior.
645 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
646 SourceRange Range,
647 NamespaceDecl *NS);
648
649 /// \brief Build a new nested-name-specifier given the prefix and the
650 /// type named in the next step in the nested-name-specifier.
651 ///
652 /// By default, performs semantic analysis when building the new
653 /// nested-name-specifier. Subclasses may override this routine to provide
654 /// different behavior.
655 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
656 SourceRange Range,
657 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000658 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000659
660 /// \brief Build a new template name given a nested name specifier, a flag
661 /// indicating whether the "template" keyword was provided, and the template
662 /// that the template name refers to.
663 ///
664 /// By default, builds the new template name directly. Subclasses may override
665 /// this routine to provide different behavior.
666 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
667 bool TemplateKW,
668 TemplateDecl *Template);
669
Douglas Gregord1067e52009-08-06 06:41:21 +0000670 /// \brief Build a new template name given a nested name specifier and the
671 /// name that is referred to as a template.
672 ///
673 /// By default, performs semantic analysis to determine whether the name can
674 /// be resolved to a specific template, then builds the appropriate kind of
675 /// template name. Subclasses may override this routine to provide different
676 /// behavior.
677 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000678 const IdentifierInfo &II,
679 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000680
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000681 /// \brief Build a new template name given a nested name specifier and the
682 /// overloaded operator name that is referred to as a template.
683 ///
684 /// By default, performs semantic analysis to determine whether the name can
685 /// be resolved to a specific template, then builds the appropriate kind of
686 /// template name. Subclasses may override this routine to provide different
687 /// behavior.
688 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
689 OverloadedOperatorKind Operator,
690 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000691
Douglas Gregor43959a92009-08-20 07:17:43 +0000692 /// \brief Build a new compound statement.
693 ///
694 /// By default, performs semantic analysis to build the new statement.
695 /// Subclasses may override this routine to provide different behavior.
696 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
697 MultiStmtArg Statements,
698 SourceLocation RBraceLoc,
699 bool IsStmtExpr) {
700 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
701 IsStmtExpr);
702 }
703
704 /// \brief Build a new case statement.
705 ///
706 /// By default, performs semantic analysis to build the new statement.
707 /// Subclasses may override this routine to provide different behavior.
708 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
709 ExprArg LHS,
710 SourceLocation EllipsisLoc,
711 ExprArg RHS,
712 SourceLocation ColonLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000713 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregor43959a92009-08-20 07:17:43 +0000714 ColonLoc);
715 }
Mike Stump1eb44332009-09-09 15:08:12 +0000716
Douglas Gregor43959a92009-08-20 07:17:43 +0000717 /// \brief Attach the body to a new case statement.
718 ///
719 /// By default, performs semantic analysis to build the new statement.
720 /// Subclasses may override this routine to provide different behavior.
721 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
722 getSema().ActOnCaseStmtBody(S.get(), move(Body));
723 return move(S);
724 }
Mike Stump1eb44332009-09-09 15:08:12 +0000725
Douglas Gregor43959a92009-08-20 07:17:43 +0000726 /// \brief Build a new default statement.
727 ///
728 /// By default, performs semantic analysis to build the new statement.
729 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000730 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000731 SourceLocation ColonLoc,
732 StmtArg SubStmt) {
Mike Stump1eb44332009-09-09 15:08:12 +0000733 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregor43959a92009-08-20 07:17:43 +0000734 /*CurScope=*/0);
735 }
Mike Stump1eb44332009-09-09 15:08:12 +0000736
Douglas Gregor43959a92009-08-20 07:17:43 +0000737 /// \brief Build a new label statement.
738 ///
739 /// By default, performs semantic analysis to build the new statement.
740 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000741 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000742 IdentifierInfo *Id,
743 SourceLocation ColonLoc,
744 StmtArg SubStmt) {
745 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
746 }
Mike Stump1eb44332009-09-09 15:08:12 +0000747
Douglas Gregor43959a92009-08-20 07:17:43 +0000748 /// \brief Build a new "if" statement.
749 ///
750 /// By default, performs semantic analysis to build the new statement.
751 /// Subclasses may override this routine to provide different behavior.
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000752 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Sean Huntc3021132010-05-05 15:23:54 +0000753 VarDecl *CondVar, StmtArg Then,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000754 SourceLocation ElseLoc, StmtArg Else) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000755 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000756 move(Then), ElseLoc, move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +0000757 }
Mike Stump1eb44332009-09-09 15:08:12 +0000758
Douglas Gregor43959a92009-08-20 07:17:43 +0000759 /// \brief Start building a new switch statement.
760 ///
761 /// By default, performs semantic analysis to build the new statement.
762 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor586596f2010-05-06 17:25:47 +0000763 OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
764 Sema::ExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000765 VarDecl *CondVar) {
Douglas Gregor586596f2010-05-06 17:25:47 +0000766 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond),
767 DeclPtrTy::make(CondVar));
Douglas Gregor43959a92009-08-20 07:17:43 +0000768 }
Mike Stump1eb44332009-09-09 15:08:12 +0000769
Douglas Gregor43959a92009-08-20 07:17:43 +0000770 /// \brief Attach the body to the switch statement.
771 ///
772 /// By default, performs semantic analysis to build the new statement.
773 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000774 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000775 StmtArg Switch, StmtArg Body) {
776 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
777 move(Body));
778 }
779
780 /// \brief Build a new while statement.
781 ///
782 /// By default, performs semantic analysis to build the new statement.
783 /// Subclasses may override this routine to provide different behavior.
784 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000785 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000786 VarDecl *CondVar,
Douglas Gregor43959a92009-08-20 07:17:43 +0000787 StmtArg Body) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000788 return getSema().ActOnWhileStmt(WhileLoc, Cond,
Douglas Gregor586596f2010-05-06 17:25:47 +0000789 DeclPtrTy::make(CondVar), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000790 }
Mike Stump1eb44332009-09-09 15:08:12 +0000791
Douglas Gregor43959a92009-08-20 07:17:43 +0000792 /// \brief Build a new do-while statement.
793 ///
794 /// By default, performs semantic analysis to build the new statement.
795 /// Subclasses may override this routine to provide different behavior.
796 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
797 SourceLocation WhileLoc,
798 SourceLocation LParenLoc,
799 ExprArg Cond,
800 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000801 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000802 move(Cond), RParenLoc);
803 }
804
805 /// \brief Build a new for statement.
806 ///
807 /// By default, performs semantic analysis to build the new statement.
808 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000809 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000810 SourceLocation LParenLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000811 StmtArg Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000812 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000813 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000814 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000815 DeclPtrTy::make(CondVar),
816 Inc, RParenLoc, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000817 }
Mike Stump1eb44332009-09-09 15:08:12 +0000818
Douglas Gregor43959a92009-08-20 07:17:43 +0000819 /// \brief Build a new goto statement.
820 ///
821 /// By default, performs semantic analysis to build the new statement.
822 /// Subclasses may override this routine to provide different behavior.
823 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
824 SourceLocation LabelLoc,
825 LabelStmt *Label) {
826 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
827 }
828
829 /// \brief Build a new indirect goto statement.
830 ///
831 /// By default, performs semantic analysis to build the new statement.
832 /// Subclasses may override this routine to provide different behavior.
833 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
834 SourceLocation StarLoc,
835 ExprArg Target) {
836 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
837 }
Mike Stump1eb44332009-09-09 15:08:12 +0000838
Douglas Gregor43959a92009-08-20 07:17:43 +0000839 /// \brief Build a new return statement.
840 ///
841 /// By default, performs semantic analysis to build the new statement.
842 /// Subclasses may override this routine to provide different behavior.
843 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
844 ExprArg Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000845
Douglas Gregor43959a92009-08-20 07:17:43 +0000846 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
847 }
Mike Stump1eb44332009-09-09 15:08:12 +0000848
Douglas Gregor43959a92009-08-20 07:17:43 +0000849 /// \brief Build a new declaration statement.
850 ///
851 /// By default, performs semantic analysis to build the new statement.
852 /// Subclasses may override this routine to provide different behavior.
853 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000854 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000855 SourceLocation EndLoc) {
856 return getSema().Owned(
857 new (getSema().Context) DeclStmt(
858 DeclGroupRef::Create(getSema().Context,
859 Decls, NumDecls),
860 StartLoc, EndLoc));
861 }
Mike Stump1eb44332009-09-09 15:08:12 +0000862
Anders Carlsson703e3942010-01-24 05:50:09 +0000863 /// \brief Build a new inline asm 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 RebuildAsmStmt(SourceLocation AsmLoc,
868 bool IsSimple,
869 bool IsVolatile,
870 unsigned NumOutputs,
871 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000872 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000873 MultiExprArg Constraints,
874 MultiExprArg Exprs,
875 ExprArg AsmString,
876 MultiExprArg Clobbers,
877 SourceLocation RParenLoc,
878 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000879 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000880 NumInputs, Names, move(Constraints),
881 move(Exprs), move(AsmString), move(Clobbers),
882 RParenLoc, MSAsm);
883 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000884
885 /// \brief Build a new Objective-C @try statement.
886 ///
887 /// By default, performs semantic analysis to build the new statement.
888 /// Subclasses may override this routine to provide different behavior.
889 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
890 StmtArg TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000891 MultiStmtArg CatchStmts,
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000892 StmtArg Finally) {
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000893 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000894 move(Finally));
895 }
896
Douglas Gregorbe270a02010-04-26 17:57:08 +0000897 /// \brief Rebuild an Objective-C exception declaration.
898 ///
899 /// By default, performs semantic analysis to build the new declaration.
900 /// Subclasses may override this routine to provide different behavior.
901 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
902 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +0000903 return getSema().BuildObjCExceptionDecl(TInfo, T,
904 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +0000905 ExceptionDecl->getLocation());
906 }
Sean Huntc3021132010-05-05 15:23:54 +0000907
Douglas Gregorbe270a02010-04-26 17:57:08 +0000908 /// \brief Build a new Objective-C @catch statement.
909 ///
910 /// By default, performs semantic analysis to build the new statement.
911 /// Subclasses may override this routine to provide different behavior.
912 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
913 SourceLocation RParenLoc,
914 VarDecl *Var,
915 StmtArg Body) {
916 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
917 Sema::DeclPtrTy::make(Var),
918 move(Body));
919 }
Sean Huntc3021132010-05-05 15:23:54 +0000920
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000921 /// \brief Build a new Objective-C @finally statement.
922 ///
923 /// By default, performs semantic analysis to build the new statement.
924 /// Subclasses may override this routine to provide different behavior.
925 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
926 StmtArg Body) {
927 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
928 }
Sean Huntc3021132010-05-05 15:23:54 +0000929
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000930 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +0000931 ///
932 /// By default, performs semantic analysis to build the new statement.
933 /// Subclasses may override this routine to provide different behavior.
934 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
935 ExprArg Operand) {
936 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
937 }
Sean Huntc3021132010-05-05 15:23:54 +0000938
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000939 /// \brief Build a new Objective-C @synchronized statement.
940 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000941 /// By default, performs semantic analysis to build the new statement.
942 /// Subclasses may override this routine to provide different behavior.
943 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
944 ExprArg Object,
945 StmtArg Body) {
946 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
947 move(Body));
948 }
Douglas Gregorc3203e72010-04-22 23:10:45 +0000949
950 /// \brief Build a new Objective-C fast enumeration statement.
951 ///
952 /// By default, performs semantic analysis to build the new statement.
953 /// Subclasses may override this routine to provide different behavior.
954 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
955 SourceLocation LParenLoc,
956 StmtArg Element,
957 ExprArg Collection,
958 SourceLocation RParenLoc,
959 StmtArg Body) {
960 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
Sean Huntc3021132010-05-05 15:23:54 +0000961 move(Element),
Douglas Gregorc3203e72010-04-22 23:10:45 +0000962 move(Collection),
963 RParenLoc,
964 move(Body));
965 }
Sean Huntc3021132010-05-05 15:23:54 +0000966
Douglas Gregor43959a92009-08-20 07:17:43 +0000967 /// \brief Build a new C++ exception declaration.
968 ///
969 /// By default, performs semantic analysis to build the new decaration.
970 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000971 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000972 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000973 IdentifierInfo *Name,
974 SourceLocation Loc,
975 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000976 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000977 TypeRange);
978 }
979
980 /// \brief Build a new C++ catch statement.
981 ///
982 /// By default, performs semantic analysis to build the new statement.
983 /// Subclasses may override this routine to provide different behavior.
984 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
985 VarDecl *ExceptionDecl,
986 StmtArg Handler) {
987 return getSema().Owned(
Mike Stump1eb44332009-09-09 15:08:12 +0000988 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregor43959a92009-08-20 07:17:43 +0000989 Handler.takeAs<Stmt>()));
990 }
Mike Stump1eb44332009-09-09 15:08:12 +0000991
Douglas Gregor43959a92009-08-20 07:17:43 +0000992 /// \brief Build a new C++ try statement.
993 ///
994 /// By default, performs semantic analysis to build the new statement.
995 /// Subclasses may override this routine to provide different behavior.
996 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
997 StmtArg TryBlock,
998 MultiStmtArg Handlers) {
999 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
1000 }
Mike Stump1eb44332009-09-09 15:08:12 +00001001
Douglas Gregorb98b1992009-08-11 05:31:07 +00001002 /// \brief Build a new expression that references a declaration.
1003 ///
1004 /// By default, performs semantic analysis to build the new expression.
1005 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001006 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1007 LookupResult &R,
1008 bool RequiresADL) {
1009 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1010 }
1011
1012
1013 /// \brief Build a new expression that references a declaration.
1014 ///
1015 /// By default, performs semantic analysis to build the new expression.
1016 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora2813ce2009-10-23 18:54:35 +00001017 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1018 SourceRange QualifierRange,
John McCalldbd872f2009-12-08 09:08:17 +00001019 ValueDecl *VD, SourceLocation Loc,
1020 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001021 CXXScopeSpec SS;
1022 SS.setScopeRep(Qualifier);
1023 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001024
1025 // FIXME: loses template args.
Sean Huntc3021132010-05-05 15:23:54 +00001026
John McCalldbd872f2009-12-08 09:08:17 +00001027 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001028 }
Mike Stump1eb44332009-09-09 15:08:12 +00001029
Douglas Gregorb98b1992009-08-11 05:31:07 +00001030 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001031 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001032 /// By default, performs semantic analysis to build the new expression.
1033 /// Subclasses may override this routine to provide different behavior.
1034 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1035 SourceLocation RParen) {
1036 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1037 }
1038
Douglas Gregora71d8192009-09-04 17:36:40 +00001039 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001040 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001041 /// By default, performs semantic analysis to build the new expression.
1042 /// Subclasses may override this routine to provide different behavior.
1043 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1044 SourceLocation OperatorLoc,
1045 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001046 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001047 SourceRange QualifierRange,
1048 TypeSourceInfo *ScopeType,
1049 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001050 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001051 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001052
Douglas Gregorb98b1992009-08-11 05:31:07 +00001053 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001054 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001055 /// By default, performs semantic analysis to build the new expression.
1056 /// Subclasses may override this routine to provide different behavior.
1057 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1058 UnaryOperator::Opcode Opc,
1059 ExprArg SubExpr) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001060 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001061 }
Mike Stump1eb44332009-09-09 15:08:12 +00001062
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001063 /// \brief Build a new builtin offsetof expression.
1064 ///
1065 /// By default, performs semantic analysis to build the new expression.
1066 /// Subclasses may override this routine to provide different behavior.
1067 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1068 TypeSourceInfo *Type,
1069 Action::OffsetOfComponent *Components,
1070 unsigned NumComponents,
1071 SourceLocation RParenLoc) {
1072 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1073 NumComponents, RParenLoc);
1074 }
Sean Huntc3021132010-05-05 15:23:54 +00001075
Douglas Gregorb98b1992009-08-11 05:31:07 +00001076 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001077 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001078 /// By default, performs semantic analysis to build the new expression.
1079 /// Subclasses may override this routine to provide different behavior.
John McCalla93c9342009-12-07 02:54:59 +00001080 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001081 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001082 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001083 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001084 }
1085
Mike Stump1eb44332009-09-09 15:08:12 +00001086 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001087 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001088 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001089 /// By default, performs semantic analysis to build the new expression.
1090 /// Subclasses may override this routine to provide different behavior.
1091 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1092 bool isSizeOf, SourceRange R) {
Mike Stump1eb44332009-09-09 15:08:12 +00001093 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001094 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1095 OpLoc, isSizeOf, R);
1096 if (Result.isInvalid())
1097 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001098
Douglas Gregorb98b1992009-08-11 05:31:07 +00001099 SubExpr.release();
1100 return move(Result);
1101 }
Mike Stump1eb44332009-09-09 15:08:12 +00001102
Douglas Gregorb98b1992009-08-11 05:31:07 +00001103 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001104 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001105 /// By default, performs semantic analysis to build the new expression.
1106 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001107 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001108 SourceLocation LBracketLoc,
1109 ExprArg RHS,
1110 SourceLocation RBracketLoc) {
1111 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump1eb44332009-09-09 15:08:12 +00001112 LBracketLoc, move(RHS),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001113 RBracketLoc);
1114 }
1115
1116 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001117 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001118 /// By default, performs semantic analysis to build the new expression.
1119 /// Subclasses may override this routine to provide different behavior.
1120 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1121 MultiExprArg Args,
1122 SourceLocation *CommaLocs,
1123 SourceLocation RParenLoc) {
1124 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1125 move(Args), CommaLocs, RParenLoc);
1126 }
1127
1128 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001129 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001130 /// By default, performs semantic analysis to build the new expression.
1131 /// Subclasses may override this routine to provide different behavior.
1132 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001133 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001134 NestedNameSpecifier *Qualifier,
1135 SourceRange QualifierRange,
1136 SourceLocation MemberLoc,
Eli Friedmanf595cc42009-12-04 06:40:45 +00001137 ValueDecl *Member,
John McCall6bb80172010-03-30 21:47:33 +00001138 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001139 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +00001140 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001141 if (!Member->getDeclName()) {
1142 // We have a reference to an unnamed field.
1143 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +00001144
Douglas Gregor83a56c42009-12-24 20:02:50 +00001145 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall6bb80172010-03-30 21:47:33 +00001146 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1147 FoundDecl, Member))
Douglas Gregor83a56c42009-12-24 20:02:50 +00001148 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001149
Mike Stump1eb44332009-09-09 15:08:12 +00001150 MemberExpr *ME =
Douglas Gregor83a56c42009-12-24 20:02:50 +00001151 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlssond8b285f2009-09-01 04:26:58 +00001152 Member, MemberLoc,
1153 cast<FieldDecl>(Member)->getType());
1154 return getSema().Owned(ME);
1155 }
Mike Stump1eb44332009-09-09 15:08:12 +00001156
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001157 CXXScopeSpec SS;
1158 if (Qualifier) {
1159 SS.setRange(QualifierRange);
1160 SS.setScopeRep(Qualifier);
1161 }
1162
John McCallaa81e162009-12-01 22:10:20 +00001163 QualType BaseType = ((Expr*) Base.get())->getType();
1164
John McCall6bb80172010-03-30 21:47:33 +00001165 // FIXME: this involves duplicating earlier analysis in a lot of
1166 // cases; we should avoid this when possible.
John McCallc2233c52010-01-15 08:34:02 +00001167 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1168 Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001169 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001170 R.resolveKind();
1171
John McCallaa81e162009-12-01 22:10:20 +00001172 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1173 OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001174 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001175 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001176 }
Mike Stump1eb44332009-09-09 15:08:12 +00001177
Douglas Gregorb98b1992009-08-11 05:31:07 +00001178 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001179 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001180 /// By default, performs semantic analysis to build the new expression.
1181 /// Subclasses may override this routine to provide different behavior.
1182 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1183 BinaryOperator::Opcode Opc,
1184 ExprArg LHS, ExprArg RHS) {
Sean Huntc3021132010-05-05 15:23:54 +00001185 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001186 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregorb98b1992009-08-11 05:31:07 +00001187 }
1188
1189 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001190 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001191 /// By default, performs semantic analysis to build the new expression.
1192 /// Subclasses may override this routine to provide different behavior.
1193 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1194 SourceLocation QuestionLoc,
1195 ExprArg LHS,
1196 SourceLocation ColonLoc,
1197 ExprArg RHS) {
Mike Stump1eb44332009-09-09 15:08:12 +00001198 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001199 move(LHS), move(RHS));
1200 }
1201
Douglas Gregorb98b1992009-08-11 05:31:07 +00001202 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001203 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001204 /// By default, performs semantic analysis to build the new expression.
1205 /// Subclasses may override this routine to provide different behavior.
John McCall9d125032010-01-15 18:39:57 +00001206 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1207 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001208 SourceLocation RParenLoc,
1209 ExprArg SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001210 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1211 move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001212 }
Mike Stump1eb44332009-09-09 15:08:12 +00001213
Douglas Gregorb98b1992009-08-11 05:31:07 +00001214 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001215 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001216 /// By default, performs semantic analysis to build the new expression.
1217 /// Subclasses may override this routine to provide different behavior.
1218 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001219 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001220 SourceLocation RParenLoc,
1221 ExprArg Init) {
John McCall42f56b52010-01-18 19:35:47 +00001222 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1223 move(Init));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001224 }
Mike Stump1eb44332009-09-09 15:08:12 +00001225
Douglas Gregorb98b1992009-08-11 05:31:07 +00001226 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001227 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001228 /// By default, performs semantic analysis to build the new expression.
1229 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001230 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001231 SourceLocation OpLoc,
1232 SourceLocation AccessorLoc,
1233 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001234
John McCall129e2df2009-11-30 22:42:35 +00001235 CXXScopeSpec SS;
John McCallaa81e162009-12-01 22:10:20 +00001236 QualType BaseType = ((Expr*) Base.get())->getType();
1237 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001238 OpLoc, /*IsArrow*/ false,
1239 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor2d1c2142009-11-03 19:44:04 +00001240 DeclarationName(&Accessor),
John McCall129e2df2009-11-30 22:42:35 +00001241 AccessorLoc,
1242 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001243 }
Mike Stump1eb44332009-09-09 15:08:12 +00001244
Douglas Gregorb98b1992009-08-11 05:31:07 +00001245 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001246 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001247 /// By default, performs semantic analysis to build the new expression.
1248 /// Subclasses may override this routine to provide different behavior.
1249 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1250 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001251 SourceLocation RBraceLoc,
1252 QualType ResultTy) {
1253 OwningExprResult Result
1254 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1255 if (Result.isInvalid() || ResultTy->isDependentType())
1256 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001257
Douglas Gregore48319a2009-11-09 17:16:50 +00001258 // Patch in the result type we were given, which may have been computed
1259 // when the initial InitListExpr was built.
1260 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1261 ILE->setType(ResultTy);
1262 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001263 }
Mike Stump1eb44332009-09-09 15:08:12 +00001264
Douglas Gregorb98b1992009-08-11 05:31:07 +00001265 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001266 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001267 /// By default, performs semantic analysis to build the new expression.
1268 /// Subclasses may override this routine to provide different behavior.
1269 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1270 MultiExprArg ArrayExprs,
1271 SourceLocation EqualOrColonLoc,
1272 bool GNUSyntax,
1273 ExprArg Init) {
1274 OwningExprResult Result
1275 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1276 move(Init));
1277 if (Result.isInvalid())
1278 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001279
Douglas Gregorb98b1992009-08-11 05:31:07 +00001280 ArrayExprs.release();
1281 return move(Result);
1282 }
Mike Stump1eb44332009-09-09 15:08:12 +00001283
Douglas Gregorb98b1992009-08-11 05:31:07 +00001284 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001285 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001286 /// By default, builds the implicit value initialization without performing
1287 /// any semantic analysis. Subclasses may override this routine to provide
1288 /// different behavior.
1289 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1290 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1291 }
Mike Stump1eb44332009-09-09 15:08:12 +00001292
Douglas Gregorb98b1992009-08-11 05:31:07 +00001293 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001294 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001295 /// By default, performs semantic analysis to build the new expression.
1296 /// Subclasses may override this routine to provide different behavior.
1297 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1298 QualType T, SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001299 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001300 RParenLoc);
1301 }
1302
1303 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001304 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001305 /// By default, performs semantic analysis to build the new expression.
1306 /// Subclasses may override this routine to provide different behavior.
1307 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1308 MultiExprArg SubExprs,
1309 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001310 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001311 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001312 }
Mike Stump1eb44332009-09-09 15:08:12 +00001313
Douglas Gregorb98b1992009-08-11 05:31:07 +00001314 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001315 ///
1316 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001317 /// rather than attempting to map the label statement itself.
1318 /// Subclasses may override this routine to provide different behavior.
1319 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1320 SourceLocation LabelLoc,
1321 LabelStmt *Label) {
1322 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1323 }
Mike Stump1eb44332009-09-09 15:08:12 +00001324
Douglas Gregorb98b1992009-08-11 05:31:07 +00001325 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001326 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001327 /// By default, performs semantic analysis to build the new expression.
1328 /// Subclasses may override this routine to provide different behavior.
1329 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1330 StmtArg SubStmt,
1331 SourceLocation RParenLoc) {
1332 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1333 }
Mike Stump1eb44332009-09-09 15:08:12 +00001334
Douglas Gregorb98b1992009-08-11 05:31:07 +00001335 /// \brief Build a new __builtin_types_compatible_p expression.
1336 ///
1337 /// By default, performs semantic analysis to build the new expression.
1338 /// Subclasses may override this routine to provide different behavior.
1339 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1340 QualType T1, QualType T2,
1341 SourceLocation RParenLoc) {
1342 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1343 T1.getAsOpaquePtr(),
1344 T2.getAsOpaquePtr(),
1345 RParenLoc);
1346 }
Mike Stump1eb44332009-09-09 15:08:12 +00001347
Douglas Gregorb98b1992009-08-11 05:31:07 +00001348 /// \brief Build a new __builtin_choose_expr expression.
1349 ///
1350 /// By default, performs semantic analysis to build the new expression.
1351 /// Subclasses may override this routine to provide different behavior.
1352 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1353 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1354 SourceLocation RParenLoc) {
1355 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1356 move(Cond), move(LHS), move(RHS),
1357 RParenLoc);
1358 }
Mike Stump1eb44332009-09-09 15:08:12 +00001359
Douglas Gregorb98b1992009-08-11 05:31:07 +00001360 /// \brief Build a new overloaded operator call expression.
1361 ///
1362 /// By default, performs semantic analysis to build the new expression.
1363 /// The semantic analysis provides the behavior of template instantiation,
1364 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001365 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001366 /// argument-dependent lookup, etc. Subclasses may override this routine to
1367 /// provide different behavior.
1368 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1369 SourceLocation OpLoc,
1370 ExprArg Callee,
1371 ExprArg First,
1372 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001373
1374 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001375 /// reinterpret_cast.
1376 ///
1377 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001378 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001379 /// Subclasses may override this routine to provide different behavior.
1380 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1381 Stmt::StmtClass Class,
1382 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001383 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001384 SourceLocation RAngleLoc,
1385 SourceLocation LParenLoc,
1386 ExprArg SubExpr,
1387 SourceLocation RParenLoc) {
1388 switch (Class) {
1389 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001390 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001391 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001392 move(SubExpr), RParenLoc);
1393
1394 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001395 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001396 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001397 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001398
Douglas Gregorb98b1992009-08-11 05:31:07 +00001399 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001400 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001401 RAngleLoc, LParenLoc,
1402 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001403 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001404
Douglas Gregorb98b1992009-08-11 05:31:07 +00001405 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001406 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001407 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001408 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001409
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 default:
1411 assert(false && "Invalid C++ named cast");
1412 break;
1413 }
Mike Stump1eb44332009-09-09 15:08:12 +00001414
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 return getSema().ExprError();
1416 }
Mike Stump1eb44332009-09-09 15:08:12 +00001417
Douglas Gregorb98b1992009-08-11 05:31:07 +00001418 /// \brief Build a new C++ static_cast expression.
1419 ///
1420 /// By default, performs semantic analysis to build the new expression.
1421 /// Subclasses may override this routine to provide different behavior.
1422 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1423 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001424 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001425 SourceLocation RAngleLoc,
1426 SourceLocation LParenLoc,
1427 ExprArg SubExpr,
1428 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001429 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1430 TInfo, move(SubExpr),
1431 SourceRange(LAngleLoc, RAngleLoc),
1432 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001433 }
1434
1435 /// \brief Build a new C++ dynamic_cast expression.
1436 ///
1437 /// By default, performs semantic analysis to build the new expression.
1438 /// Subclasses may override this routine to provide different behavior.
1439 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1440 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001441 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001442 SourceLocation RAngleLoc,
1443 SourceLocation LParenLoc,
1444 ExprArg SubExpr,
1445 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001446 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1447 TInfo, move(SubExpr),
1448 SourceRange(LAngleLoc, RAngleLoc),
1449 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 }
1451
1452 /// \brief Build a new C++ reinterpret_cast expression.
1453 ///
1454 /// By default, performs semantic analysis to build the new expression.
1455 /// Subclasses may override this routine to provide different behavior.
1456 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1457 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001458 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001459 SourceLocation RAngleLoc,
1460 SourceLocation LParenLoc,
1461 ExprArg SubExpr,
1462 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001463 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1464 TInfo, move(SubExpr),
1465 SourceRange(LAngleLoc, RAngleLoc),
1466 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 }
1468
1469 /// \brief Build a new C++ const_cast expression.
1470 ///
1471 /// By default, performs semantic analysis to build the new expression.
1472 /// Subclasses may override this routine to provide different behavior.
1473 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1474 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001475 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001476 SourceLocation RAngleLoc,
1477 SourceLocation LParenLoc,
1478 ExprArg SubExpr,
1479 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001480 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1481 TInfo, move(SubExpr),
1482 SourceRange(LAngleLoc, RAngleLoc),
1483 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 }
Mike Stump1eb44332009-09-09 15:08:12 +00001485
Douglas Gregorb98b1992009-08-11 05:31:07 +00001486 /// \brief Build a new C++ functional-style cast expression.
1487 ///
1488 /// By default, performs semantic analysis to build the new expression.
1489 /// Subclasses may override this routine to provide different behavior.
1490 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001491 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 SourceLocation LParenLoc,
1493 ExprArg SubExpr,
1494 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001495 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001496 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001497 TInfo->getType().getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001499 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001500 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 RParenLoc);
1502 }
Mike Stump1eb44332009-09-09 15:08:12 +00001503
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 /// \brief Build a new C++ typeid(type) expression.
1505 ///
1506 /// By default, performs semantic analysis to build the new expression.
1507 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001508 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1509 SourceLocation TypeidLoc,
1510 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001512 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001513 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 }
Mike Stump1eb44332009-09-09 15:08:12 +00001515
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 /// \brief Build a new C++ typeid(expr) expression.
1517 ///
1518 /// By default, performs semantic analysis to build the new expression.
1519 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001520 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1521 SourceLocation TypeidLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001522 ExprArg Operand,
1523 SourceLocation RParenLoc) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001524 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1525 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001526 }
1527
Douglas Gregorb98b1992009-08-11 05:31:07 +00001528 /// \brief Build a new C++ "this" expression.
1529 ///
1530 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001531 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001532 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001533 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001534 QualType ThisType,
1535 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001536 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001537 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1538 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001539 }
1540
1541 /// \brief Build a new C++ throw expression.
1542 ///
1543 /// By default, performs semantic analysis to build the new expression.
1544 /// Subclasses may override this routine to provide different behavior.
1545 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1546 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1547 }
1548
1549 /// \brief Build a new C++ default-argument expression.
1550 ///
1551 /// By default, builds a new default-argument expression, which does not
1552 /// require any semantic analysis. Subclasses may override this routine to
1553 /// provide different behavior.
Sean Huntc3021132010-05-05 15:23:54 +00001554 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001555 ParmVarDecl *Param) {
1556 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1557 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001558 }
1559
1560 /// \brief Build a new C++ zero-initialization expression.
1561 ///
1562 /// By default, performs semantic analysis to build the new expression.
1563 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001564 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 SourceLocation LParenLoc,
1566 QualType T,
1567 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001568 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1569 T.getAsOpaquePtr(), LParenLoc,
1570 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 0, RParenLoc);
1572 }
Mike Stump1eb44332009-09-09 15:08:12 +00001573
Douglas Gregorb98b1992009-08-11 05:31:07 +00001574 /// \brief Build a new C++ "new" expression.
1575 ///
1576 /// By default, performs semantic analysis to build the new expression.
1577 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001578 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 bool UseGlobal,
1580 SourceLocation PlacementLParen,
1581 MultiExprArg PlacementArgs,
1582 SourceLocation PlacementRParen,
Mike Stump1eb44332009-09-09 15:08:12 +00001583 bool ParenTypeId,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 QualType AllocType,
1585 SourceLocation TypeLoc,
1586 SourceRange TypeRange,
1587 ExprArg ArraySize,
1588 SourceLocation ConstructorLParen,
1589 MultiExprArg ConstructorArgs,
1590 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001591 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 PlacementLParen,
1593 move(PlacementArgs),
1594 PlacementRParen,
1595 ParenTypeId,
1596 AllocType,
1597 TypeLoc,
1598 TypeRange,
1599 move(ArraySize),
1600 ConstructorLParen,
1601 move(ConstructorArgs),
1602 ConstructorRParen);
1603 }
Mike Stump1eb44332009-09-09 15:08:12 +00001604
Douglas Gregorb98b1992009-08-11 05:31:07 +00001605 /// \brief Build a new C++ "delete" expression.
1606 ///
1607 /// By default, performs semantic analysis to build the new expression.
1608 /// Subclasses may override this routine to provide different behavior.
1609 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1610 bool IsGlobalDelete,
1611 bool IsArrayForm,
1612 ExprArg Operand) {
1613 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1614 move(Operand));
1615 }
Mike Stump1eb44332009-09-09 15:08:12 +00001616
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 /// \brief Build a new unary type trait expression.
1618 ///
1619 /// By default, performs semantic analysis to build the new expression.
1620 /// Subclasses may override this routine to provide different behavior.
1621 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1622 SourceLocation StartLoc,
1623 SourceLocation LParenLoc,
1624 QualType T,
1625 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001626 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001627 T.getAsOpaquePtr(), RParenLoc);
1628 }
1629
Mike Stump1eb44332009-09-09 15:08:12 +00001630 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 /// expression.
1632 ///
1633 /// By default, performs semantic analysis to build the new expression.
1634 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001635 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 SourceRange QualifierRange,
1637 DeclarationName Name,
1638 SourceLocation Location,
John McCallf7a1a742009-11-24 19:00:30 +00001639 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001640 CXXScopeSpec SS;
1641 SS.setRange(QualifierRange);
1642 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001643
1644 if (TemplateArgs)
1645 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1646 *TemplateArgs);
1647
1648 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 }
1650
1651 /// \brief Build a new template-id expression.
1652 ///
1653 /// By default, performs semantic analysis to build the new expression.
1654 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001655 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1656 LookupResult &R,
1657 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001658 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001659 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 }
1661
1662 /// \brief Build a new object-construction expression.
1663 ///
1664 /// By default, performs semantic analysis to build the new expression.
1665 /// Subclasses may override this routine to provide different behavior.
1666 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001667 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 CXXConstructorDecl *Constructor,
1669 bool IsElidable,
1670 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001671 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001672 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001673 ConvertedArgs))
1674 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001675
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001676 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1677 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 }
1679
1680 /// \brief Build a new object-construction expression.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
1684 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1685 QualType T,
1686 SourceLocation LParenLoc,
1687 MultiExprArg Args,
1688 SourceLocation *Commas,
1689 SourceLocation RParenLoc) {
1690 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1691 T.getAsOpaquePtr(),
1692 LParenLoc,
1693 move(Args),
1694 Commas,
1695 RParenLoc);
1696 }
1697
1698 /// \brief Build a new object-construction expression.
1699 ///
1700 /// By default, performs semantic analysis to build the new expression.
1701 /// Subclasses may override this routine to provide different behavior.
1702 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1703 QualType T,
1704 SourceLocation LParenLoc,
1705 MultiExprArg Args,
1706 SourceLocation *Commas,
1707 SourceLocation RParenLoc) {
1708 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1709 /*FIXME*/LParenLoc),
1710 T.getAsOpaquePtr(),
1711 LParenLoc,
1712 move(Args),
1713 Commas,
1714 RParenLoc);
1715 }
Mike Stump1eb44332009-09-09 15:08:12 +00001716
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 /// \brief Build a new member reference expression.
1718 ///
1719 /// By default, performs semantic analysis to build the new expression.
1720 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001721 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001722 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 bool IsArrow,
1724 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001725 NestedNameSpecifier *Qualifier,
1726 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001727 NamedDecl *FirstQualifierInScope,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001728 DeclarationName Name,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001729 SourceLocation MemberLoc,
John McCall129e2df2009-11-30 22:42:35 +00001730 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001731 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001732 SS.setRange(QualifierRange);
1733 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001734
John McCallaa81e162009-12-01 22:10:20 +00001735 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1736 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001737 SS, FirstQualifierInScope,
1738 Name, MemberLoc, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001739 }
1740
John McCall129e2df2009-11-30 22:42:35 +00001741 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001742 ///
1743 /// By default, performs semantic analysis to build the new expression.
1744 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001745 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001746 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001747 SourceLocation OperatorLoc,
1748 bool IsArrow,
1749 NestedNameSpecifier *Qualifier,
1750 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001751 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001752 LookupResult &R,
1753 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001754 CXXScopeSpec SS;
1755 SS.setRange(QualifierRange);
1756 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001757
John McCallaa81e162009-12-01 22:10:20 +00001758 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1759 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001760 SS, FirstQualifierInScope,
1761 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001762 }
Mike Stump1eb44332009-09-09 15:08:12 +00001763
Douglas Gregorb98b1992009-08-11 05:31:07 +00001764 /// \brief Build a new Objective-C @encode expression.
1765 ///
1766 /// By default, performs semantic analysis to build the new expression.
1767 /// Subclasses may override this routine to provide different behavior.
1768 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001769 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001771 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001772 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001773 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001774
Douglas Gregor92e986e2010-04-22 16:44:27 +00001775 /// \brief Build a new Objective-C class message.
1776 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1777 Selector Sel,
1778 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001779 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001780 MultiExprArg Args,
1781 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001782 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1783 ReceiverTypeInfo->getType(),
1784 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001785 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001786 move(Args));
1787 }
1788
1789 /// \brief Build a new Objective-C instance message.
1790 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1791 Selector Sel,
1792 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001793 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001794 MultiExprArg Args,
1795 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001796 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1797 return SemaRef.BuildInstanceMessage(move(Receiver),
1798 ReceiverType,
1799 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001800 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001801 move(Args));
1802 }
1803
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001804 /// \brief Build a new Objective-C ivar reference expression.
1805 ///
1806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
1808 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1809 SourceLocation IvarLoc,
1810 bool IsArrow, bool IsFreeIvar) {
1811 // FIXME: We lose track of the IsFreeIvar bit.
1812 CXXScopeSpec SS;
1813 Expr *Base = BaseArg.takeAs<Expr>();
1814 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1815 Sema::LookupMemberName);
1816 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1817 /*FIME:*/IvarLoc,
1818 SS, DeclPtrTy());
1819 if (Result.isInvalid())
1820 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001821
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001822 if (Result.get())
1823 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001824
1825 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001826 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001827 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001828 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001829 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001830 /*TemplateArgs=*/0);
1831 }
Douglas Gregore3303542010-04-26 20:47:02 +00001832
1833 /// \brief Build a new Objective-C property reference expression.
1834 ///
1835 /// By default, performs semantic analysis to build the new expression.
1836 /// Subclasses may override this routine to provide different behavior.
Sean Huntc3021132010-05-05 15:23:54 +00001837 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001838 ObjCPropertyDecl *Property,
1839 SourceLocation PropertyLoc) {
1840 CXXScopeSpec SS;
1841 Expr *Base = BaseArg.takeAs<Expr>();
1842 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1843 Sema::LookupMemberName);
1844 bool IsArrow = false;
1845 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1846 /*FIME:*/PropertyLoc,
1847 SS, DeclPtrTy());
1848 if (Result.isInvalid())
1849 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001850
Douglas Gregore3303542010-04-26 20:47:02 +00001851 if (Result.get())
1852 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001853
1854 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregore3303542010-04-26 20:47:02 +00001855 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001856 /*FIXME:*/PropertyLoc, IsArrow,
1857 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001858 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001859 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001860 /*TemplateArgs=*/0);
1861 }
Sean Huntc3021132010-05-05 15:23:54 +00001862
1863 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001864 /// expression.
1865 ///
1866 /// By default, performs semantic analysis to build the new expression.
Sean Huntc3021132010-05-05 15:23:54 +00001867 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001868 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1869 ObjCMethodDecl *Getter,
1870 QualType T,
1871 ObjCMethodDecl *Setter,
1872 SourceLocation NameLoc,
1873 ExprArg Base) {
1874 // Since these expressions can only be value-dependent, we do not need to
1875 // perform semantic analysis again.
1876 return getSema().Owned(
1877 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1878 Setter,
1879 NameLoc,
1880 Base.takeAs<Expr>()));
1881 }
1882
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001883 /// \brief Build a new Objective-C "isa" expression.
1884 ///
1885 /// By default, performs semantic analysis to build the new expression.
1886 /// Subclasses may override this routine to provide different behavior.
1887 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1888 bool IsArrow) {
1889 CXXScopeSpec SS;
1890 Expr *Base = BaseArg.takeAs<Expr>();
1891 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1892 Sema::LookupMemberName);
1893 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1894 /*FIME:*/IsaLoc,
1895 SS, DeclPtrTy());
1896 if (Result.isInvalid())
1897 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001898
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001899 if (Result.get())
1900 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001901
1902 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001903 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001904 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001905 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001906 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001907 /*TemplateArgs=*/0);
1908 }
Sean Huntc3021132010-05-05 15:23:54 +00001909
Douglas Gregorb98b1992009-08-11 05:31:07 +00001910 /// \brief Build a new shuffle vector expression.
1911 ///
1912 /// By default, performs semantic analysis to build the new expression.
1913 /// Subclasses may override this routine to provide different behavior.
1914 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1915 MultiExprArg SubExprs,
1916 SourceLocation RParenLoc) {
1917 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001918 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001919 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1920 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1921 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1922 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001923
Douglas Gregorb98b1992009-08-11 05:31:07 +00001924 // Build a reference to the __builtin_shufflevector builtin
1925 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001926 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001927 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001928 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001929 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001930
1931 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001932 unsigned NumSubExprs = SubExprs.size();
1933 Expr **Subs = (Expr **)SubExprs.release();
1934 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1935 Subs, NumSubExprs,
1936 Builtin->getResultType(),
1937 RParenLoc);
1938 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001939
Douglas Gregorb98b1992009-08-11 05:31:07 +00001940 // Type-check the __builtin_shufflevector expression.
1941 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1942 if (Result.isInvalid())
1943 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001944
Douglas Gregorb98b1992009-08-11 05:31:07 +00001945 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001946 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001948};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001949
Douglas Gregor43959a92009-08-20 07:17:43 +00001950template<typename Derived>
1951Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1952 if (!S)
1953 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001954
Douglas Gregor43959a92009-08-20 07:17:43 +00001955 switch (S->getStmtClass()) {
1956 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001957
Douglas Gregor43959a92009-08-20 07:17:43 +00001958 // Transform individual statement nodes
1959#define STMT(Node, Parent) \
1960 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1961#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00001962#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001963
Douglas Gregor43959a92009-08-20 07:17:43 +00001964 // Transform expressions by calling TransformExpr.
1965#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00001966#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00001967#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00001968#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00001969 {
1970 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1971 if (E.isInvalid())
1972 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001973
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001974 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001975 }
Mike Stump1eb44332009-09-09 15:08:12 +00001976 }
1977
Douglas Gregor43959a92009-08-20 07:17:43 +00001978 return SemaRef.Owned(S->Retain());
1979}
Mike Stump1eb44332009-09-09 15:08:12 +00001980
1981
Douglas Gregor670444e2009-08-04 22:27:00 +00001982template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00001983Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001984 if (!E)
1985 return SemaRef.Owned(E);
1986
1987 switch (E->getStmtClass()) {
1988 case Stmt::NoStmtClass: break;
1989#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00001990#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00001991#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00001992 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00001993#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001994 }
1995
Douglas Gregorb98b1992009-08-11 05:31:07 +00001996 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00001997}
1998
1999template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002000NestedNameSpecifier *
2001TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002002 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002003 QualType ObjectType,
2004 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00002005 if (!NNS)
2006 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002007
Douglas Gregor43959a92009-08-20 07:17:43 +00002008 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002009 NestedNameSpecifier *Prefix = NNS->getPrefix();
2010 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002011 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002012 ObjectType,
2013 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002014 if (!Prefix)
2015 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002016
2017 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00002018 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00002019 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00002020 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002021 }
Mike Stump1eb44332009-09-09 15:08:12 +00002022
Douglas Gregordcee1a12009-08-06 05:28:30 +00002023 switch (NNS->getKind()) {
2024 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00002025 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002026 "Identifier nested-name-specifier with no prefix or object type");
2027 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2028 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002029 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002030
2031 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002032 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002033 ObjectType,
2034 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002035
Douglas Gregordcee1a12009-08-06 05:28:30 +00002036 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002037 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002038 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002039 getDerived().TransformDecl(Range.getBegin(),
2040 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002041 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002042 Prefix == NNS->getPrefix() &&
2043 NS == NNS->getAsNamespace())
2044 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002045
Douglas Gregordcee1a12009-08-06 05:28:30 +00002046 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2047 }
Mike Stump1eb44332009-09-09 15:08:12 +00002048
Douglas Gregordcee1a12009-08-06 05:28:30 +00002049 case NestedNameSpecifier::Global:
2050 // There is no meaningful transformation that one could perform on the
2051 // global scope.
2052 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002053
Douglas Gregordcee1a12009-08-06 05:28:30 +00002054 case NestedNameSpecifier::TypeSpecWithTemplate:
2055 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002056 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00002057 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2058 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002059 if (T.isNull())
2060 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002061
Douglas Gregordcee1a12009-08-06 05:28:30 +00002062 if (!getDerived().AlwaysRebuild() &&
2063 Prefix == NNS->getPrefix() &&
2064 T == QualType(NNS->getAsType(), 0))
2065 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002066
2067 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2068 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002069 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002070 }
2071 }
Mike Stump1eb44332009-09-09 15:08:12 +00002072
Douglas Gregordcee1a12009-08-06 05:28:30 +00002073 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002074 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002075}
2076
2077template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002078DeclarationName
Douglas Gregor81499bb2009-09-03 22:13:48 +00002079TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +00002080 SourceLocation Loc,
2081 QualType ObjectType) {
Douglas Gregor81499bb2009-09-03 22:13:48 +00002082 if (!Name)
2083 return Name;
2084
2085 switch (Name.getNameKind()) {
2086 case DeclarationName::Identifier:
2087 case DeclarationName::ObjCZeroArgSelector:
2088 case DeclarationName::ObjCOneArgSelector:
2089 case DeclarationName::ObjCMultiArgSelector:
2090 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002091 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002092 case DeclarationName::CXXUsingDirective:
2093 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002094
Douglas Gregor81499bb2009-09-03 22:13:48 +00002095 case DeclarationName::CXXConstructorName:
2096 case DeclarationName::CXXDestructorName:
2097 case DeclarationName::CXXConversionFunctionName: {
2098 TemporaryBase Rebase(*this, Loc, Name);
Sean Huntc3021132010-05-05 15:23:54 +00002099 QualType T = getDerived().TransformType(Name.getCXXNameType(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002100 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00002101 if (T.isNull())
2102 return DeclarationName();
Mike Stump1eb44332009-09-09 15:08:12 +00002103
Douglas Gregor81499bb2009-09-03 22:13:48 +00002104 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump1eb44332009-09-09 15:08:12 +00002105 Name.getNameKind(),
Douglas Gregor81499bb2009-09-03 22:13:48 +00002106 SemaRef.Context.getCanonicalType(T));
Douglas Gregor81499bb2009-09-03 22:13:48 +00002107 }
Mike Stump1eb44332009-09-09 15:08:12 +00002108 }
2109
Douglas Gregor81499bb2009-09-03 22:13:48 +00002110 return DeclarationName();
2111}
2112
2113template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002114TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002115TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2116 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002117 SourceLocation Loc = getDerived().getBaseLocation();
2118
Douglas Gregord1067e52009-08-06 06:41:21 +00002119 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002120 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002121 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002122 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2123 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002124 if (!NNS)
2125 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002126
Douglas Gregord1067e52009-08-06 06:41:21 +00002127 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002128 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002129 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002130 if (!TransTemplate)
2131 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002132
Douglas Gregord1067e52009-08-06 06:41:21 +00002133 if (!getDerived().AlwaysRebuild() &&
2134 NNS == QTN->getQualifier() &&
2135 TransTemplate == Template)
2136 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002137
Douglas Gregord1067e52009-08-06 06:41:21 +00002138 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2139 TransTemplate);
2140 }
Mike Stump1eb44332009-09-09 15:08:12 +00002141
John McCallf7a1a742009-11-24 19:00:30 +00002142 // These should be getting filtered out before they make it into the AST.
2143 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002144 }
Mike Stump1eb44332009-09-09 15:08:12 +00002145
Douglas Gregord1067e52009-08-06 06:41:21 +00002146 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002147 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002148 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002149 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2150 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002151 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00002152 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002153
Douglas Gregord1067e52009-08-06 06:41:21 +00002154 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002155 NNS == DTN->getQualifier() &&
2156 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002157 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002158
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002159 if (DTN->isIdentifier())
Sean Huntc3021132010-05-05 15:23:54 +00002160 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002161 ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +00002162
2163 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002164 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002165 }
Mike Stump1eb44332009-09-09 15:08:12 +00002166
Douglas Gregord1067e52009-08-06 06:41:21 +00002167 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002168 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002169 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002170 if (!TransTemplate)
2171 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002172
Douglas Gregord1067e52009-08-06 06:41:21 +00002173 if (!getDerived().AlwaysRebuild() &&
2174 TransTemplate == Template)
2175 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002176
Douglas Gregord1067e52009-08-06 06:41:21 +00002177 return TemplateName(TransTemplate);
2178 }
Mike Stump1eb44332009-09-09 15:08:12 +00002179
John McCallf7a1a742009-11-24 19:00:30 +00002180 // These should be getting filtered out before they reach the AST.
2181 assert(false && "overloaded function decl survived to here");
2182 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002183}
2184
2185template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002186void TreeTransform<Derived>::InventTemplateArgumentLoc(
2187 const TemplateArgument &Arg,
2188 TemplateArgumentLoc &Output) {
2189 SourceLocation Loc = getDerived().getBaseLocation();
2190 switch (Arg.getKind()) {
2191 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002192 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002193 break;
2194
2195 case TemplateArgument::Type:
2196 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002197 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002198
John McCall833ca992009-10-29 08:12:44 +00002199 break;
2200
Douglas Gregor788cd062009-11-11 01:00:40 +00002201 case TemplateArgument::Template:
2202 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2203 break;
Sean Huntc3021132010-05-05 15:23:54 +00002204
John McCall833ca992009-10-29 08:12:44 +00002205 case TemplateArgument::Expression:
2206 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2207 break;
2208
2209 case TemplateArgument::Declaration:
2210 case TemplateArgument::Integral:
2211 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002212 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002213 break;
2214 }
2215}
2216
2217template<typename Derived>
2218bool TreeTransform<Derived>::TransformTemplateArgument(
2219 const TemplateArgumentLoc &Input,
2220 TemplateArgumentLoc &Output) {
2221 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002222 switch (Arg.getKind()) {
2223 case TemplateArgument::Null:
2224 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002225 Output = Input;
2226 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002227
Douglas Gregor670444e2009-08-04 22:27:00 +00002228 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002229 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002230 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002231 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002232
2233 DI = getDerived().TransformType(DI);
2234 if (!DI) return true;
2235
2236 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2237 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002238 }
Mike Stump1eb44332009-09-09 15:08:12 +00002239
Douglas Gregor670444e2009-08-04 22:27:00 +00002240 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002241 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002242 DeclarationName Name;
2243 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2244 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002245 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002246 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002247 if (!D) return true;
2248
John McCall828bff22009-10-29 18:45:58 +00002249 Expr *SourceExpr = Input.getSourceDeclExpression();
2250 if (SourceExpr) {
2251 EnterExpressionEvaluationContext Unevaluated(getSema(),
2252 Action::Unevaluated);
2253 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2254 if (E.isInvalid())
2255 SourceExpr = NULL;
2256 else {
2257 SourceExpr = E.takeAs<Expr>();
2258 SourceExpr->Retain();
2259 }
2260 }
2261
2262 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002263 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002264 }
Mike Stump1eb44332009-09-09 15:08:12 +00002265
Douglas Gregor788cd062009-11-11 01:00:40 +00002266 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002267 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002268 TemplateName Template
2269 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2270 if (Template.isNull())
2271 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002272
Douglas Gregor788cd062009-11-11 01:00:40 +00002273 Output = TemplateArgumentLoc(TemplateArgument(Template),
2274 Input.getTemplateQualifierRange(),
2275 Input.getTemplateNameLoc());
2276 return false;
2277 }
Sean Huntc3021132010-05-05 15:23:54 +00002278
Douglas Gregor670444e2009-08-04 22:27:00 +00002279 case TemplateArgument::Expression: {
2280 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002281 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002282 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002283
John McCall833ca992009-10-29 08:12:44 +00002284 Expr *InputExpr = Input.getSourceExpression();
2285 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2286
2287 Sema::OwningExprResult E
2288 = getDerived().TransformExpr(InputExpr);
2289 if (E.isInvalid()) return true;
2290
2291 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00002292 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00002293 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2294 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002295 }
Mike Stump1eb44332009-09-09 15:08:12 +00002296
Douglas Gregor670444e2009-08-04 22:27:00 +00002297 case TemplateArgument::Pack: {
2298 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2299 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002300 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002301 AEnd = Arg.pack_end();
2302 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002303
John McCall833ca992009-10-29 08:12:44 +00002304 // FIXME: preserve source information here when we start
2305 // caring about parameter packs.
2306
John McCall828bff22009-10-29 18:45:58 +00002307 TemplateArgumentLoc InputArg;
2308 TemplateArgumentLoc OutputArg;
2309 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2310 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002311 return true;
2312
John McCall828bff22009-10-29 18:45:58 +00002313 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002314 }
2315 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002316 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002317 true);
John McCall828bff22009-10-29 18:45:58 +00002318 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002319 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002320 }
2321 }
Mike Stump1eb44332009-09-09 15:08:12 +00002322
Douglas Gregor670444e2009-08-04 22:27:00 +00002323 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002324 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002325}
2326
Douglas Gregor577f75a2009-08-04 16:50:30 +00002327//===----------------------------------------------------------------------===//
2328// Type transformation
2329//===----------------------------------------------------------------------===//
2330
2331template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00002332QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregor124b8782010-02-16 19:09:40 +00002333 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002334 if (getDerived().AlreadyTransformed(T))
2335 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002336
John McCalla2becad2009-10-21 00:40:46 +00002337 // Temporary workaround. All of these transformations should
2338 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002339 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002340 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002341
Douglas Gregor124b8782010-02-16 19:09:40 +00002342 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002343
John McCalla2becad2009-10-21 00:40:46 +00002344 if (!NewDI)
2345 return QualType();
2346
2347 return NewDI->getType();
2348}
2349
2350template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002351TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2352 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002353 if (getDerived().AlreadyTransformed(DI->getType()))
2354 return DI;
2355
2356 TypeLocBuilder TLB;
2357
2358 TypeLoc TL = DI->getTypeLoc();
2359 TLB.reserve(TL.getFullDataSize());
2360
Douglas Gregor124b8782010-02-16 19:09:40 +00002361 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002362 if (Result.isNull())
2363 return 0;
2364
John McCalla93c9342009-12-07 02:54:59 +00002365 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002366}
2367
2368template<typename Derived>
2369QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002370TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2371 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002372 switch (T.getTypeLocClass()) {
2373#define ABSTRACT_TYPELOC(CLASS, PARENT)
2374#define TYPELOC(CLASS, PARENT) \
2375 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002376 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2377 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002378#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002379 }
Mike Stump1eb44332009-09-09 15:08:12 +00002380
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002381 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002382 return QualType();
2383}
2384
2385/// FIXME: By default, this routine adds type qualifiers only to types
2386/// that can have qualifiers, and silently suppresses those qualifiers
2387/// that are not permitted (e.g., qualifiers on reference or function
2388/// types). This is the right thing for template instantiation, but
2389/// probably not for other clients.
2390template<typename Derived>
2391QualType
2392TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002393 QualifiedTypeLoc T,
2394 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002395 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002396
Douglas Gregor124b8782010-02-16 19:09:40 +00002397 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2398 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002399 if (Result.isNull())
2400 return QualType();
2401
2402 // Silently suppress qualifiers if the result type can't be qualified.
2403 // FIXME: this is the right thing for template instantiation, but
2404 // probably not for other clients.
2405 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002406 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002407
John McCall28654742010-06-05 06:41:15 +00002408 if (!Quals.empty()) {
2409 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2410 TLB.push<QualifiedTypeLoc>(Result);
2411 // No location information to preserve.
2412 }
John McCalla2becad2009-10-21 00:40:46 +00002413
2414 return Result;
2415}
2416
2417template <class TyLoc> static inline
2418QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2419 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2420 NewT.setNameLoc(T.getNameLoc());
2421 return T.getType();
2422}
2423
John McCalla2becad2009-10-21 00:40:46 +00002424template<typename Derived>
2425QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002426 BuiltinTypeLoc T,
2427 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002428 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2429 NewT.setBuiltinLoc(T.getBuiltinLoc());
2430 if (T.needsExtraLocalData())
2431 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2432 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002433}
Mike Stump1eb44332009-09-09 15:08:12 +00002434
Douglas Gregor577f75a2009-08-04 16:50:30 +00002435template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002436QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002437 ComplexTypeLoc T,
2438 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002439 // FIXME: recurse?
2440 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002441}
Mike Stump1eb44332009-09-09 15:08:12 +00002442
Douglas Gregor577f75a2009-08-04 16:50:30 +00002443template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002444QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Sean Huntc3021132010-05-05 15:23:54 +00002445 PointerTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00002446 QualType ObjectType) {
Sean Huntc3021132010-05-05 15:23:54 +00002447 QualType PointeeType
2448 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002449 if (PointeeType.isNull())
2450 return QualType();
2451
2452 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002453 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002454 // A dependent pointer type 'T *' has is being transformed such
2455 // that an Objective-C class type is being replaced for 'T'. The
2456 // resulting pointer type is an ObjCObjectPointerType, not a
2457 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002458 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002459
John McCallc12c5bb2010-05-15 11:32:37 +00002460 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2461 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002462 return Result;
2463 }
Sean Huntc3021132010-05-05 15:23:54 +00002464
Douglas Gregor92e986e2010-04-22 16:44:27 +00002465 if (getDerived().AlwaysRebuild() ||
2466 PointeeType != TL.getPointeeLoc().getType()) {
2467 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2468 if (Result.isNull())
2469 return QualType();
2470 }
Sean Huntc3021132010-05-05 15:23:54 +00002471
Douglas Gregor92e986e2010-04-22 16:44:27 +00002472 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2473 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002474 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002475}
Mike Stump1eb44332009-09-09 15:08:12 +00002476
2477template<typename Derived>
2478QualType
John McCalla2becad2009-10-21 00:40:46 +00002479TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002480 BlockPointerTypeLoc TL,
2481 QualType ObjectType) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002482 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002483 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2484 if (PointeeType.isNull())
2485 return QualType();
2486
2487 QualType Result = TL.getType();
2488 if (getDerived().AlwaysRebuild() ||
2489 PointeeType != TL.getPointeeLoc().getType()) {
2490 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002491 TL.getSigilLoc());
2492 if (Result.isNull())
2493 return QualType();
2494 }
2495
Douglas Gregor39968ad2010-04-22 16:50:51 +00002496 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002497 NewT.setSigilLoc(TL.getSigilLoc());
2498 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002499}
2500
John McCall85737a72009-10-30 00:06:24 +00002501/// Transforms a reference type. Note that somewhat paradoxically we
2502/// don't care whether the type itself is an l-value type or an r-value
2503/// type; we only care if the type was *written* as an l-value type
2504/// or an r-value type.
2505template<typename Derived>
2506QualType
2507TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002508 ReferenceTypeLoc TL,
2509 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002510 const ReferenceType *T = TL.getTypePtr();
2511
2512 // Note that this works with the pointee-as-written.
2513 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2514 if (PointeeType.isNull())
2515 return QualType();
2516
2517 QualType Result = TL.getType();
2518 if (getDerived().AlwaysRebuild() ||
2519 PointeeType != T->getPointeeTypeAsWritten()) {
2520 Result = getDerived().RebuildReferenceType(PointeeType,
2521 T->isSpelledAsLValue(),
2522 TL.getSigilLoc());
2523 if (Result.isNull())
2524 return QualType();
2525 }
2526
2527 // r-value references can be rebuilt as l-value references.
2528 ReferenceTypeLoc NewTL;
2529 if (isa<LValueReferenceType>(Result))
2530 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2531 else
2532 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2533 NewTL.setSigilLoc(TL.getSigilLoc());
2534
2535 return Result;
2536}
2537
Mike Stump1eb44332009-09-09 15:08:12 +00002538template<typename Derived>
2539QualType
John McCalla2becad2009-10-21 00:40:46 +00002540TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002541 LValueReferenceTypeLoc TL,
2542 QualType ObjectType) {
2543 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002544}
2545
Mike Stump1eb44332009-09-09 15:08:12 +00002546template<typename Derived>
2547QualType
John McCalla2becad2009-10-21 00:40:46 +00002548TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002549 RValueReferenceTypeLoc TL,
2550 QualType ObjectType) {
2551 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002552}
Mike Stump1eb44332009-09-09 15:08:12 +00002553
Douglas Gregor577f75a2009-08-04 16:50:30 +00002554template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002555QualType
John McCalla2becad2009-10-21 00:40:46 +00002556TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002557 MemberPointerTypeLoc TL,
2558 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002559 MemberPointerType *T = TL.getTypePtr();
2560
2561 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002562 if (PointeeType.isNull())
2563 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002564
John McCalla2becad2009-10-21 00:40:46 +00002565 // TODO: preserve source information for this.
2566 QualType ClassType
2567 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002568 if (ClassType.isNull())
2569 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002570
John McCalla2becad2009-10-21 00:40:46 +00002571 QualType Result = TL.getType();
2572 if (getDerived().AlwaysRebuild() ||
2573 PointeeType != T->getPointeeType() ||
2574 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002575 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2576 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002577 if (Result.isNull())
2578 return QualType();
2579 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002580
John McCalla2becad2009-10-21 00:40:46 +00002581 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2582 NewTL.setSigilLoc(TL.getSigilLoc());
2583
2584 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002585}
2586
Mike Stump1eb44332009-09-09 15:08:12 +00002587template<typename Derived>
2588QualType
John McCalla2becad2009-10-21 00:40:46 +00002589TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002590 ConstantArrayTypeLoc TL,
2591 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002592 ConstantArrayType *T = TL.getTypePtr();
2593 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002594 if (ElementType.isNull())
2595 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002596
John McCalla2becad2009-10-21 00:40:46 +00002597 QualType Result = TL.getType();
2598 if (getDerived().AlwaysRebuild() ||
2599 ElementType != T->getElementType()) {
2600 Result = getDerived().RebuildConstantArrayType(ElementType,
2601 T->getSizeModifier(),
2602 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002603 T->getIndexTypeCVRQualifiers(),
2604 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002605 if (Result.isNull())
2606 return QualType();
2607 }
Sean Huntc3021132010-05-05 15:23:54 +00002608
John McCalla2becad2009-10-21 00:40:46 +00002609 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2610 NewTL.setLBracketLoc(TL.getLBracketLoc());
2611 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002612
John McCalla2becad2009-10-21 00:40:46 +00002613 Expr *Size = TL.getSizeExpr();
2614 if (Size) {
2615 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2616 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2617 }
2618 NewTL.setSizeExpr(Size);
2619
2620 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002621}
Mike Stump1eb44332009-09-09 15:08:12 +00002622
Douglas Gregor577f75a2009-08-04 16:50:30 +00002623template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002624QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002625 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002626 IncompleteArrayTypeLoc TL,
2627 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002628 IncompleteArrayType *T = TL.getTypePtr();
2629 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002630 if (ElementType.isNull())
2631 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002632
John McCalla2becad2009-10-21 00:40:46 +00002633 QualType Result = TL.getType();
2634 if (getDerived().AlwaysRebuild() ||
2635 ElementType != T->getElementType()) {
2636 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002637 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002638 T->getIndexTypeCVRQualifiers(),
2639 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002640 if (Result.isNull())
2641 return QualType();
2642 }
Sean Huntc3021132010-05-05 15:23:54 +00002643
John McCalla2becad2009-10-21 00:40:46 +00002644 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2645 NewTL.setLBracketLoc(TL.getLBracketLoc());
2646 NewTL.setRBracketLoc(TL.getRBracketLoc());
2647 NewTL.setSizeExpr(0);
2648
2649 return Result;
2650}
2651
2652template<typename Derived>
2653QualType
2654TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002655 VariableArrayTypeLoc TL,
2656 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002657 VariableArrayType *T = TL.getTypePtr();
2658 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2659 if (ElementType.isNull())
2660 return QualType();
2661
2662 // Array bounds are not potentially evaluated contexts
2663 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2664
2665 Sema::OwningExprResult SizeResult
2666 = getDerived().TransformExpr(T->getSizeExpr());
2667 if (SizeResult.isInvalid())
2668 return QualType();
2669
2670 Expr *Size = static_cast<Expr*>(SizeResult.get());
2671
2672 QualType Result = TL.getType();
2673 if (getDerived().AlwaysRebuild() ||
2674 ElementType != T->getElementType() ||
2675 Size != T->getSizeExpr()) {
2676 Result = getDerived().RebuildVariableArrayType(ElementType,
2677 T->getSizeModifier(),
2678 move(SizeResult),
2679 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002680 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002681 if (Result.isNull())
2682 return QualType();
2683 }
2684 else SizeResult.take();
Sean Huntc3021132010-05-05 15:23:54 +00002685
John McCalla2becad2009-10-21 00:40:46 +00002686 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2687 NewTL.setLBracketLoc(TL.getLBracketLoc());
2688 NewTL.setRBracketLoc(TL.getRBracketLoc());
2689 NewTL.setSizeExpr(Size);
2690
2691 return Result;
2692}
2693
2694template<typename Derived>
2695QualType
2696TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002697 DependentSizedArrayTypeLoc TL,
2698 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002699 DependentSizedArrayType *T = TL.getTypePtr();
2700 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2701 if (ElementType.isNull())
2702 return QualType();
2703
2704 // Array bounds are not potentially evaluated contexts
2705 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2706
2707 Sema::OwningExprResult SizeResult
2708 = getDerived().TransformExpr(T->getSizeExpr());
2709 if (SizeResult.isInvalid())
2710 return QualType();
2711
2712 Expr *Size = static_cast<Expr*>(SizeResult.get());
2713
2714 QualType Result = TL.getType();
2715 if (getDerived().AlwaysRebuild() ||
2716 ElementType != T->getElementType() ||
2717 Size != T->getSizeExpr()) {
2718 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2719 T->getSizeModifier(),
2720 move(SizeResult),
2721 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002722 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002723 if (Result.isNull())
2724 return QualType();
2725 }
2726 else SizeResult.take();
2727
2728 // We might have any sort of array type now, but fortunately they
2729 // all have the same location layout.
2730 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2731 NewTL.setLBracketLoc(TL.getLBracketLoc());
2732 NewTL.setRBracketLoc(TL.getRBracketLoc());
2733 NewTL.setSizeExpr(Size);
2734
2735 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002736}
Mike Stump1eb44332009-09-09 15:08:12 +00002737
2738template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002739QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002740 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002741 DependentSizedExtVectorTypeLoc TL,
2742 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002743 DependentSizedExtVectorType *T = TL.getTypePtr();
2744
2745 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002746 QualType ElementType = getDerived().TransformType(T->getElementType());
2747 if (ElementType.isNull())
2748 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002749
Douglas Gregor670444e2009-08-04 22:27:00 +00002750 // Vector sizes are not potentially evaluated contexts
2751 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2752
Douglas Gregor577f75a2009-08-04 16:50:30 +00002753 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2754 if (Size.isInvalid())
2755 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002756
John McCalla2becad2009-10-21 00:40:46 +00002757 QualType Result = TL.getType();
2758 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002759 ElementType != T->getElementType() ||
2760 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002761 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002762 move(Size),
2763 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002764 if (Result.isNull())
2765 return QualType();
2766 }
2767 else Size.take();
2768
2769 // Result might be dependent or not.
2770 if (isa<DependentSizedExtVectorType>(Result)) {
2771 DependentSizedExtVectorTypeLoc NewTL
2772 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2773 NewTL.setNameLoc(TL.getNameLoc());
2774 } else {
2775 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2776 NewTL.setNameLoc(TL.getNameLoc());
2777 }
2778
2779 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002780}
Mike Stump1eb44332009-09-09 15:08:12 +00002781
2782template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002783QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002784 VectorTypeLoc TL,
2785 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002786 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002787 QualType ElementType = getDerived().TransformType(T->getElementType());
2788 if (ElementType.isNull())
2789 return QualType();
2790
John McCalla2becad2009-10-21 00:40:46 +00002791 QualType Result = TL.getType();
2792 if (getDerived().AlwaysRebuild() ||
2793 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002794 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2795 T->isAltiVec(), T->isPixel());
John McCalla2becad2009-10-21 00:40:46 +00002796 if (Result.isNull())
2797 return QualType();
2798 }
Sean Huntc3021132010-05-05 15:23:54 +00002799
John McCalla2becad2009-10-21 00:40:46 +00002800 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2801 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002802
John McCalla2becad2009-10-21 00:40:46 +00002803 return Result;
2804}
2805
2806template<typename Derived>
2807QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002808 ExtVectorTypeLoc TL,
2809 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002810 VectorType *T = TL.getTypePtr();
2811 QualType ElementType = getDerived().TransformType(T->getElementType());
2812 if (ElementType.isNull())
2813 return QualType();
2814
2815 QualType Result = TL.getType();
2816 if (getDerived().AlwaysRebuild() ||
2817 ElementType != T->getElementType()) {
2818 Result = getDerived().RebuildExtVectorType(ElementType,
2819 T->getNumElements(),
2820 /*FIXME*/ SourceLocation());
2821 if (Result.isNull())
2822 return QualType();
2823 }
Sean Huntc3021132010-05-05 15:23:54 +00002824
John McCalla2becad2009-10-21 00:40:46 +00002825 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2826 NewTL.setNameLoc(TL.getNameLoc());
2827
2828 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002829}
Mike Stump1eb44332009-09-09 15:08:12 +00002830
2831template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002832ParmVarDecl *
2833TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2834 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2835 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2836 if (!NewDI)
2837 return 0;
2838
2839 if (NewDI == OldDI)
2840 return OldParm;
2841 else
2842 return ParmVarDecl::Create(SemaRef.Context,
2843 OldParm->getDeclContext(),
2844 OldParm->getLocation(),
2845 OldParm->getIdentifier(),
2846 NewDI->getType(),
2847 NewDI,
2848 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002849 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002850 /* DefArg */ NULL);
2851}
2852
2853template<typename Derived>
2854bool TreeTransform<Derived>::
2855 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2856 llvm::SmallVectorImpl<QualType> &PTypes,
2857 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2858 FunctionProtoType *T = TL.getTypePtr();
2859
2860 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2861 ParmVarDecl *OldParm = TL.getArg(i);
2862
2863 QualType NewType;
2864 ParmVarDecl *NewParm;
2865
2866 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002867 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2868 if (!NewParm)
2869 return true;
2870 NewType = NewParm->getType();
2871
2872 // Deal with the possibility that we don't have a parameter
2873 // declaration for this parameter.
2874 } else {
2875 NewParm = 0;
2876
2877 QualType OldType = T->getArgType(i);
2878 NewType = getDerived().TransformType(OldType);
2879 if (NewType.isNull())
2880 return true;
2881 }
2882
2883 PTypes.push_back(NewType);
2884 PVars.push_back(NewParm);
2885 }
2886
2887 return false;
2888}
2889
2890template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002891QualType
John McCalla2becad2009-10-21 00:40:46 +00002892TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002893 FunctionProtoTypeLoc TL,
2894 QualType ObjectType) {
Douglas Gregor895162d2010-04-30 18:55:50 +00002895 // Transform the parameters. We do this first for the benefit of template
2896 // instantiations, so that the ParmVarDecls get/ placed into the template
2897 // instantiation scope before we transform the function type.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002898 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002899 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall21ef0fa2010-03-11 09:03:00 +00002900 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2901 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002902
Douglas Gregor895162d2010-04-30 18:55:50 +00002903 FunctionProtoType *T = TL.getTypePtr();
2904 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2905 if (ResultType.isNull())
2906 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002907
John McCalla2becad2009-10-21 00:40:46 +00002908 QualType Result = TL.getType();
2909 if (getDerived().AlwaysRebuild() ||
2910 ResultType != T->getResultType() ||
2911 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2912 Result = getDerived().RebuildFunctionProtoType(ResultType,
2913 ParamTypes.data(),
2914 ParamTypes.size(),
2915 T->isVariadic(),
2916 T->getTypeQuals());
2917 if (Result.isNull())
2918 return QualType();
2919 }
Mike Stump1eb44332009-09-09 15:08:12 +00002920
John McCalla2becad2009-10-21 00:40:46 +00002921 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2922 NewTL.setLParenLoc(TL.getLParenLoc());
2923 NewTL.setRParenLoc(TL.getRParenLoc());
2924 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2925 NewTL.setArg(i, ParamDecls[i]);
2926
2927 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002928}
Mike Stump1eb44332009-09-09 15:08:12 +00002929
Douglas Gregor577f75a2009-08-04 16:50:30 +00002930template<typename Derived>
2931QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002932 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002933 FunctionNoProtoTypeLoc TL,
2934 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002935 FunctionNoProtoType *T = TL.getTypePtr();
2936 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2937 if (ResultType.isNull())
2938 return QualType();
2939
2940 QualType Result = TL.getType();
2941 if (getDerived().AlwaysRebuild() ||
2942 ResultType != T->getResultType())
2943 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2944
2945 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2946 NewTL.setLParenLoc(TL.getLParenLoc());
2947 NewTL.setRParenLoc(TL.getRParenLoc());
2948
2949 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002950}
Mike Stump1eb44332009-09-09 15:08:12 +00002951
John McCalled976492009-12-04 22:46:56 +00002952template<typename Derived> QualType
2953TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002954 UnresolvedUsingTypeLoc TL,
2955 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00002956 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002957 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00002958 if (!D)
2959 return QualType();
2960
2961 QualType Result = TL.getType();
2962 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2963 Result = getDerived().RebuildUnresolvedUsingType(D);
2964 if (Result.isNull())
2965 return QualType();
2966 }
2967
2968 // We might get an arbitrary type spec type back. We should at
2969 // least always get a type spec type, though.
2970 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2971 NewTL.setNameLoc(TL.getNameLoc());
2972
2973 return Result;
2974}
2975
Douglas Gregor577f75a2009-08-04 16:50:30 +00002976template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002977QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002978 TypedefTypeLoc TL,
2979 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002980 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002981 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002982 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2983 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002984 if (!Typedef)
2985 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002986
John McCalla2becad2009-10-21 00:40:46 +00002987 QualType Result = TL.getType();
2988 if (getDerived().AlwaysRebuild() ||
2989 Typedef != T->getDecl()) {
2990 Result = getDerived().RebuildTypedefType(Typedef);
2991 if (Result.isNull())
2992 return QualType();
2993 }
Mike Stump1eb44332009-09-09 15:08:12 +00002994
John McCalla2becad2009-10-21 00:40:46 +00002995 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2996 NewTL.setNameLoc(TL.getNameLoc());
2997
2998 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002999}
Mike Stump1eb44332009-09-09 15:08:12 +00003000
Douglas Gregor577f75a2009-08-04 16:50:30 +00003001template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003002QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003003 TypeOfExprTypeLoc TL,
3004 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003005 // typeof expressions are not potentially evaluated contexts
3006 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003007
John McCallcfb708c2010-01-13 20:03:27 +00003008 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003009 if (E.isInvalid())
3010 return QualType();
3011
John McCalla2becad2009-10-21 00:40:46 +00003012 QualType Result = TL.getType();
3013 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003014 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003015 Result = getDerived().RebuildTypeOfExprType(move(E));
3016 if (Result.isNull())
3017 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003018 }
John McCalla2becad2009-10-21 00:40:46 +00003019 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003020
John McCalla2becad2009-10-21 00:40:46 +00003021 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003022 NewTL.setTypeofLoc(TL.getTypeofLoc());
3023 NewTL.setLParenLoc(TL.getLParenLoc());
3024 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003025
3026 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003027}
Mike Stump1eb44332009-09-09 15:08:12 +00003028
3029template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003030QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003031 TypeOfTypeLoc TL,
3032 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00003033 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3034 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3035 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003036 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003037
John McCalla2becad2009-10-21 00:40:46 +00003038 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003039 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3040 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003041 if (Result.isNull())
3042 return QualType();
3043 }
Mike Stump1eb44332009-09-09 15:08:12 +00003044
John McCalla2becad2009-10-21 00:40:46 +00003045 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003046 NewTL.setTypeofLoc(TL.getTypeofLoc());
3047 NewTL.setLParenLoc(TL.getLParenLoc());
3048 NewTL.setRParenLoc(TL.getRParenLoc());
3049 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003050
3051 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003052}
Mike Stump1eb44332009-09-09 15:08:12 +00003053
3054template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003055QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003056 DecltypeTypeLoc TL,
3057 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003058 DecltypeType *T = TL.getTypePtr();
3059
Douglas Gregor670444e2009-08-04 22:27:00 +00003060 // decltype expressions are not potentially evaluated contexts
3061 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003062
Douglas Gregor577f75a2009-08-04 16:50:30 +00003063 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3064 if (E.isInvalid())
3065 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003066
John McCalla2becad2009-10-21 00:40:46 +00003067 QualType Result = TL.getType();
3068 if (getDerived().AlwaysRebuild() ||
3069 E.get() != T->getUnderlyingExpr()) {
3070 Result = getDerived().RebuildDecltypeType(move(E));
3071 if (Result.isNull())
3072 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003073 }
John McCalla2becad2009-10-21 00:40:46 +00003074 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003075
John McCalla2becad2009-10-21 00:40:46 +00003076 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3077 NewTL.setNameLoc(TL.getNameLoc());
3078
3079 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003080}
3081
3082template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003083QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003084 RecordTypeLoc TL,
3085 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003086 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003087 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003088 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3089 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003090 if (!Record)
3091 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003092
John McCalla2becad2009-10-21 00:40:46 +00003093 QualType Result = TL.getType();
3094 if (getDerived().AlwaysRebuild() ||
3095 Record != T->getDecl()) {
3096 Result = getDerived().RebuildRecordType(Record);
3097 if (Result.isNull())
3098 return QualType();
3099 }
Mike Stump1eb44332009-09-09 15:08:12 +00003100
John McCalla2becad2009-10-21 00:40:46 +00003101 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3102 NewTL.setNameLoc(TL.getNameLoc());
3103
3104 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003105}
Mike Stump1eb44332009-09-09 15:08:12 +00003106
3107template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003108QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003109 EnumTypeLoc TL,
3110 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003111 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003112 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003113 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3114 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003115 if (!Enum)
3116 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003117
John McCalla2becad2009-10-21 00:40:46 +00003118 QualType Result = TL.getType();
3119 if (getDerived().AlwaysRebuild() ||
3120 Enum != T->getDecl()) {
3121 Result = getDerived().RebuildEnumType(Enum);
3122 if (Result.isNull())
3123 return QualType();
3124 }
Mike Stump1eb44332009-09-09 15:08:12 +00003125
John McCalla2becad2009-10-21 00:40:46 +00003126 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3127 NewTL.setNameLoc(TL.getNameLoc());
3128
3129 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003130}
John McCall7da24312009-09-05 00:15:47 +00003131
John McCall3cb0ebd2010-03-10 03:28:59 +00003132template<typename Derived>
3133QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3134 TypeLocBuilder &TLB,
3135 InjectedClassNameTypeLoc TL,
3136 QualType ObjectType) {
3137 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3138 TL.getTypePtr()->getDecl());
3139 if (!D) return QualType();
3140
3141 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3142 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3143 return T;
3144}
3145
Mike Stump1eb44332009-09-09 15:08:12 +00003146
Douglas Gregor577f75a2009-08-04 16:50:30 +00003147template<typename Derived>
3148QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003149 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003150 TemplateTypeParmTypeLoc TL,
3151 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003152 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003153}
3154
Mike Stump1eb44332009-09-09 15:08:12 +00003155template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003156QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003157 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003158 SubstTemplateTypeParmTypeLoc TL,
3159 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003160 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003161}
3162
3163template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003164QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3165 const TemplateSpecializationType *TST,
3166 QualType ObjectType) {
3167 // FIXME: this entire method is a temporary workaround; callers
3168 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00003169
John McCall833ca992009-10-29 08:12:44 +00003170 // Fake up a TemplateSpecializationTypeLoc.
3171 TypeLocBuilder TLB;
3172 TemplateSpecializationTypeLoc TL
3173 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3174
John McCall828bff22009-10-29 18:45:58 +00003175 SourceLocation BaseLoc = getDerived().getBaseLocation();
3176
3177 TL.setTemplateNameLoc(BaseLoc);
3178 TL.setLAngleLoc(BaseLoc);
3179 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00003180 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3181 const TemplateArgument &TA = TST->getArg(i);
3182 TemplateArgumentLoc TAL;
3183 getDerived().InventTemplateArgumentLoc(TA, TAL);
3184 TL.setArgLocInfo(i, TAL.getLocInfo());
3185 }
3186
3187 TypeLocBuilder IgnoredTLB;
3188 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00003189}
Sean Huntc3021132010-05-05 15:23:54 +00003190
Douglas Gregordd62b152009-10-19 22:04:39 +00003191template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003192QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003193 TypeLocBuilder &TLB,
3194 TemplateSpecializationTypeLoc TL,
3195 QualType ObjectType) {
3196 const TemplateSpecializationType *T = TL.getTypePtr();
3197
Mike Stump1eb44332009-09-09 15:08:12 +00003198 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00003199 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003200 if (Template.isNull())
3201 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003202
John McCalld5532b62009-11-23 01:53:49 +00003203 TemplateArgumentListInfo NewTemplateArgs;
3204 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3205 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3206
3207 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3208 TemplateArgumentLoc Loc;
3209 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003210 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003211 NewTemplateArgs.addArgument(Loc);
3212 }
Mike Stump1eb44332009-09-09 15:08:12 +00003213
John McCall833ca992009-10-29 08:12:44 +00003214 // FIXME: maybe don't rebuild if all the template arguments are the same.
3215
3216 QualType Result =
3217 getDerived().RebuildTemplateSpecializationType(Template,
3218 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003219 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003220
3221 if (!Result.isNull()) {
3222 TemplateSpecializationTypeLoc NewTL
3223 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3224 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3225 NewTL.setLAngleLoc(TL.getLAngleLoc());
3226 NewTL.setRAngleLoc(TL.getRAngleLoc());
3227 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3228 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003229 }
Mike Stump1eb44332009-09-09 15:08:12 +00003230
John McCall833ca992009-10-29 08:12:44 +00003231 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003232}
Mike Stump1eb44332009-09-09 15:08:12 +00003233
3234template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003235QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003236TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3237 ElaboratedTypeLoc TL,
3238 QualType ObjectType) {
3239 ElaboratedType *T = TL.getTypePtr();
3240
3241 NestedNameSpecifier *NNS = 0;
3242 // NOTE: the qualifier in an ElaboratedType is optional.
3243 if (T->getQualifier() != 0) {
3244 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003245 TL.getQualifierRange(),
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003246 ObjectType);
3247 if (!NNS)
3248 return QualType();
3249 }
Mike Stump1eb44332009-09-09 15:08:12 +00003250
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003251 QualType NamedT;
3252 // FIXME: this test is meant to workaround a problem (failing assertion)
3253 // occurring if directly executing the code in the else branch.
3254 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3255 TemplateSpecializationTypeLoc OldNamedTL
3256 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3257 const TemplateSpecializationType* OldTST
Jim Grosbach9cbb4d82010-05-19 23:53:08 +00003258 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003259 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3260 if (NamedT.isNull())
3261 return QualType();
3262 TemplateSpecializationTypeLoc NewNamedTL
3263 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3264 NewNamedTL.copy(OldNamedTL);
3265 }
3266 else {
3267 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3268 if (NamedT.isNull())
3269 return QualType();
3270 }
Daniel Dunbara63db842010-05-14 16:34:09 +00003271
John McCalla2becad2009-10-21 00:40:46 +00003272 QualType Result = TL.getType();
3273 if (getDerived().AlwaysRebuild() ||
3274 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003275 NamedT != T->getNamedType()) {
3276 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003277 if (Result.isNull())
3278 return QualType();
3279 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003280
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003281 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003282 NewTL.setKeywordLoc(TL.getKeywordLoc());
3283 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003284
3285 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003286}
Mike Stump1eb44332009-09-09 15:08:12 +00003287
3288template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003289QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3290 DependentNameTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00003291 QualType ObjectType) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003292 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003293
Douglas Gregor577f75a2009-08-04 16:50:30 +00003294 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003295 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3296 TL.getQualifierRange(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003297 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003298 if (!NNS)
3299 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003300
John McCalla2becad2009-10-21 00:40:46 +00003301 QualType Result;
3302
Douglas Gregor577f75a2009-08-04 16:50:30 +00003303 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump1eb44332009-09-09 15:08:12 +00003304 QualType NewTemplateId
Douglas Gregor577f75a2009-08-04 16:50:30 +00003305 = getDerived().TransformType(QualType(TemplateId, 0));
3306 if (NewTemplateId.isNull())
3307 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003308
Douglas Gregor577f75a2009-08-04 16:50:30 +00003309 if (!getDerived().AlwaysRebuild() &&
3310 NNS == T->getQualifier() &&
3311 NewTemplateId == QualType(TemplateId, 0))
3312 return QualType(T, 0);
Mike Stump1eb44332009-09-09 15:08:12 +00003313
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003314 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
Douglas Gregor4a2023f2010-03-31 20:19:30 +00003315 NewTemplateId);
John McCalla2becad2009-10-21 00:40:46 +00003316 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003317 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3318 T->getIdentifier(),
3319 TL.getKeywordLoc(),
3320 TL.getQualifierRange(),
3321 TL.getNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003322 }
John McCalla2becad2009-10-21 00:40:46 +00003323 if (Result.isNull())
3324 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003325
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003326 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3327 QualType NamedT = ElabT->getNamedType();
3328 if (isa<TemplateSpecializationType>(NamedT)) {
3329 TemplateSpecializationTypeLoc NamedTLoc
3330 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3331 // FIXME: fill locations
3332 NamedTLoc.initializeLocal(TL.getNameLoc());
3333 } else {
3334 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3335 }
3336 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3337 NewTL.setKeywordLoc(TL.getKeywordLoc());
3338 NewTL.setQualifierRange(TL.getQualifierRange());
3339 }
3340 else {
3341 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3342 NewTL.setKeywordLoc(TL.getKeywordLoc());
3343 NewTL.setQualifierRange(TL.getQualifierRange());
3344 NewTL.setNameLoc(TL.getNameLoc());
3345 }
John McCalla2becad2009-10-21 00:40:46 +00003346 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003347}
Mike Stump1eb44332009-09-09 15:08:12 +00003348
Douglas Gregor577f75a2009-08-04 16:50:30 +00003349template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003350QualType
3351TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003352 ObjCInterfaceTypeLoc TL,
3353 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003354 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003355 TLB.pushFullCopy(TL);
3356 return TL.getType();
3357}
3358
3359template<typename Derived>
3360QualType
3361TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3362 ObjCObjectTypeLoc TL,
3363 QualType ObjectType) {
3364 // ObjCObjectType is never dependent.
3365 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003366 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003367}
Mike Stump1eb44332009-09-09 15:08:12 +00003368
3369template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003370QualType
3371TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003372 ObjCObjectPointerTypeLoc TL,
3373 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003374 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003375 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003376 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003377}
3378
Douglas Gregor577f75a2009-08-04 16:50:30 +00003379//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003380// Statement transformation
3381//===----------------------------------------------------------------------===//
3382template<typename Derived>
3383Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003384TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3385 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003386}
3387
3388template<typename Derived>
3389Sema::OwningStmtResult
3390TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3391 return getDerived().TransformCompoundStmt(S, false);
3392}
3393
3394template<typename Derived>
3395Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003396TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003397 bool IsStmtExpr) {
3398 bool SubStmtChanged = false;
3399 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3400 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3401 B != BEnd; ++B) {
3402 OwningStmtResult Result = getDerived().TransformStmt(*B);
3403 if (Result.isInvalid())
3404 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003405
Douglas Gregor43959a92009-08-20 07:17:43 +00003406 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3407 Statements.push_back(Result.takeAs<Stmt>());
3408 }
Mike Stump1eb44332009-09-09 15:08:12 +00003409
Douglas Gregor43959a92009-08-20 07:17:43 +00003410 if (!getDerived().AlwaysRebuild() &&
3411 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003412 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003413
3414 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3415 move_arg(Statements),
3416 S->getRBracLoc(),
3417 IsStmtExpr);
3418}
Mike Stump1eb44332009-09-09 15:08:12 +00003419
Douglas Gregor43959a92009-08-20 07:17:43 +00003420template<typename Derived>
3421Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003422TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00003423 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3424 {
3425 // The case value expressions are not potentially evaluated.
3426 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003427
Eli Friedman264c1f82009-11-19 03:14:00 +00003428 // Transform the left-hand case value.
3429 LHS = getDerived().TransformExpr(S->getLHS());
3430 if (LHS.isInvalid())
3431 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003432
Eli Friedman264c1f82009-11-19 03:14:00 +00003433 // Transform the right-hand case value (for the GNU case-range extension).
3434 RHS = getDerived().TransformExpr(S->getRHS());
3435 if (RHS.isInvalid())
3436 return SemaRef.StmtError();
3437 }
Mike Stump1eb44332009-09-09 15:08:12 +00003438
Douglas Gregor43959a92009-08-20 07:17:43 +00003439 // Build the case statement.
3440 // Case statements are always rebuilt so that they will attached to their
3441 // transformed switch statement.
3442 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3443 move(LHS),
3444 S->getEllipsisLoc(),
3445 move(RHS),
3446 S->getColonLoc());
3447 if (Case.isInvalid())
3448 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003449
Douglas Gregor43959a92009-08-20 07:17:43 +00003450 // Transform the statement following the case
3451 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3452 if (SubStmt.isInvalid())
3453 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003454
Douglas Gregor43959a92009-08-20 07:17:43 +00003455 // Attach the body to the case statement
3456 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3457}
3458
3459template<typename Derived>
3460Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003461TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003462 // Transform the statement following the default case
3463 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3464 if (SubStmt.isInvalid())
3465 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003466
Douglas Gregor43959a92009-08-20 07:17:43 +00003467 // Default statements are always rebuilt
3468 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3469 move(SubStmt));
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>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003475 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3476 if (SubStmt.isInvalid())
3477 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003478
Douglas Gregor43959a92009-08-20 07:17:43 +00003479 // FIXME: Pass the real colon location in.
3480 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3481 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3482 move(SubStmt));
3483}
Mike Stump1eb44332009-09-09 15:08:12 +00003484
Douglas Gregor43959a92009-08-20 07:17:43 +00003485template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003486Sema::OwningStmtResult
3487TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003488 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003489 OwningExprResult Cond(SemaRef);
3490 VarDecl *ConditionVar = 0;
3491 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003492 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003493 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003494 getDerived().TransformDefinition(
3495 S->getConditionVariable()->getLocation(),
3496 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003497 if (!ConditionVar)
3498 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003499 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003500 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003501
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003502 if (Cond.isInvalid())
3503 return SemaRef.StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003504
3505 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003506 if (S->getCond()) {
3507 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3508 S->getIfLoc(),
3509 move(Cond));
3510 if (CondE.isInvalid())
3511 return getSema().StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003512
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003513 Cond = move(CondE);
3514 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003515 }
Sean Huntc3021132010-05-05 15:23:54 +00003516
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003517 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3518 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3519 return SemaRef.StmtError();
3520
Douglas Gregor43959a92009-08-20 07:17:43 +00003521 // Transform the "then" branch.
3522 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3523 if (Then.isInvalid())
3524 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003525
Douglas Gregor43959a92009-08-20 07:17:43 +00003526 // Transform the "else" branch.
3527 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3528 if (Else.isInvalid())
3529 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003530
Douglas Gregor43959a92009-08-20 07:17:43 +00003531 if (!getDerived().AlwaysRebuild() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003532 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003533 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003534 Then.get() == S->getThen() &&
3535 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003536 return SemaRef.Owned(S->Retain());
3537
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003538 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003539 move(Then),
Mike Stump1eb44332009-09-09 15:08:12 +00003540 S->getElseLoc(), move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +00003541}
3542
3543template<typename Derived>
3544Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003545TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003546 // Transform the condition.
Douglas Gregord3d53012009-11-24 17:07:59 +00003547 OwningExprResult Cond(SemaRef);
3548 VarDecl *ConditionVar = 0;
3549 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003550 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003551 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003552 getDerived().TransformDefinition(
3553 S->getConditionVariable()->getLocation(),
3554 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003555 if (!ConditionVar)
3556 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003557 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003558 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003559
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003560 if (Cond.isInvalid())
3561 return SemaRef.StmtError();
3562 }
Mike Stump1eb44332009-09-09 15:08:12 +00003563
Douglas Gregor43959a92009-08-20 07:17:43 +00003564 // Rebuild the switch statement.
Douglas Gregor586596f2010-05-06 17:25:47 +00003565 OwningStmtResult Switch
3566 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3567 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003568 if (Switch.isInvalid())
3569 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003570
Douglas Gregor43959a92009-08-20 07:17:43 +00003571 // Transform the body of the switch statement.
3572 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3573 if (Body.isInvalid())
3574 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003575
Douglas Gregor43959a92009-08-20 07:17:43 +00003576 // Complete the switch statement.
3577 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3578 move(Body));
3579}
Mike Stump1eb44332009-09-09 15:08:12 +00003580
Douglas Gregor43959a92009-08-20 07:17:43 +00003581template<typename Derived>
3582Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003583TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003584 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003585 OwningExprResult Cond(SemaRef);
3586 VarDecl *ConditionVar = 0;
3587 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003588 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003589 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003590 getDerived().TransformDefinition(
3591 S->getConditionVariable()->getLocation(),
3592 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003593 if (!ConditionVar)
3594 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003595 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003596 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003597
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003598 if (Cond.isInvalid())
3599 return SemaRef.StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003600
3601 if (S->getCond()) {
3602 // Convert the condition to a boolean value.
3603 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003604 S->getWhileLoc(),
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003605 move(Cond));
3606 if (CondE.isInvalid())
3607 return getSema().StmtError();
3608 Cond = move(CondE);
3609 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003610 }
Mike Stump1eb44332009-09-09 15:08:12 +00003611
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003612 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3613 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3614 return SemaRef.StmtError();
3615
Douglas Gregor43959a92009-08-20 07:17:43 +00003616 // Transform the body
3617 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3618 if (Body.isInvalid())
3619 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003620
Douglas Gregor43959a92009-08-20 07:17:43 +00003621 if (!getDerived().AlwaysRebuild() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003622 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003623 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003624 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003625 return SemaRef.Owned(S->Retain());
3626
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003627 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregor586596f2010-05-06 17:25:47 +00003628 ConditionVar, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003629}
Mike Stump1eb44332009-09-09 15:08:12 +00003630
Douglas Gregor43959a92009-08-20 07:17:43 +00003631template<typename Derived>
3632Sema::OwningStmtResult
3633TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003634 // Transform the body
3635 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3636 if (Body.isInvalid())
3637 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003638
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003639 // Transform the condition
3640 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3641 if (Cond.isInvalid())
3642 return SemaRef.StmtError();
3643
Douglas Gregor43959a92009-08-20 07:17:43 +00003644 if (!getDerived().AlwaysRebuild() &&
3645 Cond.get() == S->getCond() &&
3646 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003647 return SemaRef.Owned(S->Retain());
3648
Douglas Gregor43959a92009-08-20 07:17:43 +00003649 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3650 /*FIXME:*/S->getWhileLoc(), move(Cond),
3651 S->getRParenLoc());
3652}
Mike Stump1eb44332009-09-09 15:08:12 +00003653
Douglas Gregor43959a92009-08-20 07:17:43 +00003654template<typename Derived>
3655Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003656TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003657 // Transform the initialization statement
3658 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3659 if (Init.isInvalid())
3660 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003661
Douglas Gregor43959a92009-08-20 07:17:43 +00003662 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003663 OwningExprResult Cond(SemaRef);
3664 VarDecl *ConditionVar = 0;
3665 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003666 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003667 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003668 getDerived().TransformDefinition(
3669 S->getConditionVariable()->getLocation(),
3670 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003671 if (!ConditionVar)
3672 return SemaRef.StmtError();
3673 } else {
3674 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003675
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003676 if (Cond.isInvalid())
3677 return SemaRef.StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003678
3679 if (S->getCond()) {
3680 // Convert the condition to a boolean value.
3681 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3682 S->getForLoc(),
3683 move(Cond));
3684 if (CondE.isInvalid())
3685 return getSema().StmtError();
3686
3687 Cond = move(CondE);
3688 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003689 }
Mike Stump1eb44332009-09-09 15:08:12 +00003690
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003691 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3692 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3693 return SemaRef.StmtError();
3694
Douglas Gregor43959a92009-08-20 07:17:43 +00003695 // Transform the increment
3696 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3697 if (Inc.isInvalid())
3698 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003699
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003700 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3701 if (S->getInc() && !FullInc->get())
3702 return SemaRef.StmtError();
3703
Douglas Gregor43959a92009-08-20 07:17:43 +00003704 // Transform the body
3705 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3706 if (Body.isInvalid())
3707 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003708
Douglas Gregor43959a92009-08-20 07:17:43 +00003709 if (!getDerived().AlwaysRebuild() &&
3710 Init.get() == S->getInit() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003711 FullCond->get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003712 Inc.get() == S->getInc() &&
3713 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003714 return SemaRef.Owned(S->Retain());
3715
Douglas Gregor43959a92009-08-20 07:17:43 +00003716 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003717 move(Init), FullCond, ConditionVar,
3718 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003719}
3720
3721template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003722Sema::OwningStmtResult
3723TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003724 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003725 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003726 S->getLabel());
3727}
3728
3729template<typename Derived>
3730Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003731TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003732 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3733 if (Target.isInvalid())
3734 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003735
Douglas Gregor43959a92009-08-20 07:17:43 +00003736 if (!getDerived().AlwaysRebuild() &&
3737 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003738 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003739
3740 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3741 move(Target));
3742}
3743
3744template<typename Derived>
3745Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003746TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3747 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003748}
Mike Stump1eb44332009-09-09 15:08:12 +00003749
Douglas Gregor43959a92009-08-20 07:17:43 +00003750template<typename Derived>
3751Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003752TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3753 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003754}
Mike Stump1eb44332009-09-09 15:08:12 +00003755
Douglas Gregor43959a92009-08-20 07:17:43 +00003756template<typename Derived>
3757Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003758TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003759 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3760 if (Result.isInvalid())
3761 return SemaRef.StmtError();
3762
Mike Stump1eb44332009-09-09 15:08:12 +00003763 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003764 // to tell whether the return type of the function has changed.
3765 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3766}
Mike Stump1eb44332009-09-09 15:08:12 +00003767
Douglas Gregor43959a92009-08-20 07:17:43 +00003768template<typename Derived>
3769Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003770TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003771 bool DeclChanged = false;
3772 llvm::SmallVector<Decl *, 4> Decls;
3773 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3774 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003775 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3776 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003777 if (!Transformed)
3778 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003779
Douglas Gregor43959a92009-08-20 07:17:43 +00003780 if (Transformed != *D)
3781 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003782
Douglas Gregor43959a92009-08-20 07:17:43 +00003783 Decls.push_back(Transformed);
3784 }
Mike Stump1eb44332009-09-09 15:08:12 +00003785
Douglas Gregor43959a92009-08-20 07:17:43 +00003786 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003787 return SemaRef.Owned(S->Retain());
3788
3789 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003790 S->getStartLoc(), S->getEndLoc());
3791}
Mike Stump1eb44332009-09-09 15:08:12 +00003792
Douglas Gregor43959a92009-08-20 07:17:43 +00003793template<typename Derived>
3794Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003795TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003796 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003797 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003798}
3799
3800template<typename Derived>
3801Sema::OwningStmtResult
3802TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003803
Anders Carlsson703e3942010-01-24 05:50:09 +00003804 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3805 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003806 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003807
Anders Carlsson703e3942010-01-24 05:50:09 +00003808 OwningExprResult AsmString(SemaRef);
3809 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3810
3811 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003812
Anders Carlsson703e3942010-01-24 05:50:09 +00003813 // Go through the outputs.
3814 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003815 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003816
Anders Carlsson703e3942010-01-24 05:50:09 +00003817 // No need to transform the constraint literal.
3818 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003819
Anders Carlsson703e3942010-01-24 05:50:09 +00003820 // Transform the output expr.
3821 Expr *OutputExpr = S->getOutputExpr(I);
3822 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3823 if (Result.isInvalid())
3824 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003825
Anders Carlsson703e3942010-01-24 05:50:09 +00003826 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003827
Anders Carlsson703e3942010-01-24 05:50:09 +00003828 Exprs.push_back(Result.takeAs<Expr>());
3829 }
Sean Huntc3021132010-05-05 15:23:54 +00003830
Anders Carlsson703e3942010-01-24 05:50:09 +00003831 // Go through the inputs.
3832 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003833 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003834
Anders Carlsson703e3942010-01-24 05:50:09 +00003835 // No need to transform the constraint literal.
3836 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003837
Anders Carlsson703e3942010-01-24 05:50:09 +00003838 // Transform the input expr.
3839 Expr *InputExpr = S->getInputExpr(I);
3840 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3841 if (Result.isInvalid())
3842 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003843
Anders Carlsson703e3942010-01-24 05:50:09 +00003844 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003845
Anders Carlsson703e3942010-01-24 05:50:09 +00003846 Exprs.push_back(Result.takeAs<Expr>());
3847 }
Sean Huntc3021132010-05-05 15:23:54 +00003848
Anders Carlsson703e3942010-01-24 05:50:09 +00003849 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3850 return SemaRef.Owned(S->Retain());
3851
3852 // Go through the clobbers.
3853 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3854 Clobbers.push_back(S->getClobber(I)->Retain());
3855
3856 // No need to transform the asm string literal.
3857 AsmString = SemaRef.Owned(S->getAsmString());
3858
3859 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3860 S->isSimple(),
3861 S->isVolatile(),
3862 S->getNumOutputs(),
3863 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003864 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003865 move_arg(Constraints),
3866 move_arg(Exprs),
3867 move(AsmString),
3868 move_arg(Clobbers),
3869 S->getRParenLoc(),
3870 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003871}
3872
3873
3874template<typename Derived>
3875Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003876TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003877 // Transform the body of the @try.
3878 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3879 if (TryBody.isInvalid())
3880 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003881
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003882 // Transform the @catch statements (if present).
3883 bool AnyCatchChanged = false;
3884 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3885 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3886 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003887 if (Catch.isInvalid())
3888 return SemaRef.StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003889 if (Catch.get() != S->getCatchStmt(I))
3890 AnyCatchChanged = true;
3891 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003892 }
Sean Huntc3021132010-05-05 15:23:54 +00003893
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003894 // Transform the @finally statement (if present).
3895 OwningStmtResult Finally(SemaRef);
3896 if (S->getFinallyStmt()) {
3897 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3898 if (Finally.isInvalid())
3899 return SemaRef.StmtError();
3900 }
3901
3902 // If nothing changed, just retain this statement.
3903 if (!getDerived().AlwaysRebuild() &&
3904 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003905 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003906 Finally.get() == S->getFinallyStmt())
3907 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003908
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003909 // Build a new statement.
3910 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003911 move_arg(CatchStmts), move(Finally));
Douglas Gregor43959a92009-08-20 07:17:43 +00003912}
Mike Stump1eb44332009-09-09 15:08:12 +00003913
Douglas Gregor43959a92009-08-20 07:17:43 +00003914template<typename Derived>
3915Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003916TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00003917 // Transform the @catch parameter, if there is one.
3918 VarDecl *Var = 0;
3919 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3920 TypeSourceInfo *TSInfo = 0;
3921 if (FromVar->getTypeSourceInfo()) {
3922 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3923 if (!TSInfo)
3924 return SemaRef.StmtError();
3925 }
Sean Huntc3021132010-05-05 15:23:54 +00003926
Douglas Gregorbe270a02010-04-26 17:57:08 +00003927 QualType T;
3928 if (TSInfo)
3929 T = TSInfo->getType();
3930 else {
3931 T = getDerived().TransformType(FromVar->getType());
3932 if (T.isNull())
Sean Huntc3021132010-05-05 15:23:54 +00003933 return SemaRef.StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00003934 }
Sean Huntc3021132010-05-05 15:23:54 +00003935
Douglas Gregorbe270a02010-04-26 17:57:08 +00003936 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3937 if (!Var)
3938 return SemaRef.StmtError();
3939 }
Sean Huntc3021132010-05-05 15:23:54 +00003940
Douglas Gregorbe270a02010-04-26 17:57:08 +00003941 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3942 if (Body.isInvalid())
3943 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003944
3945 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00003946 S->getRParenLoc(),
3947 Var, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003948}
Mike Stump1eb44332009-09-09 15:08:12 +00003949
Douglas Gregor43959a92009-08-20 07:17:43 +00003950template<typename Derived>
3951Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003952TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003953 // Transform the body.
3954 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
3955 if (Body.isInvalid())
3956 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003957
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003958 // If nothing changed, just retain this statement.
3959 if (!getDerived().AlwaysRebuild() &&
3960 Body.get() == S->getFinallyBody())
3961 return SemaRef.Owned(S->Retain());
3962
3963 // Build a new statement.
3964 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
3965 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003966}
Mike Stump1eb44332009-09-09 15:08:12 +00003967
Douglas Gregor43959a92009-08-20 07:17:43 +00003968template<typename Derived>
3969Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003970TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregord1377b22010-04-22 21:44:01 +00003971 OwningExprResult Operand(SemaRef);
3972 if (S->getThrowExpr()) {
3973 Operand = getDerived().TransformExpr(S->getThrowExpr());
3974 if (Operand.isInvalid())
3975 return getSema().StmtError();
3976 }
Sean Huntc3021132010-05-05 15:23:54 +00003977
Douglas Gregord1377b22010-04-22 21:44:01 +00003978 if (!getDerived().AlwaysRebuild() &&
3979 Operand.get() == S->getThrowExpr())
3980 return getSema().Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003981
Douglas Gregord1377b22010-04-22 21:44:01 +00003982 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregor43959a92009-08-20 07:17:43 +00003983}
Mike Stump1eb44332009-09-09 15:08:12 +00003984
Douglas Gregor43959a92009-08-20 07:17:43 +00003985template<typename Derived>
3986Sema::OwningStmtResult
3987TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003988 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00003989 // Transform the object we are locking.
3990 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3991 if (Object.isInvalid())
3992 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003993
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00003994 // Transform the body.
3995 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3996 if (Body.isInvalid())
3997 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003998
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00003999 // If nothing change, just retain the current statement.
4000 if (!getDerived().AlwaysRebuild() &&
4001 Object.get() == S->getSynchExpr() &&
4002 Body.get() == S->getSynchBody())
4003 return SemaRef.Owned(S->Retain());
4004
4005 // Build a new statement.
4006 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
4007 move(Object), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004008}
4009
4010template<typename Derived>
4011Sema::OwningStmtResult
4012TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004013 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004014 // Transform the element statement.
4015 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
4016 if (Element.isInvalid())
4017 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004018
Douglas Gregorc3203e72010-04-22 23:10:45 +00004019 // Transform the collection expression.
4020 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
4021 if (Collection.isInvalid())
4022 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004023
Douglas Gregorc3203e72010-04-22 23:10:45 +00004024 // Transform the body.
4025 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
4026 if (Body.isInvalid())
4027 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004028
Douglas Gregorc3203e72010-04-22 23:10:45 +00004029 // If nothing changed, just retain this statement.
4030 if (!getDerived().AlwaysRebuild() &&
4031 Element.get() == S->getElement() &&
4032 Collection.get() == S->getCollection() &&
4033 Body.get() == S->getBody())
4034 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004035
Douglas Gregorc3203e72010-04-22 23:10:45 +00004036 // Build a new statement.
4037 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4038 /*FIXME:*/S->getForLoc(),
4039 move(Element),
4040 move(Collection),
4041 S->getRParenLoc(),
4042 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004043}
4044
4045
4046template<typename Derived>
4047Sema::OwningStmtResult
4048TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4049 // Transform the exception declaration, if any.
4050 VarDecl *Var = 0;
4051 if (S->getExceptionDecl()) {
4052 VarDecl *ExceptionDecl = S->getExceptionDecl();
4053 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4054 ExceptionDecl->getDeclName());
4055
4056 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4057 if (T.isNull())
4058 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004059
Douglas Gregor43959a92009-08-20 07:17:43 +00004060 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4061 T,
John McCalla93c9342009-12-07 02:54:59 +00004062 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004063 ExceptionDecl->getIdentifier(),
4064 ExceptionDecl->getLocation(),
4065 /*FIXME: Inaccurate*/
4066 SourceRange(ExceptionDecl->getLocation()));
4067 if (!Var || Var->isInvalidDecl()) {
4068 if (Var)
4069 Var->Destroy(SemaRef.Context);
4070 return SemaRef.StmtError();
4071 }
4072 }
Mike Stump1eb44332009-09-09 15:08:12 +00004073
Douglas Gregor43959a92009-08-20 07:17:43 +00004074 // Transform the actual exception handler.
4075 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4076 if (Handler.isInvalid()) {
4077 if (Var)
4078 Var->Destroy(SemaRef.Context);
4079 return SemaRef.StmtError();
4080 }
Mike Stump1eb44332009-09-09 15:08:12 +00004081
Douglas Gregor43959a92009-08-20 07:17:43 +00004082 if (!getDerived().AlwaysRebuild() &&
4083 !Var &&
4084 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00004085 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004086
4087 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4088 Var,
4089 move(Handler));
4090}
Mike Stump1eb44332009-09-09 15:08:12 +00004091
Douglas Gregor43959a92009-08-20 07:17:43 +00004092template<typename Derived>
4093Sema::OwningStmtResult
4094TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4095 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00004096 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004097 = getDerived().TransformCompoundStmt(S->getTryBlock());
4098 if (TryBlock.isInvalid())
4099 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004100
Douglas Gregor43959a92009-08-20 07:17:43 +00004101 // Transform the handlers.
4102 bool HandlerChanged = false;
4103 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4104 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00004105 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004106 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4107 if (Handler.isInvalid())
4108 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004109
Douglas Gregor43959a92009-08-20 07:17:43 +00004110 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4111 Handlers.push_back(Handler.takeAs<Stmt>());
4112 }
Mike Stump1eb44332009-09-09 15:08:12 +00004113
Douglas Gregor43959a92009-08-20 07:17:43 +00004114 if (!getDerived().AlwaysRebuild() &&
4115 TryBlock.get() == S->getTryBlock() &&
4116 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004117 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004118
4119 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00004120 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004121}
Mike Stump1eb44332009-09-09 15:08:12 +00004122
Douglas Gregor43959a92009-08-20 07:17:43 +00004123//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004124// Expression transformation
4125//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004126template<typename Derived>
4127Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004128TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004129 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004130}
Mike Stump1eb44332009-09-09 15:08:12 +00004131
4132template<typename Derived>
4133Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004134TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004135 NestedNameSpecifier *Qualifier = 0;
4136 if (E->getQualifier()) {
4137 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004138 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004139 if (!Qualifier)
4140 return SemaRef.ExprError();
4141 }
John McCalldbd872f2009-12-08 09:08:17 +00004142
4143 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004144 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4145 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004146 if (!ND)
4147 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004148
Sean Huntc3021132010-05-05 15:23:54 +00004149 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004150 Qualifier == E->getQualifier() &&
4151 ND == E->getDecl() &&
John McCalldbd872f2009-12-08 09:08:17 +00004152 !E->hasExplicitTemplateArgumentList()) {
4153
4154 // Mark it referenced in the new context regardless.
4155 // FIXME: this is a bit instantiation-specific.
4156 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4157
Mike Stump1eb44332009-09-09 15:08:12 +00004158 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004159 }
John McCalldbd872f2009-12-08 09:08:17 +00004160
4161 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4162 if (E->hasExplicitTemplateArgumentList()) {
4163 TemplateArgs = &TransArgs;
4164 TransArgs.setLAngleLoc(E->getLAngleLoc());
4165 TransArgs.setRAngleLoc(E->getRAngleLoc());
4166 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4167 TemplateArgumentLoc Loc;
4168 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4169 return SemaRef.ExprError();
4170 TransArgs.addArgument(Loc);
4171 }
4172 }
4173
Douglas Gregora2813ce2009-10-23 18:54:35 +00004174 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCalldbd872f2009-12-08 09:08:17 +00004175 ND, E->getLocation(), TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004176}
Mike Stump1eb44332009-09-09 15:08:12 +00004177
Douglas Gregorb98b1992009-08-11 05:31:07 +00004178template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004179Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004180TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *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
Douglas Gregorb98b1992009-08-11 05:31:07 +00004184template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004185Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004186TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004187 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004188}
Mike Stump1eb44332009-09-09 15:08:12 +00004189
Douglas Gregorb98b1992009-08-11 05:31:07 +00004190template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004191Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004192TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004193 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004194}
Mike Stump1eb44332009-09-09 15:08:12 +00004195
Douglas Gregorb98b1992009-08-11 05:31:07 +00004196template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004197Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004198TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004199 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004200}
Mike Stump1eb44332009-09-09 15:08:12 +00004201
Douglas Gregorb98b1992009-08-11 05:31:07 +00004202template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004203Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004204TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004205 return SemaRef.Owned(E->Retain());
4206}
4207
4208template<typename Derived>
4209Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004210TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004211 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4212 if (SubExpr.isInvalid())
4213 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004214
Douglas Gregorb98b1992009-08-11 05:31:07 +00004215 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004216 return SemaRef.Owned(E->Retain());
4217
4218 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004219 E->getRParen());
4220}
4221
Mike Stump1eb44332009-09-09 15:08:12 +00004222template<typename Derived>
4223Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004224TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4225 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004226 if (SubExpr.isInvalid())
4227 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004228
Douglas Gregorb98b1992009-08-11 05:31:07 +00004229 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004230 return SemaRef.Owned(E->Retain());
4231
Douglas Gregorb98b1992009-08-11 05:31:07 +00004232 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4233 E->getOpcode(),
4234 move(SubExpr));
4235}
Mike Stump1eb44332009-09-09 15:08:12 +00004236
Douglas Gregorb98b1992009-08-11 05:31:07 +00004237template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004238Sema::OwningExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004239TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4240 // Transform the type.
4241 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4242 if (!Type)
4243 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004244
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004245 // Transform all of the components into components similar to what the
4246 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004247 // FIXME: It would be slightly more efficient in the non-dependent case to
4248 // just map FieldDecls, rather than requiring the rebuilder to look for
4249 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004250 // template code that we don't care.
4251 bool ExprChanged = false;
4252 typedef Action::OffsetOfComponent Component;
4253 typedef OffsetOfExpr::OffsetOfNode Node;
4254 llvm::SmallVector<Component, 4> Components;
4255 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4256 const Node &ON = E->getComponent(I);
4257 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004258 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004259 Comp.LocStart = ON.getRange().getBegin();
4260 Comp.LocEnd = ON.getRange().getEnd();
4261 switch (ON.getKind()) {
4262 case Node::Array: {
4263 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4264 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4265 if (Index.isInvalid())
4266 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004267
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004268 ExprChanged = ExprChanged || Index.get() != FromIndex;
4269 Comp.isBrackets = true;
4270 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4271 break;
4272 }
Sean Huntc3021132010-05-05 15:23:54 +00004273
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004274 case Node::Field:
4275 case Node::Identifier:
4276 Comp.isBrackets = false;
4277 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004278 if (!Comp.U.IdentInfo)
4279 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004280
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004281 break;
Sean Huntc3021132010-05-05 15:23:54 +00004282
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004283 case Node::Base:
4284 // Will be recomputed during the rebuild.
4285 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004286 }
Sean Huntc3021132010-05-05 15:23:54 +00004287
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004288 Components.push_back(Comp);
4289 }
Sean Huntc3021132010-05-05 15:23:54 +00004290
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004291 // If nothing changed, retain the existing expression.
4292 if (!getDerived().AlwaysRebuild() &&
4293 Type == E->getTypeSourceInfo() &&
4294 !ExprChanged)
4295 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004296
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004297 // Build a new offsetof expression.
4298 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4299 Components.data(), Components.size(),
4300 E->getRParenLoc());
4301}
4302
4303template<typename Derived>
4304Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004305TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004306 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004307 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004308
John McCalla93c9342009-12-07 02:54:59 +00004309 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004310 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004311 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004312
John McCall5ab75172009-11-04 07:28:41 +00004313 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004314 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004315
John McCall5ab75172009-11-04 07:28:41 +00004316 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004317 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004318 E->getSourceRange());
4319 }
Mike Stump1eb44332009-09-09 15:08:12 +00004320
Douglas Gregorb98b1992009-08-11 05:31:07 +00004321 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00004322 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004323 // C++0x [expr.sizeof]p1:
4324 // The operand is either an expression, which is an unevaluated operand
4325 // [...]
4326 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004327
Douglas Gregorb98b1992009-08-11 05:31:07 +00004328 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4329 if (SubExpr.isInvalid())
4330 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004331
Douglas Gregorb98b1992009-08-11 05:31:07 +00004332 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4333 return SemaRef.Owned(E->Retain());
4334 }
Mike Stump1eb44332009-09-09 15:08:12 +00004335
Douglas Gregorb98b1992009-08-11 05:31:07 +00004336 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4337 E->isSizeOf(),
4338 E->getSourceRange());
4339}
Mike Stump1eb44332009-09-09 15:08:12 +00004340
Douglas Gregorb98b1992009-08-11 05:31:07 +00004341template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004342Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004343TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004344 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4345 if (LHS.isInvalid())
4346 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004347
Douglas Gregorb98b1992009-08-11 05:31:07 +00004348 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4349 if (RHS.isInvalid())
4350 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004351
4352
Douglas Gregorb98b1992009-08-11 05:31:07 +00004353 if (!getDerived().AlwaysRebuild() &&
4354 LHS.get() == E->getLHS() &&
4355 RHS.get() == E->getRHS())
4356 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004357
Douglas Gregorb98b1992009-08-11 05:31:07 +00004358 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4359 /*FIXME:*/E->getLHS()->getLocStart(),
4360 move(RHS),
4361 E->getRBracketLoc());
4362}
Mike Stump1eb44332009-09-09 15:08:12 +00004363
4364template<typename Derived>
4365Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004366TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004367 // Transform the callee.
4368 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4369 if (Callee.isInvalid())
4370 return SemaRef.ExprError();
4371
4372 // Transform arguments.
4373 bool ArgChanged = false;
4374 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4375 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4376 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4377 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4378 if (Arg.isInvalid())
4379 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004380
Douglas Gregorb98b1992009-08-11 05:31:07 +00004381 // FIXME: Wrong source location information for the ','.
4382 FakeCommaLocs.push_back(
4383 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00004384
4385 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004386 Args.push_back(Arg.takeAs<Expr>());
4387 }
Mike Stump1eb44332009-09-09 15:08:12 +00004388
Douglas Gregorb98b1992009-08-11 05:31:07 +00004389 if (!getDerived().AlwaysRebuild() &&
4390 Callee.get() == E->getCallee() &&
4391 !ArgChanged)
4392 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004393
Douglas Gregorb98b1992009-08-11 05:31:07 +00004394 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004395 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004396 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4397 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4398 move_arg(Args),
4399 FakeCommaLocs.data(),
4400 E->getRParenLoc());
4401}
Mike Stump1eb44332009-09-09 15:08:12 +00004402
4403template<typename Derived>
4404Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004405TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004406 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4407 if (Base.isInvalid())
4408 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004409
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004410 NestedNameSpecifier *Qualifier = 0;
4411 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004412 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004413 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004414 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004415 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004416 return SemaRef.ExprError();
4417 }
Mike Stump1eb44332009-09-09 15:08:12 +00004418
Eli Friedmanf595cc42009-12-04 06:40:45 +00004419 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004420 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4421 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004422 if (!Member)
4423 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004424
John McCall6bb80172010-03-30 21:47:33 +00004425 NamedDecl *FoundDecl = E->getFoundDecl();
4426 if (FoundDecl == E->getMemberDecl()) {
4427 FoundDecl = Member;
4428 } else {
4429 FoundDecl = cast_or_null<NamedDecl>(
4430 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4431 if (!FoundDecl)
4432 return SemaRef.ExprError();
4433 }
4434
Douglas Gregorb98b1992009-08-11 05:31:07 +00004435 if (!getDerived().AlwaysRebuild() &&
4436 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004437 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004438 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004439 FoundDecl == E->getFoundDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00004440 !E->hasExplicitTemplateArgumentList()) {
Sean Huntc3021132010-05-05 15:23:54 +00004441
Anders Carlsson1f240322009-12-22 05:24:09 +00004442 // Mark it referenced in the new context regardless.
4443 // FIXME: this is a bit instantiation-specific.
4444 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00004445 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00004446 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004447
John McCalld5532b62009-11-23 01:53:49 +00004448 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004449 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00004450 TransArgs.setLAngleLoc(E->getLAngleLoc());
4451 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004452 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004453 TemplateArgumentLoc Loc;
4454 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004455 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004456 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004457 }
4458 }
Sean Huntc3021132010-05-05 15:23:54 +00004459
Douglas Gregorb98b1992009-08-11 05:31:07 +00004460 // FIXME: Bogus source location for the operator
4461 SourceLocation FakeOperatorLoc
4462 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4463
John McCallc2233c52010-01-15 08:34:02 +00004464 // FIXME: to do this check properly, we will need to preserve the
4465 // first-qualifier-in-scope here, just in case we had a dependent
4466 // base (and therefore couldn't do the check) and a
4467 // nested-name-qualifier (and therefore could do the lookup).
4468 NamedDecl *FirstQualifierInScope = 0;
4469
Douglas Gregorb98b1992009-08-11 05:31:07 +00004470 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4471 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004472 Qualifier,
4473 E->getQualifierRange(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004474 E->getMemberLoc(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004475 Member,
John McCall6bb80172010-03-30 21:47:33 +00004476 FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00004477 (E->hasExplicitTemplateArgumentList()
4478 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004479 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004480}
Mike Stump1eb44332009-09-09 15:08:12 +00004481
Douglas Gregorb98b1992009-08-11 05:31:07 +00004482template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004483Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004484TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004485 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4486 if (LHS.isInvalid())
4487 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004488
Douglas Gregorb98b1992009-08-11 05:31:07 +00004489 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4490 if (RHS.isInvalid())
4491 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004492
Douglas Gregorb98b1992009-08-11 05:31:07 +00004493 if (!getDerived().AlwaysRebuild() &&
4494 LHS.get() == E->getLHS() &&
4495 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004496 return SemaRef.Owned(E->Retain());
4497
Douglas Gregorb98b1992009-08-11 05:31:07 +00004498 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4499 move(LHS), move(RHS));
4500}
4501
Mike Stump1eb44332009-09-09 15:08:12 +00004502template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004503Sema::OwningExprResult
4504TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004505 CompoundAssignOperator *E) {
4506 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004507}
Mike Stump1eb44332009-09-09 15:08:12 +00004508
Douglas Gregorb98b1992009-08-11 05:31:07 +00004509template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004510Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004511TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004512 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4513 if (Cond.isInvalid())
4514 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004515
Douglas Gregorb98b1992009-08-11 05:31:07 +00004516 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4517 if (LHS.isInvalid())
4518 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004519
Douglas Gregorb98b1992009-08-11 05:31:07 +00004520 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4521 if (RHS.isInvalid())
4522 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004523
Douglas Gregorb98b1992009-08-11 05:31:07 +00004524 if (!getDerived().AlwaysRebuild() &&
4525 Cond.get() == E->getCond() &&
4526 LHS.get() == E->getLHS() &&
4527 RHS.get() == E->getRHS())
4528 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004529
4530 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004531 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004532 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004533 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004534 move(RHS));
4535}
Mike Stump1eb44332009-09-09 15:08:12 +00004536
4537template<typename Derived>
4538Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004539TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004540 // Implicit casts are eliminated during transformation, since they
4541 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004542 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004543}
Mike Stump1eb44332009-09-09 15:08:12 +00004544
Douglas Gregorb98b1992009-08-11 05:31:07 +00004545template<typename Derived>
4546Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004547TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004548 TypeSourceInfo *OldT;
4549 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004550 {
4551 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004552 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004553 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4554 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004555
John McCall9d125032010-01-15 18:39:57 +00004556 OldT = E->getTypeInfoAsWritten();
4557 NewT = getDerived().TransformType(OldT);
4558 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004559 return SemaRef.ExprError();
4560 }
Mike Stump1eb44332009-09-09 15:08:12 +00004561
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004562 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004563 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004564 if (SubExpr.isInvalid())
4565 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004566
Douglas Gregorb98b1992009-08-11 05:31:07 +00004567 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004568 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004569 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004570 return SemaRef.Owned(E->Retain());
4571
John McCall9d125032010-01-15 18:39:57 +00004572 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4573 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004574 E->getRParenLoc(),
4575 move(SubExpr));
4576}
Mike Stump1eb44332009-09-09 15:08:12 +00004577
Douglas Gregorb98b1992009-08-11 05:31:07 +00004578template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004579Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004580TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004581 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4582 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4583 if (!NewT)
4584 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004585
Douglas Gregorb98b1992009-08-11 05:31:07 +00004586 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4587 if (Init.isInvalid())
4588 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004589
Douglas Gregorb98b1992009-08-11 05:31:07 +00004590 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004591 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004592 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00004593 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004594
John McCall1d7d8d62010-01-19 22:33:45 +00004595 // Note: the expression type doesn't necessarily match the
4596 // type-as-written, but that's okay, because it should always be
4597 // derivable from the initializer.
4598
John McCall42f56b52010-01-18 19:35:47 +00004599 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004600 /*FIXME:*/E->getInitializer()->getLocEnd(),
4601 move(Init));
4602}
Mike Stump1eb44332009-09-09 15:08:12 +00004603
Douglas Gregorb98b1992009-08-11 05:31:07 +00004604template<typename Derived>
4605Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004606TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004607 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4608 if (Base.isInvalid())
4609 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004610
Douglas Gregorb98b1992009-08-11 05:31:07 +00004611 if (!getDerived().AlwaysRebuild() &&
4612 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00004613 return SemaRef.Owned(E->Retain());
4614
Douglas Gregorb98b1992009-08-11 05:31:07 +00004615 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004616 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004617 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4618 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4619 E->getAccessorLoc(),
4620 E->getAccessor());
4621}
Mike Stump1eb44332009-09-09 15:08:12 +00004622
Douglas Gregorb98b1992009-08-11 05:31:07 +00004623template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004624Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004625TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004626 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004627
Douglas Gregorb98b1992009-08-11 05:31:07 +00004628 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4629 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4630 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4631 if (Init.isInvalid())
4632 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004633
Douglas Gregorb98b1992009-08-11 05:31:07 +00004634 InitChanged = InitChanged || Init.get() != E->getInit(I);
4635 Inits.push_back(Init.takeAs<Expr>());
4636 }
Mike Stump1eb44332009-09-09 15:08:12 +00004637
Douglas Gregorb98b1992009-08-11 05:31:07 +00004638 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004639 return SemaRef.Owned(E->Retain());
4640
Douglas Gregorb98b1992009-08-11 05:31:07 +00004641 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004642 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004643}
Mike Stump1eb44332009-09-09 15:08:12 +00004644
Douglas Gregorb98b1992009-08-11 05:31:07 +00004645template<typename Derived>
4646Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004647TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004648 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004649
Douglas Gregor43959a92009-08-20 07:17:43 +00004650 // transform the initializer value
Douglas Gregorb98b1992009-08-11 05:31:07 +00004651 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4652 if (Init.isInvalid())
4653 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004654
Douglas Gregor43959a92009-08-20 07:17:43 +00004655 // transform the designators.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004656 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4657 bool ExprChanged = false;
4658 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4659 DEnd = E->designators_end();
4660 D != DEnd; ++D) {
4661 if (D->isFieldDesignator()) {
4662 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4663 D->getDotLoc(),
4664 D->getFieldLoc()));
4665 continue;
4666 }
Mike Stump1eb44332009-09-09 15:08:12 +00004667
Douglas Gregorb98b1992009-08-11 05:31:07 +00004668 if (D->isArrayDesignator()) {
4669 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4670 if (Index.isInvalid())
4671 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004672
4673 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004674 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004675
Douglas Gregorb98b1992009-08-11 05:31:07 +00004676 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4677 ArrayExprs.push_back(Index.release());
4678 continue;
4679 }
Mike Stump1eb44332009-09-09 15:08:12 +00004680
Douglas Gregorb98b1992009-08-11 05:31:07 +00004681 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump1eb44332009-09-09 15:08:12 +00004682 OwningExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004683 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4684 if (Start.isInvalid())
4685 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004686
Douglas Gregorb98b1992009-08-11 05:31:07 +00004687 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4688 if (End.isInvalid())
4689 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004690
4691 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004692 End.get(),
4693 D->getLBracketLoc(),
4694 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004695
Douglas Gregorb98b1992009-08-11 05:31:07 +00004696 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4697 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004698
Douglas Gregorb98b1992009-08-11 05:31:07 +00004699 ArrayExprs.push_back(Start.release());
4700 ArrayExprs.push_back(End.release());
4701 }
Mike Stump1eb44332009-09-09 15:08:12 +00004702
Douglas Gregorb98b1992009-08-11 05:31:07 +00004703 if (!getDerived().AlwaysRebuild() &&
4704 Init.get() == E->getInit() &&
4705 !ExprChanged)
4706 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004707
Douglas Gregorb98b1992009-08-11 05:31:07 +00004708 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4709 E->getEqualOrColonLoc(),
4710 E->usesGNUSyntax(), move(Init));
4711}
Mike Stump1eb44332009-09-09 15:08:12 +00004712
Douglas Gregorb98b1992009-08-11 05:31:07 +00004713template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004714Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004715TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004716 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004717 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004718
Douglas Gregor5557b252009-10-28 00:29:27 +00004719 // FIXME: Will we ever have proper type location here? Will we actually
4720 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004721 QualType T = getDerived().TransformType(E->getType());
4722 if (T.isNull())
4723 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004724
Douglas Gregorb98b1992009-08-11 05:31:07 +00004725 if (!getDerived().AlwaysRebuild() &&
4726 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004727 return SemaRef.Owned(E->Retain());
4728
Douglas Gregorb98b1992009-08-11 05:31:07 +00004729 return getDerived().RebuildImplicitValueInitExpr(T);
4730}
Mike Stump1eb44332009-09-09 15:08:12 +00004731
Douglas Gregorb98b1992009-08-11 05:31:07 +00004732template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004733Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004734TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004735 // FIXME: Do we want the type as written?
4736 QualType T;
Mike Stump1eb44332009-09-09 15:08:12 +00004737
Douglas Gregorb98b1992009-08-11 05:31:07 +00004738 {
4739 // FIXME: Source location isn't quite accurate.
4740 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4741 T = getDerived().TransformType(E->getType());
4742 if (T.isNull())
4743 return SemaRef.ExprError();
4744 }
Mike Stump1eb44332009-09-09 15:08:12 +00004745
Douglas Gregorb98b1992009-08-11 05:31:07 +00004746 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4747 if (SubExpr.isInvalid())
4748 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004749
Douglas Gregorb98b1992009-08-11 05:31:07 +00004750 if (!getDerived().AlwaysRebuild() &&
4751 T == E->getType() &&
4752 SubExpr.get() == E->getSubExpr())
4753 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004754
Douglas Gregorb98b1992009-08-11 05:31:07 +00004755 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4756 T, E->getRParenLoc());
4757}
4758
4759template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004760Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004761TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004762 bool ArgumentChanged = false;
4763 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4764 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4765 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4766 if (Init.isInvalid())
4767 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004768
Douglas Gregorb98b1992009-08-11 05:31:07 +00004769 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4770 Inits.push_back(Init.takeAs<Expr>());
4771 }
Mike Stump1eb44332009-09-09 15:08:12 +00004772
Douglas Gregorb98b1992009-08-11 05:31:07 +00004773 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4774 move_arg(Inits),
4775 E->getRParenLoc());
4776}
Mike Stump1eb44332009-09-09 15:08:12 +00004777
Douglas Gregorb98b1992009-08-11 05:31:07 +00004778/// \brief Transform an address-of-label expression.
4779///
4780/// By default, the transformation of an address-of-label expression always
4781/// rebuilds the expression, so that the label identifier can be resolved to
4782/// the corresponding label statement by semantic analysis.
4783template<typename Derived>
4784Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004785TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004786 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4787 E->getLabel());
4788}
Mike Stump1eb44332009-09-09 15:08:12 +00004789
4790template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00004791Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004792TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004793 OwningStmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004794 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4795 if (SubStmt.isInvalid())
4796 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004797
Douglas Gregorb98b1992009-08-11 05:31:07 +00004798 if (!getDerived().AlwaysRebuild() &&
4799 SubStmt.get() == E->getSubStmt())
4800 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004801
4802 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004803 move(SubStmt),
4804 E->getRParenLoc());
4805}
Mike Stump1eb44332009-09-09 15:08:12 +00004806
Douglas Gregorb98b1992009-08-11 05:31:07 +00004807template<typename Derived>
4808Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004809TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004810 QualType T1, T2;
4811 {
4812 // FIXME: Source location isn't quite accurate.
4813 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004814
Douglas Gregorb98b1992009-08-11 05:31:07 +00004815 T1 = getDerived().TransformType(E->getArgType1());
4816 if (T1.isNull())
4817 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004818
Douglas Gregorb98b1992009-08-11 05:31:07 +00004819 T2 = getDerived().TransformType(E->getArgType2());
4820 if (T2.isNull())
4821 return SemaRef.ExprError();
4822 }
4823
4824 if (!getDerived().AlwaysRebuild() &&
4825 T1 == E->getArgType1() &&
4826 T2 == E->getArgType2())
Mike Stump1eb44332009-09-09 15:08:12 +00004827 return SemaRef.Owned(E->Retain());
4828
Douglas Gregorb98b1992009-08-11 05:31:07 +00004829 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4830 T1, T2, E->getRParenLoc());
4831}
Mike Stump1eb44332009-09-09 15:08:12 +00004832
Douglas Gregorb98b1992009-08-11 05:31:07 +00004833template<typename Derived>
4834Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004835TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004836 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4837 if (Cond.isInvalid())
4838 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004839
Douglas Gregorb98b1992009-08-11 05:31:07 +00004840 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4841 if (LHS.isInvalid())
4842 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004843
Douglas Gregorb98b1992009-08-11 05:31:07 +00004844 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4845 if (RHS.isInvalid())
4846 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004847
Douglas Gregorb98b1992009-08-11 05:31:07 +00004848 if (!getDerived().AlwaysRebuild() &&
4849 Cond.get() == E->getCond() &&
4850 LHS.get() == E->getLHS() &&
4851 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004852 return SemaRef.Owned(E->Retain());
4853
Douglas Gregorb98b1992009-08-11 05:31:07 +00004854 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4855 move(Cond), move(LHS), move(RHS),
4856 E->getRParenLoc());
4857}
Mike Stump1eb44332009-09-09 15:08:12 +00004858
Douglas Gregorb98b1992009-08-11 05:31:07 +00004859template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004860Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004861TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004862 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004863}
4864
4865template<typename Derived>
4866Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004867TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004868 switch (E->getOperator()) {
4869 case OO_New:
4870 case OO_Delete:
4871 case OO_Array_New:
4872 case OO_Array_Delete:
4873 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4874 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004875
Douglas Gregor668d6d92009-12-13 20:44:55 +00004876 case OO_Call: {
4877 // This is a call to an object's operator().
4878 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4879
4880 // Transform the object itself.
4881 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4882 if (Object.isInvalid())
4883 return SemaRef.ExprError();
4884
4885 // FIXME: Poor location information
4886 SourceLocation FakeLParenLoc
4887 = SemaRef.PP.getLocForEndOfToken(
4888 static_cast<Expr *>(Object.get())->getLocEnd());
4889
4890 // Transform the call arguments.
4891 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4892 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4893 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004894 if (getDerived().DropCallArgument(E->getArg(I)))
4895 break;
Sean Huntc3021132010-05-05 15:23:54 +00004896
Douglas Gregor668d6d92009-12-13 20:44:55 +00004897 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4898 if (Arg.isInvalid())
4899 return SemaRef.ExprError();
4900
4901 // FIXME: Poor source location information.
4902 SourceLocation FakeCommaLoc
4903 = SemaRef.PP.getLocForEndOfToken(
4904 static_cast<Expr *>(Arg.get())->getLocEnd());
4905 FakeCommaLocs.push_back(FakeCommaLoc);
4906 Args.push_back(Arg.release());
4907 }
4908
4909 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4910 move_arg(Args),
4911 FakeCommaLocs.data(),
4912 E->getLocEnd());
4913 }
4914
4915#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4916 case OO_##Name:
4917#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4918#include "clang/Basic/OperatorKinds.def"
4919 case OO_Subscript:
4920 // Handled below.
4921 break;
4922
4923 case OO_Conditional:
4924 llvm_unreachable("conditional operator is not actually overloadable");
4925 return SemaRef.ExprError();
4926
4927 case OO_None:
4928 case NUM_OVERLOADED_OPERATORS:
4929 llvm_unreachable("not an overloaded operator?");
4930 return SemaRef.ExprError();
4931 }
4932
Douglas Gregorb98b1992009-08-11 05:31:07 +00004933 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4934 if (Callee.isInvalid())
4935 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004936
John McCall454feb92009-12-08 09:21:05 +00004937 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004938 if (First.isInvalid())
4939 return SemaRef.ExprError();
4940
4941 OwningExprResult Second(SemaRef);
4942 if (E->getNumArgs() == 2) {
4943 Second = getDerived().TransformExpr(E->getArg(1));
4944 if (Second.isInvalid())
4945 return SemaRef.ExprError();
4946 }
Mike Stump1eb44332009-09-09 15:08:12 +00004947
Douglas Gregorb98b1992009-08-11 05:31:07 +00004948 if (!getDerived().AlwaysRebuild() &&
4949 Callee.get() == E->getCallee() &&
4950 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00004951 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4952 return SemaRef.Owned(E->Retain());
4953
Douglas Gregorb98b1992009-08-11 05:31:07 +00004954 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4955 E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004956 move(Callee),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004957 move(First),
4958 move(Second));
4959}
Mike Stump1eb44332009-09-09 15:08:12 +00004960
Douglas Gregorb98b1992009-08-11 05:31:07 +00004961template<typename Derived>
4962Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004963TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4964 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004965}
Mike Stump1eb44332009-09-09 15:08:12 +00004966
Douglas Gregorb98b1992009-08-11 05:31:07 +00004967template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004968Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004969TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004970 TypeSourceInfo *OldT;
4971 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004972 {
4973 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004974 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004975 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4976 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004977
John McCall9d125032010-01-15 18:39:57 +00004978 OldT = E->getTypeInfoAsWritten();
4979 NewT = getDerived().TransformType(OldT);
4980 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004981 return SemaRef.ExprError();
4982 }
Mike Stump1eb44332009-09-09 15:08:12 +00004983
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004984 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004985 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004986 if (SubExpr.isInvalid())
4987 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004988
Douglas Gregorb98b1992009-08-11 05:31:07 +00004989 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004990 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004991 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004992 return SemaRef.Owned(E->Retain());
4993
Douglas Gregorb98b1992009-08-11 05:31:07 +00004994 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00004995 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004996 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4997 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4998 SourceLocation FakeRParenLoc
4999 = SemaRef.PP.getLocForEndOfToken(
5000 E->getSubExpr()->getSourceRange().getEnd());
5001 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005002 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005003 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00005004 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005005 FakeRAngleLoc,
5006 FakeRAngleLoc,
5007 move(SubExpr),
5008 FakeRParenLoc);
5009}
Mike Stump1eb44332009-09-09 15:08:12 +00005010
Douglas Gregorb98b1992009-08-11 05:31:07 +00005011template<typename Derived>
5012Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005013TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5014 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005015}
Mike Stump1eb44332009-09-09 15:08:12 +00005016
5017template<typename Derived>
5018Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005019TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5020 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005021}
5022
Douglas Gregorb98b1992009-08-11 05:31:07 +00005023template<typename Derived>
5024Sema::OwningExprResult
5025TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005026 CXXReinterpretCastExpr *E) {
5027 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005028}
Mike Stump1eb44332009-09-09 15:08:12 +00005029
Douglas Gregorb98b1992009-08-11 05:31:07 +00005030template<typename Derived>
5031Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005032TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5033 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005034}
Mike Stump1eb44332009-09-09 15:08:12 +00005035
Douglas Gregorb98b1992009-08-11 05:31:07 +00005036template<typename Derived>
5037Sema::OwningExprResult
5038TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005039 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00005040 TypeSourceInfo *OldT;
5041 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005042 {
5043 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005044
John McCall9d125032010-01-15 18:39:57 +00005045 OldT = E->getTypeInfoAsWritten();
5046 NewT = getDerived().TransformType(OldT);
5047 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005048 return SemaRef.ExprError();
5049 }
Mike Stump1eb44332009-09-09 15:08:12 +00005050
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005051 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005052 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005053 if (SubExpr.isInvalid())
5054 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005055
Douglas Gregorb98b1992009-08-11 05:31:07 +00005056 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00005057 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005058 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005059 return SemaRef.Owned(E->Retain());
5060
Douglas Gregorb98b1992009-08-11 05:31:07 +00005061 // FIXME: The end of the type's source range is wrong
5062 return getDerived().RebuildCXXFunctionalCastExpr(
5063 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall9d125032010-01-15 18:39:57 +00005064 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005065 /*FIXME:*/E->getSubExpr()->getLocStart(),
5066 move(SubExpr),
5067 E->getRParenLoc());
5068}
Mike Stump1eb44332009-09-09 15:08:12 +00005069
Douglas Gregorb98b1992009-08-11 05:31:07 +00005070template<typename Derived>
5071Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005072TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005073 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005074 TypeSourceInfo *TInfo
5075 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5076 if (!TInfo)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005077 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005078
Douglas Gregorb98b1992009-08-11 05:31:07 +00005079 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005080 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005081 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005082
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005083 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5084 E->getLocStart(),
5085 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005086 E->getLocEnd());
5087 }
Mike Stump1eb44332009-09-09 15:08:12 +00005088
Douglas Gregorb98b1992009-08-11 05:31:07 +00005089 // We don't know whether the expression is potentially evaluated until
5090 // after we perform semantic analysis, so the expression is potentially
5091 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005092 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005093 Action::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005094
Douglas Gregorb98b1992009-08-11 05:31:07 +00005095 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5096 if (SubExpr.isInvalid())
5097 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005098
Douglas Gregorb98b1992009-08-11 05:31:07 +00005099 if (!getDerived().AlwaysRebuild() &&
5100 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00005101 return SemaRef.Owned(E->Retain());
5102
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005103 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5104 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005105 move(SubExpr),
5106 E->getLocEnd());
5107}
5108
5109template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005110Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005111TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005112 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005113}
Mike Stump1eb44332009-09-09 15:08:12 +00005114
Douglas Gregorb98b1992009-08-11 05:31:07 +00005115template<typename Derived>
5116Sema::OwningExprResult
5117TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005118 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005119 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005120}
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>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005125 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005126
Douglas Gregorb98b1992009-08-11 05:31:07 +00005127 QualType T = getDerived().TransformType(E->getType());
5128 if (T.isNull())
5129 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005130
Douglas Gregorb98b1992009-08-11 05:31:07 +00005131 if (!getDerived().AlwaysRebuild() &&
5132 T == E->getType())
5133 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005134
Douglas Gregor828a1972010-01-07 23:12:05 +00005135 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005136}
Mike Stump1eb44332009-09-09 15:08:12 +00005137
Douglas Gregorb98b1992009-08-11 05:31:07 +00005138template<typename Derived>
5139Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005140TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005141 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5142 if (SubExpr.isInvalid())
5143 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005144
Douglas Gregorb98b1992009-08-11 05:31:07 +00005145 if (!getDerived().AlwaysRebuild() &&
5146 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005147 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005148
5149 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5150}
Mike Stump1eb44332009-09-09 15:08:12 +00005151
Douglas Gregorb98b1992009-08-11 05:31:07 +00005152template<typename Derived>
5153Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005154TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005155 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005156 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5157 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005158 if (!Param)
5159 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005160
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005161 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005162 Param == E->getParam())
5163 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005164
Douglas Gregor036aed12009-12-23 23:03:06 +00005165 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005166}
Mike Stump1eb44332009-09-09 15:08:12 +00005167
Douglas Gregorb98b1992009-08-11 05:31:07 +00005168template<typename Derived>
5169Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005170TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005171 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5172
5173 QualType T = getDerived().TransformType(E->getType());
5174 if (T.isNull())
5175 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005176
Douglas Gregorb98b1992009-08-11 05:31:07 +00005177 if (!getDerived().AlwaysRebuild() &&
5178 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00005179 return SemaRef.Owned(E->Retain());
5180
5181 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005182 /*FIXME:*/E->getTypeBeginLoc(),
5183 T,
5184 E->getRParenLoc());
5185}
Mike Stump1eb44332009-09-09 15:08:12 +00005186
Douglas Gregorb98b1992009-08-11 05:31:07 +00005187template<typename Derived>
5188Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005189TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005190 // Transform the type that we're allocating
5191 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5192 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5193 if (AllocType.isNull())
5194 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005195
Douglas Gregorb98b1992009-08-11 05:31:07 +00005196 // Transform the size of the array we're allocating (if any).
5197 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5198 if (ArraySize.isInvalid())
5199 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005200
Douglas Gregorb98b1992009-08-11 05:31:07 +00005201 // Transform the placement arguments (if any).
5202 bool ArgumentChanged = false;
5203 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5204 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5205 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5206 if (Arg.isInvalid())
5207 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005208
Douglas Gregorb98b1992009-08-11 05:31:07 +00005209 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5210 PlacementArgs.push_back(Arg.take());
5211 }
Mike Stump1eb44332009-09-09 15:08:12 +00005212
Douglas Gregor43959a92009-08-20 07:17:43 +00005213 // transform the constructor arguments (if any).
Douglas Gregorb98b1992009-08-11 05:31:07 +00005214 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5215 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005216 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5217 break;
5218
Douglas Gregorb98b1992009-08-11 05:31:07 +00005219 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5220 if (Arg.isInvalid())
5221 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005222
Douglas Gregorb98b1992009-08-11 05:31:07 +00005223 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5224 ConstructorArgs.push_back(Arg.take());
5225 }
Mike Stump1eb44332009-09-09 15:08:12 +00005226
Douglas Gregor1af74512010-02-26 00:38:10 +00005227 // Transform constructor, new operator, and delete operator.
5228 CXXConstructorDecl *Constructor = 0;
5229 if (E->getConstructor()) {
5230 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005231 getDerived().TransformDecl(E->getLocStart(),
5232 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005233 if (!Constructor)
5234 return SemaRef.ExprError();
5235 }
5236
5237 FunctionDecl *OperatorNew = 0;
5238 if (E->getOperatorNew()) {
5239 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005240 getDerived().TransformDecl(E->getLocStart(),
5241 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005242 if (!OperatorNew)
5243 return SemaRef.ExprError();
5244 }
5245
5246 FunctionDecl *OperatorDelete = 0;
5247 if (E->getOperatorDelete()) {
5248 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005249 getDerived().TransformDecl(E->getLocStart(),
5250 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005251 if (!OperatorDelete)
5252 return SemaRef.ExprError();
5253 }
Sean Huntc3021132010-05-05 15:23:54 +00005254
Douglas Gregorb98b1992009-08-11 05:31:07 +00005255 if (!getDerived().AlwaysRebuild() &&
5256 AllocType == E->getAllocatedType() &&
5257 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005258 Constructor == E->getConstructor() &&
5259 OperatorNew == E->getOperatorNew() &&
5260 OperatorDelete == E->getOperatorDelete() &&
5261 !ArgumentChanged) {
5262 // Mark any declarations we need as referenced.
5263 // FIXME: instantiation-specific.
5264 if (Constructor)
5265 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5266 if (OperatorNew)
5267 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5268 if (OperatorDelete)
5269 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005270 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005271 }
Mike Stump1eb44332009-09-09 15:08:12 +00005272
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005273 if (!ArraySize.get()) {
5274 // If no array size was specified, but the new expression was
5275 // instantiated with an array type (e.g., "new T" where T is
5276 // instantiated with "int[4]"), extract the outer bound from the
5277 // array type as our array size. We do this with constant and
5278 // dependently-sized array types.
5279 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5280 if (!ArrayT) {
5281 // Do nothing
5282 } else if (const ConstantArrayType *ConsArrayT
5283 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005284 ArraySize
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005285 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Sean Huntc3021132010-05-05 15:23:54 +00005286 ConsArrayT->getSize(),
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005287 SemaRef.Context.getSizeType(),
5288 /*FIXME:*/E->getLocStart()));
5289 AllocType = ConsArrayT->getElementType();
5290 } else if (const DependentSizedArrayType *DepArrayT
5291 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5292 if (DepArrayT->getSizeExpr()) {
5293 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5294 AllocType = DepArrayT->getElementType();
5295 }
5296 }
5297 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005298 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5299 E->isGlobalNew(),
5300 /*FIXME:*/E->getLocStart(),
5301 move_arg(PlacementArgs),
5302 /*FIXME:*/E->getLocStart(),
5303 E->isParenTypeId(),
5304 AllocType,
5305 /*FIXME:*/E->getLocStart(),
5306 /*FIXME:*/SourceRange(),
5307 move(ArraySize),
5308 /*FIXME:*/E->getLocStart(),
5309 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005310 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005311}
Mike Stump1eb44332009-09-09 15:08:12 +00005312
Douglas Gregorb98b1992009-08-11 05:31:07 +00005313template<typename Derived>
5314Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005315TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005316 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5317 if (Operand.isInvalid())
5318 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005319
Douglas Gregor1af74512010-02-26 00:38:10 +00005320 // Transform the delete operator, if known.
5321 FunctionDecl *OperatorDelete = 0;
5322 if (E->getOperatorDelete()) {
5323 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005324 getDerived().TransformDecl(E->getLocStart(),
5325 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005326 if (!OperatorDelete)
5327 return SemaRef.ExprError();
5328 }
Sean Huntc3021132010-05-05 15:23:54 +00005329
Douglas Gregorb98b1992009-08-11 05:31:07 +00005330 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005331 Operand.get() == E->getArgument() &&
5332 OperatorDelete == E->getOperatorDelete()) {
5333 // Mark any declarations we need as referenced.
5334 // FIXME: instantiation-specific.
5335 if (OperatorDelete)
5336 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005337 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005338 }
Mike Stump1eb44332009-09-09 15:08:12 +00005339
Douglas Gregorb98b1992009-08-11 05:31:07 +00005340 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5341 E->isGlobalDelete(),
5342 E->isArrayForm(),
5343 move(Operand));
5344}
Mike Stump1eb44332009-09-09 15:08:12 +00005345
Douglas Gregorb98b1992009-08-11 05:31:07 +00005346template<typename Derived>
5347Sema::OwningExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005348TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005349 CXXPseudoDestructorExpr *E) {
Douglas Gregora71d8192009-09-04 17:36:40 +00005350 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5351 if (Base.isInvalid())
5352 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005353
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005354 Sema::TypeTy *ObjectTypePtr = 0;
5355 bool MayBePseudoDestructor = false;
Sean Huntc3021132010-05-05 15:23:54 +00005356 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005357 E->getOperatorLoc(),
5358 E->isArrow()? tok::arrow : tok::period,
5359 ObjectTypePtr,
5360 MayBePseudoDestructor);
5361 if (Base.isInvalid())
5362 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005363
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005364 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregora71d8192009-09-04 17:36:40 +00005365 NestedNameSpecifier *Qualifier
5366 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00005367 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005368 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00005369 if (E->getQualifier() && !Qualifier)
5370 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005371
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005372 PseudoDestructorTypeStorage Destroyed;
5373 if (E->getDestroyedTypeInfo()) {
5374 TypeSourceInfo *DestroyedTypeInfo
5375 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5376 if (!DestroyedTypeInfo)
5377 return SemaRef.ExprError();
5378 Destroyed = DestroyedTypeInfo;
5379 } else if (ObjectType->isDependentType()) {
5380 // We aren't likely to be able to resolve the identifier down to a type
5381 // now anyway, so just retain the identifier.
5382 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5383 E->getDestroyedTypeLoc());
5384 } else {
5385 // Look for a destructor known with the given name.
5386 CXXScopeSpec SS;
5387 if (Qualifier) {
5388 SS.setScopeRep(Qualifier);
5389 SS.setRange(E->getQualifierRange());
5390 }
Sean Huntc3021132010-05-05 15:23:54 +00005391
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005392 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5393 *E->getDestroyedTypeIdentifier(),
5394 E->getDestroyedTypeLoc(),
5395 /*Scope=*/0,
5396 SS, ObjectTypePtr,
5397 false);
5398 if (!T)
5399 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005400
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005401 Destroyed
5402 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5403 E->getDestroyedTypeLoc());
5404 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005405
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005406 TypeSourceInfo *ScopeTypeInfo = 0;
5407 if (E->getScopeTypeInfo()) {
Sean Huntc3021132010-05-05 15:23:54 +00005408 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005409 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005410 if (!ScopeTypeInfo)
Douglas Gregora71d8192009-09-04 17:36:40 +00005411 return SemaRef.ExprError();
5412 }
Sean Huntc3021132010-05-05 15:23:54 +00005413
Douglas Gregora71d8192009-09-04 17:36:40 +00005414 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5415 E->getOperatorLoc(),
5416 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005417 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005418 E->getQualifierRange(),
5419 ScopeTypeInfo,
5420 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005421 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005422 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005423}
Mike Stump1eb44332009-09-09 15:08:12 +00005424
Douglas Gregora71d8192009-09-04 17:36:40 +00005425template<typename Derived>
5426Sema::OwningExprResult
John McCallba135432009-11-21 08:51:07 +00005427TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005428 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005429 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5430
5431 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5432 Sema::LookupOrdinaryName);
5433
5434 // Transform all the decls.
5435 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5436 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005437 NamedDecl *InstD = static_cast<NamedDecl*>(
5438 getDerived().TransformDecl(Old->getNameLoc(),
5439 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005440 if (!InstD) {
5441 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5442 // This can happen because of dependent hiding.
5443 if (isa<UsingShadowDecl>(*I))
5444 continue;
5445 else
5446 return SemaRef.ExprError();
5447 }
John McCallf7a1a742009-11-24 19:00:30 +00005448
5449 // Expand using declarations.
5450 if (isa<UsingDecl>(InstD)) {
5451 UsingDecl *UD = cast<UsingDecl>(InstD);
5452 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5453 E = UD->shadow_end(); I != E; ++I)
5454 R.addDecl(*I);
5455 continue;
5456 }
5457
5458 R.addDecl(InstD);
5459 }
5460
5461 // Resolve a kind, but don't do any further analysis. If it's
5462 // ambiguous, the callee needs to deal with it.
5463 R.resolveKind();
5464
5465 // Rebuild the nested-name qualifier, if present.
5466 CXXScopeSpec SS;
5467 NestedNameSpecifier *Qualifier = 0;
5468 if (Old->getQualifier()) {
5469 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005470 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005471 if (!Qualifier)
5472 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005473
John McCallf7a1a742009-11-24 19:00:30 +00005474 SS.setScopeRep(Qualifier);
5475 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005476 }
5477
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005478 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005479 CXXRecordDecl *NamingClass
5480 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5481 Old->getNameLoc(),
5482 Old->getNamingClass()));
5483 if (!NamingClass)
5484 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005485
Douglas Gregor66c45152010-04-27 16:10:10 +00005486 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005487 }
5488
5489 // If we have no template arguments, it's a normal declaration name.
5490 if (!Old->hasExplicitTemplateArgs())
5491 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5492
5493 // If we have template arguments, rebuild them, then rebuild the
5494 // templateid expression.
5495 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5496 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5497 TemplateArgumentLoc Loc;
5498 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5499 return SemaRef.ExprError();
5500 TransArgs.addArgument(Loc);
5501 }
5502
5503 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5504 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005505}
Mike Stump1eb44332009-09-09 15:08:12 +00005506
Douglas Gregorb98b1992009-08-11 05:31:07 +00005507template<typename Derived>
5508Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005509TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005510 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005511
Douglas Gregorb98b1992009-08-11 05:31:07 +00005512 QualType T = getDerived().TransformType(E->getQueriedType());
5513 if (T.isNull())
5514 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005515
Douglas Gregorb98b1992009-08-11 05:31:07 +00005516 if (!getDerived().AlwaysRebuild() &&
5517 T == E->getQueriedType())
5518 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005519
Douglas Gregorb98b1992009-08-11 05:31:07 +00005520 // FIXME: Bad location information
5521 SourceLocation FakeLParenLoc
5522 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00005523
5524 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005525 E->getLocStart(),
5526 /*FIXME:*/FakeLParenLoc,
5527 T,
5528 E->getLocEnd());
5529}
Mike Stump1eb44332009-09-09 15:08:12 +00005530
Douglas Gregorb98b1992009-08-11 05:31:07 +00005531template<typename Derived>
5532Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005533TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005534 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005535 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005536 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005537 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005538 if (!NNS)
5539 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005540
5541 DeclarationName Name
Douglas Gregor81499bb2009-09-03 22:13:48 +00005542 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5543 if (!Name)
5544 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005545
John McCallf7a1a742009-11-24 19:00:30 +00005546 if (!E->hasExplicitTemplateArgs()) {
5547 if (!getDerived().AlwaysRebuild() &&
5548 NNS == E->getQualifier() &&
5549 Name == E->getDeclName())
5550 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005551
John McCallf7a1a742009-11-24 19:00:30 +00005552 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5553 E->getQualifierRange(),
5554 Name, E->getLocation(),
5555 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005556 }
John McCalld5532b62009-11-23 01:53:49 +00005557
5558 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005559 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005560 TemplateArgumentLoc Loc;
5561 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb98b1992009-08-11 05:31:07 +00005562 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005563 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005564 }
5565
John McCallf7a1a742009-11-24 19:00:30 +00005566 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5567 E->getQualifierRange(),
5568 Name, E->getLocation(),
5569 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005570}
5571
5572template<typename Derived>
5573Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005574TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005575 // CXXConstructExprs are always implicit, so when we have a
5576 // 1-argument construction we just transform that argument.
5577 if (E->getNumArgs() == 1 ||
5578 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5579 return getDerived().TransformExpr(E->getArg(0));
5580
Douglas Gregorb98b1992009-08-11 05:31:07 +00005581 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5582
5583 QualType T = getDerived().TransformType(E->getType());
5584 if (T.isNull())
5585 return SemaRef.ExprError();
5586
5587 CXXConstructorDecl *Constructor
5588 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005589 getDerived().TransformDecl(E->getLocStart(),
5590 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005591 if (!Constructor)
5592 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005593
Douglas Gregorb98b1992009-08-11 05:31:07 +00005594 bool ArgumentChanged = false;
5595 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005596 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005597 ArgEnd = E->arg_end();
5598 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005599 if (getDerived().DropCallArgument(*Arg)) {
5600 ArgumentChanged = true;
5601 break;
5602 }
5603
Douglas Gregorb98b1992009-08-11 05:31:07 +00005604 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5605 if (TransArg.isInvalid())
5606 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005607
Douglas Gregorb98b1992009-08-11 05:31:07 +00005608 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5609 Args.push_back(TransArg.takeAs<Expr>());
5610 }
5611
5612 if (!getDerived().AlwaysRebuild() &&
5613 T == E->getType() &&
5614 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005615 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005616 // Mark the constructor as referenced.
5617 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005618 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005619 return SemaRef.Owned(E->Retain());
Douglas Gregorc845aad2010-02-26 00:01:57 +00005620 }
Mike Stump1eb44332009-09-09 15:08:12 +00005621
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005622 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5623 Constructor, E->isElidable(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005624 move_arg(Args));
5625}
Mike Stump1eb44332009-09-09 15:08:12 +00005626
Douglas Gregorb98b1992009-08-11 05:31:07 +00005627/// \brief Transform a C++ temporary-binding expression.
5628///
Douglas Gregor51326552009-12-24 18:51:59 +00005629/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5630/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005631template<typename Derived>
5632Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005633TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005634 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005635}
Mike Stump1eb44332009-09-09 15:08:12 +00005636
Anders Carlssoneb60edf2010-01-29 02:39:32 +00005637/// \brief Transform a C++ reference-binding expression.
5638///
5639/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5640/// transform the subexpression and return that.
5641template<typename Derived>
5642Sema::OwningExprResult
5643TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5644 return getDerived().TransformExpr(E->getSubExpr());
5645}
5646
Mike Stump1eb44332009-09-09 15:08:12 +00005647/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005648/// be destroyed after the expression is evaluated.
5649///
Douglas Gregor51326552009-12-24 18:51:59 +00005650/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5651/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005652template<typename Derived>
5653Sema::OwningExprResult
5654TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005655 CXXExprWithTemporaries *E) {
5656 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005657}
Mike Stump1eb44332009-09-09 15:08:12 +00005658
Douglas Gregorb98b1992009-08-11 05:31:07 +00005659template<typename Derived>
5660Sema::OwningExprResult
5661TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00005662 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005663 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5664 QualType T = getDerived().TransformType(E->getType());
5665 if (T.isNull())
5666 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005667
Douglas Gregorb98b1992009-08-11 05:31:07 +00005668 CXXConstructorDecl *Constructor
5669 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005670 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005671 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005672 if (!Constructor)
5673 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005674
Douglas Gregorb98b1992009-08-11 05:31:07 +00005675 bool ArgumentChanged = false;
5676 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5677 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005678 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005679 ArgEnd = E->arg_end();
5680 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005681 if (getDerived().DropCallArgument(*Arg)) {
5682 ArgumentChanged = true;
5683 break;
5684 }
5685
Douglas Gregorb98b1992009-08-11 05:31:07 +00005686 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5687 if (TransArg.isInvalid())
5688 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005689
Douglas Gregorb98b1992009-08-11 05:31:07 +00005690 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5691 Args.push_back((Expr *)TransArg.release());
5692 }
Mike Stump1eb44332009-09-09 15:08:12 +00005693
Douglas Gregorb98b1992009-08-11 05:31:07 +00005694 if (!getDerived().AlwaysRebuild() &&
5695 T == E->getType() &&
5696 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005697 !ArgumentChanged) {
5698 // FIXME: Instantiation-specific
5699 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carrutha3ce8ae2010-03-31 18:34:58 +00005700 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor91be6f52010-03-02 17:18:33 +00005701 }
Mike Stump1eb44332009-09-09 15:08:12 +00005702
Douglas Gregorb98b1992009-08-11 05:31:07 +00005703 // FIXME: Bogus location information
5704 SourceLocation CommaLoc;
5705 if (Args.size() > 1) {
5706 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00005707 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005708 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5709 }
5710 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5711 T,
5712 /*FIXME:*/E->getTypeBeginLoc(),
5713 move_arg(Args),
5714 &CommaLoc,
5715 E->getLocEnd());
5716}
Mike Stump1eb44332009-09-09 15:08:12 +00005717
Douglas Gregorb98b1992009-08-11 05:31:07 +00005718template<typename Derived>
5719Sema::OwningExprResult
5720TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005721 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005722 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5723 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5724 if (T.isNull())
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 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5730 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5731 ArgEnd = E->arg_end();
5732 Arg != ArgEnd; ++Arg) {
5733 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5734 if (TransArg.isInvalid())
5735 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005736
Douglas Gregorb98b1992009-08-11 05:31:07 +00005737 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5738 FakeCommaLocs.push_back(
5739 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5740 Args.push_back(TransArg.takeAs<Expr>());
5741 }
Mike Stump1eb44332009-09-09 15:08:12 +00005742
Douglas Gregorb98b1992009-08-11 05:31:07 +00005743 if (!getDerived().AlwaysRebuild() &&
5744 T == E->getTypeAsWritten() &&
5745 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005746 return SemaRef.Owned(E->Retain());
5747
Douglas Gregorb98b1992009-08-11 05:31:07 +00005748 // FIXME: we're faking the locations of the commas
5749 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5750 T,
5751 E->getLParenLoc(),
5752 move_arg(Args),
5753 FakeCommaLocs.data(),
5754 E->getRParenLoc());
5755}
Mike Stump1eb44332009-09-09 15:08:12 +00005756
Douglas Gregorb98b1992009-08-11 05:31:07 +00005757template<typename Derived>
5758Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005759TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall454feb92009-12-08 09:21:05 +00005760 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005761 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005762 OwningExprResult Base(SemaRef, (Expr*) 0);
5763 Expr *OldBase;
5764 QualType BaseType;
5765 QualType ObjectType;
5766 if (!E->isImplicitAccess()) {
5767 OldBase = E->getBase();
5768 Base = getDerived().TransformExpr(OldBase);
5769 if (Base.isInvalid())
5770 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005771
John McCallaa81e162009-12-01 22:10:20 +00005772 // Start the member reference and compute the object's type.
5773 Sema::TypeTy *ObjectTy = 0;
Douglas Gregord4dca082010-02-24 18:44:31 +00005774 bool MayBePseudoDestructor = false;
John McCallaa81e162009-12-01 22:10:20 +00005775 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5776 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005777 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005778 ObjectTy,
5779 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005780 if (Base.isInvalid())
5781 return SemaRef.ExprError();
5782
5783 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5784 BaseType = ((Expr*) Base.get())->getType();
5785 } else {
5786 OldBase = 0;
5787 BaseType = getDerived().TransformType(E->getBaseType());
5788 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5789 }
Mike Stump1eb44332009-09-09 15:08:12 +00005790
Douglas Gregor6cd21982009-10-20 05:58:46 +00005791 // Transform the first part of the nested-name-specifier that qualifies
5792 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005793 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005794 = getDerived().TransformFirstQualifierInScope(
5795 E->getFirstQualifierFoundInScope(),
5796 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005797
Douglas Gregora38c6872009-09-03 16:14:30 +00005798 NestedNameSpecifier *Qualifier = 0;
5799 if (E->getQualifier()) {
5800 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5801 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005802 ObjectType,
5803 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005804 if (!Qualifier)
5805 return SemaRef.ExprError();
5806 }
Mike Stump1eb44332009-09-09 15:08:12 +00005807
5808 DeclarationName Name
Douglas Gregordd62b152009-10-19 22:04:39 +00005809 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCallaa81e162009-12-01 22:10:20 +00005810 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00005811 if (!Name)
5812 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005813
John McCallaa81e162009-12-01 22:10:20 +00005814 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005815 // This is a reference to a member without an explicitly-specified
5816 // template argument list. Optimize for this common case.
5817 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005818 Base.get() == OldBase &&
5819 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005820 Qualifier == E->getQualifier() &&
5821 Name == E->getMember() &&
5822 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005823 return SemaRef.Owned(E->Retain());
5824
John McCall865d4472009-11-19 22:55:06 +00005825 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005826 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005827 E->isArrow(),
5828 E->getOperatorLoc(),
5829 Qualifier,
5830 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005831 FirstQualifierInScope,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005832 Name,
5833 E->getMemberLoc(),
John McCall129e2df2009-11-30 22:42:35 +00005834 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005835 }
5836
John McCalld5532b62009-11-23 01:53:49 +00005837 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005838 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005839 TemplateArgumentLoc Loc;
5840 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005841 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005842 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005843 }
Mike Stump1eb44332009-09-09 15:08:12 +00005844
John McCall865d4472009-11-19 22:55:06 +00005845 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005846 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005847 E->isArrow(),
5848 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005849 Qualifier,
5850 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005851 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005852 Name,
5853 E->getMemberLoc(),
5854 &TransArgs);
5855}
5856
5857template<typename Derived>
5858Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005859TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005860 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005861 OwningExprResult Base(SemaRef, (Expr*) 0);
5862 QualType BaseType;
5863 if (!Old->isImplicitAccess()) {
5864 Base = getDerived().TransformExpr(Old->getBase());
5865 if (Base.isInvalid())
5866 return SemaRef.ExprError();
5867 BaseType = ((Expr*) Base.get())->getType();
5868 } else {
5869 BaseType = getDerived().TransformType(Old->getBaseType());
5870 }
John McCall129e2df2009-11-30 22:42:35 +00005871
5872 NestedNameSpecifier *Qualifier = 0;
5873 if (Old->getQualifier()) {
5874 Qualifier
5875 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005876 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005877 if (Qualifier == 0)
5878 return SemaRef.ExprError();
5879 }
5880
5881 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5882 Sema::LookupOrdinaryName);
5883
5884 // Transform all the decls.
5885 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5886 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005887 NamedDecl *InstD = static_cast<NamedDecl*>(
5888 getDerived().TransformDecl(Old->getMemberLoc(),
5889 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005890 if (!InstD) {
5891 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5892 // This can happen because of dependent hiding.
5893 if (isa<UsingShadowDecl>(*I))
5894 continue;
5895 else
5896 return SemaRef.ExprError();
5897 }
John McCall129e2df2009-11-30 22:42:35 +00005898
5899 // Expand using declarations.
5900 if (isa<UsingDecl>(InstD)) {
5901 UsingDecl *UD = cast<UsingDecl>(InstD);
5902 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5903 E = UD->shadow_end(); I != E; ++I)
5904 R.addDecl(*I);
5905 continue;
5906 }
5907
5908 R.addDecl(InstD);
5909 }
5910
5911 R.resolveKind();
5912
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005913 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00005914 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00005915 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005916 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00005917 Old->getMemberLoc(),
5918 Old->getNamingClass()));
5919 if (!NamingClass)
5920 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005921
Douglas Gregor66c45152010-04-27 16:10:10 +00005922 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005923 }
Sean Huntc3021132010-05-05 15:23:54 +00005924
John McCall129e2df2009-11-30 22:42:35 +00005925 TemplateArgumentListInfo TransArgs;
5926 if (Old->hasExplicitTemplateArgs()) {
5927 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5928 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5929 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5930 TemplateArgumentLoc Loc;
5931 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5932 Loc))
5933 return SemaRef.ExprError();
5934 TransArgs.addArgument(Loc);
5935 }
5936 }
John McCallc2233c52010-01-15 08:34:02 +00005937
5938 // FIXME: to do this check properly, we will need to preserve the
5939 // first-qualifier-in-scope here, just in case we had a dependent
5940 // base (and therefore couldn't do the check) and a
5941 // nested-name-qualifier (and therefore could do the lookup).
5942 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00005943
John McCall129e2df2009-11-30 22:42:35 +00005944 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005945 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005946 Old->getOperatorLoc(),
5947 Old->isArrow(),
5948 Qualifier,
5949 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00005950 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005951 R,
5952 (Old->hasExplicitTemplateArgs()
5953 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005954}
5955
5956template<typename Derived>
5957Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005958TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005959 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005960}
5961
Mike Stump1eb44332009-09-09 15:08:12 +00005962template<typename Derived>
5963Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005964TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00005965 TypeSourceInfo *EncodedTypeInfo
5966 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5967 if (!EncodedTypeInfo)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005968 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005969
Douglas Gregorb98b1992009-08-11 05:31:07 +00005970 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00005971 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00005972 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005973
5974 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00005975 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005976 E->getRParenLoc());
5977}
Mike Stump1eb44332009-09-09 15:08:12 +00005978
Douglas Gregorb98b1992009-08-11 05:31:07 +00005979template<typename Derived>
5980Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005981TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00005982 // Transform arguments.
5983 bool ArgChanged = false;
5984 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5985 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5986 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5987 if (Arg.isInvalid())
5988 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005989
Douglas Gregor92e986e2010-04-22 16:44:27 +00005990 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5991 Args.push_back(Arg.takeAs<Expr>());
5992 }
5993
5994 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5995 // Class message: transform the receiver type.
5996 TypeSourceInfo *ReceiverTypeInfo
5997 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5998 if (!ReceiverTypeInfo)
5999 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006000
Douglas Gregor92e986e2010-04-22 16:44:27 +00006001 // If nothing changed, just retain the existing message send.
6002 if (!getDerived().AlwaysRebuild() &&
6003 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6004 return SemaRef.Owned(E->Retain());
6005
6006 // Build a new class message send.
6007 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6008 E->getSelector(),
6009 E->getMethodDecl(),
6010 E->getLeftLoc(),
6011 move_arg(Args),
6012 E->getRightLoc());
6013 }
6014
6015 // Instance message: transform the receiver
6016 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6017 "Only class and instance messages may be instantiated");
6018 OwningExprResult Receiver
6019 = getDerived().TransformExpr(E->getInstanceReceiver());
6020 if (Receiver.isInvalid())
6021 return SemaRef.ExprError();
6022
6023 // If nothing changed, just retain the existing message send.
6024 if (!getDerived().AlwaysRebuild() &&
6025 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6026 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006027
Douglas Gregor92e986e2010-04-22 16:44:27 +00006028 // Build a new instance message send.
6029 return getDerived().RebuildObjCMessageExpr(move(Receiver),
6030 E->getSelector(),
6031 E->getMethodDecl(),
6032 E->getLeftLoc(),
6033 move_arg(Args),
6034 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006035}
6036
Mike Stump1eb44332009-09-09 15:08:12 +00006037template<typename Derived>
6038Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006039TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006040 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006041}
6042
Mike Stump1eb44332009-09-09 15:08:12 +00006043template<typename Derived>
6044Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006045TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006046 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006047}
6048
Mike Stump1eb44332009-09-09 15:08:12 +00006049template<typename Derived>
6050Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006051TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006052 // Transform the base expression.
6053 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6054 if (Base.isInvalid())
6055 return SemaRef.ExprError();
6056
6057 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006058
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006059 // If nothing changed, just retain the existing expression.
6060 if (!getDerived().AlwaysRebuild() &&
6061 Base.get() == E->getBase())
6062 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006063
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006064 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6065 E->getLocation(),
6066 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006067}
6068
Mike Stump1eb44332009-09-09 15:08:12 +00006069template<typename Derived>
6070Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006071TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregore3303542010-04-26 20:47:02 +00006072 // Transform the base expression.
6073 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6074 if (Base.isInvalid())
6075 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006076
Douglas Gregore3303542010-04-26 20:47:02 +00006077 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006078
Douglas Gregore3303542010-04-26 20:47:02 +00006079 // If nothing changed, just retain the existing expression.
6080 if (!getDerived().AlwaysRebuild() &&
6081 Base.get() == E->getBase())
6082 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006083
Douglas Gregore3303542010-04-26 20:47:02 +00006084 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6085 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006086}
6087
Mike Stump1eb44332009-09-09 15:08:12 +00006088template<typename Derived>
6089Sema::OwningExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00006090TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00006091 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006092 // If this implicit setter/getter refers to class methods, it cannot have any
6093 // dependent parts. Just retain the existing declaration.
6094 if (E->getInterfaceDecl())
6095 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006096
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006097 // Transform the base expression.
6098 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6099 if (Base.isInvalid())
6100 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006101
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006102 // We don't need to transform the getters/setters; they will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006103
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006104 // If nothing changed, just retain the existing expression.
6105 if (!getDerived().AlwaysRebuild() &&
6106 Base.get() == E->getBase())
6107 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006108
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006109 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6110 E->getGetterMethod(),
6111 E->getType(),
6112 E->getSetterMethod(),
6113 E->getLocation(),
6114 move(Base));
Sean Huntc3021132010-05-05 15:23:54 +00006115
Douglas Gregorb98b1992009-08-11 05:31:07 +00006116}
6117
Mike Stump1eb44332009-09-09 15:08:12 +00006118template<typename Derived>
6119Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006120TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006121 // Can never occur in a dependent context.
Mike Stump1eb44332009-09-09 15:08:12 +00006122 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006123}
6124
Mike Stump1eb44332009-09-09 15:08:12 +00006125template<typename Derived>
6126Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006127TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006128 // Transform the base expression.
6129 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6130 if (Base.isInvalid())
6131 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006132
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006133 // If nothing changed, just retain the existing expression.
6134 if (!getDerived().AlwaysRebuild() &&
6135 Base.get() == E->getBase())
6136 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006137
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006138 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6139 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006140}
6141
Mike Stump1eb44332009-09-09 15:08:12 +00006142template<typename Derived>
6143Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006144TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006145 bool ArgumentChanged = false;
6146 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6147 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6148 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6149 if (SubExpr.isInvalid())
6150 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006151
Douglas Gregorb98b1992009-08-11 05:31:07 +00006152 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6153 SubExprs.push_back(SubExpr.takeAs<Expr>());
6154 }
Mike Stump1eb44332009-09-09 15:08:12 +00006155
Douglas Gregorb98b1992009-08-11 05:31:07 +00006156 if (!getDerived().AlwaysRebuild() &&
6157 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00006158 return SemaRef.Owned(E->Retain());
6159
Douglas Gregorb98b1992009-08-11 05:31:07 +00006160 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6161 move_arg(SubExprs),
6162 E->getRParenLoc());
6163}
6164
Mike Stump1eb44332009-09-09 15:08:12 +00006165template<typename Derived>
6166Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006167TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006168 // FIXME: Implement this!
6169 assert(false && "Cannot transform block expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00006170 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006171}
6172
Mike Stump1eb44332009-09-09 15:08:12 +00006173template<typename Derived>
6174Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006175TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006176 // FIXME: Implement this!
6177 assert(false && "Cannot transform block-related expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00006178 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006179}
Mike Stump1eb44332009-09-09 15:08:12 +00006180
Douglas Gregorb98b1992009-08-11 05:31:07 +00006181//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006182// Type reconstruction
6183//===----------------------------------------------------------------------===//
6184
Mike Stump1eb44332009-09-09 15:08:12 +00006185template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006186QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6187 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006188 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006189 getDerived().getBaseEntity());
6190}
6191
Mike Stump1eb44332009-09-09 15:08:12 +00006192template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006193QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6194 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006195 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006196 getDerived().getBaseEntity());
6197}
6198
Mike Stump1eb44332009-09-09 15:08:12 +00006199template<typename Derived>
6200QualType
John McCall85737a72009-10-30 00:06:24 +00006201TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6202 bool WrittenAsLValue,
6203 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006204 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006205 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006206}
6207
6208template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006209QualType
John McCall85737a72009-10-30 00:06:24 +00006210TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6211 QualType ClassType,
6212 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006213 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006214 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006215}
6216
6217template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006218QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006219TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6220 ArrayType::ArraySizeModifier SizeMod,
6221 const llvm::APInt *Size,
6222 Expr *SizeExpr,
6223 unsigned IndexTypeQuals,
6224 SourceRange BracketsRange) {
6225 if (SizeExpr || !Size)
6226 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6227 IndexTypeQuals, BracketsRange,
6228 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006229
6230 QualType Types[] = {
6231 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6232 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6233 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006234 };
6235 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6236 QualType SizeType;
6237 for (unsigned I = 0; I != NumTypes; ++I)
6238 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6239 SizeType = Types[I];
6240 break;
6241 }
Mike Stump1eb44332009-09-09 15:08:12 +00006242
Douglas Gregor577f75a2009-08-04 16:50:30 +00006243 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006244 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006245 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006246 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006247}
Mike Stump1eb44332009-09-09 15:08:12 +00006248
Douglas Gregor577f75a2009-08-04 16:50:30 +00006249template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006250QualType
6251TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006252 ArrayType::ArraySizeModifier SizeMod,
6253 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006254 unsigned IndexTypeQuals,
6255 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006256 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006257 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006258}
6259
6260template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006261QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006262TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006263 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006264 unsigned IndexTypeQuals,
6265 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006266 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006267 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006268}
Mike Stump1eb44332009-09-09 15:08:12 +00006269
Douglas Gregor577f75a2009-08-04 16:50:30 +00006270template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006271QualType
6272TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006273 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006274 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006275 unsigned IndexTypeQuals,
6276 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006277 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006278 SizeExpr.takeAs<Expr>(),
6279 IndexTypeQuals, BracketsRange);
6280}
6281
6282template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006283QualType
6284TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006285 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006286 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006287 unsigned IndexTypeQuals,
6288 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006289 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006290 SizeExpr.takeAs<Expr>(),
6291 IndexTypeQuals, BracketsRange);
6292}
6293
6294template<typename Derived>
6295QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson82287d12010-02-05 00:12:22 +00006296 unsigned NumElements,
6297 bool IsAltiVec, bool IsPixel) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006298 // FIXME: semantic checking!
John Thompson82287d12010-02-05 00:12:22 +00006299 return SemaRef.Context.getVectorType(ElementType, NumElements,
6300 IsAltiVec, IsPixel);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006301}
Mike Stump1eb44332009-09-09 15:08:12 +00006302
Douglas Gregor577f75a2009-08-04 16:50:30 +00006303template<typename Derived>
6304QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6305 unsigned NumElements,
6306 SourceLocation AttributeLoc) {
6307 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6308 NumElements, true);
6309 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00006310 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006311 AttributeLoc);
6312 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6313 AttributeLoc);
6314}
Mike Stump1eb44332009-09-09 15:08:12 +00006315
Douglas Gregor577f75a2009-08-04 16:50:30 +00006316template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006317QualType
6318TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006319 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006320 SourceLocation AttributeLoc) {
6321 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6322}
Mike Stump1eb44332009-09-09 15:08:12 +00006323
Douglas Gregor577f75a2009-08-04 16:50:30 +00006324template<typename Derived>
6325QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006326 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006327 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006328 bool Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006329 unsigned Quals) {
Mike Stump1eb44332009-09-09 15:08:12 +00006330 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006331 Quals,
6332 getDerived().getBaseLocation(),
6333 getDerived().getBaseEntity());
6334}
Mike Stump1eb44332009-09-09 15:08:12 +00006335
Douglas Gregor577f75a2009-08-04 16:50:30 +00006336template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006337QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6338 return SemaRef.Context.getFunctionNoProtoType(T);
6339}
6340
6341template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006342QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6343 assert(D && "no decl found");
6344 if (D->isInvalidDecl()) return QualType();
6345
Douglas Gregor92e986e2010-04-22 16:44:27 +00006346 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006347 TypeDecl *Ty;
6348 if (isa<UsingDecl>(D)) {
6349 UsingDecl *Using = cast<UsingDecl>(D);
6350 assert(Using->isTypeName() &&
6351 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6352
6353 // A valid resolved using typename decl points to exactly one type decl.
6354 assert(++Using->shadow_begin() == Using->shadow_end());
6355 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006356
John McCalled976492009-12-04 22:46:56 +00006357 } else {
6358 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6359 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6360 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6361 }
6362
6363 return SemaRef.Context.getTypeDeclType(Ty);
6364}
6365
6366template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00006367QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006368 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6369}
6370
6371template<typename Derived>
6372QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6373 return SemaRef.Context.getTypeOfType(Underlying);
6374}
6375
6376template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00006377QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006378 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6379}
6380
6381template<typename Derived>
6382QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006383 TemplateName Template,
6384 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006385 const TemplateArgumentListInfo &TemplateArgs) {
6386 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006387}
Mike Stump1eb44332009-09-09 15:08:12 +00006388
Douglas Gregordcee1a12009-08-06 05:28:30 +00006389template<typename Derived>
6390NestedNameSpecifier *
6391TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6392 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006393 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006394 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006395 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006396 CXXScopeSpec SS;
6397 // FIXME: The source location information is all wrong.
6398 SS.setRange(Range);
6399 SS.setScopeRep(Prefix);
6400 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006401 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006402 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006403 ObjectType,
6404 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006405 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006406}
6407
6408template<typename Derived>
6409NestedNameSpecifier *
6410TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6411 SourceRange Range,
6412 NamespaceDecl *NS) {
6413 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6414}
6415
6416template<typename Derived>
6417NestedNameSpecifier *
6418TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6419 SourceRange Range,
6420 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006421 QualType T) {
6422 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006423 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006424 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006425 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6426 T.getTypePtr());
6427 }
Mike Stump1eb44332009-09-09 15:08:12 +00006428
Douglas Gregordcee1a12009-08-06 05:28:30 +00006429 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6430 return 0;
6431}
Mike Stump1eb44332009-09-09 15:08:12 +00006432
Douglas Gregord1067e52009-08-06 06:41:21 +00006433template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006434TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006435TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6436 bool TemplateKW,
6437 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006438 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006439 Template);
6440}
6441
6442template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006443TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006444TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006445 const IdentifierInfo &II,
6446 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006447 CXXScopeSpec SS;
6448 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00006449 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006450 UnqualifiedId Name;
6451 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006452 return getSema().ActOnDependentTemplateName(
6453 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006454 SS,
Douglas Gregor014e88d2009-11-03 23:16:33 +00006455 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00006456 ObjectType.getAsOpaquePtr(),
6457 /*EnteringContext=*/false)
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006458 .template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00006459}
Mike Stump1eb44332009-09-09 15:08:12 +00006460
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006462TemplateName
6463TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6464 OverloadedOperatorKind Operator,
6465 QualType ObjectType) {
6466 CXXScopeSpec SS;
6467 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6468 SS.setScopeRep(Qualifier);
6469 UnqualifiedId Name;
6470 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6471 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6472 Operator, SymbolLocations);
6473 return getSema().ActOnDependentTemplateName(
6474 /*FIXME:*/getDerived().getBaseLocation(),
6475 SS,
6476 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00006477 ObjectType.getAsOpaquePtr(),
6478 /*EnteringContext=*/false)
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006479 .template getAsVal<TemplateName>();
6480}
Sean Huntc3021132010-05-05 15:23:54 +00006481
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006482template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006483Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6485 SourceLocation OpLoc,
6486 ExprArg Callee,
6487 ExprArg First,
6488 ExprArg Second) {
6489 Expr *FirstExpr = (Expr *)First.get();
6490 Expr *SecondExpr = (Expr *)Second.get();
John McCallba135432009-11-21 08:51:07 +00006491 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006492 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006493
Douglas Gregorb98b1992009-08-11 05:31:07 +00006494 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006495 if (Op == OO_Subscript) {
6496 if (!FirstExpr->getType()->isOverloadableType() &&
6497 !SecondExpr->getType()->isOverloadableType())
6498 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCallba135432009-11-21 08:51:07 +00006499 CalleeExpr->getLocStart(),
Sebastian Redlf322ed62009-10-29 20:17:01 +00006500 move(Second), OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006501 } else if (Op == OO_Arrow) {
6502 // -> is never a builtin operation.
6503 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006504 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006505 if (!FirstExpr->getType()->isOverloadableType()) {
6506 // The argument is not of overloadable type, so try to create a
6507 // built-in unary operation.
Mike Stump1eb44332009-09-09 15:08:12 +00006508 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006509 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006510
Douglas Gregorb98b1992009-08-11 05:31:07 +00006511 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6512 }
6513 } else {
Mike Stump1eb44332009-09-09 15:08:12 +00006514 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006515 !SecondExpr->getType()->isOverloadableType()) {
6516 // Neither of the arguments is an overloadable type, so try to
6517 // create a built-in binary operation.
6518 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00006519 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006520 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6521 if (Result.isInvalid())
6522 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006523
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524 First.release();
6525 Second.release();
6526 return move(Result);
6527 }
6528 }
Mike Stump1eb44332009-09-09 15:08:12 +00006529
6530 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006531 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006532 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006533
John McCallba135432009-11-21 08:51:07 +00006534 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6535 assert(ULE->requiresADL());
6536
6537 // FIXME: Do we have to check
6538 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006539 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006540 } else {
John McCall6e266892010-01-26 03:27:55 +00006541 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006542 }
Mike Stump1eb44332009-09-09 15:08:12 +00006543
Douglas Gregorb98b1992009-08-11 05:31:07 +00006544 // Add any functions found via argument-dependent lookup.
6545 Expr *Args[2] = { FirstExpr, SecondExpr };
6546 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006547
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548 // Create the overloaded operator invocation for unary operators.
6549 if (NumArgs == 1 || isPostIncDec) {
Mike Stump1eb44332009-09-09 15:08:12 +00006550 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6552 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6553 }
Mike Stump1eb44332009-09-09 15:08:12 +00006554
Sebastian Redlf322ed62009-10-29 20:17:01 +00006555 if (Op == OO_Subscript)
John McCallba135432009-11-21 08:51:07 +00006556 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6557 OpLoc,
6558 move(First),
6559 move(Second));
Sebastian Redlf322ed62009-10-29 20:17:01 +00006560
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561 // Create the overloaded operator invocation for binary operators.
Mike Stump1eb44332009-09-09 15:08:12 +00006562 BinaryOperator::Opcode Opc =
Douglas Gregorb98b1992009-08-11 05:31:07 +00006563 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00006564 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6566 if (Result.isInvalid())
6567 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006568
Douglas Gregorb98b1992009-08-11 05:31:07 +00006569 First.release();
6570 Second.release();
Mike Stump1eb44332009-09-09 15:08:12 +00006571 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006572}
Mike Stump1eb44332009-09-09 15:08:12 +00006573
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006574template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00006575Sema::OwningExprResult
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006576TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6577 SourceLocation OperatorLoc,
6578 bool isArrow,
6579 NestedNameSpecifier *Qualifier,
6580 SourceRange QualifierRange,
6581 TypeSourceInfo *ScopeType,
6582 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006583 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006584 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006585 CXXScopeSpec SS;
6586 if (Qualifier) {
6587 SS.setRange(QualifierRange);
6588 SS.setScopeRep(Qualifier);
6589 }
6590
6591 Expr *BaseE = (Expr *)Base.get();
6592 QualType BaseType = BaseE->getType();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006593 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006594 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006595 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006596 !BaseType->getAs<PointerType>()->getPointeeType()
6597 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006598 // This pseudo-destructor expression is still a pseudo-destructor.
6599 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6600 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006601 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006602 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006603 /*FIXME?*/true);
6604 }
Sean Huntc3021132010-05-05 15:23:54 +00006605
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006606 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006607 DeclarationName Name
6608 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6609 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
Sean Huntc3021132010-05-05 15:23:54 +00006610
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006611 // FIXME: the ScopeType should be tacked onto SS.
Sean Huntc3021132010-05-05 15:23:54 +00006612
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006613 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6614 OperatorLoc, isArrow,
6615 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006616 Name, Destroyed.getLocation(),
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006617 /*TemplateArgs*/ 0);
6618}
6619
Douglas Gregor577f75a2009-08-04 16:50:30 +00006620} // end namespace clang
6621
6622#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H