blob: a8120b85cddb20723377f691fa41bce0950126d8 [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 ///
Sean Huntc3021132010-05-05 15:23:54 +0000533 /// By default, builds a new DependentNameType type from the
Douglas Gregor40336422010-03-31 22:19:08 +0000534 /// nested-name-specifier
Mike Stump1eb44332009-09-09 15:08:12 +0000535 /// and the given type. Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000536 /// different behavior.
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000537 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
538 NestedNameSpecifier *NNS, QualType T) {
Douglas Gregorae628892010-02-13 06:05:33 +0000539 if (NNS->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000540 // If the name is still dependent, just build a new dependent name type.
Douglas Gregorae628892010-02-13 06:05:33 +0000541 CXXScopeSpec SS;
542 SS.setScopeRep(NNS);
543 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000544 return SemaRef.Context.getDependentNameType(Keyword, NNS,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000545 cast<TemplateSpecializationType>(T));
Douglas Gregorae628892010-02-13 06:05:33 +0000546 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000547
548 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000549 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000550
551 /// \brief Build a new typename type that refers to an identifier.
552 ///
553 /// By default, performs semantic analysis when building the typename type
Mike Stump1eb44332009-09-09 15:08:12 +0000554 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000555 /// different behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000556 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000557 NestedNameSpecifier *NNS,
558 const IdentifierInfo *Id,
559 SourceRange SR) {
Douglas Gregor40336422010-03-31 22:19:08 +0000560 CXXScopeSpec SS;
561 SS.setScopeRep(NNS);
Sean Huntc3021132010-05-05 15:23:54 +0000562
Douglas Gregor40336422010-03-31 22:19:08 +0000563 if (NNS->isDependent()) {
564 // If the name is still dependent, just build a new dependent name type.
565 if (!SemaRef.computeDeclContext(SS))
566 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
567 }
568
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000569 if (Keyword == ETK_None || Keyword == ETK_Typename)
570 return SemaRef.CheckTypenameType(Keyword, NNS, *Id, SR);
571
572 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
573
Douglas Gregor40336422010-03-31 22:19:08 +0000574 // We had a dependent elaborated-type-specifier that as been transformed
575 // into a non-dependent elaborated-type-specifier. Find the tag we're
576 // referring to.
577 LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName);
578 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
579 if (!DC)
580 return QualType();
581
582 TagDecl *Tag = 0;
583 SemaRef.LookupQualifiedName(Result, DC);
584 switch (Result.getResultKind()) {
585 case LookupResult::NotFound:
586 case LookupResult::NotFoundInCurrentInstantiation:
587 break;
Sean Huntc3021132010-05-05 15:23:54 +0000588
Douglas Gregor40336422010-03-31 22:19:08 +0000589 case LookupResult::Found:
590 Tag = Result.getAsSingle<TagDecl>();
591 break;
Sean Huntc3021132010-05-05 15:23:54 +0000592
Douglas Gregor40336422010-03-31 22:19:08 +0000593 case LookupResult::FoundOverloaded:
594 case LookupResult::FoundUnresolvedValue:
595 llvm_unreachable("Tag lookup cannot find non-tags");
596 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000597
Douglas Gregor40336422010-03-31 22:19:08 +0000598 case LookupResult::Ambiguous:
599 // Let the LookupResult structure handle ambiguities.
600 return QualType();
601 }
602
603 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000604 // FIXME: Would be nice to highlight just the source range.
Douglas Gregor40336422010-03-31 22:19:08 +0000605 SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000606 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000607 return QualType();
608 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000609
Douglas Gregor40336422010-03-31 22:19:08 +0000610 // FIXME: Terrible location information
611 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) {
612 SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id;
613 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
614 return QualType();
615 }
616
617 // Build the elaborated-type-specifier type.
618 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000619 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000620 }
Mike Stump1eb44332009-09-09 15:08:12 +0000621
Douglas Gregordcee1a12009-08-06 05:28:30 +0000622 /// \brief Build a new nested-name-specifier given the prefix and an
623 /// identifier that names the next step in the nested-name-specifier.
624 ///
625 /// By default, performs semantic analysis when building the new
626 /// nested-name-specifier. Subclasses may override this routine to provide
627 /// different behavior.
628 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
629 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000630 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000631 QualType ObjectType,
632 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000633
634 /// \brief Build a new nested-name-specifier given the prefix and the
635 /// namespace named in the next step in the nested-name-specifier.
636 ///
637 /// By default, performs semantic analysis when building the new
638 /// nested-name-specifier. Subclasses may override this routine to provide
639 /// different behavior.
640 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
641 SourceRange Range,
642 NamespaceDecl *NS);
643
644 /// \brief Build a new nested-name-specifier given the prefix and the
645 /// type named in the next step in the nested-name-specifier.
646 ///
647 /// By default, performs semantic analysis when building the new
648 /// nested-name-specifier. Subclasses may override this routine to provide
649 /// different behavior.
650 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
651 SourceRange Range,
652 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000653 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000654
655 /// \brief Build a new template name given a nested name specifier, a flag
656 /// indicating whether the "template" keyword was provided, and the template
657 /// that the template name refers to.
658 ///
659 /// By default, builds the new template name directly. Subclasses may override
660 /// this routine to provide different behavior.
661 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
662 bool TemplateKW,
663 TemplateDecl *Template);
664
Douglas Gregord1067e52009-08-06 06:41:21 +0000665 /// \brief Build a new template name given a nested name specifier and the
666 /// name that is referred to as a template.
667 ///
668 /// By default, performs semantic analysis to determine whether the name can
669 /// be resolved to a specific template, then builds the appropriate kind of
670 /// template name. Subclasses may override this routine to provide different
671 /// behavior.
672 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000673 const IdentifierInfo &II,
674 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000675
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000676 /// \brief Build a new template name given a nested name specifier and the
677 /// overloaded operator name that is referred to as a template.
678 ///
679 /// By default, performs semantic analysis to determine whether the name can
680 /// be resolved to a specific template, then builds the appropriate kind of
681 /// template name. Subclasses may override this routine to provide different
682 /// behavior.
683 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
684 OverloadedOperatorKind Operator,
685 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000686
Douglas Gregor43959a92009-08-20 07:17:43 +0000687 /// \brief Build a new compound statement.
688 ///
689 /// By default, performs semantic analysis to build the new statement.
690 /// Subclasses may override this routine to provide different behavior.
691 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
692 MultiStmtArg Statements,
693 SourceLocation RBraceLoc,
694 bool IsStmtExpr) {
695 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
696 IsStmtExpr);
697 }
698
699 /// \brief Build a new case statement.
700 ///
701 /// By default, performs semantic analysis to build the new statement.
702 /// Subclasses may override this routine to provide different behavior.
703 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
704 ExprArg LHS,
705 SourceLocation EllipsisLoc,
706 ExprArg RHS,
707 SourceLocation ColonLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000708 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregor43959a92009-08-20 07:17:43 +0000709 ColonLoc);
710 }
Mike Stump1eb44332009-09-09 15:08:12 +0000711
Douglas Gregor43959a92009-08-20 07:17:43 +0000712 /// \brief Attach the body to a new case statement.
713 ///
714 /// By default, performs semantic analysis to build the new statement.
715 /// Subclasses may override this routine to provide different behavior.
716 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
717 getSema().ActOnCaseStmtBody(S.get(), move(Body));
718 return move(S);
719 }
Mike Stump1eb44332009-09-09 15:08:12 +0000720
Douglas Gregor43959a92009-08-20 07:17:43 +0000721 /// \brief Build a new default statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000725 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000726 SourceLocation ColonLoc,
727 StmtArg SubStmt) {
Mike Stump1eb44332009-09-09 15:08:12 +0000728 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregor43959a92009-08-20 07:17:43 +0000729 /*CurScope=*/0);
730 }
Mike Stump1eb44332009-09-09 15:08:12 +0000731
Douglas Gregor43959a92009-08-20 07:17:43 +0000732 /// \brief Build a new label statement.
733 ///
734 /// By default, performs semantic analysis to build the new statement.
735 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000736 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000737 IdentifierInfo *Id,
738 SourceLocation ColonLoc,
739 StmtArg SubStmt) {
740 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
741 }
Mike Stump1eb44332009-09-09 15:08:12 +0000742
Douglas Gregor43959a92009-08-20 07:17:43 +0000743 /// \brief Build a new "if" statement.
744 ///
745 /// By default, performs semantic analysis to build the new statement.
746 /// Subclasses may override this routine to provide different behavior.
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000747 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Sean Huntc3021132010-05-05 15:23:54 +0000748 VarDecl *CondVar, StmtArg Then,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000749 SourceLocation ElseLoc, StmtArg Else) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000750 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000751 move(Then), ElseLoc, move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +0000752 }
Mike Stump1eb44332009-09-09 15:08:12 +0000753
Douglas Gregor43959a92009-08-20 07:17:43 +0000754 /// \brief Start building a new switch statement.
755 ///
756 /// By default, performs semantic analysis to build the new statement.
757 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor586596f2010-05-06 17:25:47 +0000758 OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
759 Sema::ExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000760 VarDecl *CondVar) {
Douglas Gregor586596f2010-05-06 17:25:47 +0000761 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond),
762 DeclPtrTy::make(CondVar));
Douglas Gregor43959a92009-08-20 07:17:43 +0000763 }
Mike Stump1eb44332009-09-09 15:08:12 +0000764
Douglas Gregor43959a92009-08-20 07:17:43 +0000765 /// \brief Attach the body to the switch statement.
766 ///
767 /// By default, performs semantic analysis to build the new statement.
768 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000769 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000770 StmtArg Switch, StmtArg Body) {
771 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
772 move(Body));
773 }
774
775 /// \brief Build a new while statement.
776 ///
777 /// By default, performs semantic analysis to build the new statement.
778 /// Subclasses may override this routine to provide different behavior.
779 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000780 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000781 VarDecl *CondVar,
Douglas Gregor43959a92009-08-20 07:17:43 +0000782 StmtArg Body) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000783 return getSema().ActOnWhileStmt(WhileLoc, Cond,
Douglas Gregor586596f2010-05-06 17:25:47 +0000784 DeclPtrTy::make(CondVar), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000785 }
Mike Stump1eb44332009-09-09 15:08:12 +0000786
Douglas Gregor43959a92009-08-20 07:17:43 +0000787 /// \brief Build a new do-while statement.
788 ///
789 /// By default, performs semantic analysis to build the new statement.
790 /// Subclasses may override this routine to provide different behavior.
791 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
792 SourceLocation WhileLoc,
793 SourceLocation LParenLoc,
794 ExprArg Cond,
795 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000796 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000797 move(Cond), RParenLoc);
798 }
799
800 /// \brief Build a new for statement.
801 ///
802 /// By default, performs semantic analysis to build the new statement.
803 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000804 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000805 SourceLocation LParenLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000806 StmtArg Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000807 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000808 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000809 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000810 DeclPtrTy::make(CondVar),
811 Inc, RParenLoc, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000812 }
Mike Stump1eb44332009-09-09 15:08:12 +0000813
Douglas Gregor43959a92009-08-20 07:17:43 +0000814 /// \brief Build a new goto statement.
815 ///
816 /// By default, performs semantic analysis to build the new statement.
817 /// Subclasses may override this routine to provide different behavior.
818 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
819 SourceLocation LabelLoc,
820 LabelStmt *Label) {
821 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
822 }
823
824 /// \brief Build a new indirect goto statement.
825 ///
826 /// By default, performs semantic analysis to build the new statement.
827 /// Subclasses may override this routine to provide different behavior.
828 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
829 SourceLocation StarLoc,
830 ExprArg Target) {
831 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
832 }
Mike Stump1eb44332009-09-09 15:08:12 +0000833
Douglas Gregor43959a92009-08-20 07:17:43 +0000834 /// \brief Build a new return statement.
835 ///
836 /// By default, performs semantic analysis to build the new statement.
837 /// Subclasses may override this routine to provide different behavior.
838 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
839 ExprArg Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000840
Douglas Gregor43959a92009-08-20 07:17:43 +0000841 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
842 }
Mike Stump1eb44332009-09-09 15:08:12 +0000843
Douglas Gregor43959a92009-08-20 07:17:43 +0000844 /// \brief Build a new declaration statement.
845 ///
846 /// By default, performs semantic analysis to build the new statement.
847 /// Subclasses may override this routine to provide different behavior.
848 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000849 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000850 SourceLocation EndLoc) {
851 return getSema().Owned(
852 new (getSema().Context) DeclStmt(
853 DeclGroupRef::Create(getSema().Context,
854 Decls, NumDecls),
855 StartLoc, EndLoc));
856 }
Mike Stump1eb44332009-09-09 15:08:12 +0000857
Anders Carlsson703e3942010-01-24 05:50:09 +0000858 /// \brief Build a new inline asm statement.
859 ///
860 /// By default, performs semantic analysis to build the new statement.
861 /// Subclasses may override this routine to provide different behavior.
862 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
863 bool IsSimple,
864 bool IsVolatile,
865 unsigned NumOutputs,
866 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000867 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000868 MultiExprArg Constraints,
869 MultiExprArg Exprs,
870 ExprArg AsmString,
871 MultiExprArg Clobbers,
872 SourceLocation RParenLoc,
873 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000874 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000875 NumInputs, Names, move(Constraints),
876 move(Exprs), move(AsmString), move(Clobbers),
877 RParenLoc, MSAsm);
878 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000879
880 /// \brief Build a new Objective-C @try statement.
881 ///
882 /// By default, performs semantic analysis to build the new statement.
883 /// Subclasses may override this routine to provide different behavior.
884 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
885 StmtArg TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000886 MultiStmtArg CatchStmts,
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000887 StmtArg Finally) {
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000888 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000889 move(Finally));
890 }
891
Douglas Gregorbe270a02010-04-26 17:57:08 +0000892 /// \brief Rebuild an Objective-C exception declaration.
893 ///
894 /// By default, performs semantic analysis to build the new declaration.
895 /// Subclasses may override this routine to provide different behavior.
896 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
897 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +0000898 return getSema().BuildObjCExceptionDecl(TInfo, T,
899 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +0000900 ExceptionDecl->getLocation());
901 }
Sean Huntc3021132010-05-05 15:23:54 +0000902
Douglas Gregorbe270a02010-04-26 17:57:08 +0000903 /// \brief Build a new Objective-C @catch statement.
904 ///
905 /// By default, performs semantic analysis to build the new statement.
906 /// Subclasses may override this routine to provide different behavior.
907 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
908 SourceLocation RParenLoc,
909 VarDecl *Var,
910 StmtArg Body) {
911 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
912 Sema::DeclPtrTy::make(Var),
913 move(Body));
914 }
Sean Huntc3021132010-05-05 15:23:54 +0000915
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000916 /// \brief Build a new Objective-C @finally statement.
917 ///
918 /// By default, performs semantic analysis to build the new statement.
919 /// Subclasses may override this routine to provide different behavior.
920 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
921 StmtArg Body) {
922 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
923 }
Sean Huntc3021132010-05-05 15:23:54 +0000924
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000925 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +0000926 ///
927 /// By default, performs semantic analysis to build the new statement.
928 /// Subclasses may override this routine to provide different behavior.
929 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
930 ExprArg Operand) {
931 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
932 }
Sean Huntc3021132010-05-05 15:23:54 +0000933
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000934 /// \brief Build a new Objective-C @synchronized statement.
935 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000936 /// By default, performs semantic analysis to build the new statement.
937 /// Subclasses may override this routine to provide different behavior.
938 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
939 ExprArg Object,
940 StmtArg Body) {
941 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
942 move(Body));
943 }
Douglas Gregorc3203e72010-04-22 23:10:45 +0000944
945 /// \brief Build a new Objective-C fast enumeration statement.
946 ///
947 /// By default, performs semantic analysis to build the new statement.
948 /// Subclasses may override this routine to provide different behavior.
949 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
950 SourceLocation LParenLoc,
951 StmtArg Element,
952 ExprArg Collection,
953 SourceLocation RParenLoc,
954 StmtArg Body) {
955 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
Sean Huntc3021132010-05-05 15:23:54 +0000956 move(Element),
Douglas Gregorc3203e72010-04-22 23:10:45 +0000957 move(Collection),
958 RParenLoc,
959 move(Body));
960 }
Sean Huntc3021132010-05-05 15:23:54 +0000961
Douglas Gregor43959a92009-08-20 07:17:43 +0000962 /// \brief Build a new C++ exception declaration.
963 ///
964 /// By default, performs semantic analysis to build the new decaration.
965 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000966 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000967 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000968 IdentifierInfo *Name,
969 SourceLocation Loc,
970 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000971 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000972 TypeRange);
973 }
974
975 /// \brief Build a new C++ catch statement.
976 ///
977 /// By default, performs semantic analysis to build the new statement.
978 /// Subclasses may override this routine to provide different behavior.
979 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
980 VarDecl *ExceptionDecl,
981 StmtArg Handler) {
982 return getSema().Owned(
Mike Stump1eb44332009-09-09 15:08:12 +0000983 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregor43959a92009-08-20 07:17:43 +0000984 Handler.takeAs<Stmt>()));
985 }
Mike Stump1eb44332009-09-09 15:08:12 +0000986
Douglas Gregor43959a92009-08-20 07:17:43 +0000987 /// \brief Build a new C++ try statement.
988 ///
989 /// By default, performs semantic analysis to build the new statement.
990 /// Subclasses may override this routine to provide different behavior.
991 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
992 StmtArg TryBlock,
993 MultiStmtArg Handlers) {
994 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
995 }
Mike Stump1eb44332009-09-09 15:08:12 +0000996
Douglas Gregorb98b1992009-08-11 05:31:07 +0000997 /// \brief Build a new expression that references a declaration.
998 ///
999 /// By default, performs semantic analysis to build the new expression.
1000 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001001 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1002 LookupResult &R,
1003 bool RequiresADL) {
1004 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1005 }
1006
1007
1008 /// \brief Build a new expression that references a declaration.
1009 ///
1010 /// By default, performs semantic analysis to build the new expression.
1011 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora2813ce2009-10-23 18:54:35 +00001012 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1013 SourceRange QualifierRange,
John McCalldbd872f2009-12-08 09:08:17 +00001014 ValueDecl *VD, SourceLocation Loc,
1015 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001016 CXXScopeSpec SS;
1017 SS.setScopeRep(Qualifier);
1018 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001019
1020 // FIXME: loses template args.
Sean Huntc3021132010-05-05 15:23:54 +00001021
John McCalldbd872f2009-12-08 09:08:17 +00001022 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001023 }
Mike Stump1eb44332009-09-09 15:08:12 +00001024
Douglas Gregorb98b1992009-08-11 05:31:07 +00001025 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001026 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001027 /// By default, performs semantic analysis to build the new expression.
1028 /// Subclasses may override this routine to provide different behavior.
1029 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1030 SourceLocation RParen) {
1031 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1032 }
1033
Douglas Gregora71d8192009-09-04 17:36:40 +00001034 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001035 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001036 /// By default, performs semantic analysis to build the new expression.
1037 /// Subclasses may override this routine to provide different behavior.
1038 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1039 SourceLocation OperatorLoc,
1040 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001041 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001042 SourceRange QualifierRange,
1043 TypeSourceInfo *ScopeType,
1044 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001045 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001046 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001047
Douglas Gregorb98b1992009-08-11 05:31:07 +00001048 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001049 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001050 /// By default, performs semantic analysis to build the new expression.
1051 /// Subclasses may override this routine to provide different behavior.
1052 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1053 UnaryOperator::Opcode Opc,
1054 ExprArg SubExpr) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001055 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001056 }
Mike Stump1eb44332009-09-09 15:08:12 +00001057
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001058 /// \brief Build a new builtin offsetof expression.
1059 ///
1060 /// By default, performs semantic analysis to build the new expression.
1061 /// Subclasses may override this routine to provide different behavior.
1062 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1063 TypeSourceInfo *Type,
1064 Action::OffsetOfComponent *Components,
1065 unsigned NumComponents,
1066 SourceLocation RParenLoc) {
1067 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1068 NumComponents, RParenLoc);
1069 }
Sean Huntc3021132010-05-05 15:23:54 +00001070
Douglas Gregorb98b1992009-08-11 05:31:07 +00001071 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001072 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001073 /// By default, performs semantic analysis to build the new expression.
1074 /// Subclasses may override this routine to provide different behavior.
John McCalla93c9342009-12-07 02:54:59 +00001075 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001076 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001077 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001078 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001079 }
1080
Mike Stump1eb44332009-09-09 15:08:12 +00001081 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001082 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001083 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001084 /// By default, performs semantic analysis to build the new expression.
1085 /// Subclasses may override this routine to provide different behavior.
1086 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1087 bool isSizeOf, SourceRange R) {
Mike Stump1eb44332009-09-09 15:08:12 +00001088 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001089 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1090 OpLoc, isSizeOf, R);
1091 if (Result.isInvalid())
1092 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001093
Douglas Gregorb98b1992009-08-11 05:31:07 +00001094 SubExpr.release();
1095 return move(Result);
1096 }
Mike Stump1eb44332009-09-09 15:08:12 +00001097
Douglas Gregorb98b1992009-08-11 05:31:07 +00001098 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001099 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001100 /// By default, performs semantic analysis to build the new expression.
1101 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001102 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001103 SourceLocation LBracketLoc,
1104 ExprArg RHS,
1105 SourceLocation RBracketLoc) {
1106 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump1eb44332009-09-09 15:08:12 +00001107 LBracketLoc, move(RHS),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001108 RBracketLoc);
1109 }
1110
1111 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001112 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001113 /// By default, performs semantic analysis to build the new expression.
1114 /// Subclasses may override this routine to provide different behavior.
1115 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1116 MultiExprArg Args,
1117 SourceLocation *CommaLocs,
1118 SourceLocation RParenLoc) {
1119 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1120 move(Args), CommaLocs, RParenLoc);
1121 }
1122
1123 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001124 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001125 /// By default, performs semantic analysis to build the new expression.
1126 /// Subclasses may override this routine to provide different behavior.
1127 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001128 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001129 NestedNameSpecifier *Qualifier,
1130 SourceRange QualifierRange,
1131 SourceLocation MemberLoc,
Eli Friedmanf595cc42009-12-04 06:40:45 +00001132 ValueDecl *Member,
John McCall6bb80172010-03-30 21:47:33 +00001133 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001134 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +00001135 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001136 if (!Member->getDeclName()) {
1137 // We have a reference to an unnamed field.
1138 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +00001139
Douglas Gregor83a56c42009-12-24 20:02:50 +00001140 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall6bb80172010-03-30 21:47:33 +00001141 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1142 FoundDecl, Member))
Douglas Gregor83a56c42009-12-24 20:02:50 +00001143 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001144
Mike Stump1eb44332009-09-09 15:08:12 +00001145 MemberExpr *ME =
Douglas Gregor83a56c42009-12-24 20:02:50 +00001146 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlssond8b285f2009-09-01 04:26:58 +00001147 Member, MemberLoc,
1148 cast<FieldDecl>(Member)->getType());
1149 return getSema().Owned(ME);
1150 }
Mike Stump1eb44332009-09-09 15:08:12 +00001151
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001152 CXXScopeSpec SS;
1153 if (Qualifier) {
1154 SS.setRange(QualifierRange);
1155 SS.setScopeRep(Qualifier);
1156 }
1157
John McCallaa81e162009-12-01 22:10:20 +00001158 QualType BaseType = ((Expr*) Base.get())->getType();
1159
John McCall6bb80172010-03-30 21:47:33 +00001160 // FIXME: this involves duplicating earlier analysis in a lot of
1161 // cases; we should avoid this when possible.
John McCallc2233c52010-01-15 08:34:02 +00001162 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1163 Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001164 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001165 R.resolveKind();
1166
John McCallaa81e162009-12-01 22:10:20 +00001167 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1168 OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001169 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001170 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001171 }
Mike Stump1eb44332009-09-09 15:08:12 +00001172
Douglas Gregorb98b1992009-08-11 05:31:07 +00001173 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001174 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001175 /// By default, performs semantic analysis to build the new expression.
1176 /// Subclasses may override this routine to provide different behavior.
1177 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1178 BinaryOperator::Opcode Opc,
1179 ExprArg LHS, ExprArg RHS) {
Sean Huntc3021132010-05-05 15:23:54 +00001180 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001181 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregorb98b1992009-08-11 05:31:07 +00001182 }
1183
1184 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001185 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001186 /// By default, performs semantic analysis to build the new expression.
1187 /// Subclasses may override this routine to provide different behavior.
1188 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1189 SourceLocation QuestionLoc,
1190 ExprArg LHS,
1191 SourceLocation ColonLoc,
1192 ExprArg RHS) {
Mike Stump1eb44332009-09-09 15:08:12 +00001193 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001194 move(LHS), move(RHS));
1195 }
1196
Douglas Gregorb98b1992009-08-11 05:31:07 +00001197 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001198 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001199 /// By default, performs semantic analysis to build the new expression.
1200 /// Subclasses may override this routine to provide different behavior.
John McCall9d125032010-01-15 18:39:57 +00001201 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1202 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001203 SourceLocation RParenLoc,
1204 ExprArg SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001205 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1206 move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001207 }
Mike Stump1eb44332009-09-09 15:08:12 +00001208
Douglas Gregorb98b1992009-08-11 05:31:07 +00001209 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001210 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001211 /// By default, performs semantic analysis to build the new expression.
1212 /// Subclasses may override this routine to provide different behavior.
1213 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001214 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001215 SourceLocation RParenLoc,
1216 ExprArg Init) {
John McCall42f56b52010-01-18 19:35:47 +00001217 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1218 move(Init));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001219 }
Mike Stump1eb44332009-09-09 15:08:12 +00001220
Douglas Gregorb98b1992009-08-11 05:31:07 +00001221 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001222 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001223 /// By default, performs semantic analysis to build the new expression.
1224 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001225 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001226 SourceLocation OpLoc,
1227 SourceLocation AccessorLoc,
1228 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001229
John McCall129e2df2009-11-30 22:42:35 +00001230 CXXScopeSpec SS;
John McCallaa81e162009-12-01 22:10:20 +00001231 QualType BaseType = ((Expr*) Base.get())->getType();
1232 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001233 OpLoc, /*IsArrow*/ false,
1234 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor2d1c2142009-11-03 19:44:04 +00001235 DeclarationName(&Accessor),
John McCall129e2df2009-11-30 22:42:35 +00001236 AccessorLoc,
1237 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001238 }
Mike Stump1eb44332009-09-09 15:08:12 +00001239
Douglas Gregorb98b1992009-08-11 05:31:07 +00001240 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001241 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001242 /// By default, performs semantic analysis to build the new expression.
1243 /// Subclasses may override this routine to provide different behavior.
1244 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1245 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001246 SourceLocation RBraceLoc,
1247 QualType ResultTy) {
1248 OwningExprResult Result
1249 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1250 if (Result.isInvalid() || ResultTy->isDependentType())
1251 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001252
Douglas Gregore48319a2009-11-09 17:16:50 +00001253 // Patch in the result type we were given, which may have been computed
1254 // when the initial InitListExpr was built.
1255 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1256 ILE->setType(ResultTy);
1257 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001258 }
Mike Stump1eb44332009-09-09 15:08:12 +00001259
Douglas Gregorb98b1992009-08-11 05:31:07 +00001260 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001261 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001262 /// By default, performs semantic analysis to build the new expression.
1263 /// Subclasses may override this routine to provide different behavior.
1264 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1265 MultiExprArg ArrayExprs,
1266 SourceLocation EqualOrColonLoc,
1267 bool GNUSyntax,
1268 ExprArg Init) {
1269 OwningExprResult Result
1270 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1271 move(Init));
1272 if (Result.isInvalid())
1273 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001274
Douglas Gregorb98b1992009-08-11 05:31:07 +00001275 ArrayExprs.release();
1276 return move(Result);
1277 }
Mike Stump1eb44332009-09-09 15:08:12 +00001278
Douglas Gregorb98b1992009-08-11 05:31:07 +00001279 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001280 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001281 /// By default, builds the implicit value initialization without performing
1282 /// any semantic analysis. Subclasses may override this routine to provide
1283 /// different behavior.
1284 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1285 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1286 }
Mike Stump1eb44332009-09-09 15:08:12 +00001287
Douglas Gregorb98b1992009-08-11 05:31:07 +00001288 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001289 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001290 /// By default, performs semantic analysis to build the new expression.
1291 /// Subclasses may override this routine to provide different behavior.
1292 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1293 QualType T, SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001294 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001295 RParenLoc);
1296 }
1297
1298 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001299 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001300 /// By default, performs semantic analysis to build the new expression.
1301 /// Subclasses may override this routine to provide different behavior.
1302 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1303 MultiExprArg SubExprs,
1304 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001305 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001306 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001307 }
Mike Stump1eb44332009-09-09 15:08:12 +00001308
Douglas Gregorb98b1992009-08-11 05:31:07 +00001309 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001310 ///
1311 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001312 /// rather than attempting to map the label statement itself.
1313 /// Subclasses may override this routine to provide different behavior.
1314 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1315 SourceLocation LabelLoc,
1316 LabelStmt *Label) {
1317 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1318 }
Mike Stump1eb44332009-09-09 15:08:12 +00001319
Douglas Gregorb98b1992009-08-11 05:31:07 +00001320 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001321 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001322 /// By default, performs semantic analysis to build the new expression.
1323 /// Subclasses may override this routine to provide different behavior.
1324 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1325 StmtArg SubStmt,
1326 SourceLocation RParenLoc) {
1327 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1328 }
Mike Stump1eb44332009-09-09 15:08:12 +00001329
Douglas Gregorb98b1992009-08-11 05:31:07 +00001330 /// \brief Build a new __builtin_types_compatible_p expression.
1331 ///
1332 /// By default, performs semantic analysis to build the new expression.
1333 /// Subclasses may override this routine to provide different behavior.
1334 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1335 QualType T1, QualType T2,
1336 SourceLocation RParenLoc) {
1337 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1338 T1.getAsOpaquePtr(),
1339 T2.getAsOpaquePtr(),
1340 RParenLoc);
1341 }
Mike Stump1eb44332009-09-09 15:08:12 +00001342
Douglas Gregorb98b1992009-08-11 05:31:07 +00001343 /// \brief Build a new __builtin_choose_expr expression.
1344 ///
1345 /// By default, performs semantic analysis to build the new expression.
1346 /// Subclasses may override this routine to provide different behavior.
1347 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1348 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1349 SourceLocation RParenLoc) {
1350 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1351 move(Cond), move(LHS), move(RHS),
1352 RParenLoc);
1353 }
Mike Stump1eb44332009-09-09 15:08:12 +00001354
Douglas Gregorb98b1992009-08-11 05:31:07 +00001355 /// \brief Build a new overloaded operator call expression.
1356 ///
1357 /// By default, performs semantic analysis to build the new expression.
1358 /// The semantic analysis provides the behavior of template instantiation,
1359 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001360 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001361 /// argument-dependent lookup, etc. Subclasses may override this routine to
1362 /// provide different behavior.
1363 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1364 SourceLocation OpLoc,
1365 ExprArg Callee,
1366 ExprArg First,
1367 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001368
1369 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001370 /// reinterpret_cast.
1371 ///
1372 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001373 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001374 /// Subclasses may override this routine to provide different behavior.
1375 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1376 Stmt::StmtClass Class,
1377 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001378 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001379 SourceLocation RAngleLoc,
1380 SourceLocation LParenLoc,
1381 ExprArg SubExpr,
1382 SourceLocation RParenLoc) {
1383 switch (Class) {
1384 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001385 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001386 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001387 move(SubExpr), RParenLoc);
1388
1389 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001390 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001391 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001392 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001393
Douglas Gregorb98b1992009-08-11 05:31:07 +00001394 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001395 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001396 RAngleLoc, LParenLoc,
1397 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001398 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001399
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001401 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001402 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001403 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001404
Douglas Gregorb98b1992009-08-11 05:31:07 +00001405 default:
1406 assert(false && "Invalid C++ named cast");
1407 break;
1408 }
Mike Stump1eb44332009-09-09 15:08:12 +00001409
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 return getSema().ExprError();
1411 }
Mike Stump1eb44332009-09-09 15:08:12 +00001412
Douglas Gregorb98b1992009-08-11 05:31:07 +00001413 /// \brief Build a new C++ static_cast expression.
1414 ///
1415 /// By default, performs semantic analysis to build the new expression.
1416 /// Subclasses may override this routine to provide different behavior.
1417 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1418 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001419 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001420 SourceLocation RAngleLoc,
1421 SourceLocation LParenLoc,
1422 ExprArg SubExpr,
1423 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001424 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1425 TInfo, move(SubExpr),
1426 SourceRange(LAngleLoc, RAngleLoc),
1427 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001428 }
1429
1430 /// \brief Build a new C++ dynamic_cast expression.
1431 ///
1432 /// By default, performs semantic analysis to build the new expression.
1433 /// Subclasses may override this routine to provide different behavior.
1434 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1435 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001436 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001437 SourceLocation RAngleLoc,
1438 SourceLocation LParenLoc,
1439 ExprArg SubExpr,
1440 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001441 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1442 TInfo, move(SubExpr),
1443 SourceRange(LAngleLoc, RAngleLoc),
1444 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001445 }
1446
1447 /// \brief Build a new C++ reinterpret_cast expression.
1448 ///
1449 /// By default, performs semantic analysis to build the new expression.
1450 /// Subclasses may override this routine to provide different behavior.
1451 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1452 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001453 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001454 SourceLocation RAngleLoc,
1455 SourceLocation LParenLoc,
1456 ExprArg SubExpr,
1457 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001458 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1459 TInfo, move(SubExpr),
1460 SourceRange(LAngleLoc, RAngleLoc),
1461 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 }
1463
1464 /// \brief Build a new C++ const_cast expression.
1465 ///
1466 /// By default, performs semantic analysis to build the new expression.
1467 /// Subclasses may override this routine to provide different behavior.
1468 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1469 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001470 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 SourceLocation RAngleLoc,
1472 SourceLocation LParenLoc,
1473 ExprArg SubExpr,
1474 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001475 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1476 TInfo, move(SubExpr),
1477 SourceRange(LAngleLoc, RAngleLoc),
1478 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001479 }
Mike Stump1eb44332009-09-09 15:08:12 +00001480
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 /// \brief Build a new C++ functional-style cast expression.
1482 ///
1483 /// By default, performs semantic analysis to build the new expression.
1484 /// Subclasses may override this routine to provide different behavior.
1485 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001486 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 SourceLocation LParenLoc,
1488 ExprArg SubExpr,
1489 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001490 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001491 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001492 TInfo->getType().getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001494 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001495 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001496 RParenLoc);
1497 }
Mike Stump1eb44332009-09-09 15:08:12 +00001498
Douglas Gregorb98b1992009-08-11 05:31:07 +00001499 /// \brief Build a new C++ typeid(type) expression.
1500 ///
1501 /// By default, performs semantic analysis to build the new expression.
1502 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001503 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1504 SourceLocation TypeidLoc,
1505 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001507 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001508 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001509 }
Mike Stump1eb44332009-09-09 15:08:12 +00001510
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 /// \brief Build a new C++ typeid(expr) expression.
1512 ///
1513 /// By default, performs semantic analysis to build the new expression.
1514 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001515 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1516 SourceLocation TypeidLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 ExprArg Operand,
1518 SourceLocation RParenLoc) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001519 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1520 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001521 }
1522
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 /// \brief Build a new C++ "this" expression.
1524 ///
1525 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001526 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001527 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001528 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001529 QualType ThisType,
1530 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001531 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001532 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1533 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001534 }
1535
1536 /// \brief Build a new C++ throw expression.
1537 ///
1538 /// By default, performs semantic analysis to build the new expression.
1539 /// Subclasses may override this routine to provide different behavior.
1540 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1541 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1542 }
1543
1544 /// \brief Build a new C++ default-argument expression.
1545 ///
1546 /// By default, builds a new default-argument expression, which does not
1547 /// require any semantic analysis. Subclasses may override this routine to
1548 /// provide different behavior.
Sean Huntc3021132010-05-05 15:23:54 +00001549 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001550 ParmVarDecl *Param) {
1551 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1552 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001553 }
1554
1555 /// \brief Build a new C++ zero-initialization expression.
1556 ///
1557 /// By default, performs semantic analysis to build the new expression.
1558 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001559 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001560 SourceLocation LParenLoc,
1561 QualType T,
1562 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001563 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1564 T.getAsOpaquePtr(), LParenLoc,
1565 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001566 0, RParenLoc);
1567 }
Mike Stump1eb44332009-09-09 15:08:12 +00001568
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 /// \brief Build a new C++ "new" expression.
1570 ///
1571 /// By default, performs semantic analysis to build the new expression.
1572 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001573 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001574 bool UseGlobal,
1575 SourceLocation PlacementLParen,
1576 MultiExprArg PlacementArgs,
1577 SourceLocation PlacementRParen,
Mike Stump1eb44332009-09-09 15:08:12 +00001578 bool ParenTypeId,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 QualType AllocType,
1580 SourceLocation TypeLoc,
1581 SourceRange TypeRange,
1582 ExprArg ArraySize,
1583 SourceLocation ConstructorLParen,
1584 MultiExprArg ConstructorArgs,
1585 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001586 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001587 PlacementLParen,
1588 move(PlacementArgs),
1589 PlacementRParen,
1590 ParenTypeId,
1591 AllocType,
1592 TypeLoc,
1593 TypeRange,
1594 move(ArraySize),
1595 ConstructorLParen,
1596 move(ConstructorArgs),
1597 ConstructorRParen);
1598 }
Mike Stump1eb44332009-09-09 15:08:12 +00001599
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 /// \brief Build a new C++ "delete" expression.
1601 ///
1602 /// By default, performs semantic analysis to build the new expression.
1603 /// Subclasses may override this routine to provide different behavior.
1604 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1605 bool IsGlobalDelete,
1606 bool IsArrayForm,
1607 ExprArg Operand) {
1608 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1609 move(Operand));
1610 }
Mike Stump1eb44332009-09-09 15:08:12 +00001611
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 /// \brief Build a new unary type trait expression.
1613 ///
1614 /// By default, performs semantic analysis to build the new expression.
1615 /// Subclasses may override this routine to provide different behavior.
1616 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1617 SourceLocation StartLoc,
1618 SourceLocation LParenLoc,
1619 QualType T,
1620 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001621 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 T.getAsOpaquePtr(), RParenLoc);
1623 }
1624
Mike Stump1eb44332009-09-09 15:08:12 +00001625 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001626 /// expression.
1627 ///
1628 /// By default, performs semantic analysis to build the new expression.
1629 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001630 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 SourceRange QualifierRange,
1632 DeclarationName Name,
1633 SourceLocation Location,
John McCallf7a1a742009-11-24 19:00:30 +00001634 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 CXXScopeSpec SS;
1636 SS.setRange(QualifierRange);
1637 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001638
1639 if (TemplateArgs)
1640 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1641 *TemplateArgs);
1642
1643 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 }
1645
1646 /// \brief Build a new template-id expression.
1647 ///
1648 /// By default, performs semantic analysis to build the new expression.
1649 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001650 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1651 LookupResult &R,
1652 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001653 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001654 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 }
1656
1657 /// \brief Build a new object-construction expression.
1658 ///
1659 /// By default, performs semantic analysis to build the new expression.
1660 /// Subclasses may override this routine to provide different behavior.
1661 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001662 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 CXXConstructorDecl *Constructor,
1664 bool IsElidable,
1665 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001666 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001667 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001668 ConvertedArgs))
1669 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001670
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001671 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1672 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 }
1674
1675 /// \brief Build a new object-construction expression.
1676 ///
1677 /// By default, performs semantic analysis to build the new expression.
1678 /// Subclasses may override this routine to provide different behavior.
1679 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1680 QualType T,
1681 SourceLocation LParenLoc,
1682 MultiExprArg Args,
1683 SourceLocation *Commas,
1684 SourceLocation RParenLoc) {
1685 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1686 T.getAsOpaquePtr(),
1687 LParenLoc,
1688 move(Args),
1689 Commas,
1690 RParenLoc);
1691 }
1692
1693 /// \brief Build a new object-construction expression.
1694 ///
1695 /// By default, performs semantic analysis to build the new expression.
1696 /// Subclasses may override this routine to provide different behavior.
1697 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1698 QualType T,
1699 SourceLocation LParenLoc,
1700 MultiExprArg Args,
1701 SourceLocation *Commas,
1702 SourceLocation RParenLoc) {
1703 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1704 /*FIXME*/LParenLoc),
1705 T.getAsOpaquePtr(),
1706 LParenLoc,
1707 move(Args),
1708 Commas,
1709 RParenLoc);
1710 }
Mike Stump1eb44332009-09-09 15:08:12 +00001711
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 /// \brief Build a new member reference expression.
1713 ///
1714 /// By default, performs semantic analysis to build the new expression.
1715 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001716 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001717 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 bool IsArrow,
1719 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001720 NestedNameSpecifier *Qualifier,
1721 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001722 NamedDecl *FirstQualifierInScope,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 DeclarationName Name,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001724 SourceLocation MemberLoc,
John McCall129e2df2009-11-30 22:42:35 +00001725 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001726 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001727 SS.setRange(QualifierRange);
1728 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001729
John McCallaa81e162009-12-01 22:10:20 +00001730 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1731 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001732 SS, FirstQualifierInScope,
1733 Name, MemberLoc, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001734 }
1735
John McCall129e2df2009-11-30 22:42:35 +00001736 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001737 ///
1738 /// By default, performs semantic analysis to build the new expression.
1739 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001740 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001741 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001742 SourceLocation OperatorLoc,
1743 bool IsArrow,
1744 NestedNameSpecifier *Qualifier,
1745 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001746 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001747 LookupResult &R,
1748 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001749 CXXScopeSpec SS;
1750 SS.setRange(QualifierRange);
1751 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001752
John McCallaa81e162009-12-01 22:10:20 +00001753 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1754 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001755 SS, FirstQualifierInScope,
1756 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001757 }
Mike Stump1eb44332009-09-09 15:08:12 +00001758
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 /// \brief Build a new Objective-C @encode expression.
1760 ///
1761 /// By default, performs semantic analysis to build the new expression.
1762 /// Subclasses may override this routine to provide different behavior.
1763 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001764 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001766 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001768 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001769
Douglas Gregor92e986e2010-04-22 16:44:27 +00001770 /// \brief Build a new Objective-C class message.
1771 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1772 Selector Sel,
1773 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001774 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001775 MultiExprArg Args,
1776 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001777 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1778 ReceiverTypeInfo->getType(),
1779 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001780 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001781 move(Args));
1782 }
1783
1784 /// \brief Build a new Objective-C instance message.
1785 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1786 Selector Sel,
1787 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001788 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001789 MultiExprArg Args,
1790 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001791 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1792 return SemaRef.BuildInstanceMessage(move(Receiver),
1793 ReceiverType,
1794 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001795 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001796 move(Args));
1797 }
1798
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001799 /// \brief Build a new Objective-C ivar reference expression.
1800 ///
1801 /// By default, performs semantic analysis to build the new expression.
1802 /// Subclasses may override this routine to provide different behavior.
1803 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1804 SourceLocation IvarLoc,
1805 bool IsArrow, bool IsFreeIvar) {
1806 // FIXME: We lose track of the IsFreeIvar bit.
1807 CXXScopeSpec SS;
1808 Expr *Base = BaseArg.takeAs<Expr>();
1809 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1810 Sema::LookupMemberName);
1811 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1812 /*FIME:*/IvarLoc,
1813 SS, DeclPtrTy());
1814 if (Result.isInvalid())
1815 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001816
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001817 if (Result.get())
1818 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001819
1820 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001821 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001822 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001823 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001824 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001825 /*TemplateArgs=*/0);
1826 }
Douglas Gregore3303542010-04-26 20:47:02 +00001827
1828 /// \brief Build a new Objective-C property reference expression.
1829 ///
1830 /// By default, performs semantic analysis to build the new expression.
1831 /// Subclasses may override this routine to provide different behavior.
Sean Huntc3021132010-05-05 15:23:54 +00001832 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001833 ObjCPropertyDecl *Property,
1834 SourceLocation PropertyLoc) {
1835 CXXScopeSpec SS;
1836 Expr *Base = BaseArg.takeAs<Expr>();
1837 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1838 Sema::LookupMemberName);
1839 bool IsArrow = false;
1840 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1841 /*FIME:*/PropertyLoc,
1842 SS, DeclPtrTy());
1843 if (Result.isInvalid())
1844 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001845
Douglas Gregore3303542010-04-26 20:47:02 +00001846 if (Result.get())
1847 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001848
1849 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregore3303542010-04-26 20:47:02 +00001850 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001851 /*FIXME:*/PropertyLoc, IsArrow,
1852 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001853 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001854 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001855 /*TemplateArgs=*/0);
1856 }
Sean Huntc3021132010-05-05 15:23:54 +00001857
1858 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001859 /// expression.
1860 ///
1861 /// By default, performs semantic analysis to build the new expression.
Sean Huntc3021132010-05-05 15:23:54 +00001862 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001863 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1864 ObjCMethodDecl *Getter,
1865 QualType T,
1866 ObjCMethodDecl *Setter,
1867 SourceLocation NameLoc,
1868 ExprArg Base) {
1869 // Since these expressions can only be value-dependent, we do not need to
1870 // perform semantic analysis again.
1871 return getSema().Owned(
1872 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1873 Setter,
1874 NameLoc,
1875 Base.takeAs<Expr>()));
1876 }
1877
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001878 /// \brief Build a new Objective-C "isa" expression.
1879 ///
1880 /// By default, performs semantic analysis to build the new expression.
1881 /// Subclasses may override this routine to provide different behavior.
1882 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1883 bool IsArrow) {
1884 CXXScopeSpec SS;
1885 Expr *Base = BaseArg.takeAs<Expr>();
1886 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1887 Sema::LookupMemberName);
1888 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1889 /*FIME:*/IsaLoc,
1890 SS, DeclPtrTy());
1891 if (Result.isInvalid())
1892 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001893
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001894 if (Result.get())
1895 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001896
1897 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001898 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001899 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001900 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001901 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001902 /*TemplateArgs=*/0);
1903 }
Sean Huntc3021132010-05-05 15:23:54 +00001904
Douglas Gregorb98b1992009-08-11 05:31:07 +00001905 /// \brief Build a new shuffle vector expression.
1906 ///
1907 /// By default, performs semantic analysis to build the new expression.
1908 /// Subclasses may override this routine to provide different behavior.
1909 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1910 MultiExprArg SubExprs,
1911 SourceLocation RParenLoc) {
1912 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001913 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001914 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1915 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1916 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1917 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001918
Douglas Gregorb98b1992009-08-11 05:31:07 +00001919 // Build a reference to the __builtin_shufflevector builtin
1920 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001921 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001922 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001923 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001924 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001925
1926 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001927 unsigned NumSubExprs = SubExprs.size();
1928 Expr **Subs = (Expr **)SubExprs.release();
1929 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1930 Subs, NumSubExprs,
1931 Builtin->getResultType(),
1932 RParenLoc);
1933 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001934
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 // Type-check the __builtin_shufflevector expression.
1936 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1937 if (Result.isInvalid())
1938 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001939
Douglas Gregorb98b1992009-08-11 05:31:07 +00001940 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001941 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001942 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001943};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001944
Douglas Gregor43959a92009-08-20 07:17:43 +00001945template<typename Derived>
1946Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1947 if (!S)
1948 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001949
Douglas Gregor43959a92009-08-20 07:17:43 +00001950 switch (S->getStmtClass()) {
1951 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001952
Douglas Gregor43959a92009-08-20 07:17:43 +00001953 // Transform individual statement nodes
1954#define STMT(Node, Parent) \
1955 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1956#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00001957#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001958
Douglas Gregor43959a92009-08-20 07:17:43 +00001959 // Transform expressions by calling TransformExpr.
1960#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00001961#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00001962#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00001963#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00001964 {
1965 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1966 if (E.isInvalid())
1967 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001968
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001969 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001970 }
Mike Stump1eb44332009-09-09 15:08:12 +00001971 }
1972
Douglas Gregor43959a92009-08-20 07:17:43 +00001973 return SemaRef.Owned(S->Retain());
1974}
Mike Stump1eb44332009-09-09 15:08:12 +00001975
1976
Douglas Gregor670444e2009-08-04 22:27:00 +00001977template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00001978Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001979 if (!E)
1980 return SemaRef.Owned(E);
1981
1982 switch (E->getStmtClass()) {
1983 case Stmt::NoStmtClass: break;
1984#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00001985#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00001986#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00001987 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00001988#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001989 }
1990
Douglas Gregorb98b1992009-08-11 05:31:07 +00001991 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00001992}
1993
1994template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00001995NestedNameSpecifier *
1996TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00001997 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001998 QualType ObjectType,
1999 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00002000 if (!NNS)
2001 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002002
Douglas Gregor43959a92009-08-20 07:17:43 +00002003 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002004 NestedNameSpecifier *Prefix = NNS->getPrefix();
2005 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002006 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002007 ObjectType,
2008 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002009 if (!Prefix)
2010 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002011
2012 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00002013 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00002014 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00002015 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002016 }
Mike Stump1eb44332009-09-09 15:08:12 +00002017
Douglas Gregordcee1a12009-08-06 05:28:30 +00002018 switch (NNS->getKind()) {
2019 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00002020 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002021 "Identifier nested-name-specifier with no prefix or object type");
2022 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2023 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002024 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002025
2026 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002027 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002028 ObjectType,
2029 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002030
Douglas Gregordcee1a12009-08-06 05:28:30 +00002031 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002032 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002033 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002034 getDerived().TransformDecl(Range.getBegin(),
2035 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002036 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002037 Prefix == NNS->getPrefix() &&
2038 NS == NNS->getAsNamespace())
2039 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002040
Douglas Gregordcee1a12009-08-06 05:28:30 +00002041 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2042 }
Mike Stump1eb44332009-09-09 15:08:12 +00002043
Douglas Gregordcee1a12009-08-06 05:28:30 +00002044 case NestedNameSpecifier::Global:
2045 // There is no meaningful transformation that one could perform on the
2046 // global scope.
2047 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002048
Douglas Gregordcee1a12009-08-06 05:28:30 +00002049 case NestedNameSpecifier::TypeSpecWithTemplate:
2050 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002051 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00002052 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2053 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002054 if (T.isNull())
2055 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002056
Douglas Gregordcee1a12009-08-06 05:28:30 +00002057 if (!getDerived().AlwaysRebuild() &&
2058 Prefix == NNS->getPrefix() &&
2059 T == QualType(NNS->getAsType(), 0))
2060 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002061
2062 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2063 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002064 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002065 }
2066 }
Mike Stump1eb44332009-09-09 15:08:12 +00002067
Douglas Gregordcee1a12009-08-06 05:28:30 +00002068 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002069 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002070}
2071
2072template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002073DeclarationName
Douglas Gregor81499bb2009-09-03 22:13:48 +00002074TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +00002075 SourceLocation Loc,
2076 QualType ObjectType) {
Douglas Gregor81499bb2009-09-03 22:13:48 +00002077 if (!Name)
2078 return Name;
2079
2080 switch (Name.getNameKind()) {
2081 case DeclarationName::Identifier:
2082 case DeclarationName::ObjCZeroArgSelector:
2083 case DeclarationName::ObjCOneArgSelector:
2084 case DeclarationName::ObjCMultiArgSelector:
2085 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002086 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002087 case DeclarationName::CXXUsingDirective:
2088 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002089
Douglas Gregor81499bb2009-09-03 22:13:48 +00002090 case DeclarationName::CXXConstructorName:
2091 case DeclarationName::CXXDestructorName:
2092 case DeclarationName::CXXConversionFunctionName: {
2093 TemporaryBase Rebase(*this, Loc, Name);
Sean Huntc3021132010-05-05 15:23:54 +00002094 QualType T = getDerived().TransformType(Name.getCXXNameType(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002095 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00002096 if (T.isNull())
2097 return DeclarationName();
Mike Stump1eb44332009-09-09 15:08:12 +00002098
Douglas Gregor81499bb2009-09-03 22:13:48 +00002099 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump1eb44332009-09-09 15:08:12 +00002100 Name.getNameKind(),
Douglas Gregor81499bb2009-09-03 22:13:48 +00002101 SemaRef.Context.getCanonicalType(T));
Douglas Gregor81499bb2009-09-03 22:13:48 +00002102 }
Mike Stump1eb44332009-09-09 15:08:12 +00002103 }
2104
Douglas Gregor81499bb2009-09-03 22:13:48 +00002105 return DeclarationName();
2106}
2107
2108template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002109TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002110TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2111 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002112 SourceLocation Loc = getDerived().getBaseLocation();
2113
Douglas Gregord1067e52009-08-06 06:41:21 +00002114 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002115 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002116 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002117 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2118 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002119 if (!NNS)
2120 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002121
Douglas Gregord1067e52009-08-06 06:41:21 +00002122 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002123 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002124 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002125 if (!TransTemplate)
2126 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002127
Douglas Gregord1067e52009-08-06 06:41:21 +00002128 if (!getDerived().AlwaysRebuild() &&
2129 NNS == QTN->getQualifier() &&
2130 TransTemplate == Template)
2131 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002132
Douglas Gregord1067e52009-08-06 06:41:21 +00002133 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2134 TransTemplate);
2135 }
Mike Stump1eb44332009-09-09 15:08:12 +00002136
John McCallf7a1a742009-11-24 19:00:30 +00002137 // These should be getting filtered out before they make it into the AST.
2138 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002139 }
Mike Stump1eb44332009-09-09 15:08:12 +00002140
Douglas Gregord1067e52009-08-06 06:41:21 +00002141 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002142 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002143 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002144 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2145 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002146 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00002147 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002148
Douglas Gregord1067e52009-08-06 06:41:21 +00002149 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002150 NNS == DTN->getQualifier() &&
2151 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002152 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002153
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002154 if (DTN->isIdentifier())
Sean Huntc3021132010-05-05 15:23:54 +00002155 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002156 ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +00002157
2158 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002159 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002160 }
Mike Stump1eb44332009-09-09 15:08:12 +00002161
Douglas Gregord1067e52009-08-06 06:41:21 +00002162 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002163 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002164 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002165 if (!TransTemplate)
2166 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002167
Douglas Gregord1067e52009-08-06 06:41:21 +00002168 if (!getDerived().AlwaysRebuild() &&
2169 TransTemplate == Template)
2170 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002171
Douglas Gregord1067e52009-08-06 06:41:21 +00002172 return TemplateName(TransTemplate);
2173 }
Mike Stump1eb44332009-09-09 15:08:12 +00002174
John McCallf7a1a742009-11-24 19:00:30 +00002175 // These should be getting filtered out before they reach the AST.
2176 assert(false && "overloaded function decl survived to here");
2177 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002178}
2179
2180template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002181void TreeTransform<Derived>::InventTemplateArgumentLoc(
2182 const TemplateArgument &Arg,
2183 TemplateArgumentLoc &Output) {
2184 SourceLocation Loc = getDerived().getBaseLocation();
2185 switch (Arg.getKind()) {
2186 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002187 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002188 break;
2189
2190 case TemplateArgument::Type:
2191 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002192 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002193
John McCall833ca992009-10-29 08:12:44 +00002194 break;
2195
Douglas Gregor788cd062009-11-11 01:00:40 +00002196 case TemplateArgument::Template:
2197 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2198 break;
Sean Huntc3021132010-05-05 15:23:54 +00002199
John McCall833ca992009-10-29 08:12:44 +00002200 case TemplateArgument::Expression:
2201 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2202 break;
2203
2204 case TemplateArgument::Declaration:
2205 case TemplateArgument::Integral:
2206 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002207 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002208 break;
2209 }
2210}
2211
2212template<typename Derived>
2213bool TreeTransform<Derived>::TransformTemplateArgument(
2214 const TemplateArgumentLoc &Input,
2215 TemplateArgumentLoc &Output) {
2216 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002217 switch (Arg.getKind()) {
2218 case TemplateArgument::Null:
2219 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002220 Output = Input;
2221 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002222
Douglas Gregor670444e2009-08-04 22:27:00 +00002223 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002224 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002225 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002226 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002227
2228 DI = getDerived().TransformType(DI);
2229 if (!DI) return true;
2230
2231 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2232 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002233 }
Mike Stump1eb44332009-09-09 15:08:12 +00002234
Douglas Gregor670444e2009-08-04 22:27:00 +00002235 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002236 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002237 DeclarationName Name;
2238 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2239 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002240 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002241 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002242 if (!D) return true;
2243
John McCall828bff22009-10-29 18:45:58 +00002244 Expr *SourceExpr = Input.getSourceDeclExpression();
2245 if (SourceExpr) {
2246 EnterExpressionEvaluationContext Unevaluated(getSema(),
2247 Action::Unevaluated);
2248 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2249 if (E.isInvalid())
2250 SourceExpr = NULL;
2251 else {
2252 SourceExpr = E.takeAs<Expr>();
2253 SourceExpr->Retain();
2254 }
2255 }
2256
2257 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002258 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002259 }
Mike Stump1eb44332009-09-09 15:08:12 +00002260
Douglas Gregor788cd062009-11-11 01:00:40 +00002261 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002262 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002263 TemplateName Template
2264 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2265 if (Template.isNull())
2266 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002267
Douglas Gregor788cd062009-11-11 01:00:40 +00002268 Output = TemplateArgumentLoc(TemplateArgument(Template),
2269 Input.getTemplateQualifierRange(),
2270 Input.getTemplateNameLoc());
2271 return false;
2272 }
Sean Huntc3021132010-05-05 15:23:54 +00002273
Douglas Gregor670444e2009-08-04 22:27:00 +00002274 case TemplateArgument::Expression: {
2275 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002276 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002277 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002278
John McCall833ca992009-10-29 08:12:44 +00002279 Expr *InputExpr = Input.getSourceExpression();
2280 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2281
2282 Sema::OwningExprResult E
2283 = getDerived().TransformExpr(InputExpr);
2284 if (E.isInvalid()) return true;
2285
2286 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00002287 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00002288 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2289 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002290 }
Mike Stump1eb44332009-09-09 15:08:12 +00002291
Douglas Gregor670444e2009-08-04 22:27:00 +00002292 case TemplateArgument::Pack: {
2293 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2294 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002295 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002296 AEnd = Arg.pack_end();
2297 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002298
John McCall833ca992009-10-29 08:12:44 +00002299 // FIXME: preserve source information here when we start
2300 // caring about parameter packs.
2301
John McCall828bff22009-10-29 18:45:58 +00002302 TemplateArgumentLoc InputArg;
2303 TemplateArgumentLoc OutputArg;
2304 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2305 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002306 return true;
2307
John McCall828bff22009-10-29 18:45:58 +00002308 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002309 }
2310 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002311 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002312 true);
John McCall828bff22009-10-29 18:45:58 +00002313 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002314 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002315 }
2316 }
Mike Stump1eb44332009-09-09 15:08:12 +00002317
Douglas Gregor670444e2009-08-04 22:27:00 +00002318 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002319 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002320}
2321
Douglas Gregor577f75a2009-08-04 16:50:30 +00002322//===----------------------------------------------------------------------===//
2323// Type transformation
2324//===----------------------------------------------------------------------===//
2325
2326template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00002327QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregor124b8782010-02-16 19:09:40 +00002328 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002329 if (getDerived().AlreadyTransformed(T))
2330 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002331
John McCalla2becad2009-10-21 00:40:46 +00002332 // Temporary workaround. All of these transformations should
2333 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002334 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002335 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002336
Douglas Gregor124b8782010-02-16 19:09:40 +00002337 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002338
John McCalla2becad2009-10-21 00:40:46 +00002339 if (!NewDI)
2340 return QualType();
2341
2342 return NewDI->getType();
2343}
2344
2345template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002346TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2347 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002348 if (getDerived().AlreadyTransformed(DI->getType()))
2349 return DI;
2350
2351 TypeLocBuilder TLB;
2352
2353 TypeLoc TL = DI->getTypeLoc();
2354 TLB.reserve(TL.getFullDataSize());
2355
Douglas Gregor124b8782010-02-16 19:09:40 +00002356 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002357 if (Result.isNull())
2358 return 0;
2359
John McCalla93c9342009-12-07 02:54:59 +00002360 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002361}
2362
2363template<typename Derived>
2364QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002365TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2366 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002367 switch (T.getTypeLocClass()) {
2368#define ABSTRACT_TYPELOC(CLASS, PARENT)
2369#define TYPELOC(CLASS, PARENT) \
2370 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002371 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2372 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002373#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002374 }
Mike Stump1eb44332009-09-09 15:08:12 +00002375
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002376 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002377 return QualType();
2378}
2379
2380/// FIXME: By default, this routine adds type qualifiers only to types
2381/// that can have qualifiers, and silently suppresses those qualifiers
2382/// that are not permitted (e.g., qualifiers on reference or function
2383/// types). This is the right thing for template instantiation, but
2384/// probably not for other clients.
2385template<typename Derived>
2386QualType
2387TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002388 QualifiedTypeLoc T,
2389 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002390 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002391
Douglas Gregor124b8782010-02-16 19:09:40 +00002392 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2393 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002394 if (Result.isNull())
2395 return QualType();
2396
2397 // Silently suppress qualifiers if the result type can't be qualified.
2398 // FIXME: this is the right thing for template instantiation, but
2399 // probably not for other clients.
2400 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002401 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002402
John McCalla2becad2009-10-21 00:40:46 +00002403 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2404
2405 TLB.push<QualifiedTypeLoc>(Result);
2406
2407 // No location information to preserve.
2408
2409 return Result;
2410}
2411
2412template <class TyLoc> static inline
2413QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2414 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2415 NewT.setNameLoc(T.getNameLoc());
2416 return T.getType();
2417}
2418
John McCalla2becad2009-10-21 00:40:46 +00002419template<typename Derived>
2420QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002421 BuiltinTypeLoc T,
2422 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002423 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2424 NewT.setBuiltinLoc(T.getBuiltinLoc());
2425 if (T.needsExtraLocalData())
2426 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2427 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002428}
Mike Stump1eb44332009-09-09 15:08:12 +00002429
Douglas Gregor577f75a2009-08-04 16:50:30 +00002430template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002431QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002432 ComplexTypeLoc T,
2433 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002434 // FIXME: recurse?
2435 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002436}
Mike Stump1eb44332009-09-09 15:08:12 +00002437
Douglas Gregor577f75a2009-08-04 16:50:30 +00002438template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002439QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Sean Huntc3021132010-05-05 15:23:54 +00002440 PointerTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00002441 QualType ObjectType) {
Sean Huntc3021132010-05-05 15:23:54 +00002442 QualType PointeeType
2443 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002444 if (PointeeType.isNull())
2445 return QualType();
2446
2447 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002448 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002449 // A dependent pointer type 'T *' has is being transformed such
2450 // that an Objective-C class type is being replaced for 'T'. The
2451 // resulting pointer type is an ObjCObjectPointerType, not a
2452 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002453 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002454
John McCallc12c5bb2010-05-15 11:32:37 +00002455 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2456 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002457 return Result;
2458 }
Sean Huntc3021132010-05-05 15:23:54 +00002459
Douglas Gregor92e986e2010-04-22 16:44:27 +00002460 if (getDerived().AlwaysRebuild() ||
2461 PointeeType != TL.getPointeeLoc().getType()) {
2462 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2463 if (Result.isNull())
2464 return QualType();
2465 }
Sean Huntc3021132010-05-05 15:23:54 +00002466
Douglas Gregor92e986e2010-04-22 16:44:27 +00002467 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2468 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002469 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002470}
Mike Stump1eb44332009-09-09 15:08:12 +00002471
2472template<typename Derived>
2473QualType
John McCalla2becad2009-10-21 00:40:46 +00002474TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002475 BlockPointerTypeLoc TL,
2476 QualType ObjectType) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002477 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002478 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2479 if (PointeeType.isNull())
2480 return QualType();
2481
2482 QualType Result = TL.getType();
2483 if (getDerived().AlwaysRebuild() ||
2484 PointeeType != TL.getPointeeLoc().getType()) {
2485 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002486 TL.getSigilLoc());
2487 if (Result.isNull())
2488 return QualType();
2489 }
2490
Douglas Gregor39968ad2010-04-22 16:50:51 +00002491 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002492 NewT.setSigilLoc(TL.getSigilLoc());
2493 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002494}
2495
John McCall85737a72009-10-30 00:06:24 +00002496/// Transforms a reference type. Note that somewhat paradoxically we
2497/// don't care whether the type itself is an l-value type or an r-value
2498/// type; we only care if the type was *written* as an l-value type
2499/// or an r-value type.
2500template<typename Derived>
2501QualType
2502TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002503 ReferenceTypeLoc TL,
2504 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002505 const ReferenceType *T = TL.getTypePtr();
2506
2507 // Note that this works with the pointee-as-written.
2508 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2509 if (PointeeType.isNull())
2510 return QualType();
2511
2512 QualType Result = TL.getType();
2513 if (getDerived().AlwaysRebuild() ||
2514 PointeeType != T->getPointeeTypeAsWritten()) {
2515 Result = getDerived().RebuildReferenceType(PointeeType,
2516 T->isSpelledAsLValue(),
2517 TL.getSigilLoc());
2518 if (Result.isNull())
2519 return QualType();
2520 }
2521
2522 // r-value references can be rebuilt as l-value references.
2523 ReferenceTypeLoc NewTL;
2524 if (isa<LValueReferenceType>(Result))
2525 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2526 else
2527 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2528 NewTL.setSigilLoc(TL.getSigilLoc());
2529
2530 return Result;
2531}
2532
Mike Stump1eb44332009-09-09 15:08:12 +00002533template<typename Derived>
2534QualType
John McCalla2becad2009-10-21 00:40:46 +00002535TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002536 LValueReferenceTypeLoc TL,
2537 QualType ObjectType) {
2538 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002539}
2540
Mike Stump1eb44332009-09-09 15:08:12 +00002541template<typename Derived>
2542QualType
John McCalla2becad2009-10-21 00:40:46 +00002543TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002544 RValueReferenceTypeLoc TL,
2545 QualType ObjectType) {
2546 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002547}
Mike Stump1eb44332009-09-09 15:08:12 +00002548
Douglas Gregor577f75a2009-08-04 16:50:30 +00002549template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002550QualType
John McCalla2becad2009-10-21 00:40:46 +00002551TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002552 MemberPointerTypeLoc TL,
2553 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002554 MemberPointerType *T = TL.getTypePtr();
2555
2556 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002557 if (PointeeType.isNull())
2558 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002559
John McCalla2becad2009-10-21 00:40:46 +00002560 // TODO: preserve source information for this.
2561 QualType ClassType
2562 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002563 if (ClassType.isNull())
2564 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002565
John McCalla2becad2009-10-21 00:40:46 +00002566 QualType Result = TL.getType();
2567 if (getDerived().AlwaysRebuild() ||
2568 PointeeType != T->getPointeeType() ||
2569 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002570 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2571 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002572 if (Result.isNull())
2573 return QualType();
2574 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002575
John McCalla2becad2009-10-21 00:40:46 +00002576 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2577 NewTL.setSigilLoc(TL.getSigilLoc());
2578
2579 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002580}
2581
Mike Stump1eb44332009-09-09 15:08:12 +00002582template<typename Derived>
2583QualType
John McCalla2becad2009-10-21 00:40:46 +00002584TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002585 ConstantArrayTypeLoc TL,
2586 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002587 ConstantArrayType *T = TL.getTypePtr();
2588 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002589 if (ElementType.isNull())
2590 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002591
John McCalla2becad2009-10-21 00:40:46 +00002592 QualType Result = TL.getType();
2593 if (getDerived().AlwaysRebuild() ||
2594 ElementType != T->getElementType()) {
2595 Result = getDerived().RebuildConstantArrayType(ElementType,
2596 T->getSizeModifier(),
2597 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002598 T->getIndexTypeCVRQualifiers(),
2599 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002600 if (Result.isNull())
2601 return QualType();
2602 }
Sean Huntc3021132010-05-05 15:23:54 +00002603
John McCalla2becad2009-10-21 00:40:46 +00002604 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2605 NewTL.setLBracketLoc(TL.getLBracketLoc());
2606 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002607
John McCalla2becad2009-10-21 00:40:46 +00002608 Expr *Size = TL.getSizeExpr();
2609 if (Size) {
2610 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2611 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2612 }
2613 NewTL.setSizeExpr(Size);
2614
2615 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002616}
Mike Stump1eb44332009-09-09 15:08:12 +00002617
Douglas Gregor577f75a2009-08-04 16:50:30 +00002618template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002619QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002620 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002621 IncompleteArrayTypeLoc TL,
2622 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002623 IncompleteArrayType *T = TL.getTypePtr();
2624 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002625 if (ElementType.isNull())
2626 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002627
John McCalla2becad2009-10-21 00:40:46 +00002628 QualType Result = TL.getType();
2629 if (getDerived().AlwaysRebuild() ||
2630 ElementType != T->getElementType()) {
2631 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002632 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002633 T->getIndexTypeCVRQualifiers(),
2634 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002635 if (Result.isNull())
2636 return QualType();
2637 }
Sean Huntc3021132010-05-05 15:23:54 +00002638
John McCalla2becad2009-10-21 00:40:46 +00002639 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2640 NewTL.setLBracketLoc(TL.getLBracketLoc());
2641 NewTL.setRBracketLoc(TL.getRBracketLoc());
2642 NewTL.setSizeExpr(0);
2643
2644 return Result;
2645}
2646
2647template<typename Derived>
2648QualType
2649TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002650 VariableArrayTypeLoc TL,
2651 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002652 VariableArrayType *T = TL.getTypePtr();
2653 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2654 if (ElementType.isNull())
2655 return QualType();
2656
2657 // Array bounds are not potentially evaluated contexts
2658 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2659
2660 Sema::OwningExprResult SizeResult
2661 = getDerived().TransformExpr(T->getSizeExpr());
2662 if (SizeResult.isInvalid())
2663 return QualType();
2664
2665 Expr *Size = static_cast<Expr*>(SizeResult.get());
2666
2667 QualType Result = TL.getType();
2668 if (getDerived().AlwaysRebuild() ||
2669 ElementType != T->getElementType() ||
2670 Size != T->getSizeExpr()) {
2671 Result = getDerived().RebuildVariableArrayType(ElementType,
2672 T->getSizeModifier(),
2673 move(SizeResult),
2674 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002675 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002676 if (Result.isNull())
2677 return QualType();
2678 }
2679 else SizeResult.take();
Sean Huntc3021132010-05-05 15:23:54 +00002680
John McCalla2becad2009-10-21 00:40:46 +00002681 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2682 NewTL.setLBracketLoc(TL.getLBracketLoc());
2683 NewTL.setRBracketLoc(TL.getRBracketLoc());
2684 NewTL.setSizeExpr(Size);
2685
2686 return Result;
2687}
2688
2689template<typename Derived>
2690QualType
2691TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002692 DependentSizedArrayTypeLoc TL,
2693 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002694 DependentSizedArrayType *T = TL.getTypePtr();
2695 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2696 if (ElementType.isNull())
2697 return QualType();
2698
2699 // Array bounds are not potentially evaluated contexts
2700 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2701
2702 Sema::OwningExprResult SizeResult
2703 = getDerived().TransformExpr(T->getSizeExpr());
2704 if (SizeResult.isInvalid())
2705 return QualType();
2706
2707 Expr *Size = static_cast<Expr*>(SizeResult.get());
2708
2709 QualType Result = TL.getType();
2710 if (getDerived().AlwaysRebuild() ||
2711 ElementType != T->getElementType() ||
2712 Size != T->getSizeExpr()) {
2713 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2714 T->getSizeModifier(),
2715 move(SizeResult),
2716 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002717 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002718 if (Result.isNull())
2719 return QualType();
2720 }
2721 else SizeResult.take();
2722
2723 // We might have any sort of array type now, but fortunately they
2724 // all have the same location layout.
2725 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2726 NewTL.setLBracketLoc(TL.getLBracketLoc());
2727 NewTL.setRBracketLoc(TL.getRBracketLoc());
2728 NewTL.setSizeExpr(Size);
2729
2730 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002731}
Mike Stump1eb44332009-09-09 15:08:12 +00002732
2733template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002734QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002735 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002736 DependentSizedExtVectorTypeLoc TL,
2737 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002738 DependentSizedExtVectorType *T = TL.getTypePtr();
2739
2740 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002741 QualType ElementType = getDerived().TransformType(T->getElementType());
2742 if (ElementType.isNull())
2743 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002744
Douglas Gregor670444e2009-08-04 22:27:00 +00002745 // Vector sizes are not potentially evaluated contexts
2746 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2747
Douglas Gregor577f75a2009-08-04 16:50:30 +00002748 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2749 if (Size.isInvalid())
2750 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002751
John McCalla2becad2009-10-21 00:40:46 +00002752 QualType Result = TL.getType();
2753 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002754 ElementType != T->getElementType() ||
2755 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002756 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002757 move(Size),
2758 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002759 if (Result.isNull())
2760 return QualType();
2761 }
2762 else Size.take();
2763
2764 // Result might be dependent or not.
2765 if (isa<DependentSizedExtVectorType>(Result)) {
2766 DependentSizedExtVectorTypeLoc NewTL
2767 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2768 NewTL.setNameLoc(TL.getNameLoc());
2769 } else {
2770 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2771 NewTL.setNameLoc(TL.getNameLoc());
2772 }
2773
2774 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002775}
Mike Stump1eb44332009-09-09 15:08:12 +00002776
2777template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002778QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002779 VectorTypeLoc TL,
2780 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002781 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002782 QualType ElementType = getDerived().TransformType(T->getElementType());
2783 if (ElementType.isNull())
2784 return QualType();
2785
John McCalla2becad2009-10-21 00:40:46 +00002786 QualType Result = TL.getType();
2787 if (getDerived().AlwaysRebuild() ||
2788 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002789 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2790 T->isAltiVec(), T->isPixel());
John McCalla2becad2009-10-21 00:40:46 +00002791 if (Result.isNull())
2792 return QualType();
2793 }
Sean Huntc3021132010-05-05 15:23:54 +00002794
John McCalla2becad2009-10-21 00:40:46 +00002795 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2796 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002797
John McCalla2becad2009-10-21 00:40:46 +00002798 return Result;
2799}
2800
2801template<typename Derived>
2802QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002803 ExtVectorTypeLoc TL,
2804 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002805 VectorType *T = TL.getTypePtr();
2806 QualType ElementType = getDerived().TransformType(T->getElementType());
2807 if (ElementType.isNull())
2808 return QualType();
2809
2810 QualType Result = TL.getType();
2811 if (getDerived().AlwaysRebuild() ||
2812 ElementType != T->getElementType()) {
2813 Result = getDerived().RebuildExtVectorType(ElementType,
2814 T->getNumElements(),
2815 /*FIXME*/ SourceLocation());
2816 if (Result.isNull())
2817 return QualType();
2818 }
Sean Huntc3021132010-05-05 15:23:54 +00002819
John McCalla2becad2009-10-21 00:40:46 +00002820 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2821 NewTL.setNameLoc(TL.getNameLoc());
2822
2823 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002824}
Mike Stump1eb44332009-09-09 15:08:12 +00002825
2826template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002827ParmVarDecl *
2828TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2829 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2830 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2831 if (!NewDI)
2832 return 0;
2833
2834 if (NewDI == OldDI)
2835 return OldParm;
2836 else
2837 return ParmVarDecl::Create(SemaRef.Context,
2838 OldParm->getDeclContext(),
2839 OldParm->getLocation(),
2840 OldParm->getIdentifier(),
2841 NewDI->getType(),
2842 NewDI,
2843 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002844 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002845 /* DefArg */ NULL);
2846}
2847
2848template<typename Derived>
2849bool TreeTransform<Derived>::
2850 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2851 llvm::SmallVectorImpl<QualType> &PTypes,
2852 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2853 FunctionProtoType *T = TL.getTypePtr();
2854
2855 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2856 ParmVarDecl *OldParm = TL.getArg(i);
2857
2858 QualType NewType;
2859 ParmVarDecl *NewParm;
2860
2861 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002862 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2863 if (!NewParm)
2864 return true;
2865 NewType = NewParm->getType();
2866
2867 // Deal with the possibility that we don't have a parameter
2868 // declaration for this parameter.
2869 } else {
2870 NewParm = 0;
2871
2872 QualType OldType = T->getArgType(i);
2873 NewType = getDerived().TransformType(OldType);
2874 if (NewType.isNull())
2875 return true;
2876 }
2877
2878 PTypes.push_back(NewType);
2879 PVars.push_back(NewParm);
2880 }
2881
2882 return false;
2883}
2884
2885template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002886QualType
John McCalla2becad2009-10-21 00:40:46 +00002887TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002888 FunctionProtoTypeLoc TL,
2889 QualType ObjectType) {
Douglas Gregor895162d2010-04-30 18:55:50 +00002890 // Transform the parameters. We do this first for the benefit of template
2891 // instantiations, so that the ParmVarDecls get/ placed into the template
2892 // instantiation scope before we transform the function type.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002893 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002894 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall21ef0fa2010-03-11 09:03:00 +00002895 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2896 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002897
Douglas Gregor895162d2010-04-30 18:55:50 +00002898 FunctionProtoType *T = TL.getTypePtr();
2899 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2900 if (ResultType.isNull())
2901 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002902
John McCalla2becad2009-10-21 00:40:46 +00002903 QualType Result = TL.getType();
2904 if (getDerived().AlwaysRebuild() ||
2905 ResultType != T->getResultType() ||
2906 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2907 Result = getDerived().RebuildFunctionProtoType(ResultType,
2908 ParamTypes.data(),
2909 ParamTypes.size(),
2910 T->isVariadic(),
2911 T->getTypeQuals());
2912 if (Result.isNull())
2913 return QualType();
2914 }
Mike Stump1eb44332009-09-09 15:08:12 +00002915
John McCalla2becad2009-10-21 00:40:46 +00002916 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2917 NewTL.setLParenLoc(TL.getLParenLoc());
2918 NewTL.setRParenLoc(TL.getRParenLoc());
2919 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2920 NewTL.setArg(i, ParamDecls[i]);
2921
2922 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002923}
Mike Stump1eb44332009-09-09 15:08:12 +00002924
Douglas Gregor577f75a2009-08-04 16:50:30 +00002925template<typename Derived>
2926QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002927 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002928 FunctionNoProtoTypeLoc TL,
2929 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002930 FunctionNoProtoType *T = TL.getTypePtr();
2931 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2932 if (ResultType.isNull())
2933 return QualType();
2934
2935 QualType Result = TL.getType();
2936 if (getDerived().AlwaysRebuild() ||
2937 ResultType != T->getResultType())
2938 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2939
2940 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2941 NewTL.setLParenLoc(TL.getLParenLoc());
2942 NewTL.setRParenLoc(TL.getRParenLoc());
2943
2944 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002945}
Mike Stump1eb44332009-09-09 15:08:12 +00002946
John McCalled976492009-12-04 22:46:56 +00002947template<typename Derived> QualType
2948TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002949 UnresolvedUsingTypeLoc TL,
2950 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00002951 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002952 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00002953 if (!D)
2954 return QualType();
2955
2956 QualType Result = TL.getType();
2957 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2958 Result = getDerived().RebuildUnresolvedUsingType(D);
2959 if (Result.isNull())
2960 return QualType();
2961 }
2962
2963 // We might get an arbitrary type spec type back. We should at
2964 // least always get a type spec type, though.
2965 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2966 NewTL.setNameLoc(TL.getNameLoc());
2967
2968 return Result;
2969}
2970
Douglas Gregor577f75a2009-08-04 16:50:30 +00002971template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002972QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002973 TypedefTypeLoc TL,
2974 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002975 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002976 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002977 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2978 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002979 if (!Typedef)
2980 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002981
John McCalla2becad2009-10-21 00:40:46 +00002982 QualType Result = TL.getType();
2983 if (getDerived().AlwaysRebuild() ||
2984 Typedef != T->getDecl()) {
2985 Result = getDerived().RebuildTypedefType(Typedef);
2986 if (Result.isNull())
2987 return QualType();
2988 }
Mike Stump1eb44332009-09-09 15:08:12 +00002989
John McCalla2becad2009-10-21 00:40:46 +00002990 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2991 NewTL.setNameLoc(TL.getNameLoc());
2992
2993 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002994}
Mike Stump1eb44332009-09-09 15:08:12 +00002995
Douglas Gregor577f75a2009-08-04 16:50:30 +00002996template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002997QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002998 TypeOfExprTypeLoc TL,
2999 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003000 // typeof expressions are not potentially evaluated contexts
3001 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003002
John McCallcfb708c2010-01-13 20:03:27 +00003003 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003004 if (E.isInvalid())
3005 return QualType();
3006
John McCalla2becad2009-10-21 00:40:46 +00003007 QualType Result = TL.getType();
3008 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003009 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003010 Result = getDerived().RebuildTypeOfExprType(move(E));
3011 if (Result.isNull())
3012 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003013 }
John McCalla2becad2009-10-21 00:40:46 +00003014 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003015
John McCalla2becad2009-10-21 00:40:46 +00003016 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003017 NewTL.setTypeofLoc(TL.getTypeofLoc());
3018 NewTL.setLParenLoc(TL.getLParenLoc());
3019 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003020
3021 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003022}
Mike Stump1eb44332009-09-09 15:08:12 +00003023
3024template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003025QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003026 TypeOfTypeLoc TL,
3027 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00003028 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3029 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3030 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003031 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003032
John McCalla2becad2009-10-21 00:40:46 +00003033 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003034 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3035 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003036 if (Result.isNull())
3037 return QualType();
3038 }
Mike Stump1eb44332009-09-09 15:08:12 +00003039
John McCalla2becad2009-10-21 00:40:46 +00003040 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003041 NewTL.setTypeofLoc(TL.getTypeofLoc());
3042 NewTL.setLParenLoc(TL.getLParenLoc());
3043 NewTL.setRParenLoc(TL.getRParenLoc());
3044 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003045
3046 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003047}
Mike Stump1eb44332009-09-09 15:08:12 +00003048
3049template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003050QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003051 DecltypeTypeLoc TL,
3052 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003053 DecltypeType *T = TL.getTypePtr();
3054
Douglas Gregor670444e2009-08-04 22:27:00 +00003055 // decltype expressions are not potentially evaluated contexts
3056 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003057
Douglas Gregor577f75a2009-08-04 16:50:30 +00003058 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3059 if (E.isInvalid())
3060 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003061
John McCalla2becad2009-10-21 00:40:46 +00003062 QualType Result = TL.getType();
3063 if (getDerived().AlwaysRebuild() ||
3064 E.get() != T->getUnderlyingExpr()) {
3065 Result = getDerived().RebuildDecltypeType(move(E));
3066 if (Result.isNull())
3067 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003068 }
John McCalla2becad2009-10-21 00:40:46 +00003069 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003070
John McCalla2becad2009-10-21 00:40:46 +00003071 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3072 NewTL.setNameLoc(TL.getNameLoc());
3073
3074 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003075}
3076
3077template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003078QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003079 RecordTypeLoc TL,
3080 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003081 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003082 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003083 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3084 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003085 if (!Record)
3086 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003087
John McCalla2becad2009-10-21 00:40:46 +00003088 QualType Result = TL.getType();
3089 if (getDerived().AlwaysRebuild() ||
3090 Record != T->getDecl()) {
3091 Result = getDerived().RebuildRecordType(Record);
3092 if (Result.isNull())
3093 return QualType();
3094 }
Mike Stump1eb44332009-09-09 15:08:12 +00003095
John McCalla2becad2009-10-21 00:40:46 +00003096 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3097 NewTL.setNameLoc(TL.getNameLoc());
3098
3099 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003100}
Mike Stump1eb44332009-09-09 15:08:12 +00003101
3102template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003103QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003104 EnumTypeLoc TL,
3105 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003106 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003107 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003108 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3109 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003110 if (!Enum)
3111 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003112
John McCalla2becad2009-10-21 00:40:46 +00003113 QualType Result = TL.getType();
3114 if (getDerived().AlwaysRebuild() ||
3115 Enum != T->getDecl()) {
3116 Result = getDerived().RebuildEnumType(Enum);
3117 if (Result.isNull())
3118 return QualType();
3119 }
Mike Stump1eb44332009-09-09 15:08:12 +00003120
John McCalla2becad2009-10-21 00:40:46 +00003121 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3122 NewTL.setNameLoc(TL.getNameLoc());
3123
3124 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003125}
John McCall7da24312009-09-05 00:15:47 +00003126
John McCall3cb0ebd2010-03-10 03:28:59 +00003127template<typename Derived>
3128QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3129 TypeLocBuilder &TLB,
3130 InjectedClassNameTypeLoc TL,
3131 QualType ObjectType) {
3132 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3133 TL.getTypePtr()->getDecl());
3134 if (!D) return QualType();
3135
3136 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3137 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3138 return T;
3139}
3140
Mike Stump1eb44332009-09-09 15:08:12 +00003141
Douglas Gregor577f75a2009-08-04 16:50:30 +00003142template<typename Derived>
3143QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003144 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003145 TemplateTypeParmTypeLoc TL,
3146 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003147 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003148}
3149
Mike Stump1eb44332009-09-09 15:08:12 +00003150template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003151QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003152 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003153 SubstTemplateTypeParmTypeLoc TL,
3154 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003155 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003156}
3157
3158template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003159QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3160 const TemplateSpecializationType *TST,
3161 QualType ObjectType) {
3162 // FIXME: this entire method is a temporary workaround; callers
3163 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00003164
John McCall833ca992009-10-29 08:12:44 +00003165 // Fake up a TemplateSpecializationTypeLoc.
3166 TypeLocBuilder TLB;
3167 TemplateSpecializationTypeLoc TL
3168 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3169
John McCall828bff22009-10-29 18:45:58 +00003170 SourceLocation BaseLoc = getDerived().getBaseLocation();
3171
3172 TL.setTemplateNameLoc(BaseLoc);
3173 TL.setLAngleLoc(BaseLoc);
3174 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00003175 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3176 const TemplateArgument &TA = TST->getArg(i);
3177 TemplateArgumentLoc TAL;
3178 getDerived().InventTemplateArgumentLoc(TA, TAL);
3179 TL.setArgLocInfo(i, TAL.getLocInfo());
3180 }
3181
3182 TypeLocBuilder IgnoredTLB;
3183 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00003184}
Sean Huntc3021132010-05-05 15:23:54 +00003185
Douglas Gregordd62b152009-10-19 22:04:39 +00003186template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003187QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003188 TypeLocBuilder &TLB,
3189 TemplateSpecializationTypeLoc TL,
3190 QualType ObjectType) {
3191 const TemplateSpecializationType *T = TL.getTypePtr();
3192
Mike Stump1eb44332009-09-09 15:08:12 +00003193 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00003194 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003195 if (Template.isNull())
3196 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003197
John McCalld5532b62009-11-23 01:53:49 +00003198 TemplateArgumentListInfo NewTemplateArgs;
3199 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3200 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3201
3202 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3203 TemplateArgumentLoc Loc;
3204 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003205 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003206 NewTemplateArgs.addArgument(Loc);
3207 }
Mike Stump1eb44332009-09-09 15:08:12 +00003208
John McCall833ca992009-10-29 08:12:44 +00003209 // FIXME: maybe don't rebuild if all the template arguments are the same.
3210
3211 QualType Result =
3212 getDerived().RebuildTemplateSpecializationType(Template,
3213 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003214 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003215
3216 if (!Result.isNull()) {
3217 TemplateSpecializationTypeLoc NewTL
3218 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3219 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3220 NewTL.setLAngleLoc(TL.getLAngleLoc());
3221 NewTL.setRAngleLoc(TL.getRAngleLoc());
3222 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3223 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003224 }
Mike Stump1eb44332009-09-09 15:08:12 +00003225
John McCall833ca992009-10-29 08:12:44 +00003226 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003227}
Mike Stump1eb44332009-09-09 15:08:12 +00003228
3229template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003230QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003231TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3232 ElaboratedTypeLoc TL,
3233 QualType ObjectType) {
3234 ElaboratedType *T = TL.getTypePtr();
3235
3236 NestedNameSpecifier *NNS = 0;
3237 // NOTE: the qualifier in an ElaboratedType is optional.
3238 if (T->getQualifier() != 0) {
3239 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Daniel Dunbara63db842010-05-14 16:34:09 +00003240 SourceRange(),
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003241 ObjectType);
3242 if (!NNS)
3243 return QualType();
3244 }
Mike Stump1eb44332009-09-09 15:08:12 +00003245
Daniel Dunbara63db842010-05-14 16:34:09 +00003246 QualType Named = getDerived().TransformType(T->getNamedType());
3247 if (Named.isNull())
3248 return QualType();
3249
John McCalla2becad2009-10-21 00:40:46 +00003250 QualType Result = TL.getType();
3251 if (getDerived().AlwaysRebuild() ||
3252 NNS != T->getQualifier() ||
3253 Named != T->getNamedType()) {
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003254 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, Named);
John McCalla2becad2009-10-21 00:40:46 +00003255 if (Result.isNull())
3256 return QualType();
3257 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003258
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003259 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Daniel Dunbara63db842010-05-14 16:34:09 +00003260 NewTL.setNameLoc(TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003261
3262 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003263}
Mike Stump1eb44332009-09-09 15:08:12 +00003264
3265template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003266QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3267 DependentNameTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00003268 QualType ObjectType) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003269 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003270
3271 /* FIXME: preserve source information better than this */
3272 SourceRange SR(TL.getNameLoc());
3273
Douglas Gregor577f75a2009-08-04 16:50:30 +00003274 NestedNameSpecifier *NNS
Douglas Gregor124b8782010-02-16 19:09:40 +00003275 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregoredc90502010-02-25 04:46:04 +00003276 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003277 if (!NNS)
3278 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003279
John McCalla2becad2009-10-21 00:40:46 +00003280 QualType Result;
3281
Douglas Gregor577f75a2009-08-04 16:50:30 +00003282 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump1eb44332009-09-09 15:08:12 +00003283 QualType NewTemplateId
Douglas Gregor577f75a2009-08-04 16:50:30 +00003284 = getDerived().TransformType(QualType(TemplateId, 0));
3285 if (NewTemplateId.isNull())
3286 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003287
Douglas Gregor577f75a2009-08-04 16:50:30 +00003288 if (!getDerived().AlwaysRebuild() &&
3289 NNS == T->getQualifier() &&
3290 NewTemplateId == QualType(TemplateId, 0))
3291 return QualType(T, 0);
Mike Stump1eb44332009-09-09 15:08:12 +00003292
Sean Huntc3021132010-05-05 15:23:54 +00003293 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
Douglas Gregor4a2023f2010-03-31 20:19:30 +00003294 NewTemplateId);
John McCalla2becad2009-10-21 00:40:46 +00003295 } else {
Sean Huntc3021132010-05-05 15:23:54 +00003296 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
Douglas Gregor4a2023f2010-03-31 20:19:30 +00003297 T->getIdentifier(), SR);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003298 }
John McCalla2becad2009-10-21 00:40:46 +00003299 if (Result.isNull())
3300 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003301
Daniel Dunbara63db842010-05-14 16:34:09 +00003302 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3303 NewTL.setNameLoc(TL.getNameLoc());
3304
John McCalla2becad2009-10-21 00:40:46 +00003305 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003306}
Mike Stump1eb44332009-09-09 15:08:12 +00003307
Douglas Gregor577f75a2009-08-04 16:50:30 +00003308template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003309QualType
3310TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003311 ObjCInterfaceTypeLoc TL,
3312 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003313 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003314 TLB.pushFullCopy(TL);
3315 return TL.getType();
3316}
3317
3318template<typename Derived>
3319QualType
3320TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3321 ObjCObjectTypeLoc TL,
3322 QualType ObjectType) {
3323 // ObjCObjectType is never dependent.
3324 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003325 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003326}
Mike Stump1eb44332009-09-09 15:08:12 +00003327
3328template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003329QualType
3330TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003331 ObjCObjectPointerTypeLoc TL,
3332 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003333 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003334 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003335 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003336}
3337
Douglas Gregor577f75a2009-08-04 16:50:30 +00003338//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003339// Statement transformation
3340//===----------------------------------------------------------------------===//
3341template<typename Derived>
3342Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003343TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3344 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003345}
3346
3347template<typename Derived>
3348Sema::OwningStmtResult
3349TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3350 return getDerived().TransformCompoundStmt(S, false);
3351}
3352
3353template<typename Derived>
3354Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003355TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003356 bool IsStmtExpr) {
3357 bool SubStmtChanged = false;
3358 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3359 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3360 B != BEnd; ++B) {
3361 OwningStmtResult Result = getDerived().TransformStmt(*B);
3362 if (Result.isInvalid())
3363 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003364
Douglas Gregor43959a92009-08-20 07:17:43 +00003365 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3366 Statements.push_back(Result.takeAs<Stmt>());
3367 }
Mike Stump1eb44332009-09-09 15:08:12 +00003368
Douglas Gregor43959a92009-08-20 07:17:43 +00003369 if (!getDerived().AlwaysRebuild() &&
3370 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003371 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003372
3373 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3374 move_arg(Statements),
3375 S->getRBracLoc(),
3376 IsStmtExpr);
3377}
Mike Stump1eb44332009-09-09 15:08:12 +00003378
Douglas Gregor43959a92009-08-20 07:17:43 +00003379template<typename Derived>
3380Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003381TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00003382 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3383 {
3384 // The case value expressions are not potentially evaluated.
3385 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003386
Eli Friedman264c1f82009-11-19 03:14:00 +00003387 // Transform the left-hand case value.
3388 LHS = getDerived().TransformExpr(S->getLHS());
3389 if (LHS.isInvalid())
3390 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003391
Eli Friedman264c1f82009-11-19 03:14:00 +00003392 // Transform the right-hand case value (for the GNU case-range extension).
3393 RHS = getDerived().TransformExpr(S->getRHS());
3394 if (RHS.isInvalid())
3395 return SemaRef.StmtError();
3396 }
Mike Stump1eb44332009-09-09 15:08:12 +00003397
Douglas Gregor43959a92009-08-20 07:17:43 +00003398 // Build the case statement.
3399 // Case statements are always rebuilt so that they will attached to their
3400 // transformed switch statement.
3401 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3402 move(LHS),
3403 S->getEllipsisLoc(),
3404 move(RHS),
3405 S->getColonLoc());
3406 if (Case.isInvalid())
3407 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003408
Douglas Gregor43959a92009-08-20 07:17:43 +00003409 // Transform the statement following the case
3410 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3411 if (SubStmt.isInvalid())
3412 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003413
Douglas Gregor43959a92009-08-20 07:17:43 +00003414 // Attach the body to the case statement
3415 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3416}
3417
3418template<typename Derived>
3419Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003420TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003421 // Transform the statement following the default case
3422 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3423 if (SubStmt.isInvalid())
3424 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003425
Douglas Gregor43959a92009-08-20 07:17:43 +00003426 // Default statements are always rebuilt
3427 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3428 move(SubStmt));
3429}
Mike Stump1eb44332009-09-09 15:08:12 +00003430
Douglas Gregor43959a92009-08-20 07:17:43 +00003431template<typename Derived>
3432Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003433TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003434 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3435 if (SubStmt.isInvalid())
3436 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003437
Douglas Gregor43959a92009-08-20 07:17:43 +00003438 // FIXME: Pass the real colon location in.
3439 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3440 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3441 move(SubStmt));
3442}
Mike Stump1eb44332009-09-09 15:08:12 +00003443
Douglas Gregor43959a92009-08-20 07:17:43 +00003444template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003445Sema::OwningStmtResult
3446TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003447 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003448 OwningExprResult Cond(SemaRef);
3449 VarDecl *ConditionVar = 0;
3450 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003451 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003452 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003453 getDerived().TransformDefinition(
3454 S->getConditionVariable()->getLocation(),
3455 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003456 if (!ConditionVar)
3457 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003458 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003459 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003460
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003461 if (Cond.isInvalid())
3462 return SemaRef.StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003463
3464 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003465 if (S->getCond()) {
3466 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3467 S->getIfLoc(),
3468 move(Cond));
3469 if (CondE.isInvalid())
3470 return getSema().StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003471
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003472 Cond = move(CondE);
3473 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003474 }
Sean Huntc3021132010-05-05 15:23:54 +00003475
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003476 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3477 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3478 return SemaRef.StmtError();
3479
Douglas Gregor43959a92009-08-20 07:17:43 +00003480 // Transform the "then" branch.
3481 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3482 if (Then.isInvalid())
3483 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003484
Douglas Gregor43959a92009-08-20 07:17:43 +00003485 // Transform the "else" branch.
3486 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3487 if (Else.isInvalid())
3488 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003489
Douglas Gregor43959a92009-08-20 07:17:43 +00003490 if (!getDerived().AlwaysRebuild() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003491 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003492 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003493 Then.get() == S->getThen() &&
3494 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003495 return SemaRef.Owned(S->Retain());
3496
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003497 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003498 move(Then),
Mike Stump1eb44332009-09-09 15:08:12 +00003499 S->getElseLoc(), move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +00003500}
3501
3502template<typename Derived>
3503Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003504TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003505 // Transform the condition.
Douglas Gregord3d53012009-11-24 17:07:59 +00003506 OwningExprResult Cond(SemaRef);
3507 VarDecl *ConditionVar = 0;
3508 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003509 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003510 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003511 getDerived().TransformDefinition(
3512 S->getConditionVariable()->getLocation(),
3513 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003514 if (!ConditionVar)
3515 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003516 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003517 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003518
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003519 if (Cond.isInvalid())
3520 return SemaRef.StmtError();
3521 }
Mike Stump1eb44332009-09-09 15:08:12 +00003522
Douglas Gregor43959a92009-08-20 07:17:43 +00003523 // Rebuild the switch statement.
Douglas Gregor586596f2010-05-06 17:25:47 +00003524 OwningStmtResult Switch
3525 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3526 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003527 if (Switch.isInvalid())
3528 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003529
Douglas Gregor43959a92009-08-20 07:17:43 +00003530 // Transform the body of the switch statement.
3531 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3532 if (Body.isInvalid())
3533 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003534
Douglas Gregor43959a92009-08-20 07:17:43 +00003535 // Complete the switch statement.
3536 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3537 move(Body));
3538}
Mike Stump1eb44332009-09-09 15:08:12 +00003539
Douglas Gregor43959a92009-08-20 07:17:43 +00003540template<typename Derived>
3541Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003542TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003543 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003544 OwningExprResult Cond(SemaRef);
3545 VarDecl *ConditionVar = 0;
3546 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003547 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003548 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003549 getDerived().TransformDefinition(
3550 S->getConditionVariable()->getLocation(),
3551 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003552 if (!ConditionVar)
3553 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003554 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003555 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003556
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003557 if (Cond.isInvalid())
3558 return SemaRef.StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003559
3560 if (S->getCond()) {
3561 // Convert the condition to a boolean value.
3562 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003563 S->getWhileLoc(),
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003564 move(Cond));
3565 if (CondE.isInvalid())
3566 return getSema().StmtError();
3567 Cond = move(CondE);
3568 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003569 }
Mike Stump1eb44332009-09-09 15:08:12 +00003570
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003571 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3572 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3573 return SemaRef.StmtError();
3574
Douglas Gregor43959a92009-08-20 07:17:43 +00003575 // Transform the body
3576 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3577 if (Body.isInvalid())
3578 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003579
Douglas Gregor43959a92009-08-20 07:17:43 +00003580 if (!getDerived().AlwaysRebuild() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003581 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003582 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003583 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003584 return SemaRef.Owned(S->Retain());
3585
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003586 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregor586596f2010-05-06 17:25:47 +00003587 ConditionVar, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003588}
Mike Stump1eb44332009-09-09 15:08:12 +00003589
Douglas Gregor43959a92009-08-20 07:17:43 +00003590template<typename Derived>
3591Sema::OwningStmtResult
3592TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003593 // Transform the body
3594 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3595 if (Body.isInvalid())
3596 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003597
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003598 // Transform the condition
3599 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3600 if (Cond.isInvalid())
3601 return SemaRef.StmtError();
3602
Douglas Gregor43959a92009-08-20 07:17:43 +00003603 if (!getDerived().AlwaysRebuild() &&
3604 Cond.get() == S->getCond() &&
3605 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003606 return SemaRef.Owned(S->Retain());
3607
Douglas Gregor43959a92009-08-20 07:17:43 +00003608 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3609 /*FIXME:*/S->getWhileLoc(), move(Cond),
3610 S->getRParenLoc());
3611}
Mike Stump1eb44332009-09-09 15:08:12 +00003612
Douglas Gregor43959a92009-08-20 07:17:43 +00003613template<typename Derived>
3614Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003615TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003616 // Transform the initialization statement
3617 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3618 if (Init.isInvalid())
3619 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003620
Douglas Gregor43959a92009-08-20 07:17:43 +00003621 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003622 OwningExprResult Cond(SemaRef);
3623 VarDecl *ConditionVar = 0;
3624 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003625 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003626 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003627 getDerived().TransformDefinition(
3628 S->getConditionVariable()->getLocation(),
3629 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003630 if (!ConditionVar)
3631 return SemaRef.StmtError();
3632 } else {
3633 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003634
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003635 if (Cond.isInvalid())
3636 return SemaRef.StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003637
3638 if (S->getCond()) {
3639 // Convert the condition to a boolean value.
3640 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3641 S->getForLoc(),
3642 move(Cond));
3643 if (CondE.isInvalid())
3644 return getSema().StmtError();
3645
3646 Cond = move(CondE);
3647 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003648 }
Mike Stump1eb44332009-09-09 15:08:12 +00003649
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003650 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3651 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3652 return SemaRef.StmtError();
3653
Douglas Gregor43959a92009-08-20 07:17:43 +00003654 // Transform the increment
3655 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3656 if (Inc.isInvalid())
3657 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003658
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003659 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3660 if (S->getInc() && !FullInc->get())
3661 return SemaRef.StmtError();
3662
Douglas Gregor43959a92009-08-20 07:17:43 +00003663 // Transform the body
3664 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3665 if (Body.isInvalid())
3666 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003667
Douglas Gregor43959a92009-08-20 07:17:43 +00003668 if (!getDerived().AlwaysRebuild() &&
3669 Init.get() == S->getInit() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003670 FullCond->get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003671 Inc.get() == S->getInc() &&
3672 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003673 return SemaRef.Owned(S->Retain());
3674
Douglas Gregor43959a92009-08-20 07:17:43 +00003675 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003676 move(Init), FullCond, ConditionVar,
3677 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003678}
3679
3680template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003681Sema::OwningStmtResult
3682TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003683 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003684 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003685 S->getLabel());
3686}
3687
3688template<typename Derived>
3689Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003690TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003691 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3692 if (Target.isInvalid())
3693 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003694
Douglas Gregor43959a92009-08-20 07:17:43 +00003695 if (!getDerived().AlwaysRebuild() &&
3696 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003697 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003698
3699 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3700 move(Target));
3701}
3702
3703template<typename Derived>
3704Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003705TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3706 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003707}
Mike Stump1eb44332009-09-09 15:08:12 +00003708
Douglas Gregor43959a92009-08-20 07:17:43 +00003709template<typename Derived>
3710Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003711TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3712 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003713}
Mike Stump1eb44332009-09-09 15:08:12 +00003714
Douglas Gregor43959a92009-08-20 07:17:43 +00003715template<typename Derived>
3716Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003717TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003718 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3719 if (Result.isInvalid())
3720 return SemaRef.StmtError();
3721
Mike Stump1eb44332009-09-09 15:08:12 +00003722 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003723 // to tell whether the return type of the function has changed.
3724 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3725}
Mike Stump1eb44332009-09-09 15:08:12 +00003726
Douglas Gregor43959a92009-08-20 07:17:43 +00003727template<typename Derived>
3728Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003729TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003730 bool DeclChanged = false;
3731 llvm::SmallVector<Decl *, 4> Decls;
3732 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3733 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003734 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3735 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003736 if (!Transformed)
3737 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003738
Douglas Gregor43959a92009-08-20 07:17:43 +00003739 if (Transformed != *D)
3740 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003741
Douglas Gregor43959a92009-08-20 07:17:43 +00003742 Decls.push_back(Transformed);
3743 }
Mike Stump1eb44332009-09-09 15:08:12 +00003744
Douglas Gregor43959a92009-08-20 07:17:43 +00003745 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003746 return SemaRef.Owned(S->Retain());
3747
3748 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003749 S->getStartLoc(), S->getEndLoc());
3750}
Mike Stump1eb44332009-09-09 15:08:12 +00003751
Douglas Gregor43959a92009-08-20 07:17:43 +00003752template<typename Derived>
3753Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003754TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003755 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003756 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003757}
3758
3759template<typename Derived>
3760Sema::OwningStmtResult
3761TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003762
Anders Carlsson703e3942010-01-24 05:50:09 +00003763 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3764 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003765 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003766
Anders Carlsson703e3942010-01-24 05:50:09 +00003767 OwningExprResult AsmString(SemaRef);
3768 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3769
3770 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003771
Anders Carlsson703e3942010-01-24 05:50:09 +00003772 // Go through the outputs.
3773 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003774 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003775
Anders Carlsson703e3942010-01-24 05:50:09 +00003776 // No need to transform the constraint literal.
3777 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003778
Anders Carlsson703e3942010-01-24 05:50:09 +00003779 // Transform the output expr.
3780 Expr *OutputExpr = S->getOutputExpr(I);
3781 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3782 if (Result.isInvalid())
3783 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003784
Anders Carlsson703e3942010-01-24 05:50:09 +00003785 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003786
Anders Carlsson703e3942010-01-24 05:50:09 +00003787 Exprs.push_back(Result.takeAs<Expr>());
3788 }
Sean Huntc3021132010-05-05 15:23:54 +00003789
Anders Carlsson703e3942010-01-24 05:50:09 +00003790 // Go through the inputs.
3791 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003792 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003793
Anders Carlsson703e3942010-01-24 05:50:09 +00003794 // No need to transform the constraint literal.
3795 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003796
Anders Carlsson703e3942010-01-24 05:50:09 +00003797 // Transform the input expr.
3798 Expr *InputExpr = S->getInputExpr(I);
3799 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3800 if (Result.isInvalid())
3801 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003802
Anders Carlsson703e3942010-01-24 05:50:09 +00003803 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003804
Anders Carlsson703e3942010-01-24 05:50:09 +00003805 Exprs.push_back(Result.takeAs<Expr>());
3806 }
Sean Huntc3021132010-05-05 15:23:54 +00003807
Anders Carlsson703e3942010-01-24 05:50:09 +00003808 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3809 return SemaRef.Owned(S->Retain());
3810
3811 // Go through the clobbers.
3812 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3813 Clobbers.push_back(S->getClobber(I)->Retain());
3814
3815 // No need to transform the asm string literal.
3816 AsmString = SemaRef.Owned(S->getAsmString());
3817
3818 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3819 S->isSimple(),
3820 S->isVolatile(),
3821 S->getNumOutputs(),
3822 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003823 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003824 move_arg(Constraints),
3825 move_arg(Exprs),
3826 move(AsmString),
3827 move_arg(Clobbers),
3828 S->getRParenLoc(),
3829 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003830}
3831
3832
3833template<typename Derived>
3834Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003835TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003836 // Transform the body of the @try.
3837 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3838 if (TryBody.isInvalid())
3839 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003840
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003841 // Transform the @catch statements (if present).
3842 bool AnyCatchChanged = false;
3843 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3844 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3845 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003846 if (Catch.isInvalid())
3847 return SemaRef.StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003848 if (Catch.get() != S->getCatchStmt(I))
3849 AnyCatchChanged = true;
3850 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003851 }
Sean Huntc3021132010-05-05 15:23:54 +00003852
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003853 // Transform the @finally statement (if present).
3854 OwningStmtResult Finally(SemaRef);
3855 if (S->getFinallyStmt()) {
3856 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3857 if (Finally.isInvalid())
3858 return SemaRef.StmtError();
3859 }
3860
3861 // If nothing changed, just retain this statement.
3862 if (!getDerived().AlwaysRebuild() &&
3863 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003864 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003865 Finally.get() == S->getFinallyStmt())
3866 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003867
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003868 // Build a new statement.
3869 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003870 move_arg(CatchStmts), move(Finally));
Douglas Gregor43959a92009-08-20 07:17:43 +00003871}
Mike Stump1eb44332009-09-09 15:08:12 +00003872
Douglas Gregor43959a92009-08-20 07:17:43 +00003873template<typename Derived>
3874Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003875TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00003876 // Transform the @catch parameter, if there is one.
3877 VarDecl *Var = 0;
3878 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3879 TypeSourceInfo *TSInfo = 0;
3880 if (FromVar->getTypeSourceInfo()) {
3881 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3882 if (!TSInfo)
3883 return SemaRef.StmtError();
3884 }
Sean Huntc3021132010-05-05 15:23:54 +00003885
Douglas Gregorbe270a02010-04-26 17:57:08 +00003886 QualType T;
3887 if (TSInfo)
3888 T = TSInfo->getType();
3889 else {
3890 T = getDerived().TransformType(FromVar->getType());
3891 if (T.isNull())
Sean Huntc3021132010-05-05 15:23:54 +00003892 return SemaRef.StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00003893 }
Sean Huntc3021132010-05-05 15:23:54 +00003894
Douglas Gregorbe270a02010-04-26 17:57:08 +00003895 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3896 if (!Var)
3897 return SemaRef.StmtError();
3898 }
Sean Huntc3021132010-05-05 15:23:54 +00003899
Douglas Gregorbe270a02010-04-26 17:57:08 +00003900 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3901 if (Body.isInvalid())
3902 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003903
3904 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00003905 S->getRParenLoc(),
3906 Var, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003907}
Mike Stump1eb44332009-09-09 15:08:12 +00003908
Douglas Gregor43959a92009-08-20 07:17:43 +00003909template<typename Derived>
3910Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003911TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003912 // Transform the body.
3913 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
3914 if (Body.isInvalid())
3915 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003916
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003917 // If nothing changed, just retain this statement.
3918 if (!getDerived().AlwaysRebuild() &&
3919 Body.get() == S->getFinallyBody())
3920 return SemaRef.Owned(S->Retain());
3921
3922 // Build a new statement.
3923 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
3924 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003925}
Mike Stump1eb44332009-09-09 15:08:12 +00003926
Douglas Gregor43959a92009-08-20 07:17:43 +00003927template<typename Derived>
3928Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003929TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregord1377b22010-04-22 21:44:01 +00003930 OwningExprResult Operand(SemaRef);
3931 if (S->getThrowExpr()) {
3932 Operand = getDerived().TransformExpr(S->getThrowExpr());
3933 if (Operand.isInvalid())
3934 return getSema().StmtError();
3935 }
Sean Huntc3021132010-05-05 15:23:54 +00003936
Douglas Gregord1377b22010-04-22 21:44:01 +00003937 if (!getDerived().AlwaysRebuild() &&
3938 Operand.get() == S->getThrowExpr())
3939 return getSema().Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003940
Douglas Gregord1377b22010-04-22 21:44:01 +00003941 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregor43959a92009-08-20 07:17:43 +00003942}
Mike Stump1eb44332009-09-09 15:08:12 +00003943
Douglas Gregor43959a92009-08-20 07:17:43 +00003944template<typename Derived>
3945Sema::OwningStmtResult
3946TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003947 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00003948 // Transform the object we are locking.
3949 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3950 if (Object.isInvalid())
3951 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003952
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00003953 // Transform the body.
3954 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3955 if (Body.isInvalid())
3956 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003957
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00003958 // If nothing change, just retain the current statement.
3959 if (!getDerived().AlwaysRebuild() &&
3960 Object.get() == S->getSynchExpr() &&
3961 Body.get() == S->getSynchBody())
3962 return SemaRef.Owned(S->Retain());
3963
3964 // Build a new statement.
3965 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
3966 move(Object), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003967}
3968
3969template<typename Derived>
3970Sema::OwningStmtResult
3971TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003972 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00003973 // Transform the element statement.
3974 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
3975 if (Element.isInvalid())
3976 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003977
Douglas Gregorc3203e72010-04-22 23:10:45 +00003978 // Transform the collection expression.
3979 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
3980 if (Collection.isInvalid())
3981 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003982
Douglas Gregorc3203e72010-04-22 23:10:45 +00003983 // Transform the body.
3984 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3985 if (Body.isInvalid())
3986 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003987
Douglas Gregorc3203e72010-04-22 23:10:45 +00003988 // If nothing changed, just retain this statement.
3989 if (!getDerived().AlwaysRebuild() &&
3990 Element.get() == S->getElement() &&
3991 Collection.get() == S->getCollection() &&
3992 Body.get() == S->getBody())
3993 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003994
Douglas Gregorc3203e72010-04-22 23:10:45 +00003995 // Build a new statement.
3996 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
3997 /*FIXME:*/S->getForLoc(),
3998 move(Element),
3999 move(Collection),
4000 S->getRParenLoc(),
4001 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004002}
4003
4004
4005template<typename Derived>
4006Sema::OwningStmtResult
4007TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4008 // Transform the exception declaration, if any.
4009 VarDecl *Var = 0;
4010 if (S->getExceptionDecl()) {
4011 VarDecl *ExceptionDecl = S->getExceptionDecl();
4012 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4013 ExceptionDecl->getDeclName());
4014
4015 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4016 if (T.isNull())
4017 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004018
Douglas Gregor43959a92009-08-20 07:17:43 +00004019 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4020 T,
John McCalla93c9342009-12-07 02:54:59 +00004021 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004022 ExceptionDecl->getIdentifier(),
4023 ExceptionDecl->getLocation(),
4024 /*FIXME: Inaccurate*/
4025 SourceRange(ExceptionDecl->getLocation()));
4026 if (!Var || Var->isInvalidDecl()) {
4027 if (Var)
4028 Var->Destroy(SemaRef.Context);
4029 return SemaRef.StmtError();
4030 }
4031 }
Mike Stump1eb44332009-09-09 15:08:12 +00004032
Douglas Gregor43959a92009-08-20 07:17:43 +00004033 // Transform the actual exception handler.
4034 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4035 if (Handler.isInvalid()) {
4036 if (Var)
4037 Var->Destroy(SemaRef.Context);
4038 return SemaRef.StmtError();
4039 }
Mike Stump1eb44332009-09-09 15:08:12 +00004040
Douglas Gregor43959a92009-08-20 07:17:43 +00004041 if (!getDerived().AlwaysRebuild() &&
4042 !Var &&
4043 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00004044 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004045
4046 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4047 Var,
4048 move(Handler));
4049}
Mike Stump1eb44332009-09-09 15:08:12 +00004050
Douglas Gregor43959a92009-08-20 07:17:43 +00004051template<typename Derived>
4052Sema::OwningStmtResult
4053TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4054 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00004055 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004056 = getDerived().TransformCompoundStmt(S->getTryBlock());
4057 if (TryBlock.isInvalid())
4058 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004059
Douglas Gregor43959a92009-08-20 07:17:43 +00004060 // Transform the handlers.
4061 bool HandlerChanged = false;
4062 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4063 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00004064 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004065 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4066 if (Handler.isInvalid())
4067 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004068
Douglas Gregor43959a92009-08-20 07:17:43 +00004069 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4070 Handlers.push_back(Handler.takeAs<Stmt>());
4071 }
Mike Stump1eb44332009-09-09 15:08:12 +00004072
Douglas Gregor43959a92009-08-20 07:17:43 +00004073 if (!getDerived().AlwaysRebuild() &&
4074 TryBlock.get() == S->getTryBlock() &&
4075 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004076 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004077
4078 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00004079 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004080}
Mike Stump1eb44332009-09-09 15:08:12 +00004081
Douglas Gregor43959a92009-08-20 07:17:43 +00004082//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004083// Expression transformation
4084//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004085template<typename Derived>
4086Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004087TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004088 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004089}
Mike Stump1eb44332009-09-09 15:08:12 +00004090
4091template<typename Derived>
4092Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004093TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004094 NestedNameSpecifier *Qualifier = 0;
4095 if (E->getQualifier()) {
4096 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004097 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004098 if (!Qualifier)
4099 return SemaRef.ExprError();
4100 }
John McCalldbd872f2009-12-08 09:08:17 +00004101
4102 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004103 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4104 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004105 if (!ND)
4106 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004107
Sean Huntc3021132010-05-05 15:23:54 +00004108 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004109 Qualifier == E->getQualifier() &&
4110 ND == E->getDecl() &&
John McCalldbd872f2009-12-08 09:08:17 +00004111 !E->hasExplicitTemplateArgumentList()) {
4112
4113 // Mark it referenced in the new context regardless.
4114 // FIXME: this is a bit instantiation-specific.
4115 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4116
Mike Stump1eb44332009-09-09 15:08:12 +00004117 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004118 }
John McCalldbd872f2009-12-08 09:08:17 +00004119
4120 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4121 if (E->hasExplicitTemplateArgumentList()) {
4122 TemplateArgs = &TransArgs;
4123 TransArgs.setLAngleLoc(E->getLAngleLoc());
4124 TransArgs.setRAngleLoc(E->getRAngleLoc());
4125 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4126 TemplateArgumentLoc Loc;
4127 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4128 return SemaRef.ExprError();
4129 TransArgs.addArgument(Loc);
4130 }
4131 }
4132
Douglas Gregora2813ce2009-10-23 18:54:35 +00004133 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCalldbd872f2009-12-08 09:08:17 +00004134 ND, E->getLocation(), TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004135}
Mike Stump1eb44332009-09-09 15:08:12 +00004136
Douglas Gregorb98b1992009-08-11 05:31:07 +00004137template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004138Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004139TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004140 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004141}
Mike Stump1eb44332009-09-09 15:08:12 +00004142
Douglas Gregorb98b1992009-08-11 05:31:07 +00004143template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004144Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004145TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004146 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004147}
Mike Stump1eb44332009-09-09 15:08:12 +00004148
Douglas Gregorb98b1992009-08-11 05:31:07 +00004149template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004150Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004151TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004152 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004153}
Mike Stump1eb44332009-09-09 15:08:12 +00004154
Douglas Gregorb98b1992009-08-11 05:31:07 +00004155template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004156Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004157TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004158 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004159}
Mike Stump1eb44332009-09-09 15:08:12 +00004160
Douglas Gregorb98b1992009-08-11 05:31:07 +00004161template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004162Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004163TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004164 return SemaRef.Owned(E->Retain());
4165}
4166
4167template<typename Derived>
4168Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004169TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004170 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4171 if (SubExpr.isInvalid())
4172 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004173
Douglas Gregorb98b1992009-08-11 05:31:07 +00004174 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004175 return SemaRef.Owned(E->Retain());
4176
4177 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004178 E->getRParen());
4179}
4180
Mike Stump1eb44332009-09-09 15:08:12 +00004181template<typename Derived>
4182Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004183TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4184 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004185 if (SubExpr.isInvalid())
4186 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004187
Douglas Gregorb98b1992009-08-11 05:31:07 +00004188 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004189 return SemaRef.Owned(E->Retain());
4190
Douglas Gregorb98b1992009-08-11 05:31:07 +00004191 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4192 E->getOpcode(),
4193 move(SubExpr));
4194}
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
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004198TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4199 // Transform the type.
4200 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4201 if (!Type)
4202 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004203
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004204 // Transform all of the components into components similar to what the
4205 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004206 // FIXME: It would be slightly more efficient in the non-dependent case to
4207 // just map FieldDecls, rather than requiring the rebuilder to look for
4208 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004209 // template code that we don't care.
4210 bool ExprChanged = false;
4211 typedef Action::OffsetOfComponent Component;
4212 typedef OffsetOfExpr::OffsetOfNode Node;
4213 llvm::SmallVector<Component, 4> Components;
4214 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4215 const Node &ON = E->getComponent(I);
4216 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004217 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004218 Comp.LocStart = ON.getRange().getBegin();
4219 Comp.LocEnd = ON.getRange().getEnd();
4220 switch (ON.getKind()) {
4221 case Node::Array: {
4222 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4223 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4224 if (Index.isInvalid())
4225 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004226
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004227 ExprChanged = ExprChanged || Index.get() != FromIndex;
4228 Comp.isBrackets = true;
4229 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4230 break;
4231 }
Sean Huntc3021132010-05-05 15:23:54 +00004232
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004233 case Node::Field:
4234 case Node::Identifier:
4235 Comp.isBrackets = false;
4236 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004237 if (!Comp.U.IdentInfo)
4238 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004239
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004240 break;
Sean Huntc3021132010-05-05 15:23:54 +00004241
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004242 case Node::Base:
4243 // Will be recomputed during the rebuild.
4244 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004245 }
Sean Huntc3021132010-05-05 15:23:54 +00004246
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004247 Components.push_back(Comp);
4248 }
Sean Huntc3021132010-05-05 15:23:54 +00004249
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004250 // If nothing changed, retain the existing expression.
4251 if (!getDerived().AlwaysRebuild() &&
4252 Type == E->getTypeSourceInfo() &&
4253 !ExprChanged)
4254 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004255
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004256 // Build a new offsetof expression.
4257 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4258 Components.data(), Components.size(),
4259 E->getRParenLoc());
4260}
4261
4262template<typename Derived>
4263Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004264TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004265 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004266 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004267
John McCalla93c9342009-12-07 02:54:59 +00004268 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004269 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004270 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004271
John McCall5ab75172009-11-04 07:28:41 +00004272 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004273 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004274
John McCall5ab75172009-11-04 07:28:41 +00004275 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004276 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004277 E->getSourceRange());
4278 }
Mike Stump1eb44332009-09-09 15:08:12 +00004279
Douglas Gregorb98b1992009-08-11 05:31:07 +00004280 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00004281 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004282 // C++0x [expr.sizeof]p1:
4283 // The operand is either an expression, which is an unevaluated operand
4284 // [...]
4285 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004286
Douglas Gregorb98b1992009-08-11 05:31:07 +00004287 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4288 if (SubExpr.isInvalid())
4289 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004290
Douglas Gregorb98b1992009-08-11 05:31:07 +00004291 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4292 return SemaRef.Owned(E->Retain());
4293 }
Mike Stump1eb44332009-09-09 15:08:12 +00004294
Douglas Gregorb98b1992009-08-11 05:31:07 +00004295 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4296 E->isSizeOf(),
4297 E->getSourceRange());
4298}
Mike Stump1eb44332009-09-09 15:08:12 +00004299
Douglas Gregorb98b1992009-08-11 05:31:07 +00004300template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004301Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004302TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004303 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4304 if (LHS.isInvalid())
4305 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004306
Douglas Gregorb98b1992009-08-11 05:31:07 +00004307 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4308 if (RHS.isInvalid())
4309 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004310
4311
Douglas Gregorb98b1992009-08-11 05:31:07 +00004312 if (!getDerived().AlwaysRebuild() &&
4313 LHS.get() == E->getLHS() &&
4314 RHS.get() == E->getRHS())
4315 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004316
Douglas Gregorb98b1992009-08-11 05:31:07 +00004317 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4318 /*FIXME:*/E->getLHS()->getLocStart(),
4319 move(RHS),
4320 E->getRBracketLoc());
4321}
Mike Stump1eb44332009-09-09 15:08:12 +00004322
4323template<typename Derived>
4324Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004325TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004326 // Transform the callee.
4327 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4328 if (Callee.isInvalid())
4329 return SemaRef.ExprError();
4330
4331 // Transform arguments.
4332 bool ArgChanged = false;
4333 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4334 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4335 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4336 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4337 if (Arg.isInvalid())
4338 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004339
Douglas Gregorb98b1992009-08-11 05:31:07 +00004340 // FIXME: Wrong source location information for the ','.
4341 FakeCommaLocs.push_back(
4342 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00004343
4344 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004345 Args.push_back(Arg.takeAs<Expr>());
4346 }
Mike Stump1eb44332009-09-09 15:08:12 +00004347
Douglas Gregorb98b1992009-08-11 05:31:07 +00004348 if (!getDerived().AlwaysRebuild() &&
4349 Callee.get() == E->getCallee() &&
4350 !ArgChanged)
4351 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004352
Douglas Gregorb98b1992009-08-11 05:31:07 +00004353 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004354 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004355 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4356 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4357 move_arg(Args),
4358 FakeCommaLocs.data(),
4359 E->getRParenLoc());
4360}
Mike Stump1eb44332009-09-09 15:08:12 +00004361
4362template<typename Derived>
4363Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004364TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004365 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4366 if (Base.isInvalid())
4367 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004368
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004369 NestedNameSpecifier *Qualifier = 0;
4370 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004371 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004372 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004373 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004374 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004375 return SemaRef.ExprError();
4376 }
Mike Stump1eb44332009-09-09 15:08:12 +00004377
Eli Friedmanf595cc42009-12-04 06:40:45 +00004378 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004379 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4380 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004381 if (!Member)
4382 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004383
John McCall6bb80172010-03-30 21:47:33 +00004384 NamedDecl *FoundDecl = E->getFoundDecl();
4385 if (FoundDecl == E->getMemberDecl()) {
4386 FoundDecl = Member;
4387 } else {
4388 FoundDecl = cast_or_null<NamedDecl>(
4389 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4390 if (!FoundDecl)
4391 return SemaRef.ExprError();
4392 }
4393
Douglas Gregorb98b1992009-08-11 05:31:07 +00004394 if (!getDerived().AlwaysRebuild() &&
4395 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004396 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004397 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004398 FoundDecl == E->getFoundDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00004399 !E->hasExplicitTemplateArgumentList()) {
Sean Huntc3021132010-05-05 15:23:54 +00004400
Anders Carlsson1f240322009-12-22 05:24:09 +00004401 // Mark it referenced in the new context regardless.
4402 // FIXME: this is a bit instantiation-specific.
4403 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00004404 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00004405 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004406
John McCalld5532b62009-11-23 01:53:49 +00004407 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004408 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00004409 TransArgs.setLAngleLoc(E->getLAngleLoc());
4410 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004411 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004412 TemplateArgumentLoc Loc;
4413 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004414 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004415 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004416 }
4417 }
Sean Huntc3021132010-05-05 15:23:54 +00004418
Douglas Gregorb98b1992009-08-11 05:31:07 +00004419 // FIXME: Bogus source location for the operator
4420 SourceLocation FakeOperatorLoc
4421 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4422
John McCallc2233c52010-01-15 08:34:02 +00004423 // FIXME: to do this check properly, we will need to preserve the
4424 // first-qualifier-in-scope here, just in case we had a dependent
4425 // base (and therefore couldn't do the check) and a
4426 // nested-name-qualifier (and therefore could do the lookup).
4427 NamedDecl *FirstQualifierInScope = 0;
4428
Douglas Gregorb98b1992009-08-11 05:31:07 +00004429 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4430 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004431 Qualifier,
4432 E->getQualifierRange(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004433 E->getMemberLoc(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004434 Member,
John McCall6bb80172010-03-30 21:47:33 +00004435 FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00004436 (E->hasExplicitTemplateArgumentList()
4437 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004438 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004439}
Mike Stump1eb44332009-09-09 15:08:12 +00004440
Douglas Gregorb98b1992009-08-11 05:31:07 +00004441template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004442Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004443TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004444 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4445 if (LHS.isInvalid())
4446 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004447
Douglas Gregorb98b1992009-08-11 05:31:07 +00004448 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4449 if (RHS.isInvalid())
4450 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004451
Douglas Gregorb98b1992009-08-11 05:31:07 +00004452 if (!getDerived().AlwaysRebuild() &&
4453 LHS.get() == E->getLHS() &&
4454 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004455 return SemaRef.Owned(E->Retain());
4456
Douglas Gregorb98b1992009-08-11 05:31:07 +00004457 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4458 move(LHS), move(RHS));
4459}
4460
Mike Stump1eb44332009-09-09 15:08:12 +00004461template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004462Sema::OwningExprResult
4463TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004464 CompoundAssignOperator *E) {
4465 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004466}
Mike Stump1eb44332009-09-09 15:08:12 +00004467
Douglas Gregorb98b1992009-08-11 05:31:07 +00004468template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004469Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004470TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004471 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4472 if (Cond.isInvalid())
4473 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004474
Douglas Gregorb98b1992009-08-11 05:31:07 +00004475 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4476 if (LHS.isInvalid())
4477 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004478
Douglas Gregorb98b1992009-08-11 05:31:07 +00004479 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4480 if (RHS.isInvalid())
4481 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004482
Douglas Gregorb98b1992009-08-11 05:31:07 +00004483 if (!getDerived().AlwaysRebuild() &&
4484 Cond.get() == E->getCond() &&
4485 LHS.get() == E->getLHS() &&
4486 RHS.get() == E->getRHS())
4487 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004488
4489 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004490 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004491 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004492 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004493 move(RHS));
4494}
Mike Stump1eb44332009-09-09 15:08:12 +00004495
4496template<typename Derived>
4497Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004498TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004499 // Implicit casts are eliminated during transformation, since they
4500 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004501 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004502}
Mike Stump1eb44332009-09-09 15:08:12 +00004503
Douglas Gregorb98b1992009-08-11 05:31:07 +00004504template<typename Derived>
4505Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004506TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004507 TypeSourceInfo *OldT;
4508 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004509 {
4510 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004511 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004512 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4513 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004514
John McCall9d125032010-01-15 18:39:57 +00004515 OldT = E->getTypeInfoAsWritten();
4516 NewT = getDerived().TransformType(OldT);
4517 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004518 return SemaRef.ExprError();
4519 }
Mike Stump1eb44332009-09-09 15:08:12 +00004520
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004521 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004522 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004523 if (SubExpr.isInvalid())
4524 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004525
Douglas Gregorb98b1992009-08-11 05:31:07 +00004526 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004527 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004528 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004529 return SemaRef.Owned(E->Retain());
4530
John McCall9d125032010-01-15 18:39:57 +00004531 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4532 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004533 E->getRParenLoc(),
4534 move(SubExpr));
4535}
Mike Stump1eb44332009-09-09 15:08:12 +00004536
Douglas Gregorb98b1992009-08-11 05:31:07 +00004537template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004538Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004539TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004540 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4541 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4542 if (!NewT)
4543 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004544
Douglas Gregorb98b1992009-08-11 05:31:07 +00004545 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4546 if (Init.isInvalid())
4547 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004548
Douglas Gregorb98b1992009-08-11 05:31:07 +00004549 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004550 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004551 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00004552 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004553
John McCall1d7d8d62010-01-19 22:33:45 +00004554 // Note: the expression type doesn't necessarily match the
4555 // type-as-written, but that's okay, because it should always be
4556 // derivable from the initializer.
4557
John McCall42f56b52010-01-18 19:35:47 +00004558 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004559 /*FIXME:*/E->getInitializer()->getLocEnd(),
4560 move(Init));
4561}
Mike Stump1eb44332009-09-09 15:08:12 +00004562
Douglas Gregorb98b1992009-08-11 05:31:07 +00004563template<typename Derived>
4564Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004565TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004566 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4567 if (Base.isInvalid())
4568 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004569
Douglas Gregorb98b1992009-08-11 05:31:07 +00004570 if (!getDerived().AlwaysRebuild() &&
4571 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00004572 return SemaRef.Owned(E->Retain());
4573
Douglas Gregorb98b1992009-08-11 05:31:07 +00004574 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004575 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004576 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4577 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4578 E->getAccessorLoc(),
4579 E->getAccessor());
4580}
Mike Stump1eb44332009-09-09 15:08:12 +00004581
Douglas Gregorb98b1992009-08-11 05:31:07 +00004582template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004583Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004584TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004585 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004586
Douglas Gregorb98b1992009-08-11 05:31:07 +00004587 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4588 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4589 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4590 if (Init.isInvalid())
4591 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004592
Douglas Gregorb98b1992009-08-11 05:31:07 +00004593 InitChanged = InitChanged || Init.get() != E->getInit(I);
4594 Inits.push_back(Init.takeAs<Expr>());
4595 }
Mike Stump1eb44332009-09-09 15:08:12 +00004596
Douglas Gregorb98b1992009-08-11 05:31:07 +00004597 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004598 return SemaRef.Owned(E->Retain());
4599
Douglas Gregorb98b1992009-08-11 05:31:07 +00004600 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004601 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004602}
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>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004607 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004608
Douglas Gregor43959a92009-08-20 07:17:43 +00004609 // transform the initializer value
Douglas Gregorb98b1992009-08-11 05:31:07 +00004610 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4611 if (Init.isInvalid())
4612 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004613
Douglas Gregor43959a92009-08-20 07:17:43 +00004614 // transform the designators.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004615 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4616 bool ExprChanged = false;
4617 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4618 DEnd = E->designators_end();
4619 D != DEnd; ++D) {
4620 if (D->isFieldDesignator()) {
4621 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4622 D->getDotLoc(),
4623 D->getFieldLoc()));
4624 continue;
4625 }
Mike Stump1eb44332009-09-09 15:08:12 +00004626
Douglas Gregorb98b1992009-08-11 05:31:07 +00004627 if (D->isArrayDesignator()) {
4628 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4629 if (Index.isInvalid())
4630 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004631
4632 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004633 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004634
Douglas Gregorb98b1992009-08-11 05:31:07 +00004635 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4636 ArrayExprs.push_back(Index.release());
4637 continue;
4638 }
Mike Stump1eb44332009-09-09 15:08:12 +00004639
Douglas Gregorb98b1992009-08-11 05:31:07 +00004640 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump1eb44332009-09-09 15:08:12 +00004641 OwningExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004642 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4643 if (Start.isInvalid())
4644 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004645
Douglas Gregorb98b1992009-08-11 05:31:07 +00004646 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4647 if (End.isInvalid())
4648 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004649
4650 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004651 End.get(),
4652 D->getLBracketLoc(),
4653 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004654
Douglas Gregorb98b1992009-08-11 05:31:07 +00004655 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4656 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004657
Douglas Gregorb98b1992009-08-11 05:31:07 +00004658 ArrayExprs.push_back(Start.release());
4659 ArrayExprs.push_back(End.release());
4660 }
Mike Stump1eb44332009-09-09 15:08:12 +00004661
Douglas Gregorb98b1992009-08-11 05:31:07 +00004662 if (!getDerived().AlwaysRebuild() &&
4663 Init.get() == E->getInit() &&
4664 !ExprChanged)
4665 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004666
Douglas Gregorb98b1992009-08-11 05:31:07 +00004667 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4668 E->getEqualOrColonLoc(),
4669 E->usesGNUSyntax(), move(Init));
4670}
Mike Stump1eb44332009-09-09 15:08:12 +00004671
Douglas Gregorb98b1992009-08-11 05:31:07 +00004672template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004673Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004674TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004675 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004676 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004677
Douglas Gregor5557b252009-10-28 00:29:27 +00004678 // FIXME: Will we ever have proper type location here? Will we actually
4679 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004680 QualType T = getDerived().TransformType(E->getType());
4681 if (T.isNull())
4682 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004683
Douglas Gregorb98b1992009-08-11 05:31:07 +00004684 if (!getDerived().AlwaysRebuild() &&
4685 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004686 return SemaRef.Owned(E->Retain());
4687
Douglas Gregorb98b1992009-08-11 05:31:07 +00004688 return getDerived().RebuildImplicitValueInitExpr(T);
4689}
Mike Stump1eb44332009-09-09 15:08:12 +00004690
Douglas Gregorb98b1992009-08-11 05:31:07 +00004691template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004692Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004693TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004694 // FIXME: Do we want the type as written?
4695 QualType T;
Mike Stump1eb44332009-09-09 15:08:12 +00004696
Douglas Gregorb98b1992009-08-11 05:31:07 +00004697 {
4698 // FIXME: Source location isn't quite accurate.
4699 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4700 T = getDerived().TransformType(E->getType());
4701 if (T.isNull())
4702 return SemaRef.ExprError();
4703 }
Mike Stump1eb44332009-09-09 15:08:12 +00004704
Douglas Gregorb98b1992009-08-11 05:31:07 +00004705 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4706 if (SubExpr.isInvalid())
4707 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004708
Douglas Gregorb98b1992009-08-11 05:31:07 +00004709 if (!getDerived().AlwaysRebuild() &&
4710 T == E->getType() &&
4711 SubExpr.get() == E->getSubExpr())
4712 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004713
Douglas Gregorb98b1992009-08-11 05:31:07 +00004714 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4715 T, E->getRParenLoc());
4716}
4717
4718template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004719Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004720TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004721 bool ArgumentChanged = false;
4722 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4723 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4724 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4725 if (Init.isInvalid())
4726 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004727
Douglas Gregorb98b1992009-08-11 05:31:07 +00004728 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4729 Inits.push_back(Init.takeAs<Expr>());
4730 }
Mike Stump1eb44332009-09-09 15:08:12 +00004731
Douglas Gregorb98b1992009-08-11 05:31:07 +00004732 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4733 move_arg(Inits),
4734 E->getRParenLoc());
4735}
Mike Stump1eb44332009-09-09 15:08:12 +00004736
Douglas Gregorb98b1992009-08-11 05:31:07 +00004737/// \brief Transform an address-of-label expression.
4738///
4739/// By default, the transformation of an address-of-label expression always
4740/// rebuilds the expression, so that the label identifier can be resolved to
4741/// the corresponding label statement by semantic analysis.
4742template<typename Derived>
4743Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004744TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004745 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4746 E->getLabel());
4747}
Mike Stump1eb44332009-09-09 15:08:12 +00004748
4749template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00004750Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004751TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004752 OwningStmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004753 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4754 if (SubStmt.isInvalid())
4755 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004756
Douglas Gregorb98b1992009-08-11 05:31:07 +00004757 if (!getDerived().AlwaysRebuild() &&
4758 SubStmt.get() == E->getSubStmt())
4759 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004760
4761 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004762 move(SubStmt),
4763 E->getRParenLoc());
4764}
Mike Stump1eb44332009-09-09 15:08:12 +00004765
Douglas Gregorb98b1992009-08-11 05:31:07 +00004766template<typename Derived>
4767Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004768TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004769 QualType T1, T2;
4770 {
4771 // FIXME: Source location isn't quite accurate.
4772 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004773
Douglas Gregorb98b1992009-08-11 05:31:07 +00004774 T1 = getDerived().TransformType(E->getArgType1());
4775 if (T1.isNull())
4776 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004777
Douglas Gregorb98b1992009-08-11 05:31:07 +00004778 T2 = getDerived().TransformType(E->getArgType2());
4779 if (T2.isNull())
4780 return SemaRef.ExprError();
4781 }
4782
4783 if (!getDerived().AlwaysRebuild() &&
4784 T1 == E->getArgType1() &&
4785 T2 == E->getArgType2())
Mike Stump1eb44332009-09-09 15:08:12 +00004786 return SemaRef.Owned(E->Retain());
4787
Douglas Gregorb98b1992009-08-11 05:31:07 +00004788 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4789 T1, T2, E->getRParenLoc());
4790}
Mike Stump1eb44332009-09-09 15:08:12 +00004791
Douglas Gregorb98b1992009-08-11 05:31:07 +00004792template<typename Derived>
4793Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004794TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004795 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4796 if (Cond.isInvalid())
4797 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004798
Douglas Gregorb98b1992009-08-11 05:31:07 +00004799 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4800 if (LHS.isInvalid())
4801 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004802
Douglas Gregorb98b1992009-08-11 05:31:07 +00004803 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4804 if (RHS.isInvalid())
4805 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004806
Douglas Gregorb98b1992009-08-11 05:31:07 +00004807 if (!getDerived().AlwaysRebuild() &&
4808 Cond.get() == E->getCond() &&
4809 LHS.get() == E->getLHS() &&
4810 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004811 return SemaRef.Owned(E->Retain());
4812
Douglas Gregorb98b1992009-08-11 05:31:07 +00004813 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4814 move(Cond), move(LHS), move(RHS),
4815 E->getRParenLoc());
4816}
Mike Stump1eb44332009-09-09 15:08:12 +00004817
Douglas Gregorb98b1992009-08-11 05:31:07 +00004818template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004819Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004820TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004821 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004822}
4823
4824template<typename Derived>
4825Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004826TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004827 switch (E->getOperator()) {
4828 case OO_New:
4829 case OO_Delete:
4830 case OO_Array_New:
4831 case OO_Array_Delete:
4832 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4833 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004834
Douglas Gregor668d6d92009-12-13 20:44:55 +00004835 case OO_Call: {
4836 // This is a call to an object's operator().
4837 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4838
4839 // Transform the object itself.
4840 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4841 if (Object.isInvalid())
4842 return SemaRef.ExprError();
4843
4844 // FIXME: Poor location information
4845 SourceLocation FakeLParenLoc
4846 = SemaRef.PP.getLocForEndOfToken(
4847 static_cast<Expr *>(Object.get())->getLocEnd());
4848
4849 // Transform the call arguments.
4850 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4851 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4852 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004853 if (getDerived().DropCallArgument(E->getArg(I)))
4854 break;
Sean Huntc3021132010-05-05 15:23:54 +00004855
Douglas Gregor668d6d92009-12-13 20:44:55 +00004856 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4857 if (Arg.isInvalid())
4858 return SemaRef.ExprError();
4859
4860 // FIXME: Poor source location information.
4861 SourceLocation FakeCommaLoc
4862 = SemaRef.PP.getLocForEndOfToken(
4863 static_cast<Expr *>(Arg.get())->getLocEnd());
4864 FakeCommaLocs.push_back(FakeCommaLoc);
4865 Args.push_back(Arg.release());
4866 }
4867
4868 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4869 move_arg(Args),
4870 FakeCommaLocs.data(),
4871 E->getLocEnd());
4872 }
4873
4874#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4875 case OO_##Name:
4876#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4877#include "clang/Basic/OperatorKinds.def"
4878 case OO_Subscript:
4879 // Handled below.
4880 break;
4881
4882 case OO_Conditional:
4883 llvm_unreachable("conditional operator is not actually overloadable");
4884 return SemaRef.ExprError();
4885
4886 case OO_None:
4887 case NUM_OVERLOADED_OPERATORS:
4888 llvm_unreachable("not an overloaded operator?");
4889 return SemaRef.ExprError();
4890 }
4891
Douglas Gregorb98b1992009-08-11 05:31:07 +00004892 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4893 if (Callee.isInvalid())
4894 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004895
John McCall454feb92009-12-08 09:21:05 +00004896 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004897 if (First.isInvalid())
4898 return SemaRef.ExprError();
4899
4900 OwningExprResult Second(SemaRef);
4901 if (E->getNumArgs() == 2) {
4902 Second = getDerived().TransformExpr(E->getArg(1));
4903 if (Second.isInvalid())
4904 return SemaRef.ExprError();
4905 }
Mike Stump1eb44332009-09-09 15:08:12 +00004906
Douglas Gregorb98b1992009-08-11 05:31:07 +00004907 if (!getDerived().AlwaysRebuild() &&
4908 Callee.get() == E->getCallee() &&
4909 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00004910 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4911 return SemaRef.Owned(E->Retain());
4912
Douglas Gregorb98b1992009-08-11 05:31:07 +00004913 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4914 E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004915 move(Callee),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004916 move(First),
4917 move(Second));
4918}
Mike Stump1eb44332009-09-09 15:08:12 +00004919
Douglas Gregorb98b1992009-08-11 05:31:07 +00004920template<typename Derived>
4921Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004922TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4923 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004924}
Mike Stump1eb44332009-09-09 15:08:12 +00004925
Douglas Gregorb98b1992009-08-11 05:31:07 +00004926template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004927Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004928TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004929 TypeSourceInfo *OldT;
4930 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004931 {
4932 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004933 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004934 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4935 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004936
John McCall9d125032010-01-15 18:39:57 +00004937 OldT = E->getTypeInfoAsWritten();
4938 NewT = getDerived().TransformType(OldT);
4939 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004940 return SemaRef.ExprError();
4941 }
Mike Stump1eb44332009-09-09 15:08:12 +00004942
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004943 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004944 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004945 if (SubExpr.isInvalid())
4946 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004947
Douglas Gregorb98b1992009-08-11 05:31:07 +00004948 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004949 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004950 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004951 return SemaRef.Owned(E->Retain());
4952
Douglas Gregorb98b1992009-08-11 05:31:07 +00004953 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00004954 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004955 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4956 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4957 SourceLocation FakeRParenLoc
4958 = SemaRef.PP.getLocForEndOfToken(
4959 E->getSubExpr()->getSourceRange().getEnd());
4960 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004961 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004962 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00004963 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004964 FakeRAngleLoc,
4965 FakeRAngleLoc,
4966 move(SubExpr),
4967 FakeRParenLoc);
4968}
Mike Stump1eb44332009-09-09 15:08:12 +00004969
Douglas Gregorb98b1992009-08-11 05:31:07 +00004970template<typename Derived>
4971Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004972TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4973 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004974}
Mike Stump1eb44332009-09-09 15:08:12 +00004975
4976template<typename Derived>
4977Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004978TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4979 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004980}
4981
Douglas Gregorb98b1992009-08-11 05:31:07 +00004982template<typename Derived>
4983Sema::OwningExprResult
4984TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004985 CXXReinterpretCastExpr *E) {
4986 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004987}
Mike Stump1eb44332009-09-09 15:08:12 +00004988
Douglas Gregorb98b1992009-08-11 05:31:07 +00004989template<typename Derived>
4990Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004991TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4992 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004993}
Mike Stump1eb44332009-09-09 15:08:12 +00004994
Douglas Gregorb98b1992009-08-11 05:31:07 +00004995template<typename Derived>
4996Sema::OwningExprResult
4997TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004998 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004999 TypeSourceInfo *OldT;
5000 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005001 {
5002 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005003
John McCall9d125032010-01-15 18:39:57 +00005004 OldT = E->getTypeInfoAsWritten();
5005 NewT = getDerived().TransformType(OldT);
5006 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005007 return SemaRef.ExprError();
5008 }
Mike Stump1eb44332009-09-09 15:08:12 +00005009
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005010 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005011 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005012 if (SubExpr.isInvalid())
5013 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005014
Douglas Gregorb98b1992009-08-11 05:31:07 +00005015 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00005016 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005017 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005018 return SemaRef.Owned(E->Retain());
5019
Douglas Gregorb98b1992009-08-11 05:31:07 +00005020 // FIXME: The end of the type's source range is wrong
5021 return getDerived().RebuildCXXFunctionalCastExpr(
5022 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall9d125032010-01-15 18:39:57 +00005023 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005024 /*FIXME:*/E->getSubExpr()->getLocStart(),
5025 move(SubExpr),
5026 E->getRParenLoc());
5027}
Mike Stump1eb44332009-09-09 15:08:12 +00005028
Douglas Gregorb98b1992009-08-11 05:31:07 +00005029template<typename Derived>
5030Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005031TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005032 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005033 TypeSourceInfo *TInfo
5034 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5035 if (!TInfo)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005036 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005037
Douglas Gregorb98b1992009-08-11 05:31:07 +00005038 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005039 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005040 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005041
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005042 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5043 E->getLocStart(),
5044 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005045 E->getLocEnd());
5046 }
Mike Stump1eb44332009-09-09 15:08:12 +00005047
Douglas Gregorb98b1992009-08-11 05:31:07 +00005048 // We don't know whether the expression is potentially evaluated until
5049 // after we perform semantic analysis, so the expression is potentially
5050 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005051 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005052 Action::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005053
Douglas Gregorb98b1992009-08-11 05:31:07 +00005054 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5055 if (SubExpr.isInvalid())
5056 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005057
Douglas Gregorb98b1992009-08-11 05:31:07 +00005058 if (!getDerived().AlwaysRebuild() &&
5059 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00005060 return SemaRef.Owned(E->Retain());
5061
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005062 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5063 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005064 move(SubExpr),
5065 E->getLocEnd());
5066}
5067
5068template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005069Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005070TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005071 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005072}
Mike Stump1eb44332009-09-09 15:08:12 +00005073
Douglas Gregorb98b1992009-08-11 05:31:07 +00005074template<typename Derived>
5075Sema::OwningExprResult
5076TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005077 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005078 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005079}
Mike Stump1eb44332009-09-09 15:08:12 +00005080
Douglas Gregorb98b1992009-08-11 05:31:07 +00005081template<typename Derived>
5082Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005083TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005084 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005085
Douglas Gregorb98b1992009-08-11 05:31:07 +00005086 QualType T = getDerived().TransformType(E->getType());
5087 if (T.isNull())
5088 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005089
Douglas Gregorb98b1992009-08-11 05:31:07 +00005090 if (!getDerived().AlwaysRebuild() &&
5091 T == E->getType())
5092 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005093
Douglas Gregor828a1972010-01-07 23:12:05 +00005094 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005095}
Mike Stump1eb44332009-09-09 15:08:12 +00005096
Douglas Gregorb98b1992009-08-11 05:31:07 +00005097template<typename Derived>
5098Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005099TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005100 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5101 if (SubExpr.isInvalid())
5102 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005103
Douglas Gregorb98b1992009-08-11 05:31:07 +00005104 if (!getDerived().AlwaysRebuild() &&
5105 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005106 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005107
5108 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5109}
Mike Stump1eb44332009-09-09 15:08:12 +00005110
Douglas Gregorb98b1992009-08-11 05:31:07 +00005111template<typename Derived>
5112Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005113TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005114 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005115 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5116 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005117 if (!Param)
5118 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005119
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005120 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005121 Param == E->getParam())
5122 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005123
Douglas Gregor036aed12009-12-23 23:03:06 +00005124 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005125}
Mike Stump1eb44332009-09-09 15:08:12 +00005126
Douglas Gregorb98b1992009-08-11 05:31:07 +00005127template<typename Derived>
5128Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005129TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005130 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5131
5132 QualType T = getDerived().TransformType(E->getType());
5133 if (T.isNull())
5134 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005135
Douglas Gregorb98b1992009-08-11 05:31:07 +00005136 if (!getDerived().AlwaysRebuild() &&
5137 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00005138 return SemaRef.Owned(E->Retain());
5139
5140 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005141 /*FIXME:*/E->getTypeBeginLoc(),
5142 T,
5143 E->getRParenLoc());
5144}
Mike Stump1eb44332009-09-09 15:08:12 +00005145
Douglas Gregorb98b1992009-08-11 05:31:07 +00005146template<typename Derived>
5147Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005148TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005149 // Transform the type that we're allocating
5150 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5151 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5152 if (AllocType.isNull())
5153 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005154
Douglas Gregorb98b1992009-08-11 05:31:07 +00005155 // Transform the size of the array we're allocating (if any).
5156 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5157 if (ArraySize.isInvalid())
5158 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005159
Douglas Gregorb98b1992009-08-11 05:31:07 +00005160 // Transform the placement arguments (if any).
5161 bool ArgumentChanged = false;
5162 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5163 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5164 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5165 if (Arg.isInvalid())
5166 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005167
Douglas Gregorb98b1992009-08-11 05:31:07 +00005168 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5169 PlacementArgs.push_back(Arg.take());
5170 }
Mike Stump1eb44332009-09-09 15:08:12 +00005171
Douglas Gregor43959a92009-08-20 07:17:43 +00005172 // transform the constructor arguments (if any).
Douglas Gregorb98b1992009-08-11 05:31:07 +00005173 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5174 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
5175 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5176 if (Arg.isInvalid())
5177 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005178
Douglas Gregorb98b1992009-08-11 05:31:07 +00005179 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5180 ConstructorArgs.push_back(Arg.take());
5181 }
Mike Stump1eb44332009-09-09 15:08:12 +00005182
Douglas Gregor1af74512010-02-26 00:38:10 +00005183 // Transform constructor, new operator, and delete operator.
5184 CXXConstructorDecl *Constructor = 0;
5185 if (E->getConstructor()) {
5186 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005187 getDerived().TransformDecl(E->getLocStart(),
5188 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005189 if (!Constructor)
5190 return SemaRef.ExprError();
5191 }
5192
5193 FunctionDecl *OperatorNew = 0;
5194 if (E->getOperatorNew()) {
5195 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005196 getDerived().TransformDecl(E->getLocStart(),
5197 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005198 if (!OperatorNew)
5199 return SemaRef.ExprError();
5200 }
5201
5202 FunctionDecl *OperatorDelete = 0;
5203 if (E->getOperatorDelete()) {
5204 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005205 getDerived().TransformDecl(E->getLocStart(),
5206 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005207 if (!OperatorDelete)
5208 return SemaRef.ExprError();
5209 }
Sean Huntc3021132010-05-05 15:23:54 +00005210
Douglas Gregorb98b1992009-08-11 05:31:07 +00005211 if (!getDerived().AlwaysRebuild() &&
5212 AllocType == E->getAllocatedType() &&
5213 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005214 Constructor == E->getConstructor() &&
5215 OperatorNew == E->getOperatorNew() &&
5216 OperatorDelete == E->getOperatorDelete() &&
5217 !ArgumentChanged) {
5218 // Mark any declarations we need as referenced.
5219 // FIXME: instantiation-specific.
5220 if (Constructor)
5221 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5222 if (OperatorNew)
5223 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5224 if (OperatorDelete)
5225 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005226 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005227 }
Mike Stump1eb44332009-09-09 15:08:12 +00005228
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005229 if (!ArraySize.get()) {
5230 // If no array size was specified, but the new expression was
5231 // instantiated with an array type (e.g., "new T" where T is
5232 // instantiated with "int[4]"), extract the outer bound from the
5233 // array type as our array size. We do this with constant and
5234 // dependently-sized array types.
5235 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5236 if (!ArrayT) {
5237 // Do nothing
5238 } else if (const ConstantArrayType *ConsArrayT
5239 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005240 ArraySize
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005241 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Sean Huntc3021132010-05-05 15:23:54 +00005242 ConsArrayT->getSize(),
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005243 SemaRef.Context.getSizeType(),
5244 /*FIXME:*/E->getLocStart()));
5245 AllocType = ConsArrayT->getElementType();
5246 } else if (const DependentSizedArrayType *DepArrayT
5247 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5248 if (DepArrayT->getSizeExpr()) {
5249 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5250 AllocType = DepArrayT->getElementType();
5251 }
5252 }
5253 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005254 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5255 E->isGlobalNew(),
5256 /*FIXME:*/E->getLocStart(),
5257 move_arg(PlacementArgs),
5258 /*FIXME:*/E->getLocStart(),
5259 E->isParenTypeId(),
5260 AllocType,
5261 /*FIXME:*/E->getLocStart(),
5262 /*FIXME:*/SourceRange(),
5263 move(ArraySize),
5264 /*FIXME:*/E->getLocStart(),
5265 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005266 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005267}
Mike Stump1eb44332009-09-09 15:08:12 +00005268
Douglas Gregorb98b1992009-08-11 05:31:07 +00005269template<typename Derived>
5270Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005271TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005272 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5273 if (Operand.isInvalid())
5274 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005275
Douglas Gregor1af74512010-02-26 00:38:10 +00005276 // Transform the delete operator, if known.
5277 FunctionDecl *OperatorDelete = 0;
5278 if (E->getOperatorDelete()) {
5279 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005280 getDerived().TransformDecl(E->getLocStart(),
5281 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005282 if (!OperatorDelete)
5283 return SemaRef.ExprError();
5284 }
Sean Huntc3021132010-05-05 15:23:54 +00005285
Douglas Gregorb98b1992009-08-11 05:31:07 +00005286 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005287 Operand.get() == E->getArgument() &&
5288 OperatorDelete == E->getOperatorDelete()) {
5289 // Mark any declarations we need as referenced.
5290 // FIXME: instantiation-specific.
5291 if (OperatorDelete)
5292 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005293 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005294 }
Mike Stump1eb44332009-09-09 15:08:12 +00005295
Douglas Gregorb98b1992009-08-11 05:31:07 +00005296 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5297 E->isGlobalDelete(),
5298 E->isArrayForm(),
5299 move(Operand));
5300}
Mike Stump1eb44332009-09-09 15:08:12 +00005301
Douglas Gregorb98b1992009-08-11 05:31:07 +00005302template<typename Derived>
5303Sema::OwningExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005304TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005305 CXXPseudoDestructorExpr *E) {
Douglas Gregora71d8192009-09-04 17:36:40 +00005306 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5307 if (Base.isInvalid())
5308 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005309
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005310 Sema::TypeTy *ObjectTypePtr = 0;
5311 bool MayBePseudoDestructor = false;
Sean Huntc3021132010-05-05 15:23:54 +00005312 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005313 E->getOperatorLoc(),
5314 E->isArrow()? tok::arrow : tok::period,
5315 ObjectTypePtr,
5316 MayBePseudoDestructor);
5317 if (Base.isInvalid())
5318 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005319
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005320 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregora71d8192009-09-04 17:36:40 +00005321 NestedNameSpecifier *Qualifier
5322 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00005323 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005324 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00005325 if (E->getQualifier() && !Qualifier)
5326 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005327
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005328 PseudoDestructorTypeStorage Destroyed;
5329 if (E->getDestroyedTypeInfo()) {
5330 TypeSourceInfo *DestroyedTypeInfo
5331 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5332 if (!DestroyedTypeInfo)
5333 return SemaRef.ExprError();
5334 Destroyed = DestroyedTypeInfo;
5335 } else if (ObjectType->isDependentType()) {
5336 // We aren't likely to be able to resolve the identifier down to a type
5337 // now anyway, so just retain the identifier.
5338 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5339 E->getDestroyedTypeLoc());
5340 } else {
5341 // Look for a destructor known with the given name.
5342 CXXScopeSpec SS;
5343 if (Qualifier) {
5344 SS.setScopeRep(Qualifier);
5345 SS.setRange(E->getQualifierRange());
5346 }
Sean Huntc3021132010-05-05 15:23:54 +00005347
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005348 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5349 *E->getDestroyedTypeIdentifier(),
5350 E->getDestroyedTypeLoc(),
5351 /*Scope=*/0,
5352 SS, ObjectTypePtr,
5353 false);
5354 if (!T)
5355 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005356
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005357 Destroyed
5358 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5359 E->getDestroyedTypeLoc());
5360 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005361
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005362 TypeSourceInfo *ScopeTypeInfo = 0;
5363 if (E->getScopeTypeInfo()) {
Sean Huntc3021132010-05-05 15:23:54 +00005364 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005365 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005366 if (!ScopeTypeInfo)
Douglas Gregora71d8192009-09-04 17:36:40 +00005367 return SemaRef.ExprError();
5368 }
Sean Huntc3021132010-05-05 15:23:54 +00005369
Douglas Gregora71d8192009-09-04 17:36:40 +00005370 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5371 E->getOperatorLoc(),
5372 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005373 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005374 E->getQualifierRange(),
5375 ScopeTypeInfo,
5376 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005377 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005378 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005379}
Mike Stump1eb44332009-09-09 15:08:12 +00005380
Douglas Gregora71d8192009-09-04 17:36:40 +00005381template<typename Derived>
5382Sema::OwningExprResult
John McCallba135432009-11-21 08:51:07 +00005383TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005384 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005385 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5386
5387 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5388 Sema::LookupOrdinaryName);
5389
5390 // Transform all the decls.
5391 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5392 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005393 NamedDecl *InstD = static_cast<NamedDecl*>(
5394 getDerived().TransformDecl(Old->getNameLoc(),
5395 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005396 if (!InstD) {
5397 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5398 // This can happen because of dependent hiding.
5399 if (isa<UsingShadowDecl>(*I))
5400 continue;
5401 else
5402 return SemaRef.ExprError();
5403 }
John McCallf7a1a742009-11-24 19:00:30 +00005404
5405 // Expand using declarations.
5406 if (isa<UsingDecl>(InstD)) {
5407 UsingDecl *UD = cast<UsingDecl>(InstD);
5408 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5409 E = UD->shadow_end(); I != E; ++I)
5410 R.addDecl(*I);
5411 continue;
5412 }
5413
5414 R.addDecl(InstD);
5415 }
5416
5417 // Resolve a kind, but don't do any further analysis. If it's
5418 // ambiguous, the callee needs to deal with it.
5419 R.resolveKind();
5420
5421 // Rebuild the nested-name qualifier, if present.
5422 CXXScopeSpec SS;
5423 NestedNameSpecifier *Qualifier = 0;
5424 if (Old->getQualifier()) {
5425 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005426 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005427 if (!Qualifier)
5428 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005429
John McCallf7a1a742009-11-24 19:00:30 +00005430 SS.setScopeRep(Qualifier);
5431 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005432 }
5433
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005434 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005435 CXXRecordDecl *NamingClass
5436 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5437 Old->getNameLoc(),
5438 Old->getNamingClass()));
5439 if (!NamingClass)
5440 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005441
Douglas Gregor66c45152010-04-27 16:10:10 +00005442 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005443 }
5444
5445 // If we have no template arguments, it's a normal declaration name.
5446 if (!Old->hasExplicitTemplateArgs())
5447 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5448
5449 // If we have template arguments, rebuild them, then rebuild the
5450 // templateid expression.
5451 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5452 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5453 TemplateArgumentLoc Loc;
5454 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5455 return SemaRef.ExprError();
5456 TransArgs.addArgument(Loc);
5457 }
5458
5459 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5460 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005461}
Mike Stump1eb44332009-09-09 15:08:12 +00005462
Douglas Gregorb98b1992009-08-11 05:31:07 +00005463template<typename Derived>
5464Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005465TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005466 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005467
Douglas Gregorb98b1992009-08-11 05:31:07 +00005468 QualType T = getDerived().TransformType(E->getQueriedType());
5469 if (T.isNull())
5470 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005471
Douglas Gregorb98b1992009-08-11 05:31:07 +00005472 if (!getDerived().AlwaysRebuild() &&
5473 T == E->getQueriedType())
5474 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005475
Douglas Gregorb98b1992009-08-11 05:31:07 +00005476 // FIXME: Bad location information
5477 SourceLocation FakeLParenLoc
5478 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00005479
5480 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005481 E->getLocStart(),
5482 /*FIXME:*/FakeLParenLoc,
5483 T,
5484 E->getLocEnd());
5485}
Mike Stump1eb44332009-09-09 15:08:12 +00005486
Douglas Gregorb98b1992009-08-11 05:31:07 +00005487template<typename Derived>
5488Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005489TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005490 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005491 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005492 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005493 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005494 if (!NNS)
5495 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005496
5497 DeclarationName Name
Douglas Gregor81499bb2009-09-03 22:13:48 +00005498 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5499 if (!Name)
5500 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005501
John McCallf7a1a742009-11-24 19:00:30 +00005502 if (!E->hasExplicitTemplateArgs()) {
5503 if (!getDerived().AlwaysRebuild() &&
5504 NNS == E->getQualifier() &&
5505 Name == E->getDeclName())
5506 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005507
John McCallf7a1a742009-11-24 19:00:30 +00005508 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5509 E->getQualifierRange(),
5510 Name, E->getLocation(),
5511 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005512 }
John McCalld5532b62009-11-23 01:53:49 +00005513
5514 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005515 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005516 TemplateArgumentLoc Loc;
5517 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb98b1992009-08-11 05:31:07 +00005518 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005519 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005520 }
5521
John McCallf7a1a742009-11-24 19:00:30 +00005522 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5523 E->getQualifierRange(),
5524 Name, E->getLocation(),
5525 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005526}
5527
5528template<typename Derived>
5529Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005530TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005531 // CXXConstructExprs are always implicit, so when we have a
5532 // 1-argument construction we just transform that argument.
5533 if (E->getNumArgs() == 1 ||
5534 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5535 return getDerived().TransformExpr(E->getArg(0));
5536
Douglas Gregorb98b1992009-08-11 05:31:07 +00005537 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5538
5539 QualType T = getDerived().TransformType(E->getType());
5540 if (T.isNull())
5541 return SemaRef.ExprError();
5542
5543 CXXConstructorDecl *Constructor
5544 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005545 getDerived().TransformDecl(E->getLocStart(),
5546 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005547 if (!Constructor)
5548 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005549
Douglas Gregorb98b1992009-08-11 05:31:07 +00005550 bool ArgumentChanged = false;
5551 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005552 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005553 ArgEnd = E->arg_end();
5554 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005555 if (getDerived().DropCallArgument(*Arg)) {
5556 ArgumentChanged = true;
5557 break;
5558 }
5559
Douglas Gregorb98b1992009-08-11 05:31:07 +00005560 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5561 if (TransArg.isInvalid())
5562 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005563
Douglas Gregorb98b1992009-08-11 05:31:07 +00005564 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5565 Args.push_back(TransArg.takeAs<Expr>());
5566 }
5567
5568 if (!getDerived().AlwaysRebuild() &&
5569 T == E->getType() &&
5570 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005571 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005572 // Mark the constructor as referenced.
5573 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005574 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005575 return SemaRef.Owned(E->Retain());
Douglas Gregorc845aad2010-02-26 00:01:57 +00005576 }
Mike Stump1eb44332009-09-09 15:08:12 +00005577
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005578 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5579 Constructor, E->isElidable(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005580 move_arg(Args));
5581}
Mike Stump1eb44332009-09-09 15:08:12 +00005582
Douglas Gregorb98b1992009-08-11 05:31:07 +00005583/// \brief Transform a C++ temporary-binding expression.
5584///
Douglas Gregor51326552009-12-24 18:51:59 +00005585/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5586/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005587template<typename Derived>
5588Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005589TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005590 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005591}
Mike Stump1eb44332009-09-09 15:08:12 +00005592
Anders Carlssoneb60edf2010-01-29 02:39:32 +00005593/// \brief Transform a C++ reference-binding expression.
5594///
5595/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5596/// transform the subexpression and return that.
5597template<typename Derived>
5598Sema::OwningExprResult
5599TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5600 return getDerived().TransformExpr(E->getSubExpr());
5601}
5602
Mike Stump1eb44332009-09-09 15:08:12 +00005603/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005604/// be destroyed after the expression is evaluated.
5605///
Douglas Gregor51326552009-12-24 18:51:59 +00005606/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5607/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005608template<typename Derived>
5609Sema::OwningExprResult
5610TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005611 CXXExprWithTemporaries *E) {
5612 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005613}
Mike Stump1eb44332009-09-09 15:08:12 +00005614
Douglas Gregorb98b1992009-08-11 05:31:07 +00005615template<typename Derived>
5616Sema::OwningExprResult
5617TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00005618 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005619 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5620 QualType T = getDerived().TransformType(E->getType());
5621 if (T.isNull())
5622 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005623
Douglas Gregorb98b1992009-08-11 05:31:07 +00005624 CXXConstructorDecl *Constructor
5625 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005626 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005627 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005628 if (!Constructor)
5629 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005630
Douglas Gregorb98b1992009-08-11 05:31:07 +00005631 bool ArgumentChanged = false;
5632 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5633 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005634 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005635 ArgEnd = E->arg_end();
5636 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005637 if (getDerived().DropCallArgument(*Arg)) {
5638 ArgumentChanged = true;
5639 break;
5640 }
5641
Douglas Gregorb98b1992009-08-11 05:31:07 +00005642 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5643 if (TransArg.isInvalid())
5644 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005645
Douglas Gregorb98b1992009-08-11 05:31:07 +00005646 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5647 Args.push_back((Expr *)TransArg.release());
5648 }
Mike Stump1eb44332009-09-09 15:08:12 +00005649
Douglas Gregorb98b1992009-08-11 05:31:07 +00005650 if (!getDerived().AlwaysRebuild() &&
5651 T == E->getType() &&
5652 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005653 !ArgumentChanged) {
5654 // FIXME: Instantiation-specific
5655 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carrutha3ce8ae2010-03-31 18:34:58 +00005656 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor91be6f52010-03-02 17:18:33 +00005657 }
Mike Stump1eb44332009-09-09 15:08:12 +00005658
Douglas Gregorb98b1992009-08-11 05:31:07 +00005659 // FIXME: Bogus location information
5660 SourceLocation CommaLoc;
5661 if (Args.size() > 1) {
5662 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00005663 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005664 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5665 }
5666 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5667 T,
5668 /*FIXME:*/E->getTypeBeginLoc(),
5669 move_arg(Args),
5670 &CommaLoc,
5671 E->getLocEnd());
5672}
Mike Stump1eb44332009-09-09 15:08:12 +00005673
Douglas Gregorb98b1992009-08-11 05:31:07 +00005674template<typename Derived>
5675Sema::OwningExprResult
5676TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005677 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005678 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5679 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5680 if (T.isNull())
5681 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005682
Douglas Gregorb98b1992009-08-11 05:31:07 +00005683 bool ArgumentChanged = false;
5684 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5685 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5686 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5687 ArgEnd = E->arg_end();
5688 Arg != ArgEnd; ++Arg) {
5689 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5690 if (TransArg.isInvalid())
5691 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005692
Douglas Gregorb98b1992009-08-11 05:31:07 +00005693 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5694 FakeCommaLocs.push_back(
5695 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5696 Args.push_back(TransArg.takeAs<Expr>());
5697 }
Mike Stump1eb44332009-09-09 15:08:12 +00005698
Douglas Gregorb98b1992009-08-11 05:31:07 +00005699 if (!getDerived().AlwaysRebuild() &&
5700 T == E->getTypeAsWritten() &&
5701 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005702 return SemaRef.Owned(E->Retain());
5703
Douglas Gregorb98b1992009-08-11 05:31:07 +00005704 // FIXME: we're faking the locations of the commas
5705 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5706 T,
5707 E->getLParenLoc(),
5708 move_arg(Args),
5709 FakeCommaLocs.data(),
5710 E->getRParenLoc());
5711}
Mike Stump1eb44332009-09-09 15:08:12 +00005712
Douglas Gregorb98b1992009-08-11 05:31:07 +00005713template<typename Derived>
5714Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005715TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall454feb92009-12-08 09:21:05 +00005716 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005717 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005718 OwningExprResult Base(SemaRef, (Expr*) 0);
5719 Expr *OldBase;
5720 QualType BaseType;
5721 QualType ObjectType;
5722 if (!E->isImplicitAccess()) {
5723 OldBase = E->getBase();
5724 Base = getDerived().TransformExpr(OldBase);
5725 if (Base.isInvalid())
5726 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005727
John McCallaa81e162009-12-01 22:10:20 +00005728 // Start the member reference and compute the object's type.
5729 Sema::TypeTy *ObjectTy = 0;
Douglas Gregord4dca082010-02-24 18:44:31 +00005730 bool MayBePseudoDestructor = false;
John McCallaa81e162009-12-01 22:10:20 +00005731 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5732 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005733 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005734 ObjectTy,
5735 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005736 if (Base.isInvalid())
5737 return SemaRef.ExprError();
5738
5739 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5740 BaseType = ((Expr*) Base.get())->getType();
5741 } else {
5742 OldBase = 0;
5743 BaseType = getDerived().TransformType(E->getBaseType());
5744 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5745 }
Mike Stump1eb44332009-09-09 15:08:12 +00005746
Douglas Gregor6cd21982009-10-20 05:58:46 +00005747 // Transform the first part of the nested-name-specifier that qualifies
5748 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005749 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005750 = getDerived().TransformFirstQualifierInScope(
5751 E->getFirstQualifierFoundInScope(),
5752 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005753
Douglas Gregora38c6872009-09-03 16:14:30 +00005754 NestedNameSpecifier *Qualifier = 0;
5755 if (E->getQualifier()) {
5756 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5757 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005758 ObjectType,
5759 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005760 if (!Qualifier)
5761 return SemaRef.ExprError();
5762 }
Mike Stump1eb44332009-09-09 15:08:12 +00005763
5764 DeclarationName Name
Douglas Gregordd62b152009-10-19 22:04:39 +00005765 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCallaa81e162009-12-01 22:10:20 +00005766 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00005767 if (!Name)
5768 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005769
John McCallaa81e162009-12-01 22:10:20 +00005770 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005771 // This is a reference to a member without an explicitly-specified
5772 // template argument list. Optimize for this common case.
5773 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005774 Base.get() == OldBase &&
5775 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005776 Qualifier == E->getQualifier() &&
5777 Name == E->getMember() &&
5778 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005779 return SemaRef.Owned(E->Retain());
5780
John McCall865d4472009-11-19 22:55:06 +00005781 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005782 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005783 E->isArrow(),
5784 E->getOperatorLoc(),
5785 Qualifier,
5786 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005787 FirstQualifierInScope,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005788 Name,
5789 E->getMemberLoc(),
John McCall129e2df2009-11-30 22:42:35 +00005790 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005791 }
5792
John McCalld5532b62009-11-23 01:53:49 +00005793 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005794 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005795 TemplateArgumentLoc Loc;
5796 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005797 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005798 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005799 }
Mike Stump1eb44332009-09-09 15:08:12 +00005800
John McCall865d4472009-11-19 22:55:06 +00005801 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005802 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005803 E->isArrow(),
5804 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005805 Qualifier,
5806 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005807 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005808 Name,
5809 E->getMemberLoc(),
5810 &TransArgs);
5811}
5812
5813template<typename Derived>
5814Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005815TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005816 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005817 OwningExprResult Base(SemaRef, (Expr*) 0);
5818 QualType BaseType;
5819 if (!Old->isImplicitAccess()) {
5820 Base = getDerived().TransformExpr(Old->getBase());
5821 if (Base.isInvalid())
5822 return SemaRef.ExprError();
5823 BaseType = ((Expr*) Base.get())->getType();
5824 } else {
5825 BaseType = getDerived().TransformType(Old->getBaseType());
5826 }
John McCall129e2df2009-11-30 22:42:35 +00005827
5828 NestedNameSpecifier *Qualifier = 0;
5829 if (Old->getQualifier()) {
5830 Qualifier
5831 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005832 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005833 if (Qualifier == 0)
5834 return SemaRef.ExprError();
5835 }
5836
5837 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5838 Sema::LookupOrdinaryName);
5839
5840 // Transform all the decls.
5841 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5842 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005843 NamedDecl *InstD = static_cast<NamedDecl*>(
5844 getDerived().TransformDecl(Old->getMemberLoc(),
5845 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005846 if (!InstD) {
5847 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5848 // This can happen because of dependent hiding.
5849 if (isa<UsingShadowDecl>(*I))
5850 continue;
5851 else
5852 return SemaRef.ExprError();
5853 }
John McCall129e2df2009-11-30 22:42:35 +00005854
5855 // Expand using declarations.
5856 if (isa<UsingDecl>(InstD)) {
5857 UsingDecl *UD = cast<UsingDecl>(InstD);
5858 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5859 E = UD->shadow_end(); I != E; ++I)
5860 R.addDecl(*I);
5861 continue;
5862 }
5863
5864 R.addDecl(InstD);
5865 }
5866
5867 R.resolveKind();
5868
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005869 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00005870 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00005871 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005872 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00005873 Old->getMemberLoc(),
5874 Old->getNamingClass()));
5875 if (!NamingClass)
5876 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005877
Douglas Gregor66c45152010-04-27 16:10:10 +00005878 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005879 }
Sean Huntc3021132010-05-05 15:23:54 +00005880
John McCall129e2df2009-11-30 22:42:35 +00005881 TemplateArgumentListInfo TransArgs;
5882 if (Old->hasExplicitTemplateArgs()) {
5883 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5884 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5885 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5886 TemplateArgumentLoc Loc;
5887 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5888 Loc))
5889 return SemaRef.ExprError();
5890 TransArgs.addArgument(Loc);
5891 }
5892 }
John McCallc2233c52010-01-15 08:34:02 +00005893
5894 // FIXME: to do this check properly, we will need to preserve the
5895 // first-qualifier-in-scope here, just in case we had a dependent
5896 // base (and therefore couldn't do the check) and a
5897 // nested-name-qualifier (and therefore could do the lookup).
5898 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00005899
John McCall129e2df2009-11-30 22:42:35 +00005900 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005901 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005902 Old->getOperatorLoc(),
5903 Old->isArrow(),
5904 Qualifier,
5905 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00005906 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005907 R,
5908 (Old->hasExplicitTemplateArgs()
5909 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005910}
5911
5912template<typename Derived>
5913Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005914TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005915 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005916}
5917
Mike Stump1eb44332009-09-09 15:08:12 +00005918template<typename Derived>
5919Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005920TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00005921 TypeSourceInfo *EncodedTypeInfo
5922 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5923 if (!EncodedTypeInfo)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005924 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005925
Douglas Gregorb98b1992009-08-11 05:31:07 +00005926 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00005927 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00005928 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005929
5930 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00005931 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005932 E->getRParenLoc());
5933}
Mike Stump1eb44332009-09-09 15:08:12 +00005934
Douglas Gregorb98b1992009-08-11 05:31:07 +00005935template<typename Derived>
5936Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005937TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00005938 // Transform arguments.
5939 bool ArgChanged = false;
5940 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5941 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5942 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5943 if (Arg.isInvalid())
5944 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005945
Douglas Gregor92e986e2010-04-22 16:44:27 +00005946 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5947 Args.push_back(Arg.takeAs<Expr>());
5948 }
5949
5950 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5951 // Class message: transform the receiver type.
5952 TypeSourceInfo *ReceiverTypeInfo
5953 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5954 if (!ReceiverTypeInfo)
5955 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005956
Douglas Gregor92e986e2010-04-22 16:44:27 +00005957 // If nothing changed, just retain the existing message send.
5958 if (!getDerived().AlwaysRebuild() &&
5959 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5960 return SemaRef.Owned(E->Retain());
5961
5962 // Build a new class message send.
5963 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5964 E->getSelector(),
5965 E->getMethodDecl(),
5966 E->getLeftLoc(),
5967 move_arg(Args),
5968 E->getRightLoc());
5969 }
5970
5971 // Instance message: transform the receiver
5972 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
5973 "Only class and instance messages may be instantiated");
5974 OwningExprResult Receiver
5975 = getDerived().TransformExpr(E->getInstanceReceiver());
5976 if (Receiver.isInvalid())
5977 return SemaRef.ExprError();
5978
5979 // If nothing changed, just retain the existing message send.
5980 if (!getDerived().AlwaysRebuild() &&
5981 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
5982 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00005983
Douglas Gregor92e986e2010-04-22 16:44:27 +00005984 // Build a new instance message send.
5985 return getDerived().RebuildObjCMessageExpr(move(Receiver),
5986 E->getSelector(),
5987 E->getMethodDecl(),
5988 E->getLeftLoc(),
5989 move_arg(Args),
5990 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005991}
5992
Mike Stump1eb44332009-09-09 15:08:12 +00005993template<typename Derived>
5994Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005995TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005996 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005997}
5998
Mike Stump1eb44332009-09-09 15:08:12 +00005999template<typename Derived>
6000Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006001TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006002 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006003}
6004
Mike Stump1eb44332009-09-09 15:08:12 +00006005template<typename Derived>
6006Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006007TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006008 // Transform the base expression.
6009 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6010 if (Base.isInvalid())
6011 return SemaRef.ExprError();
6012
6013 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006014
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006015 // If nothing changed, just retain the existing expression.
6016 if (!getDerived().AlwaysRebuild() &&
6017 Base.get() == E->getBase())
6018 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006019
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006020 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6021 E->getLocation(),
6022 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006023}
6024
Mike Stump1eb44332009-09-09 15:08:12 +00006025template<typename Derived>
6026Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006027TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregore3303542010-04-26 20:47:02 +00006028 // Transform the base expression.
6029 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6030 if (Base.isInvalid())
6031 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006032
Douglas Gregore3303542010-04-26 20:47:02 +00006033 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006034
Douglas Gregore3303542010-04-26 20:47:02 +00006035 // If nothing changed, just retain the existing expression.
6036 if (!getDerived().AlwaysRebuild() &&
6037 Base.get() == E->getBase())
6038 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006039
Douglas Gregore3303542010-04-26 20:47:02 +00006040 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6041 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006042}
6043
Mike Stump1eb44332009-09-09 15:08:12 +00006044template<typename Derived>
6045Sema::OwningExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00006046TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00006047 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006048 // If this implicit setter/getter refers to class methods, it cannot have any
6049 // dependent parts. Just retain the existing declaration.
6050 if (E->getInterfaceDecl())
6051 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006052
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006053 // Transform the base expression.
6054 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6055 if (Base.isInvalid())
6056 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006057
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006058 // We don't need to transform the getters/setters; they will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006059
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006060 // If nothing changed, just retain the existing expression.
6061 if (!getDerived().AlwaysRebuild() &&
6062 Base.get() == E->getBase())
6063 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006064
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006065 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6066 E->getGetterMethod(),
6067 E->getType(),
6068 E->getSetterMethod(),
6069 E->getLocation(),
6070 move(Base));
Sean Huntc3021132010-05-05 15:23:54 +00006071
Douglas Gregorb98b1992009-08-11 05:31:07 +00006072}
6073
Mike Stump1eb44332009-09-09 15:08:12 +00006074template<typename Derived>
6075Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006076TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006077 // Can never occur in a dependent context.
Mike Stump1eb44332009-09-09 15:08:12 +00006078 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006079}
6080
Mike Stump1eb44332009-09-09 15:08:12 +00006081template<typename Derived>
6082Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006083TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006084 // Transform the base expression.
6085 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6086 if (Base.isInvalid())
6087 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006088
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006089 // If nothing changed, just retain the existing expression.
6090 if (!getDerived().AlwaysRebuild() &&
6091 Base.get() == E->getBase())
6092 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006093
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006094 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6095 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006096}
6097
Mike Stump1eb44332009-09-09 15:08:12 +00006098template<typename Derived>
6099Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006100TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006101 bool ArgumentChanged = false;
6102 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6103 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6104 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6105 if (SubExpr.isInvalid())
6106 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006107
Douglas Gregorb98b1992009-08-11 05:31:07 +00006108 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6109 SubExprs.push_back(SubExpr.takeAs<Expr>());
6110 }
Mike Stump1eb44332009-09-09 15:08:12 +00006111
Douglas Gregorb98b1992009-08-11 05:31:07 +00006112 if (!getDerived().AlwaysRebuild() &&
6113 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00006114 return SemaRef.Owned(E->Retain());
6115
Douglas Gregorb98b1992009-08-11 05:31:07 +00006116 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6117 move_arg(SubExprs),
6118 E->getRParenLoc());
6119}
6120
Mike Stump1eb44332009-09-09 15:08:12 +00006121template<typename Derived>
6122Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006123TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006124 // FIXME: Implement this!
6125 assert(false && "Cannot transform block expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00006126 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006127}
6128
Mike Stump1eb44332009-09-09 15:08:12 +00006129template<typename Derived>
6130Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006131TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006132 // FIXME: Implement this!
6133 assert(false && "Cannot transform block-related expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00006134 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006135}
Mike Stump1eb44332009-09-09 15:08:12 +00006136
Douglas Gregorb98b1992009-08-11 05:31:07 +00006137//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006138// Type reconstruction
6139//===----------------------------------------------------------------------===//
6140
Mike Stump1eb44332009-09-09 15:08:12 +00006141template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006142QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6143 SourceLocation Star) {
6144 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006145 getDerived().getBaseEntity());
6146}
6147
Mike Stump1eb44332009-09-09 15:08:12 +00006148template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006149QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6150 SourceLocation Star) {
6151 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006152 getDerived().getBaseEntity());
6153}
6154
Mike Stump1eb44332009-09-09 15:08:12 +00006155template<typename Derived>
6156QualType
John McCall85737a72009-10-30 00:06:24 +00006157TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6158 bool WrittenAsLValue,
6159 SourceLocation Sigil) {
6160 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
6161 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006162}
6163
6164template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006165QualType
John McCall85737a72009-10-30 00:06:24 +00006166TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6167 QualType ClassType,
6168 SourceLocation Sigil) {
John McCall0953e762009-09-24 19:53:00 +00006169 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall85737a72009-10-30 00:06:24 +00006170 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006171}
6172
6173template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006174QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006175TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6176 ArrayType::ArraySizeModifier SizeMod,
6177 const llvm::APInt *Size,
6178 Expr *SizeExpr,
6179 unsigned IndexTypeQuals,
6180 SourceRange BracketsRange) {
6181 if (SizeExpr || !Size)
6182 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6183 IndexTypeQuals, BracketsRange,
6184 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006185
6186 QualType Types[] = {
6187 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6188 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6189 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006190 };
6191 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6192 QualType SizeType;
6193 for (unsigned I = 0; I != NumTypes; ++I)
6194 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6195 SizeType = Types[I];
6196 break;
6197 }
Mike Stump1eb44332009-09-09 15:08:12 +00006198
Douglas Gregor577f75a2009-08-04 16:50:30 +00006199 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006200 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006201 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006202 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006203}
Mike Stump1eb44332009-09-09 15:08:12 +00006204
Douglas Gregor577f75a2009-08-04 16:50:30 +00006205template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006206QualType
6207TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006208 ArrayType::ArraySizeModifier SizeMod,
6209 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006210 unsigned IndexTypeQuals,
6211 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006212 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006213 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006214}
6215
6216template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006217QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006218TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006219 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006220 unsigned IndexTypeQuals,
6221 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006222 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006223 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006224}
Mike Stump1eb44332009-09-09 15:08:12 +00006225
Douglas Gregor577f75a2009-08-04 16:50:30 +00006226template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006227QualType
6228TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006229 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006230 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006231 unsigned IndexTypeQuals,
6232 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006233 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006234 SizeExpr.takeAs<Expr>(),
6235 IndexTypeQuals, BracketsRange);
6236}
6237
6238template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006239QualType
6240TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006241 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006242 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006243 unsigned IndexTypeQuals,
6244 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006245 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006246 SizeExpr.takeAs<Expr>(),
6247 IndexTypeQuals, BracketsRange);
6248}
6249
6250template<typename Derived>
6251QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson82287d12010-02-05 00:12:22 +00006252 unsigned NumElements,
6253 bool IsAltiVec, bool IsPixel) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006254 // FIXME: semantic checking!
John Thompson82287d12010-02-05 00:12:22 +00006255 return SemaRef.Context.getVectorType(ElementType, NumElements,
6256 IsAltiVec, IsPixel);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006257}
Mike Stump1eb44332009-09-09 15:08:12 +00006258
Douglas Gregor577f75a2009-08-04 16:50:30 +00006259template<typename Derived>
6260QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6261 unsigned NumElements,
6262 SourceLocation AttributeLoc) {
6263 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6264 NumElements, true);
6265 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00006266 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006267 AttributeLoc);
6268 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6269 AttributeLoc);
6270}
Mike Stump1eb44332009-09-09 15:08:12 +00006271
Douglas Gregor577f75a2009-08-04 16:50:30 +00006272template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006273QualType
6274TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006275 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006276 SourceLocation AttributeLoc) {
6277 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6278}
Mike Stump1eb44332009-09-09 15:08:12 +00006279
Douglas Gregor577f75a2009-08-04 16:50:30 +00006280template<typename Derived>
6281QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006282 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006283 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006284 bool Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006285 unsigned Quals) {
Mike Stump1eb44332009-09-09 15:08:12 +00006286 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006287 Quals,
6288 getDerived().getBaseLocation(),
6289 getDerived().getBaseEntity());
6290}
Mike Stump1eb44332009-09-09 15:08:12 +00006291
Douglas Gregor577f75a2009-08-04 16:50:30 +00006292template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006293QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6294 return SemaRef.Context.getFunctionNoProtoType(T);
6295}
6296
6297template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006298QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6299 assert(D && "no decl found");
6300 if (D->isInvalidDecl()) return QualType();
6301
Douglas Gregor92e986e2010-04-22 16:44:27 +00006302 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006303 TypeDecl *Ty;
6304 if (isa<UsingDecl>(D)) {
6305 UsingDecl *Using = cast<UsingDecl>(D);
6306 assert(Using->isTypeName() &&
6307 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6308
6309 // A valid resolved using typename decl points to exactly one type decl.
6310 assert(++Using->shadow_begin() == Using->shadow_end());
6311 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006312
John McCalled976492009-12-04 22:46:56 +00006313 } else {
6314 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6315 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6316 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6317 }
6318
6319 return SemaRef.Context.getTypeDeclType(Ty);
6320}
6321
6322template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00006323QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006324 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6325}
6326
6327template<typename Derived>
6328QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6329 return SemaRef.Context.getTypeOfType(Underlying);
6330}
6331
6332template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00006333QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006334 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6335}
6336
6337template<typename Derived>
6338QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006339 TemplateName Template,
6340 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006341 const TemplateArgumentListInfo &TemplateArgs) {
6342 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006343}
Mike Stump1eb44332009-09-09 15:08:12 +00006344
Douglas Gregordcee1a12009-08-06 05:28:30 +00006345template<typename Derived>
6346NestedNameSpecifier *
6347TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6348 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006349 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006350 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006351 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006352 CXXScopeSpec SS;
6353 // FIXME: The source location information is all wrong.
6354 SS.setRange(Range);
6355 SS.setScopeRep(Prefix);
6356 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006357 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006358 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006359 ObjectType,
6360 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006361 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006362}
6363
6364template<typename Derived>
6365NestedNameSpecifier *
6366TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6367 SourceRange Range,
6368 NamespaceDecl *NS) {
6369 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6370}
6371
6372template<typename Derived>
6373NestedNameSpecifier *
6374TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6375 SourceRange Range,
6376 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006377 QualType T) {
6378 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006379 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006380 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006381 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6382 T.getTypePtr());
6383 }
Mike Stump1eb44332009-09-09 15:08:12 +00006384
Douglas Gregordcee1a12009-08-06 05:28:30 +00006385 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6386 return 0;
6387}
Mike Stump1eb44332009-09-09 15:08:12 +00006388
Douglas Gregord1067e52009-08-06 06:41:21 +00006389template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006390TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006391TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6392 bool TemplateKW,
6393 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006394 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006395 Template);
6396}
6397
6398template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006399TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006400TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006401 const IdentifierInfo &II,
6402 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006403 CXXScopeSpec SS;
6404 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00006405 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006406 UnqualifiedId Name;
6407 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006408 return getSema().ActOnDependentTemplateName(
6409 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006410 SS,
Douglas Gregor014e88d2009-11-03 23:16:33 +00006411 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00006412 ObjectType.getAsOpaquePtr(),
6413 /*EnteringContext=*/false)
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006414 .template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00006415}
Mike Stump1eb44332009-09-09 15:08:12 +00006416
Douglas Gregorb98b1992009-08-11 05:31:07 +00006417template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006418TemplateName
6419TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6420 OverloadedOperatorKind Operator,
6421 QualType ObjectType) {
6422 CXXScopeSpec SS;
6423 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6424 SS.setScopeRep(Qualifier);
6425 UnqualifiedId Name;
6426 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6427 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6428 Operator, SymbolLocations);
6429 return getSema().ActOnDependentTemplateName(
6430 /*FIXME:*/getDerived().getBaseLocation(),
6431 SS,
6432 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00006433 ObjectType.getAsOpaquePtr(),
6434 /*EnteringContext=*/false)
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006435 .template getAsVal<TemplateName>();
6436}
Sean Huntc3021132010-05-05 15:23:54 +00006437
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006438template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006439Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006440TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6441 SourceLocation OpLoc,
6442 ExprArg Callee,
6443 ExprArg First,
6444 ExprArg Second) {
6445 Expr *FirstExpr = (Expr *)First.get();
6446 Expr *SecondExpr = (Expr *)Second.get();
John McCallba135432009-11-21 08:51:07 +00006447 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006448 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006449
Douglas Gregorb98b1992009-08-11 05:31:07 +00006450 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006451 if (Op == OO_Subscript) {
6452 if (!FirstExpr->getType()->isOverloadableType() &&
6453 !SecondExpr->getType()->isOverloadableType())
6454 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCallba135432009-11-21 08:51:07 +00006455 CalleeExpr->getLocStart(),
Sebastian Redlf322ed62009-10-29 20:17:01 +00006456 move(Second), OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006457 } else if (Op == OO_Arrow) {
6458 // -> is never a builtin operation.
6459 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006460 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461 if (!FirstExpr->getType()->isOverloadableType()) {
6462 // The argument is not of overloadable type, so try to create a
6463 // built-in unary operation.
Mike Stump1eb44332009-09-09 15:08:12 +00006464 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006465 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006466
Douglas Gregorb98b1992009-08-11 05:31:07 +00006467 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6468 }
6469 } else {
Mike Stump1eb44332009-09-09 15:08:12 +00006470 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006471 !SecondExpr->getType()->isOverloadableType()) {
6472 // Neither of the arguments is an overloadable type, so try to
6473 // create a built-in binary operation.
6474 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00006475 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6477 if (Result.isInvalid())
6478 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006479
Douglas Gregorb98b1992009-08-11 05:31:07 +00006480 First.release();
6481 Second.release();
6482 return move(Result);
6483 }
6484 }
Mike Stump1eb44332009-09-09 15:08:12 +00006485
6486 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006487 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006488 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006489
John McCallba135432009-11-21 08:51:07 +00006490 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6491 assert(ULE->requiresADL());
6492
6493 // FIXME: Do we have to check
6494 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006495 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006496 } else {
John McCall6e266892010-01-26 03:27:55 +00006497 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006498 }
Mike Stump1eb44332009-09-09 15:08:12 +00006499
Douglas Gregorb98b1992009-08-11 05:31:07 +00006500 // Add any functions found via argument-dependent lookup.
6501 Expr *Args[2] = { FirstExpr, SecondExpr };
6502 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006503
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504 // Create the overloaded operator invocation for unary operators.
6505 if (NumArgs == 1 || isPostIncDec) {
Mike Stump1eb44332009-09-09 15:08:12 +00006506 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006507 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6508 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6509 }
Mike Stump1eb44332009-09-09 15:08:12 +00006510
Sebastian Redlf322ed62009-10-29 20:17:01 +00006511 if (Op == OO_Subscript)
John McCallba135432009-11-21 08:51:07 +00006512 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6513 OpLoc,
6514 move(First),
6515 move(Second));
Sebastian Redlf322ed62009-10-29 20:17:01 +00006516
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517 // Create the overloaded operator invocation for binary operators.
Mike Stump1eb44332009-09-09 15:08:12 +00006518 BinaryOperator::Opcode Opc =
Douglas Gregorb98b1992009-08-11 05:31:07 +00006519 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00006520 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006521 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6522 if (Result.isInvalid())
6523 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006524
Douglas Gregorb98b1992009-08-11 05:31:07 +00006525 First.release();
6526 Second.release();
Mike Stump1eb44332009-09-09 15:08:12 +00006527 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006528}
Mike Stump1eb44332009-09-09 15:08:12 +00006529
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006530template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00006531Sema::OwningExprResult
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006532TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6533 SourceLocation OperatorLoc,
6534 bool isArrow,
6535 NestedNameSpecifier *Qualifier,
6536 SourceRange QualifierRange,
6537 TypeSourceInfo *ScopeType,
6538 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006539 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006540 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006541 CXXScopeSpec SS;
6542 if (Qualifier) {
6543 SS.setRange(QualifierRange);
6544 SS.setScopeRep(Qualifier);
6545 }
6546
6547 Expr *BaseE = (Expr *)Base.get();
6548 QualType BaseType = BaseE->getType();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006549 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006550 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006551 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006552 !BaseType->getAs<PointerType>()->getPointeeType()
6553 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006554 // This pseudo-destructor expression is still a pseudo-destructor.
6555 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6556 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006557 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006558 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006559 /*FIXME?*/true);
6560 }
Sean Huntc3021132010-05-05 15:23:54 +00006561
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006562 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006563 DeclarationName Name
6564 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6565 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
Sean Huntc3021132010-05-05 15:23:54 +00006566
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006567 // FIXME: the ScopeType should be tacked onto SS.
Sean Huntc3021132010-05-05 15:23:54 +00006568
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006569 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6570 OperatorLoc, isArrow,
6571 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006572 Name, Destroyed.getLocation(),
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006573 /*TemplateArgs*/ 0);
6574}
6575
Douglas Gregor577f75a2009-08-04 16:50:30 +00006576} // end namespace clang
6577
6578#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H