blob: ed531c746648a700984efec8fe136213a3b80bdd [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
John McCall2d887082010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000019#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000020#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000021#include "clang/AST/DeclObjC.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000022#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000023#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
John McCalla2becad2009-10-21 00:40:46 +000028#include "clang/AST/TypeLocBuilder.h"
John McCall19510852010-08-20 18:27:03 +000029#include "clang/Sema/Ownership.h"
30#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000031#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000032#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000033#include <algorithm>
34
35namespace clang {
John McCall781472f2010-08-25 08:40:02 +000036using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000037
Douglas Gregor577f75a2009-08-04 16:50:30 +000038/// \brief A semantic tree transformation that allows one to transform one
39/// abstract syntax tree into another.
40///
Mike Stump1eb44332009-09-09 15:08:12 +000041/// A new tree transformation is defined by creating a new subclass \c X of
42/// \c TreeTransform<X> and then overriding certain operations to provide
43/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000044/// instantiation is implemented as a tree transformation where the
45/// transformation of TemplateTypeParmType nodes involves substituting the
46/// template arguments for their corresponding template parameters; a similar
47/// transformation is performed for non-type template parameters and
48/// template template parameters.
49///
50/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000051/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000052/// override any of the transformation or rebuild operators by providing an
53/// operation with the same signature as the default implementation. The
54/// overridding function should not be virtual.
55///
56/// Semantic tree transformations are split into two stages, either of which
57/// can be replaced by a subclass. The "transform" step transforms an AST node
58/// or the parts of an AST node using the various transformation functions,
59/// then passes the pieces on to the "rebuild" step, which constructs a new AST
60/// node of the appropriate kind from the pieces. The default transformation
61/// routines recursively transform the operands to composite AST nodes (e.g.,
62/// the pointee type of a PointerType node) and, if any of those operand nodes
63/// were changed by the transformation, invokes the rebuild operation to create
64/// a new AST node.
65///
Mike Stump1eb44332009-09-09 15:08:12 +000066/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000067/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000068/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
69/// TransformTemplateName(), or TransformTemplateArgument() with entirely
70/// new implementations.
71///
72/// For more fine-grained transformations, subclasses can replace any of the
73/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000074/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000075/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000076/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000077/// parameters. Additionally, subclasses can override the \c RebuildXXX
78/// functions to control how AST nodes are rebuilt when their operands change.
79/// By default, \c TreeTransform will invoke semantic analysis to rebuild
80/// AST nodes. However, certain other tree transformations (e.g, cloning) may
81/// be able to use more efficient rebuild steps.
82///
83/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000084/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000085/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
86/// operands have not changed (\c AlwaysRebuild()), and customize the
87/// default locations and entity names used for type-checking
88/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000089template<typename Derived>
90class TreeTransform {
91protected:
92 Sema &SemaRef;
Mike Stump1eb44332009-09-09 15:08:12 +000093
94public:
Douglas Gregorb98b1992009-08-11 05:31:07 +000095 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregor43959a92009-08-20 07:17:43 +000096 typedef Sema::MultiStmtArg MultiStmtArg;
Sean Huntc3021132010-05-05 15:23:54 +000097
Douglas Gregor577f75a2009-08-04 16:50:30 +000098 /// \brief Initializes a new tree transformer.
99 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000100
Douglas Gregor577f75a2009-08-04 16:50:30 +0000101 /// \brief Retrieves a reference to the derived class.
102 Derived &getDerived() { return static_cast<Derived&>(*this); }
103
104 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000105 const Derived &getDerived() const {
106 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000107 }
108
John McCall60d7b3a2010-08-24 06:29:42 +0000109 static inline ExprResult Owned(Expr *E) { return E; }
110 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112 /// \brief Retrieves a reference to the semantic analysis object used for
113 /// this tree transform.
114 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000115
Douglas Gregor577f75a2009-08-04 16:50:30 +0000116 /// \brief Whether the transformation should always rebuild AST nodes, even
117 /// if none of the children have changed.
118 ///
119 /// Subclasses may override this function to specify when the transformation
120 /// should rebuild all AST nodes.
121 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000122
Douglas Gregor577f75a2009-08-04 16:50:30 +0000123 /// \brief Returns the location of the entity being transformed, if that
124 /// information was not available elsewhere in the AST.
125 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000126 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000127 /// provide an alternative implementation that provides better location
128 /// information.
129 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000130
Douglas Gregor577f75a2009-08-04 16:50:30 +0000131 /// \brief Returns the name of the entity being transformed, if that
132 /// information was not available elsewhere in the AST.
133 ///
134 /// By default, returns an empty name. Subclasses can provide an alternative
135 /// implementation with a more precise name.
136 DeclarationName getBaseEntity() { return DeclarationName(); }
137
Douglas Gregorb98b1992009-08-11 05:31:07 +0000138 /// \brief Sets the "base" location and entity when that
139 /// information is known based on another transformation.
140 ///
141 /// By default, the source location and entity are ignored. Subclasses can
142 /// override this function to provide a customized implementation.
143 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000144
Douglas Gregorb98b1992009-08-11 05:31:07 +0000145 /// \brief RAII object that temporarily sets the base location and entity
146 /// used for reporting diagnostics in types.
147 class TemporaryBase {
148 TreeTransform &Self;
149 SourceLocation OldLocation;
150 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000151
Douglas Gregorb98b1992009-08-11 05:31:07 +0000152 public:
153 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000154 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000155 OldLocation = Self.getDerived().getBaseLocation();
156 OldEntity = Self.getDerived().getBaseEntity();
157 Self.getDerived().setBase(Location, Entity);
158 }
Mike Stump1eb44332009-09-09 15:08:12 +0000159
Douglas Gregorb98b1992009-08-11 05:31:07 +0000160 ~TemporaryBase() {
161 Self.getDerived().setBase(OldLocation, OldEntity);
162 }
163 };
Mike Stump1eb44332009-09-09 15:08:12 +0000164
165 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000166 /// transformed.
167 ///
168 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000169 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000170 /// not change. For example, template instantiation need not traverse
171 /// non-dependent types.
172 bool AlreadyTransformed(QualType T) {
173 return T.isNull();
174 }
175
Douglas Gregor6eef5192009-12-14 19:27:10 +0000176 /// \brief Determine whether the given call argument should be dropped, e.g.,
177 /// because it is a default argument.
178 ///
179 /// Subclasses can provide an alternative implementation of this routine to
180 /// determine which kinds of call arguments get dropped. By default,
181 /// CXXDefaultArgument nodes are dropped (prior to transformation).
182 bool DropCallArgument(Expr *E) {
183 return E->isDefaultArgument();
184 }
Sean Huntc3021132010-05-05 15:23:54 +0000185
Douglas Gregor577f75a2009-08-04 16:50:30 +0000186 /// \brief Transforms the given type into another type.
187 ///
John McCalla2becad2009-10-21 00:40:46 +0000188 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000189 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000190 /// function. This is expensive, but we don't mind, because
191 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000192 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000193 ///
194 /// \returns the transformed type.
Douglas Gregor124b8782010-02-16 19:09:40 +0000195 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000196
John McCalla2becad2009-10-21 00:40:46 +0000197 /// \brief Transforms the given type-with-location into a new
198 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000199 ///
John McCalla2becad2009-10-21 00:40:46 +0000200 /// By default, this routine transforms a type by delegating to the
201 /// appropriate TransformXXXType to build a new type. Subclasses
202 /// may override this function (to take over all type
203 /// transformations) or some set of the TransformXXXType functions
204 /// to alter the transformation.
Sean Huntc3021132010-05-05 15:23:54 +0000205 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
Douglas Gregor124b8782010-02-16 19:09:40 +0000206 QualType ObjectType = QualType());
John McCalla2becad2009-10-21 00:40:46 +0000207
208 /// \brief Transform the given type-with-location into a new
209 /// type, collecting location information in the given builder
210 /// as necessary.
211 ///
Sean Huntc3021132010-05-05 15:23:54 +0000212 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +0000213 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000214
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000215 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000216 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000217 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000218 /// appropriate TransformXXXStmt function to transform a specific kind of
219 /// statement or the TransformExpr() function to transform an expression.
220 /// Subclasses may override this function to transform statements using some
221 /// other mechanism.
222 ///
223 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000224 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000225
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000226 /// \brief Transform the given expression.
227 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000228 /// By default, this routine transforms an expression by delegating to the
229 /// appropriate TransformXXXExpr function to build a new expression.
230 /// Subclasses may override this function to transform expressions using some
231 /// other mechanism.
232 ///
233 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000234 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000235
Douglas Gregor577f75a2009-08-04 16:50:30 +0000236 /// \brief Transform the given declaration, which is referenced from a type
237 /// or expression.
238 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000239 /// By default, acts as the identity function on declarations. Subclasses
240 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000241 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000242
243 /// \brief Transform the definition of the given declaration.
244 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000245 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000246 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000247 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
248 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000249 }
Mike Stump1eb44332009-09-09 15:08:12 +0000250
Douglas Gregor6cd21982009-10-20 05:58:46 +0000251 /// \brief Transform the given declaration, which was the first part of a
252 /// nested-name-specifier in a member access expression.
253 ///
Sean Huntc3021132010-05-05 15:23:54 +0000254 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000255 /// identifier in a nested-name-specifier of a member access expression, e.g.,
256 /// the \c T in \c x->T::member
257 ///
258 /// By default, invokes TransformDecl() to transform the declaration.
259 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000260 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
261 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000262 }
Sean Huntc3021132010-05-05 15:23:54 +0000263
Douglas Gregor577f75a2009-08-04 16:50:30 +0000264 /// \brief Transform the given nested-name-specifier.
265 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000266 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000267 /// nested-name-specifier. Subclasses may override this function to provide
268 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000269 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000270 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000271 QualType ObjectType = QualType(),
272 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000273
Douglas Gregor81499bb2009-09-03 22:13:48 +0000274 /// \brief Transform the given declaration name.
275 ///
276 /// By default, transforms the types of conversion function, constructor,
277 /// and destructor names and then (if needed) rebuilds the declaration name.
278 /// Identifiers and selectors are returned unmodified. Sublcasses may
279 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000280 DeclarationNameInfo
281 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
282 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000283
Douglas Gregor577f75a2009-08-04 16:50:30 +0000284 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000285 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000286 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000287 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000288 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000289 TemplateName TransformTemplateName(TemplateName Name,
290 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000291
Douglas Gregor577f75a2009-08-04 16:50:30 +0000292 /// \brief Transform the given template argument.
293 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000294 /// By default, this operation transforms the type, expression, or
295 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000296 /// new template argument from the transformed result. Subclasses may
297 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000298 ///
299 /// Returns true if there was an error.
300 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
301 TemplateArgumentLoc &Output);
302
303 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
304 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
305 TemplateArgumentLoc &ArgLoc);
306
John McCalla93c9342009-12-07 02:54:59 +0000307 /// \brief Fakes up a TypeSourceInfo for a type.
308 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
309 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000310 getDerived().getBaseLocation());
311 }
Mike Stump1eb44332009-09-09 15:08:12 +0000312
John McCalla2becad2009-10-21 00:40:46 +0000313#define ABSTRACT_TYPELOC(CLASS, PARENT)
314#define TYPELOC(CLASS, PARENT) \
Douglas Gregor124b8782010-02-16 19:09:40 +0000315 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
316 QualType ObjectType = QualType());
John McCalla2becad2009-10-21 00:40:46 +0000317#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000318
John McCall21ef0fa2010-03-11 09:03:00 +0000319 /// \brief Transforms the parameters of a function type into the
320 /// given vectors.
321 ///
322 /// The result vectors should be kept in sync; null entries in the
323 /// variables vector are acceptable.
324 ///
325 /// Return true on error.
326 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
327 llvm::SmallVectorImpl<QualType> &PTypes,
328 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
329
330 /// \brief Transforms a single function-type parameter. Return null
331 /// on error.
332 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
333
Sean Huntc3021132010-05-05 15:23:54 +0000334 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +0000335 QualType ObjectType);
John McCall85737a72009-10-30 00:06:24 +0000336
Sean Huntc3021132010-05-05 15:23:54 +0000337 QualType
Douglas Gregordd62b152009-10-19 22:04:39 +0000338 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
339 QualType ObjectType);
John McCall833ca992009-10-29 08:12:44 +0000340
John McCall60d7b3a2010-08-24 06:29:42 +0000341 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
342 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000343
Douglas Gregor43959a92009-08-20 07:17:43 +0000344#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000345 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000346#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000347 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000348#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000349#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000350
Douglas Gregor577f75a2009-08-04 16:50:30 +0000351 /// \brief Build a new pointer type given its pointee type.
352 ///
353 /// By default, performs semantic analysis when building the pointer type.
354 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000355 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000356
357 /// \brief Build a new block pointer type given its pointee type.
358 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000359 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000360 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000361 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000362
John McCall85737a72009-10-30 00:06:24 +0000363 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000364 ///
John McCall85737a72009-10-30 00:06:24 +0000365 /// By default, performs semantic analysis when building the
366 /// reference type. Subclasses may override this routine to provide
367 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000368 ///
John McCall85737a72009-10-30 00:06:24 +0000369 /// \param LValue whether the type was written with an lvalue sigil
370 /// or an rvalue sigil.
371 QualType RebuildReferenceType(QualType ReferentType,
372 bool LValue,
373 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000374
Douglas Gregor577f75a2009-08-04 16:50:30 +0000375 /// \brief Build a new member pointer type given the pointee type and the
376 /// class type it refers into.
377 ///
378 /// By default, performs semantic analysis when building the member pointer
379 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000380 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
381 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000382
Douglas Gregor577f75a2009-08-04 16:50:30 +0000383 /// \brief Build a new array type given the element type, size
384 /// modifier, size of the array (if known), size expression, and index type
385 /// qualifiers.
386 ///
387 /// By default, performs semantic analysis when building the array type.
388 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000389 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000390 QualType RebuildArrayType(QualType ElementType,
391 ArrayType::ArraySizeModifier SizeMod,
392 const llvm::APInt *Size,
393 Expr *SizeExpr,
394 unsigned IndexTypeQuals,
395 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000396
Douglas Gregor577f75a2009-08-04 16:50:30 +0000397 /// \brief Build a new constant array type given the element type, size
398 /// modifier, (known) size of the array, and index type qualifiers.
399 ///
400 /// By default, performs semantic analysis when building the array type.
401 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000402 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000403 ArrayType::ArraySizeModifier SizeMod,
404 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000405 unsigned IndexTypeQuals,
406 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000407
Douglas Gregor577f75a2009-08-04 16:50:30 +0000408 /// \brief Build a new incomplete array type given the element type, size
409 /// modifier, and index type qualifiers.
410 ///
411 /// By default, performs semantic analysis when building the array type.
412 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000413 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000414 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000415 unsigned IndexTypeQuals,
416 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000417
Mike Stump1eb44332009-09-09 15:08:12 +0000418 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000419 /// size modifier, size expression, and index type qualifiers.
420 ///
421 /// By default, performs semantic analysis when building the array type.
422 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000423 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000424 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000425 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000426 unsigned IndexTypeQuals,
427 SourceRange BracketsRange);
428
Mike Stump1eb44332009-09-09 15:08:12 +0000429 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000430 /// size modifier, size expression, and index type qualifiers.
431 ///
432 /// By default, performs semantic analysis when building the array type.
433 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000434 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000435 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000436 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000437 unsigned IndexTypeQuals,
438 SourceRange BracketsRange);
439
440 /// \brief Build a new vector type given the element type and
441 /// number of elements.
442 ///
443 /// By default, performs semantic analysis when building the vector type.
444 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000445 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Chris Lattner788b0fd2010-06-23 06:00:24 +0000446 VectorType::AltiVecSpecific AltiVecSpec);
Mike Stump1eb44332009-09-09 15:08:12 +0000447
Douglas Gregor577f75a2009-08-04 16:50:30 +0000448 /// \brief Build a new extended vector type given the element type and
449 /// number of elements.
450 ///
451 /// By default, performs semantic analysis when building the vector type.
452 /// Subclasses may override this routine to provide different behavior.
453 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
454 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000455
456 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000457 /// given the element type and number of elements.
458 ///
459 /// By default, performs semantic analysis when building the vector type.
460 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000461 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000462 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000463 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000464
Douglas Gregor577f75a2009-08-04 16:50:30 +0000465 /// \brief Build a new function type.
466 ///
467 /// By default, performs semantic analysis when building the function type.
468 /// Subclasses may override this routine to provide different behavior.
469 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000470 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000471 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000472 bool Variadic, unsigned Quals,
473 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000474
John McCalla2becad2009-10-21 00:40:46 +0000475 /// \brief Build a new unprototyped function type.
476 QualType RebuildFunctionNoProtoType(QualType ResultType);
477
John McCalled976492009-12-04 22:46:56 +0000478 /// \brief Rebuild an unresolved typename type, given the decl that
479 /// the UnresolvedUsingTypenameDecl was transformed to.
480 QualType RebuildUnresolvedUsingType(Decl *D);
481
Douglas Gregor577f75a2009-08-04 16:50:30 +0000482 /// \brief Build a new typedef type.
483 QualType RebuildTypedefType(TypedefDecl *Typedef) {
484 return SemaRef.Context.getTypeDeclType(Typedef);
485 }
486
487 /// \brief Build a new class/struct/union type.
488 QualType RebuildRecordType(RecordDecl *Record) {
489 return SemaRef.Context.getTypeDeclType(Record);
490 }
491
492 /// \brief Build a new Enum type.
493 QualType RebuildEnumType(EnumDecl *Enum) {
494 return SemaRef.Context.getTypeDeclType(Enum);
495 }
John McCall7da24312009-09-05 00:15:47 +0000496
Mike Stump1eb44332009-09-09 15:08:12 +0000497 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000498 ///
499 /// By default, performs semantic analysis when building the typeof type.
500 /// Subclasses may override this routine to provide different behavior.
John McCall9ae2f072010-08-23 23:25:46 +0000501 QualType RebuildTypeOfExprType(Expr *Underlying);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000502
Mike Stump1eb44332009-09-09 15:08:12 +0000503 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000504 ///
505 /// By default, builds a new TypeOfType with the given underlying type.
506 QualType RebuildTypeOfType(QualType Underlying);
507
Mike Stump1eb44332009-09-09 15:08:12 +0000508 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000509 ///
510 /// By default, performs semantic analysis when building the decltype type.
511 /// Subclasses may override this routine to provide different behavior.
John McCall9ae2f072010-08-23 23:25:46 +0000512 QualType RebuildDecltypeType(Expr *Underlying);
Mike Stump1eb44332009-09-09 15:08:12 +0000513
Douglas Gregor577f75a2009-08-04 16:50:30 +0000514 /// \brief Build a new template specialization type.
515 ///
516 /// By default, performs semantic analysis when building the template
517 /// specialization type. Subclasses may override this routine to provide
518 /// different behavior.
519 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000520 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000521 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000522
Douglas Gregor577f75a2009-08-04 16:50:30 +0000523 /// \brief Build a new qualified name type.
524 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000525 /// By default, builds a new ElaboratedType type from the keyword,
526 /// the nested-name-specifier and the named type.
527 /// Subclasses may override this routine to provide different behavior.
528 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
529 NestedNameSpecifier *NNS, QualType Named) {
530 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000531 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000532
533 /// \brief Build a new typename type that refers to a template-id.
534 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000535 /// By default, builds a new DependentNameType type from the
536 /// nested-name-specifier and the given type. Subclasses may override
537 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000538 QualType RebuildDependentTemplateSpecializationType(
539 ElaboratedTypeKeyword Keyword,
540 NestedNameSpecifier *NNS,
541 const IdentifierInfo *Name,
542 SourceLocation NameLoc,
543 const TemplateArgumentListInfo &Args) {
544 // Rebuild the template name.
545 // TODO: avoid TemplateName abstraction
546 TemplateName InstName =
547 getDerived().RebuildTemplateName(NNS, *Name, QualType());
548
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000549 if (InstName.isNull())
550 return QualType();
551
John McCall33500952010-06-11 00:33:02 +0000552 // If it's still dependent, make a dependent specialization.
553 if (InstName.getAsDependentTemplateName())
554 return SemaRef.Context.getDependentTemplateSpecializationType(
555 Keyword, NNS, Name, Args);
556
557 // Otherwise, make an elaborated type wrapping a non-dependent
558 // specialization.
559 QualType T =
560 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
561 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000562
Abramo Bagnara22f638a2010-08-10 13:46:45 +0000563 // NOTE: NNS is already recorded in template specialization type T.
564 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000565 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000566
567 /// \brief Build a new typename type that refers to an identifier.
568 ///
569 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000570 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000571 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000572 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000573 NestedNameSpecifier *NNS,
574 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000575 SourceLocation KeywordLoc,
576 SourceRange NNSRange,
577 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000578 CXXScopeSpec SS;
579 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000580 SS.setRange(NNSRange);
581
Douglas Gregor40336422010-03-31 22:19:08 +0000582 if (NNS->isDependent()) {
583 // If the name is still dependent, just build a new dependent name type.
584 if (!SemaRef.computeDeclContext(SS))
585 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
586 }
587
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000588 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000589 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
590 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000591
592 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
593
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000594 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000595 // into a non-dependent elaborated-type-specifier. Find the tag we're
596 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000597 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000598 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
599 if (!DC)
600 return QualType();
601
John McCall56138762010-05-27 06:40:31 +0000602 if (SemaRef.RequireCompleteDeclContext(SS, DC))
603 return QualType();
604
Douglas Gregor40336422010-03-31 22:19:08 +0000605 TagDecl *Tag = 0;
606 SemaRef.LookupQualifiedName(Result, DC);
607 switch (Result.getResultKind()) {
608 case LookupResult::NotFound:
609 case LookupResult::NotFoundInCurrentInstantiation:
610 break;
Sean Huntc3021132010-05-05 15:23:54 +0000611
Douglas Gregor40336422010-03-31 22:19:08 +0000612 case LookupResult::Found:
613 Tag = Result.getAsSingle<TagDecl>();
614 break;
Sean Huntc3021132010-05-05 15:23:54 +0000615
Douglas Gregor40336422010-03-31 22:19:08 +0000616 case LookupResult::FoundOverloaded:
617 case LookupResult::FoundUnresolvedValue:
618 llvm_unreachable("Tag lookup cannot find non-tags");
619 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000620
Douglas Gregor40336422010-03-31 22:19:08 +0000621 case LookupResult::Ambiguous:
622 // Let the LookupResult structure handle ambiguities.
623 return QualType();
624 }
625
626 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000627 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000628 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000629 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000630 return QualType();
631 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000632
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000633 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
634 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000635 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
636 return QualType();
637 }
638
639 // Build the elaborated-type-specifier type.
640 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000641 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000642 }
Mike Stump1eb44332009-09-09 15:08:12 +0000643
Douglas Gregordcee1a12009-08-06 05:28:30 +0000644 /// \brief Build a new nested-name-specifier given the prefix and an
645 /// identifier that names 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,
Douglas Gregora38c6872009-09-03 16:14:30 +0000652 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000653 QualType ObjectType,
654 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000655
656 /// \brief Build a new nested-name-specifier given the prefix and the
657 /// namespace named in the next step in the nested-name-specifier.
658 ///
659 /// By default, performs semantic analysis when building the new
660 /// nested-name-specifier. Subclasses may override this routine to provide
661 /// different behavior.
662 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
663 SourceRange Range,
664 NamespaceDecl *NS);
665
666 /// \brief Build a new nested-name-specifier given the prefix and the
667 /// type named in the next step in the nested-name-specifier.
668 ///
669 /// By default, performs semantic analysis when building the new
670 /// nested-name-specifier. Subclasses may override this routine to provide
671 /// different behavior.
672 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
673 SourceRange Range,
674 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000675 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000676
677 /// \brief Build a new template name given a nested name specifier, a flag
678 /// indicating whether the "template" keyword was provided, and the template
679 /// that the template name refers to.
680 ///
681 /// By default, builds the new template name directly. Subclasses may override
682 /// this routine to provide different behavior.
683 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
684 bool TemplateKW,
685 TemplateDecl *Template);
686
Douglas Gregord1067e52009-08-06 06:41:21 +0000687 /// \brief Build a new template name given a nested name specifier and the
688 /// name that is referred to as a template.
689 ///
690 /// By default, performs semantic analysis to determine whether the name can
691 /// be resolved to a specific template, then builds the appropriate kind of
692 /// template name. Subclasses may override this routine to provide different
693 /// behavior.
694 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000695 const IdentifierInfo &II,
696 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000697
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000698 /// \brief Build a new template name given a nested name specifier and the
699 /// overloaded operator name that is referred to as a template.
700 ///
701 /// By default, performs semantic analysis to determine whether the name can
702 /// be resolved to a specific template, then builds the appropriate kind of
703 /// template name. Subclasses may override this routine to provide different
704 /// behavior.
705 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
706 OverloadedOperatorKind Operator,
707 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000708
Douglas Gregor43959a92009-08-20 07:17:43 +0000709 /// \brief Build a new compound statement.
710 ///
711 /// By default, performs semantic analysis to build the new statement.
712 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000713 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000714 MultiStmtArg Statements,
715 SourceLocation RBraceLoc,
716 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000717 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000718 IsStmtExpr);
719 }
720
721 /// \brief Build a new case statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000725 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000726 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000727 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000728 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000729 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000730 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000731 ColonLoc);
732 }
Mike Stump1eb44332009-09-09 15:08:12 +0000733
Douglas Gregor43959a92009-08-20 07:17:43 +0000734 /// \brief Attach the body to a new case statement.
735 ///
736 /// By default, performs semantic analysis to build the new statement.
737 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000738 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000739 getSema().ActOnCaseStmtBody(S, Body);
740 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000741 }
Mike Stump1eb44332009-09-09 15:08:12 +0000742
Douglas Gregor43959a92009-08-20 07:17:43 +0000743 /// \brief Build a new default statement.
744 ///
745 /// By default, performs semantic analysis to build the new statement.
746 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000747 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000748 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000749 Stmt *SubStmt) {
750 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000751 /*CurScope=*/0);
752 }
Mike Stump1eb44332009-09-09 15:08:12 +0000753
Douglas Gregor43959a92009-08-20 07:17:43 +0000754 /// \brief Build a new label statement.
755 ///
756 /// By default, performs semantic analysis to build the new statement.
757 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000758 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000759 IdentifierInfo *Id,
760 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000761 Stmt *SubStmt) {
762 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt);
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 Build a new "if" statement.
766 ///
767 /// By default, performs semantic analysis to build the new statement.
768 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000769 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCall9ae2f072010-08-23 23:25:46 +0000770 VarDecl *CondVar, Stmt *Then,
771 SourceLocation ElseLoc, Stmt *Else) {
772 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000773 }
Mike Stump1eb44332009-09-09 15:08:12 +0000774
Douglas Gregor43959a92009-08-20 07:17:43 +0000775 /// \brief Start building a new switch statement.
776 ///
777 /// By default, performs semantic analysis to build the new statement.
778 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000779 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000780 Expr *Cond, VarDecl *CondVar) {
781 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +0000782 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +0000783 }
Mike Stump1eb44332009-09-09 15:08:12 +0000784
Douglas Gregor43959a92009-08-20 07:17:43 +0000785 /// \brief Attach the body to the switch statement.
786 ///
787 /// By default, performs semantic analysis to build the new statement.
788 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000789 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000790 Stmt *Switch, Stmt *Body) {
791 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000792 }
793
794 /// \brief Build a new while statement.
795 ///
796 /// By default, performs semantic analysis to build the new statement.
797 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000798 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000799 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000800 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000801 Stmt *Body) {
802 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000803 }
Mike Stump1eb44332009-09-09 15:08:12 +0000804
Douglas Gregor43959a92009-08-20 07:17:43 +0000805 /// \brief Build a new do-while statement.
806 ///
807 /// By default, performs semantic analysis to build the new statement.
808 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000809 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregor43959a92009-08-20 07:17:43 +0000810 SourceLocation WhileLoc,
811 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000812 Expr *Cond,
Douglas Gregor43959a92009-08-20 07:17:43 +0000813 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000814 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
815 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +0000816 }
817
818 /// \brief Build a new for statement.
819 ///
820 /// By default, performs semantic analysis to build the new statement.
821 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000822 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000823 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000824 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000825 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCall9ae2f072010-08-23 23:25:46 +0000826 SourceLocation RParenLoc, Stmt *Body) {
827 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCalld226f652010-08-21 09:40:31 +0000828 CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000829 Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000830 }
Mike Stump1eb44332009-09-09 15:08:12 +0000831
Douglas Gregor43959a92009-08-20 07:17:43 +0000832 /// \brief Build a new goto statement.
833 ///
834 /// By default, performs semantic analysis to build the new statement.
835 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000836 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000837 SourceLocation LabelLoc,
838 LabelStmt *Label) {
839 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
840 }
841
842 /// \brief Build a new indirect goto statement.
843 ///
844 /// By default, performs semantic analysis to build the new statement.
845 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000846 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000847 SourceLocation StarLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000848 Expr *Target) {
849 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +0000850 }
Mike Stump1eb44332009-09-09 15:08:12 +0000851
Douglas Gregor43959a92009-08-20 07:17:43 +0000852 /// \brief Build a new return statement.
853 ///
854 /// By default, performs semantic analysis to build the new statement.
855 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000856 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000857 Expr *Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000858
John McCall9ae2f072010-08-23 23:25:46 +0000859 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +0000860 }
Mike Stump1eb44332009-09-09 15:08:12 +0000861
Douglas Gregor43959a92009-08-20 07:17:43 +0000862 /// \brief Build a new declaration statement.
863 ///
864 /// By default, performs semantic analysis to build the new statement.
865 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000866 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000867 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000868 SourceLocation EndLoc) {
869 return getSema().Owned(
870 new (getSema().Context) DeclStmt(
871 DeclGroupRef::Create(getSema().Context,
872 Decls, NumDecls),
873 StartLoc, EndLoc));
874 }
Mike Stump1eb44332009-09-09 15:08:12 +0000875
Anders Carlsson703e3942010-01-24 05:50:09 +0000876 /// \brief Build a new inline asm statement.
877 ///
878 /// By default, performs semantic analysis to build the new statement.
879 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000880 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +0000881 bool IsSimple,
882 bool IsVolatile,
883 unsigned NumOutputs,
884 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000885 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000886 MultiExprArg Constraints,
887 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +0000888 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +0000889 MultiExprArg Clobbers,
890 SourceLocation RParenLoc,
891 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000892 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000893 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +0000894 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +0000895 RParenLoc, MSAsm);
896 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000897
898 /// \brief Build a new Objective-C @try statement.
899 ///
900 /// By default, performs semantic analysis to build the new statement.
901 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000902 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000903 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000904 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +0000905 Stmt *Finally) {
906 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
907 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000908 }
909
Douglas Gregorbe270a02010-04-26 17:57:08 +0000910 /// \brief Rebuild an Objective-C exception declaration.
911 ///
912 /// By default, performs semantic analysis to build the new declaration.
913 /// Subclasses may override this routine to provide different behavior.
914 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
915 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +0000916 return getSema().BuildObjCExceptionDecl(TInfo, T,
917 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +0000918 ExceptionDecl->getLocation());
919 }
Sean Huntc3021132010-05-05 15:23:54 +0000920
Douglas Gregorbe270a02010-04-26 17:57:08 +0000921 /// \brief Build a new Objective-C @catch statement.
922 ///
923 /// By default, performs semantic analysis to build the new statement.
924 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000925 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +0000926 SourceLocation RParenLoc,
927 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +0000928 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +0000929 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000930 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +0000931 }
Sean Huntc3021132010-05-05 15:23:54 +0000932
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000933 /// \brief Build a new Objective-C @finally statement.
934 ///
935 /// By default, performs semantic analysis to build the new statement.
936 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000937 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000938 Stmt *Body) {
939 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000940 }
Sean Huntc3021132010-05-05 15:23:54 +0000941
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000942 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +0000943 ///
944 /// By default, performs semantic analysis to build the new statement.
945 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000946 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000947 Expr *Operand) {
948 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +0000949 }
Sean Huntc3021132010-05-05 15:23:54 +0000950
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000951 /// \brief Build a new Objective-C @synchronized statement.
952 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000953 /// By default, performs semantic analysis to build the new statement.
954 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000955 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000956 Expr *Object,
957 Stmt *Body) {
958 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
959 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000960 }
Douglas Gregorc3203e72010-04-22 23:10:45 +0000961
962 /// \brief Build a new Objective-C fast enumeration statement.
963 ///
964 /// By default, performs semantic analysis to build the new statement.
965 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000966 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
Douglas Gregorc3203e72010-04-22 23:10:45 +0000967 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000968 Stmt *Element,
969 Expr *Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +0000970 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000971 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +0000972 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000973 Element,
974 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +0000975 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000976 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +0000977 }
Sean Huntc3021132010-05-05 15:23:54 +0000978
Douglas Gregor43959a92009-08-20 07:17:43 +0000979 /// \brief Build a new C++ exception declaration.
980 ///
981 /// By default, performs semantic analysis to build the new decaration.
982 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000983 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000984 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000985 IdentifierInfo *Name,
986 SourceLocation Loc,
987 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000988 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000989 TypeRange);
990 }
991
992 /// \brief Build a new C++ catch statement.
993 ///
994 /// By default, performs semantic analysis to build the new statement.
995 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000996 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000997 VarDecl *ExceptionDecl,
John McCall9ae2f072010-08-23 23:25:46 +0000998 Stmt *Handler) {
999 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1000 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001001 }
Mike Stump1eb44332009-09-09 15:08:12 +00001002
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 /// \brief Build a new C++ try statement.
1004 ///
1005 /// By default, performs semantic analysis to build the new statement.
1006 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001007 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001008 Stmt *TryBlock,
Douglas Gregor43959a92009-08-20 07:17:43 +00001009 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001010 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001011 }
Mike Stump1eb44332009-09-09 15:08:12 +00001012
Douglas Gregorb98b1992009-08-11 05:31:07 +00001013 /// \brief Build a new expression that references a declaration.
1014 ///
1015 /// By default, performs semantic analysis to build the new expression.
1016 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001017 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001018 LookupResult &R,
1019 bool RequiresADL) {
1020 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1021 }
1022
1023
1024 /// \brief Build a new expression that references a declaration.
1025 ///
1026 /// By default, performs semantic analysis to build the new expression.
1027 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001028 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
Douglas Gregora2813ce2009-10-23 18:54:35 +00001029 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001030 ValueDecl *VD,
1031 const DeclarationNameInfo &NameInfo,
John McCalldbd872f2009-12-08 09:08:17 +00001032 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001033 CXXScopeSpec SS;
1034 SS.setScopeRep(Qualifier);
1035 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001036
1037 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001038
1039 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001040 }
Mike Stump1eb44332009-09-09 15:08:12 +00001041
Douglas Gregorb98b1992009-08-11 05:31:07 +00001042 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001043 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001044 /// By default, performs semantic analysis to build the new expression.
1045 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001046 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001047 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001048 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001049 }
1050
Douglas Gregora71d8192009-09-04 17:36:40 +00001051 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001052 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001053 /// By default, performs semantic analysis to build the new expression.
1054 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001055 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001056 SourceLocation OperatorLoc,
1057 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001058 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001059 SourceRange QualifierRange,
1060 TypeSourceInfo *ScopeType,
1061 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001062 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001063 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001064
Douglas Gregorb98b1992009-08-11 05:31:07 +00001065 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001066 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001067 /// By default, performs semantic analysis to build the new expression.
1068 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001069 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001070 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001071 Expr *SubExpr) {
1072 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001073 }
Mike Stump1eb44332009-09-09 15:08:12 +00001074
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001075 /// \brief Build a new builtin offsetof expression.
1076 ///
1077 /// By default, performs semantic analysis to build the new expression.
1078 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001079 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001080 TypeSourceInfo *Type,
1081 Action::OffsetOfComponent *Components,
1082 unsigned NumComponents,
1083 SourceLocation RParenLoc) {
1084 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1085 NumComponents, RParenLoc);
1086 }
Sean Huntc3021132010-05-05 15:23:54 +00001087
Douglas Gregorb98b1992009-08-11 05:31:07 +00001088 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001089 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001090 /// By default, performs semantic analysis to build the new expression.
1091 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001092 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001093 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001094 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001095 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001096 }
1097
Mike Stump1eb44332009-09-09 15:08:12 +00001098 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001099 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001100 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001101 /// By default, performs semantic analysis to build the new expression.
1102 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001103 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001104 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001105 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001106 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001107 if (Result.isInvalid())
1108 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001109
Douglas Gregorb98b1992009-08-11 05:31:07 +00001110 return move(Result);
1111 }
Mike Stump1eb44332009-09-09 15:08:12 +00001112
Douglas Gregorb98b1992009-08-11 05:31:07 +00001113 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001114 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001115 /// By default, performs semantic analysis to build the new expression.
1116 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001117 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001118 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001119 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001120 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001121 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1122 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001123 RBracketLoc);
1124 }
1125
1126 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001127 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001128 /// By default, performs semantic analysis to build the new expression.
1129 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001130 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001131 MultiExprArg Args,
1132 SourceLocation *CommaLocs,
1133 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001134 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001135 move(Args), CommaLocs, RParenLoc);
1136 }
1137
1138 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001139 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001140 /// By default, performs semantic analysis to build the new expression.
1141 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001142 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001143 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001144 NestedNameSpecifier *Qualifier,
1145 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001146 const DeclarationNameInfo &MemberNameInfo,
Eli Friedmanf595cc42009-12-04 06:40:45 +00001147 ValueDecl *Member,
John McCall6bb80172010-03-30 21:47:33 +00001148 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001149 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +00001150 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001151 if (!Member->getDeclName()) {
1152 // We have a reference to an unnamed field.
1153 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +00001154
John McCall9ae2f072010-08-23 23:25:46 +00001155 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001156 FoundDecl, Member))
Douglas Gregor83a56c42009-12-24 20:02:50 +00001157 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001158
Mike Stump1eb44332009-09-09 15:08:12 +00001159 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001160 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001161 Member, MemberNameInfo,
Anders Carlssond8b285f2009-09-01 04:26:58 +00001162 cast<FieldDecl>(Member)->getType());
1163 return getSema().Owned(ME);
1164 }
Mike Stump1eb44332009-09-09 15:08:12 +00001165
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001166 CXXScopeSpec SS;
1167 if (Qualifier) {
1168 SS.setRange(QualifierRange);
1169 SS.setScopeRep(Qualifier);
1170 }
1171
John McCall9ae2f072010-08-23 23:25:46 +00001172 getSema().DefaultFunctionArrayConversion(Base);
1173 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001174
John McCall6bb80172010-03-30 21:47:33 +00001175 // FIXME: this involves duplicating earlier analysis in a lot of
1176 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001177 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001178 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001179 R.resolveKind();
1180
John McCall9ae2f072010-08-23 23:25:46 +00001181 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001182 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001183 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001184 }
Mike Stump1eb44332009-09-09 15:08:12 +00001185
Douglas Gregorb98b1992009-08-11 05:31:07 +00001186 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001187 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001188 /// By default, performs semantic analysis to build the new expression.
1189 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001190 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001191 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001192 Expr *LHS, Expr *RHS) {
1193 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001194 }
1195
1196 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001197 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001198 /// By default, performs semantic analysis to build the new expression.
1199 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001200 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001201 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001202 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001203 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001204 Expr *RHS) {
1205 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1206 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001207 }
1208
Douglas Gregorb98b1992009-08-11 05:31:07 +00001209 /// \brief Build a new C-style cast 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.
John McCall60d7b3a2010-08-24 06:29:42 +00001213 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001214 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001215 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001216 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001217 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001218 SubExpr);
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 compound literal 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.
John McCall60d7b3a2010-08-24 06:29:42 +00001225 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001226 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001227 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001228 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001229 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001230 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001231 }
Mike Stump1eb44332009-09-09 15:08:12 +00001232
Douglas Gregorb98b1992009-08-11 05:31:07 +00001233 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001234 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001235 /// By default, performs semantic analysis to build the new expression.
1236 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001237 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001238 SourceLocation OpLoc,
1239 SourceLocation AccessorLoc,
1240 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001241
John McCall129e2df2009-11-30 22:42:35 +00001242 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001243 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001244 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001245 OpLoc, /*IsArrow*/ false,
1246 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001247 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001248 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001249 }
Mike Stump1eb44332009-09-09 15:08:12 +00001250
Douglas Gregorb98b1992009-08-11 05:31:07 +00001251 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001252 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001253 /// By default, performs semantic analysis to build the new expression.
1254 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001255 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001256 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001257 SourceLocation RBraceLoc,
1258 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001259 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001260 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1261 if (Result.isInvalid() || ResultTy->isDependentType())
1262 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001263
Douglas Gregore48319a2009-11-09 17:16:50 +00001264 // Patch in the result type we were given, which may have been computed
1265 // when the initial InitListExpr was built.
1266 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1267 ILE->setType(ResultTy);
1268 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001269 }
Mike Stump1eb44332009-09-09 15:08:12 +00001270
Douglas Gregorb98b1992009-08-11 05:31:07 +00001271 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001272 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001273 /// By default, performs semantic analysis to build the new expression.
1274 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001275 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001276 MultiExprArg ArrayExprs,
1277 SourceLocation EqualOrColonLoc,
1278 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001279 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001280 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001281 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001282 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001283 if (Result.isInvalid())
1284 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001285
Douglas Gregorb98b1992009-08-11 05:31:07 +00001286 ArrayExprs.release();
1287 return move(Result);
1288 }
Mike Stump1eb44332009-09-09 15:08:12 +00001289
Douglas Gregorb98b1992009-08-11 05:31:07 +00001290 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001291 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001292 /// By default, builds the implicit value initialization without performing
1293 /// any semantic analysis. Subclasses may override this routine to provide
1294 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001295 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001296 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1297 }
Mike Stump1eb44332009-09-09 15:08:12 +00001298
Douglas Gregorb98b1992009-08-11 05:31:07 +00001299 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001300 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001301 /// By default, performs semantic analysis to build the new expression.
1302 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001303 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001304 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001305 SourceLocation RParenLoc) {
1306 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001307 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001308 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001309 }
1310
1311 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001312 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001313 /// By default, performs semantic analysis to build the new expression.
1314 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001315 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001316 MultiExprArg SubExprs,
1317 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001318 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001319 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001320 }
Mike Stump1eb44332009-09-09 15:08:12 +00001321
Douglas Gregorb98b1992009-08-11 05:31:07 +00001322 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001323 ///
1324 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001325 /// rather than attempting to map the label statement itself.
1326 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001327 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001328 SourceLocation LabelLoc,
1329 LabelStmt *Label) {
1330 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1331 }
Mike Stump1eb44332009-09-09 15:08:12 +00001332
Douglas Gregorb98b1992009-08-11 05:31:07 +00001333 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001334 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001335 /// By default, performs semantic analysis to build the new expression.
1336 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001337 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001338 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001339 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001340 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001341 }
Mike Stump1eb44332009-09-09 15:08:12 +00001342
Douglas Gregorb98b1992009-08-11 05:31:07 +00001343 /// \brief Build a new __builtin_types_compatible_p expression.
1344 ///
1345 /// By default, performs semantic analysis to build the new expression.
1346 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001347 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001348 TypeSourceInfo *TInfo1,
1349 TypeSourceInfo *TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001350 SourceLocation RParenLoc) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001351 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1352 TInfo1, TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001353 RParenLoc);
1354 }
Mike Stump1eb44332009-09-09 15:08:12 +00001355
Douglas Gregorb98b1992009-08-11 05:31:07 +00001356 /// \brief Build a new __builtin_choose_expr expression.
1357 ///
1358 /// By default, performs semantic analysis to build the new expression.
1359 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001360 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001361 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001362 SourceLocation RParenLoc) {
1363 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001364 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001365 RParenLoc);
1366 }
Mike Stump1eb44332009-09-09 15:08:12 +00001367
Douglas Gregorb98b1992009-08-11 05:31:07 +00001368 /// \brief Build a new overloaded operator call expression.
1369 ///
1370 /// By default, performs semantic analysis to build the new expression.
1371 /// The semantic analysis provides the behavior of template instantiation,
1372 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001373 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001374 /// argument-dependent lookup, etc. Subclasses may override this routine to
1375 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001376 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001377 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001378 Expr *Callee,
1379 Expr *First,
1380 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001381
1382 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001383 /// reinterpret_cast.
1384 ///
1385 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001386 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001387 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001388 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001389 Stmt::StmtClass Class,
1390 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001391 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001392 SourceLocation RAngleLoc,
1393 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001394 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001395 SourceLocation RParenLoc) {
1396 switch (Class) {
1397 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001398 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001399 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001400 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001401
1402 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001403 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001404 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001405 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001406
Douglas Gregorb98b1992009-08-11 05:31:07 +00001407 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001408 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001409 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001410 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001411 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001412
Douglas Gregorb98b1992009-08-11 05:31:07 +00001413 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001414 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001415 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001416 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001417
Douglas Gregorb98b1992009-08-11 05:31:07 +00001418 default:
1419 assert(false && "Invalid C++ named cast");
1420 break;
1421 }
Mike Stump1eb44332009-09-09 15:08:12 +00001422
Douglas Gregorb98b1992009-08-11 05:31:07 +00001423 return getSema().ExprError();
1424 }
Mike Stump1eb44332009-09-09 15:08:12 +00001425
Douglas Gregorb98b1992009-08-11 05:31:07 +00001426 /// \brief Build a new C++ static_cast expression.
1427 ///
1428 /// By default, performs semantic analysis to build the new expression.
1429 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001430 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001432 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001433 SourceLocation RAngleLoc,
1434 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001435 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001437 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001438 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001439 SourceRange(LAngleLoc, RAngleLoc),
1440 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001441 }
1442
1443 /// \brief Build a new C++ dynamic_cast expression.
1444 ///
1445 /// By default, performs semantic analysis to build the new expression.
1446 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001447 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001448 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001449 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 SourceLocation RAngleLoc,
1451 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001452 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001453 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001454 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001455 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001456 SourceRange(LAngleLoc, RAngleLoc),
1457 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001458 }
1459
1460 /// \brief Build a new C++ reinterpret_cast expression.
1461 ///
1462 /// By default, performs semantic analysis to build the new expression.
1463 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001464 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001465 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001466 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 SourceLocation RAngleLoc,
1468 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001469 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001471 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001472 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001473 SourceRange(LAngleLoc, RAngleLoc),
1474 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 }
1476
1477 /// \brief Build a new C++ const_cast expression.
1478 ///
1479 /// By default, performs semantic analysis to build the new expression.
1480 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001481 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001483 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 SourceLocation RAngleLoc,
1485 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001486 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001488 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001489 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001490 SourceRange(LAngleLoc, RAngleLoc),
1491 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 }
Mike Stump1eb44332009-09-09 15:08:12 +00001493
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 /// \brief Build a new C++ functional-style cast expression.
1495 ///
1496 /// By default, performs semantic analysis to build the new expression.
1497 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001498 ExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001499 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001501 Expr *Sub,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCallb3d87482010-08-24 05:47:05 +00001504 ParsedType::make(TInfo->getType()),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001506 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001507 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001508 RParenLoc);
1509 }
Mike Stump1eb44332009-09-09 15:08:12 +00001510
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 /// \brief Build a new C++ typeid(type) expression.
1512 ///
1513 /// By default, performs semantic analysis to build the new expression.
1514 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001515 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001516 SourceLocation TypeidLoc,
1517 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001519 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001520 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001521 }
Mike Stump1eb44332009-09-09 15:08:12 +00001522
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 /// \brief Build a new C++ typeid(expr) expression.
1524 ///
1525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001527 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001528 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001529 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001530 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001531 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001532 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001533 }
1534
Douglas Gregorb98b1992009-08-11 05:31:07 +00001535 /// \brief Build a new C++ "this" expression.
1536 ///
1537 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001538 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001539 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001540 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001541 QualType ThisType,
1542 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001543 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001544 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1545 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001546 }
1547
1548 /// \brief Build a new C++ throw expression.
1549 ///
1550 /// By default, performs semantic analysis to build the new expression.
1551 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001552 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001553 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001554 }
1555
1556 /// \brief Build a new C++ default-argument expression.
1557 ///
1558 /// By default, builds a new default-argument expression, which does not
1559 /// require any semantic analysis. Subclasses may override this routine to
1560 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001561 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001562 ParmVarDecl *Param) {
1563 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1564 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 }
1566
1567 /// \brief Build a new C++ zero-initialization expression.
1568 ///
1569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001571 ExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001572 SourceLocation LParenLoc,
1573 QualType T,
1574 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001575 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
John McCallb3d87482010-08-24 05:47:05 +00001576 ParsedType::make(T), LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001577 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 0, RParenLoc);
1579 }
Mike Stump1eb44332009-09-09 15:08:12 +00001580
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 /// \brief Build a new C++ "new" expression.
1582 ///
1583 /// By default, performs semantic analysis to build the new expression.
1584 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001585 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 bool UseGlobal,
1587 SourceLocation PlacementLParen,
1588 MultiExprArg PlacementArgs,
1589 SourceLocation PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001590 SourceRange TypeIdParens,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 QualType AllocType,
1592 SourceLocation TypeLoc,
1593 SourceRange TypeRange,
John McCall9ae2f072010-08-23 23:25:46 +00001594 Expr *ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 SourceLocation ConstructorLParen,
1596 MultiExprArg ConstructorArgs,
1597 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001598 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 PlacementLParen,
1600 move(PlacementArgs),
1601 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001602 TypeIdParens,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 AllocType,
1604 TypeLoc,
1605 TypeRange,
John McCall9ae2f072010-08-23 23:25:46 +00001606 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 ConstructorLParen,
1608 move(ConstructorArgs),
1609 ConstructorRParen);
1610 }
Mike Stump1eb44332009-09-09 15:08:12 +00001611
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 /// \brief Build a new C++ "delete" expression.
1613 ///
1614 /// By default, performs semantic analysis to build the new expression.
1615 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001616 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 bool IsGlobalDelete,
1618 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001619 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001621 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 }
Mike Stump1eb44332009-09-09 15:08:12 +00001623
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 /// \brief Build a new unary type trait expression.
1625 ///
1626 /// By default, performs semantic analysis to build the new expression.
1627 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001628 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 SourceLocation StartLoc,
1630 SourceLocation LParenLoc,
1631 QualType T,
1632 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001633 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
John McCallb3d87482010-08-24 05:47:05 +00001634 ParsedType::make(T), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 }
1636
Mike Stump1eb44332009-09-09 15:08:12 +00001637 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001638 /// expression.
1639 ///
1640 /// By default, performs semantic analysis to build the new expression.
1641 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001642 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001643 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001644 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001645 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 CXXScopeSpec SS;
1647 SS.setRange(QualifierRange);
1648 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001649
1650 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001651 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001652 *TemplateArgs);
1653
Abramo Bagnara25777432010-08-11 22:01:17 +00001654 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 }
1656
1657 /// \brief Build a new template-id expression.
1658 ///
1659 /// By default, performs semantic analysis to build the new expression.
1660 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001661 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001662 LookupResult &R,
1663 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001664 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001665 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 }
1667
1668 /// \brief Build a new object-construction expression.
1669 ///
1670 /// By default, performs semantic analysis to build the new expression.
1671 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001672 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001673 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001674 CXXConstructorDecl *Constructor,
1675 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001676 MultiExprArg Args,
1677 bool RequiresZeroInit,
1678 CXXConstructExpr::ConstructionKind ConstructKind) {
John McCallca0408f2010-08-23 06:44:23 +00001679 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001680 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001681 ConvertedArgs))
1682 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001683
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001684 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001685 move_arg(ConvertedArgs),
1686 RequiresZeroInit, ConstructKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 }
1688
1689 /// \brief Build a new object-construction expression.
1690 ///
1691 /// By default, performs semantic analysis to build the new expression.
1692 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001693 ExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 QualType T,
1695 SourceLocation LParenLoc,
1696 MultiExprArg Args,
1697 SourceLocation *Commas,
1698 SourceLocation RParenLoc) {
1699 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
John McCallb3d87482010-08-24 05:47:05 +00001700 ParsedType::make(T),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 LParenLoc,
1702 move(Args),
1703 Commas,
1704 RParenLoc);
1705 }
1706
1707 /// \brief Build a new object-construction expression.
1708 ///
1709 /// By default, performs semantic analysis to build the new expression.
1710 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001711 ExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 QualType T,
1713 SourceLocation LParenLoc,
1714 MultiExprArg Args,
1715 SourceLocation *Commas,
1716 SourceLocation RParenLoc) {
1717 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1718 /*FIXME*/LParenLoc),
John McCallb3d87482010-08-24 05:47:05 +00001719 ParsedType::make(T),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001720 LParenLoc,
1721 move(Args),
1722 Commas,
1723 RParenLoc);
1724 }
Mike Stump1eb44332009-09-09 15:08:12 +00001725
Douglas Gregorb98b1992009-08-11 05:31:07 +00001726 /// \brief Build a new member reference expression.
1727 ///
1728 /// By default, performs semantic analysis to build the new expression.
1729 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001730 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001731 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 bool IsArrow,
1733 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001734 NestedNameSpecifier *Qualifier,
1735 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001736 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001737 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001738 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001739 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001740 SS.setRange(QualifierRange);
1741 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001742
John McCall9ae2f072010-08-23 23:25:46 +00001743 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001744 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001745 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001746 MemberNameInfo,
1747 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 }
1749
John McCall129e2df2009-11-30 22:42:35 +00001750 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001751 ///
1752 /// By default, performs semantic analysis to build the new expression.
1753 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001754 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001755 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001756 SourceLocation OperatorLoc,
1757 bool IsArrow,
1758 NestedNameSpecifier *Qualifier,
1759 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001760 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001761 LookupResult &R,
1762 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001763 CXXScopeSpec SS;
1764 SS.setRange(QualifierRange);
1765 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001766
John McCall9ae2f072010-08-23 23:25:46 +00001767 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001768 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001769 SS, FirstQualifierInScope,
1770 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001771 }
Mike Stump1eb44332009-09-09 15:08:12 +00001772
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 /// \brief Build a new Objective-C @encode expression.
1774 ///
1775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001777 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001778 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001780 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001782 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783
Douglas Gregor92e986e2010-04-22 16:44:27 +00001784 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00001785 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001786 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 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1792 ReceiverTypeInfo->getType(),
1793 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001794 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001795 move(Args));
1796 }
1797
1798 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00001799 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001800 Selector Sel,
1801 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001802 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001803 MultiExprArg Args,
1804 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001805 return SemaRef.BuildInstanceMessage(Receiver,
1806 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00001807 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001808 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001809 move(Args));
1810 }
1811
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001812 /// \brief Build a new Objective-C ivar reference expression.
1813 ///
1814 /// By default, performs semantic analysis to build the new expression.
1815 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001816 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001817 SourceLocation IvarLoc,
1818 bool IsArrow, bool IsFreeIvar) {
1819 // FIXME: We lose track of the IsFreeIvar bit.
1820 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001821 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001822 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1823 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001824 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001825 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00001826 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00001827 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001828 if (Result.isInvalid())
1829 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001830
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001831 if (Result.get())
1832 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001833
John McCall9ae2f072010-08-23 23:25:46 +00001834 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001835 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001836 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001837 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001838 /*TemplateArgs=*/0);
1839 }
Douglas Gregore3303542010-04-26 20:47:02 +00001840
1841 /// \brief Build a new Objective-C property reference expression.
1842 ///
1843 /// By default, performs semantic analysis to build the new expression.
1844 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001845 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001846 ObjCPropertyDecl *Property,
1847 SourceLocation PropertyLoc) {
1848 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001849 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00001850 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1851 Sema::LookupMemberName);
1852 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00001853 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00001854 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00001855 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00001856 if (Result.isInvalid())
1857 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001858
Douglas Gregore3303542010-04-26 20:47:02 +00001859 if (Result.get())
1860 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001861
John McCall9ae2f072010-08-23 23:25:46 +00001862 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001863 /*FIXME:*/PropertyLoc, IsArrow,
1864 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001865 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001866 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001867 /*TemplateArgs=*/0);
1868 }
Sean Huntc3021132010-05-05 15:23:54 +00001869
1870 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001871 /// expression.
1872 ///
1873 /// By default, performs semantic analysis to build the new expression.
Sean Huntc3021132010-05-05 15:23:54 +00001874 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001875 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001876 ObjCMethodDecl *Getter,
1877 QualType T,
1878 ObjCMethodDecl *Setter,
1879 SourceLocation NameLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001880 Expr *Base) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001881 // Since these expressions can only be value-dependent, we do not need to
1882 // perform semantic analysis again.
John McCall9ae2f072010-08-23 23:25:46 +00001883 return Owned(
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001884 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1885 Setter,
1886 NameLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001887 Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001888 }
1889
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001890 /// \brief Build a new Objective-C "isa" expression.
1891 ///
1892 /// By default, performs semantic analysis to build the new expression.
1893 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001894 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001895 bool IsArrow) {
1896 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001897 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001898 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1899 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001900 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001901 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00001902 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001903 if (Result.isInvalid())
1904 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001905
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001906 if (Result.get())
1907 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001908
John McCall9ae2f072010-08-23 23:25:46 +00001909 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001910 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001911 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001912 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001913 /*TemplateArgs=*/0);
1914 }
Sean Huntc3021132010-05-05 15:23:54 +00001915
Douglas Gregorb98b1992009-08-11 05:31:07 +00001916 /// \brief Build a new shuffle vector expression.
1917 ///
1918 /// By default, performs semantic analysis to build the new expression.
1919 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001920 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001921 MultiExprArg SubExprs,
1922 SourceLocation RParenLoc) {
1923 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001924 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001925 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1926 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1927 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1928 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001929
Douglas Gregorb98b1992009-08-11 05:31:07 +00001930 // Build a reference to the __builtin_shufflevector builtin
1931 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001932 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001933 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001934 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001936
1937 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 unsigned NumSubExprs = SubExprs.size();
1939 Expr **Subs = (Expr **)SubExprs.release();
1940 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1941 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00001942 Builtin->getCallResultType(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00001944 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001945
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00001947 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001948 if (Result.isInvalid())
1949 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001950
Douglas Gregorb98b1992009-08-11 05:31:07 +00001951 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001952 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001953 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001954};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001955
Douglas Gregor43959a92009-08-20 07:17:43 +00001956template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00001957StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00001958 if (!S)
1959 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001960
Douglas Gregor43959a92009-08-20 07:17:43 +00001961 switch (S->getStmtClass()) {
1962 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001963
Douglas Gregor43959a92009-08-20 07:17:43 +00001964 // Transform individual statement nodes
1965#define STMT(Node, Parent) \
1966 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1967#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00001968#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001969
Douglas Gregor43959a92009-08-20 07:17:43 +00001970 // Transform expressions by calling TransformExpr.
1971#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00001972#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00001973#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00001974#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00001975 {
John McCall60d7b3a2010-08-24 06:29:42 +00001976 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00001977 if (E.isInvalid())
1978 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001979
John McCall9ae2f072010-08-23 23:25:46 +00001980 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00001981 }
Mike Stump1eb44332009-09-09 15:08:12 +00001982 }
1983
Douglas Gregor43959a92009-08-20 07:17:43 +00001984 return SemaRef.Owned(S->Retain());
1985}
Mike Stump1eb44332009-09-09 15:08:12 +00001986
1987
Douglas Gregor670444e2009-08-04 22:27:00 +00001988template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00001989ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001990 if (!E)
1991 return SemaRef.Owned(E);
1992
1993 switch (E->getStmtClass()) {
1994 case Stmt::NoStmtClass: break;
1995#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00001996#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00001997#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00001998 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00001999#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002000 }
2001
Douglas Gregorb98b1992009-08-11 05:31:07 +00002002 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002003}
2004
2005template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002006NestedNameSpecifier *
2007TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002008 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002009 QualType ObjectType,
2010 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00002011 if (!NNS)
2012 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002013
Douglas Gregor43959a92009-08-20 07:17:43 +00002014 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002015 NestedNameSpecifier *Prefix = NNS->getPrefix();
2016 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002017 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002018 ObjectType,
2019 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002020 if (!Prefix)
2021 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002022
2023 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00002024 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00002025 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00002026 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002027 }
Mike Stump1eb44332009-09-09 15:08:12 +00002028
Douglas Gregordcee1a12009-08-06 05:28:30 +00002029 switch (NNS->getKind()) {
2030 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00002031 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002032 "Identifier nested-name-specifier with no prefix or object type");
2033 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2034 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002035 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002036
2037 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002038 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002039 ObjectType,
2040 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002041
Douglas Gregordcee1a12009-08-06 05:28:30 +00002042 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002043 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002044 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002045 getDerived().TransformDecl(Range.getBegin(),
2046 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002047 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002048 Prefix == NNS->getPrefix() &&
2049 NS == NNS->getAsNamespace())
2050 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002051
Douglas Gregordcee1a12009-08-06 05:28:30 +00002052 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2053 }
Mike Stump1eb44332009-09-09 15:08:12 +00002054
Douglas Gregordcee1a12009-08-06 05:28:30 +00002055 case NestedNameSpecifier::Global:
2056 // There is no meaningful transformation that one could perform on the
2057 // global scope.
2058 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002059
Douglas Gregordcee1a12009-08-06 05:28:30 +00002060 case NestedNameSpecifier::TypeSpecWithTemplate:
2061 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002062 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00002063 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2064 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002065 if (T.isNull())
2066 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002067
Douglas Gregordcee1a12009-08-06 05:28:30 +00002068 if (!getDerived().AlwaysRebuild() &&
2069 Prefix == NNS->getPrefix() &&
2070 T == QualType(NNS->getAsType(), 0))
2071 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002072
2073 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2074 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002075 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002076 }
2077 }
Mike Stump1eb44332009-09-09 15:08:12 +00002078
Douglas Gregordcee1a12009-08-06 05:28:30 +00002079 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002080 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002081}
2082
2083template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002084DeclarationNameInfo
2085TreeTransform<Derived>
2086::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2087 QualType ObjectType) {
2088 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002089 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002090 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002091
2092 switch (Name.getNameKind()) {
2093 case DeclarationName::Identifier:
2094 case DeclarationName::ObjCZeroArgSelector:
2095 case DeclarationName::ObjCOneArgSelector:
2096 case DeclarationName::ObjCMultiArgSelector:
2097 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002098 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002099 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002100 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002101
Douglas Gregor81499bb2009-09-03 22:13:48 +00002102 case DeclarationName::CXXConstructorName:
2103 case DeclarationName::CXXDestructorName:
2104 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002105 TypeSourceInfo *NewTInfo;
2106 CanQualType NewCanTy;
2107 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2108 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2109 if (!NewTInfo)
2110 return DeclarationNameInfo();
2111 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2112 }
2113 else {
2114 NewTInfo = 0;
2115 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2116 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2117 ObjectType);
2118 if (NewT.isNull())
2119 return DeclarationNameInfo();
2120 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2121 }
Mike Stump1eb44332009-09-09 15:08:12 +00002122
Abramo Bagnara25777432010-08-11 22:01:17 +00002123 DeclarationName NewName
2124 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2125 NewCanTy);
2126 DeclarationNameInfo NewNameInfo(NameInfo);
2127 NewNameInfo.setName(NewName);
2128 NewNameInfo.setNamedTypeInfo(NewTInfo);
2129 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002130 }
Mike Stump1eb44332009-09-09 15:08:12 +00002131 }
2132
Abramo Bagnara25777432010-08-11 22:01:17 +00002133 assert(0 && "Unknown name kind.");
2134 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002135}
2136
2137template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002138TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002139TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2140 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002141 SourceLocation Loc = getDerived().getBaseLocation();
2142
Douglas Gregord1067e52009-08-06 06:41:21 +00002143 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002144 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002145 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002146 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2147 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002148 if (!NNS)
2149 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002150
Douglas Gregord1067e52009-08-06 06:41:21 +00002151 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002152 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002153 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002154 if (!TransTemplate)
2155 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002156
Douglas Gregord1067e52009-08-06 06:41:21 +00002157 if (!getDerived().AlwaysRebuild() &&
2158 NNS == QTN->getQualifier() &&
2159 TransTemplate == Template)
2160 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002161
Douglas Gregord1067e52009-08-06 06:41:21 +00002162 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2163 TransTemplate);
2164 }
Mike Stump1eb44332009-09-09 15:08:12 +00002165
John McCallf7a1a742009-11-24 19:00:30 +00002166 // These should be getting filtered out before they make it into the AST.
2167 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002168 }
Mike Stump1eb44332009-09-09 15:08:12 +00002169
Douglas Gregord1067e52009-08-06 06:41:21 +00002170 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002171 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002172 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002173 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2174 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002175 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00002176 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002177
Douglas Gregord1067e52009-08-06 06:41:21 +00002178 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002179 NNS == DTN->getQualifier() &&
2180 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002181 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002182
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002183 if (DTN->isIdentifier())
Sean Huntc3021132010-05-05 15:23:54 +00002184 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002185 ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +00002186
2187 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002188 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002189 }
Mike Stump1eb44332009-09-09 15:08:12 +00002190
Douglas Gregord1067e52009-08-06 06:41:21 +00002191 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002192 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002193 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002194 if (!TransTemplate)
2195 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002196
Douglas Gregord1067e52009-08-06 06:41:21 +00002197 if (!getDerived().AlwaysRebuild() &&
2198 TransTemplate == Template)
2199 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002200
Douglas Gregord1067e52009-08-06 06:41:21 +00002201 return TemplateName(TransTemplate);
2202 }
Mike Stump1eb44332009-09-09 15:08:12 +00002203
John McCallf7a1a742009-11-24 19:00:30 +00002204 // These should be getting filtered out before they reach the AST.
2205 assert(false && "overloaded function decl survived to here");
2206 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002207}
2208
2209template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002210void TreeTransform<Derived>::InventTemplateArgumentLoc(
2211 const TemplateArgument &Arg,
2212 TemplateArgumentLoc &Output) {
2213 SourceLocation Loc = getDerived().getBaseLocation();
2214 switch (Arg.getKind()) {
2215 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002216 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002217 break;
2218
2219 case TemplateArgument::Type:
2220 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002221 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002222
John McCall833ca992009-10-29 08:12:44 +00002223 break;
2224
Douglas Gregor788cd062009-11-11 01:00:40 +00002225 case TemplateArgument::Template:
2226 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2227 break;
Sean Huntc3021132010-05-05 15:23:54 +00002228
John McCall833ca992009-10-29 08:12:44 +00002229 case TemplateArgument::Expression:
2230 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2231 break;
2232
2233 case TemplateArgument::Declaration:
2234 case TemplateArgument::Integral:
2235 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002236 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002237 break;
2238 }
2239}
2240
2241template<typename Derived>
2242bool TreeTransform<Derived>::TransformTemplateArgument(
2243 const TemplateArgumentLoc &Input,
2244 TemplateArgumentLoc &Output) {
2245 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002246 switch (Arg.getKind()) {
2247 case TemplateArgument::Null:
2248 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002249 Output = Input;
2250 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002251
Douglas Gregor670444e2009-08-04 22:27:00 +00002252 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002253 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002254 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002255 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002256
2257 DI = getDerived().TransformType(DI);
2258 if (!DI) return true;
2259
2260 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2261 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002262 }
Mike Stump1eb44332009-09-09 15:08:12 +00002263
Douglas Gregor670444e2009-08-04 22:27:00 +00002264 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002265 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002266 DeclarationName Name;
2267 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2268 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002269 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002270 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002271 if (!D) return true;
2272
John McCall828bff22009-10-29 18:45:58 +00002273 Expr *SourceExpr = Input.getSourceDeclExpression();
2274 if (SourceExpr) {
2275 EnterExpressionEvaluationContext Unevaluated(getSema(),
2276 Action::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002277 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002278 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002279 }
2280
2281 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002282 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002283 }
Mike Stump1eb44332009-09-09 15:08:12 +00002284
Douglas Gregor788cd062009-11-11 01:00:40 +00002285 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002286 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002287 TemplateName Template
2288 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2289 if (Template.isNull())
2290 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002291
Douglas Gregor788cd062009-11-11 01:00:40 +00002292 Output = TemplateArgumentLoc(TemplateArgument(Template),
2293 Input.getTemplateQualifierRange(),
2294 Input.getTemplateNameLoc());
2295 return false;
2296 }
Sean Huntc3021132010-05-05 15:23:54 +00002297
Douglas Gregor670444e2009-08-04 22:27:00 +00002298 case TemplateArgument::Expression: {
2299 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002300 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002301 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002302
John McCall833ca992009-10-29 08:12:44 +00002303 Expr *InputExpr = Input.getSourceExpression();
2304 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2305
John McCall60d7b3a2010-08-24 06:29:42 +00002306 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002307 = getDerived().TransformExpr(InputExpr);
2308 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002309 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002310 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002311 }
Mike Stump1eb44332009-09-09 15:08:12 +00002312
Douglas Gregor670444e2009-08-04 22:27:00 +00002313 case TemplateArgument::Pack: {
2314 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2315 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002316 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002317 AEnd = Arg.pack_end();
2318 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002319
John McCall833ca992009-10-29 08:12:44 +00002320 // FIXME: preserve source information here when we start
2321 // caring about parameter packs.
2322
John McCall828bff22009-10-29 18:45:58 +00002323 TemplateArgumentLoc InputArg;
2324 TemplateArgumentLoc OutputArg;
2325 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2326 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002327 return true;
2328
John McCall828bff22009-10-29 18:45:58 +00002329 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002330 }
2331 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002332 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002333 true);
John McCall828bff22009-10-29 18:45:58 +00002334 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002335 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002336 }
2337 }
Mike Stump1eb44332009-09-09 15:08:12 +00002338
Douglas Gregor670444e2009-08-04 22:27:00 +00002339 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002340 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002341}
2342
Douglas Gregor577f75a2009-08-04 16:50:30 +00002343//===----------------------------------------------------------------------===//
2344// Type transformation
2345//===----------------------------------------------------------------------===//
2346
2347template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00002348QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregor124b8782010-02-16 19:09:40 +00002349 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002350 if (getDerived().AlreadyTransformed(T))
2351 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002352
John McCalla2becad2009-10-21 00:40:46 +00002353 // Temporary workaround. All of these transformations should
2354 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002355 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002356 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002357
Douglas Gregor124b8782010-02-16 19:09:40 +00002358 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002359
John McCalla2becad2009-10-21 00:40:46 +00002360 if (!NewDI)
2361 return QualType();
2362
2363 return NewDI->getType();
2364}
2365
2366template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002367TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2368 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002369 if (getDerived().AlreadyTransformed(DI->getType()))
2370 return DI;
2371
2372 TypeLocBuilder TLB;
2373
2374 TypeLoc TL = DI->getTypeLoc();
2375 TLB.reserve(TL.getFullDataSize());
2376
Douglas Gregor124b8782010-02-16 19:09:40 +00002377 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002378 if (Result.isNull())
2379 return 0;
2380
John McCalla93c9342009-12-07 02:54:59 +00002381 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002382}
2383
2384template<typename Derived>
2385QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002386TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2387 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002388 switch (T.getTypeLocClass()) {
2389#define ABSTRACT_TYPELOC(CLASS, PARENT)
2390#define TYPELOC(CLASS, PARENT) \
2391 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002392 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2393 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002394#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002395 }
Mike Stump1eb44332009-09-09 15:08:12 +00002396
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002397 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002398 return QualType();
2399}
2400
2401/// FIXME: By default, this routine adds type qualifiers only to types
2402/// that can have qualifiers, and silently suppresses those qualifiers
2403/// that are not permitted (e.g., qualifiers on reference or function
2404/// types). This is the right thing for template instantiation, but
2405/// probably not for other clients.
2406template<typename Derived>
2407QualType
2408TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002409 QualifiedTypeLoc T,
2410 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002411 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002412
Douglas Gregor124b8782010-02-16 19:09:40 +00002413 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2414 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002415 if (Result.isNull())
2416 return QualType();
2417
2418 // Silently suppress qualifiers if the result type can't be qualified.
2419 // FIXME: this is the right thing for template instantiation, but
2420 // probably not for other clients.
2421 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002422 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002423
John McCall28654742010-06-05 06:41:15 +00002424 if (!Quals.empty()) {
2425 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2426 TLB.push<QualifiedTypeLoc>(Result);
2427 // No location information to preserve.
2428 }
John McCalla2becad2009-10-21 00:40:46 +00002429
2430 return Result;
2431}
2432
2433template <class TyLoc> static inline
2434QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2435 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2436 NewT.setNameLoc(T.getNameLoc());
2437 return T.getType();
2438}
2439
John McCalla2becad2009-10-21 00:40:46 +00002440template<typename Derived>
2441QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002442 BuiltinTypeLoc T,
2443 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002444 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2445 NewT.setBuiltinLoc(T.getBuiltinLoc());
2446 if (T.needsExtraLocalData())
2447 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2448 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002449}
Mike Stump1eb44332009-09-09 15:08:12 +00002450
Douglas Gregor577f75a2009-08-04 16:50:30 +00002451template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002452QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002453 ComplexTypeLoc T,
2454 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002455 // FIXME: recurse?
2456 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002457}
Mike Stump1eb44332009-09-09 15:08:12 +00002458
Douglas Gregor577f75a2009-08-04 16:50:30 +00002459template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002460QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Sean Huntc3021132010-05-05 15:23:54 +00002461 PointerTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00002462 QualType ObjectType) {
Sean Huntc3021132010-05-05 15:23:54 +00002463 QualType PointeeType
2464 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002465 if (PointeeType.isNull())
2466 return QualType();
2467
2468 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002469 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002470 // A dependent pointer type 'T *' has is being transformed such
2471 // that an Objective-C class type is being replaced for 'T'. The
2472 // resulting pointer type is an ObjCObjectPointerType, not a
2473 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002474 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002475
John McCallc12c5bb2010-05-15 11:32:37 +00002476 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2477 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002478 return Result;
2479 }
Sean Huntc3021132010-05-05 15:23:54 +00002480
Douglas Gregor92e986e2010-04-22 16:44:27 +00002481 if (getDerived().AlwaysRebuild() ||
2482 PointeeType != TL.getPointeeLoc().getType()) {
2483 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2484 if (Result.isNull())
2485 return QualType();
2486 }
Sean Huntc3021132010-05-05 15:23:54 +00002487
Douglas Gregor92e986e2010-04-22 16:44:27 +00002488 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2489 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002490 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002491}
Mike Stump1eb44332009-09-09 15:08:12 +00002492
2493template<typename Derived>
2494QualType
John McCalla2becad2009-10-21 00:40:46 +00002495TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002496 BlockPointerTypeLoc TL,
2497 QualType ObjectType) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002498 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002499 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2500 if (PointeeType.isNull())
2501 return QualType();
2502
2503 QualType Result = TL.getType();
2504 if (getDerived().AlwaysRebuild() ||
2505 PointeeType != TL.getPointeeLoc().getType()) {
2506 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002507 TL.getSigilLoc());
2508 if (Result.isNull())
2509 return QualType();
2510 }
2511
Douglas Gregor39968ad2010-04-22 16:50:51 +00002512 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002513 NewT.setSigilLoc(TL.getSigilLoc());
2514 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002515}
2516
John McCall85737a72009-10-30 00:06:24 +00002517/// Transforms a reference type. Note that somewhat paradoxically we
2518/// don't care whether the type itself is an l-value type or an r-value
2519/// type; we only care if the type was *written* as an l-value type
2520/// or an r-value type.
2521template<typename Derived>
2522QualType
2523TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002524 ReferenceTypeLoc TL,
2525 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002526 const ReferenceType *T = TL.getTypePtr();
2527
2528 // Note that this works with the pointee-as-written.
2529 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2530 if (PointeeType.isNull())
2531 return QualType();
2532
2533 QualType Result = TL.getType();
2534 if (getDerived().AlwaysRebuild() ||
2535 PointeeType != T->getPointeeTypeAsWritten()) {
2536 Result = getDerived().RebuildReferenceType(PointeeType,
2537 T->isSpelledAsLValue(),
2538 TL.getSigilLoc());
2539 if (Result.isNull())
2540 return QualType();
2541 }
2542
2543 // r-value references can be rebuilt as l-value references.
2544 ReferenceTypeLoc NewTL;
2545 if (isa<LValueReferenceType>(Result))
2546 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2547 else
2548 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2549 NewTL.setSigilLoc(TL.getSigilLoc());
2550
2551 return Result;
2552}
2553
Mike Stump1eb44332009-09-09 15:08:12 +00002554template<typename Derived>
2555QualType
John McCalla2becad2009-10-21 00:40:46 +00002556TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002557 LValueReferenceTypeLoc TL,
2558 QualType ObjectType) {
2559 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002560}
2561
Mike Stump1eb44332009-09-09 15:08:12 +00002562template<typename Derived>
2563QualType
John McCalla2becad2009-10-21 00:40:46 +00002564TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002565 RValueReferenceTypeLoc TL,
2566 QualType ObjectType) {
2567 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002568}
Mike Stump1eb44332009-09-09 15:08:12 +00002569
Douglas Gregor577f75a2009-08-04 16:50:30 +00002570template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002571QualType
John McCalla2becad2009-10-21 00:40:46 +00002572TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002573 MemberPointerTypeLoc TL,
2574 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002575 MemberPointerType *T = TL.getTypePtr();
2576
2577 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002578 if (PointeeType.isNull())
2579 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002580
John McCalla2becad2009-10-21 00:40:46 +00002581 // TODO: preserve source information for this.
2582 QualType ClassType
2583 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002584 if (ClassType.isNull())
2585 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002586
John McCalla2becad2009-10-21 00:40:46 +00002587 QualType Result = TL.getType();
2588 if (getDerived().AlwaysRebuild() ||
2589 PointeeType != T->getPointeeType() ||
2590 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002591 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2592 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002593 if (Result.isNull())
2594 return QualType();
2595 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002596
John McCalla2becad2009-10-21 00:40:46 +00002597 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2598 NewTL.setSigilLoc(TL.getSigilLoc());
2599
2600 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002601}
2602
Mike Stump1eb44332009-09-09 15:08:12 +00002603template<typename Derived>
2604QualType
John McCalla2becad2009-10-21 00:40:46 +00002605TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002606 ConstantArrayTypeLoc TL,
2607 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002608 ConstantArrayType *T = TL.getTypePtr();
2609 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002610 if (ElementType.isNull())
2611 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002612
John McCalla2becad2009-10-21 00:40:46 +00002613 QualType Result = TL.getType();
2614 if (getDerived().AlwaysRebuild() ||
2615 ElementType != T->getElementType()) {
2616 Result = getDerived().RebuildConstantArrayType(ElementType,
2617 T->getSizeModifier(),
2618 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002619 T->getIndexTypeCVRQualifiers(),
2620 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002621 if (Result.isNull())
2622 return QualType();
2623 }
Sean Huntc3021132010-05-05 15:23:54 +00002624
John McCalla2becad2009-10-21 00:40:46 +00002625 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2626 NewTL.setLBracketLoc(TL.getLBracketLoc());
2627 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002628
John McCalla2becad2009-10-21 00:40:46 +00002629 Expr *Size = TL.getSizeExpr();
2630 if (Size) {
2631 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2632 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2633 }
2634 NewTL.setSizeExpr(Size);
2635
2636 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002637}
Mike Stump1eb44332009-09-09 15:08:12 +00002638
Douglas Gregor577f75a2009-08-04 16:50:30 +00002639template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002640QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002641 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002642 IncompleteArrayTypeLoc TL,
2643 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002644 IncompleteArrayType *T = TL.getTypePtr();
2645 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002646 if (ElementType.isNull())
2647 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002648
John McCalla2becad2009-10-21 00:40:46 +00002649 QualType Result = TL.getType();
2650 if (getDerived().AlwaysRebuild() ||
2651 ElementType != T->getElementType()) {
2652 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002653 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002654 T->getIndexTypeCVRQualifiers(),
2655 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002656 if (Result.isNull())
2657 return QualType();
2658 }
Sean Huntc3021132010-05-05 15:23:54 +00002659
John McCalla2becad2009-10-21 00:40:46 +00002660 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2661 NewTL.setLBracketLoc(TL.getLBracketLoc());
2662 NewTL.setRBracketLoc(TL.getRBracketLoc());
2663 NewTL.setSizeExpr(0);
2664
2665 return Result;
2666}
2667
2668template<typename Derived>
2669QualType
2670TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002671 VariableArrayTypeLoc TL,
2672 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002673 VariableArrayType *T = TL.getTypePtr();
2674 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2675 if (ElementType.isNull())
2676 return QualType();
2677
2678 // Array bounds are not potentially evaluated contexts
2679 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2680
John McCall60d7b3a2010-08-24 06:29:42 +00002681 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002682 = getDerived().TransformExpr(T->getSizeExpr());
2683 if (SizeResult.isInvalid())
2684 return QualType();
2685
John McCall9ae2f072010-08-23 23:25:46 +00002686 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00002687
2688 QualType Result = TL.getType();
2689 if (getDerived().AlwaysRebuild() ||
2690 ElementType != T->getElementType() ||
2691 Size != T->getSizeExpr()) {
2692 Result = getDerived().RebuildVariableArrayType(ElementType,
2693 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002694 Size,
John McCalla2becad2009-10-21 00:40:46 +00002695 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002696 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002697 if (Result.isNull())
2698 return QualType();
2699 }
Sean Huntc3021132010-05-05 15:23:54 +00002700
John McCalla2becad2009-10-21 00:40:46 +00002701 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2702 NewTL.setLBracketLoc(TL.getLBracketLoc());
2703 NewTL.setRBracketLoc(TL.getRBracketLoc());
2704 NewTL.setSizeExpr(Size);
2705
2706 return Result;
2707}
2708
2709template<typename Derived>
2710QualType
2711TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002712 DependentSizedArrayTypeLoc TL,
2713 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002714 DependentSizedArrayType *T = TL.getTypePtr();
2715 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2716 if (ElementType.isNull())
2717 return QualType();
2718
2719 // Array bounds are not potentially evaluated contexts
2720 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2721
John McCall60d7b3a2010-08-24 06:29:42 +00002722 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002723 = getDerived().TransformExpr(T->getSizeExpr());
2724 if (SizeResult.isInvalid())
2725 return QualType();
2726
2727 Expr *Size = static_cast<Expr*>(SizeResult.get());
2728
2729 QualType Result = TL.getType();
2730 if (getDerived().AlwaysRebuild() ||
2731 ElementType != T->getElementType() ||
2732 Size != T->getSizeExpr()) {
2733 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2734 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002735 Size,
John McCalla2becad2009-10-21 00:40:46 +00002736 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002737 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002738 if (Result.isNull())
2739 return QualType();
2740 }
2741 else SizeResult.take();
2742
2743 // We might have any sort of array type now, but fortunately they
2744 // all have the same location layout.
2745 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2746 NewTL.setLBracketLoc(TL.getLBracketLoc());
2747 NewTL.setRBracketLoc(TL.getRBracketLoc());
2748 NewTL.setSizeExpr(Size);
2749
2750 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002751}
Mike Stump1eb44332009-09-09 15:08:12 +00002752
2753template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002754QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002755 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002756 DependentSizedExtVectorTypeLoc TL,
2757 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002758 DependentSizedExtVectorType *T = TL.getTypePtr();
2759
2760 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002761 QualType ElementType = getDerived().TransformType(T->getElementType());
2762 if (ElementType.isNull())
2763 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002764
Douglas Gregor670444e2009-08-04 22:27:00 +00002765 // Vector sizes are not potentially evaluated contexts
2766 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2767
John McCall60d7b3a2010-08-24 06:29:42 +00002768 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002769 if (Size.isInvalid())
2770 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002771
John McCalla2becad2009-10-21 00:40:46 +00002772 QualType Result = TL.getType();
2773 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002774 ElementType != T->getElementType() ||
2775 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002776 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00002777 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00002778 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002779 if (Result.isNull())
2780 return QualType();
2781 }
John McCalla2becad2009-10-21 00:40:46 +00002782
2783 // Result might be dependent or not.
2784 if (isa<DependentSizedExtVectorType>(Result)) {
2785 DependentSizedExtVectorTypeLoc NewTL
2786 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2787 NewTL.setNameLoc(TL.getNameLoc());
2788 } else {
2789 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2790 NewTL.setNameLoc(TL.getNameLoc());
2791 }
2792
2793 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002794}
Mike Stump1eb44332009-09-09 15:08:12 +00002795
2796template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002797QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002798 VectorTypeLoc TL,
2799 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002800 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002801 QualType ElementType = getDerived().TransformType(T->getElementType());
2802 if (ElementType.isNull())
2803 return QualType();
2804
John McCalla2becad2009-10-21 00:40:46 +00002805 QualType Result = TL.getType();
2806 if (getDerived().AlwaysRebuild() ||
2807 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002808 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner788b0fd2010-06-23 06:00:24 +00002809 T->getAltiVecSpecific());
John McCalla2becad2009-10-21 00:40:46 +00002810 if (Result.isNull())
2811 return QualType();
2812 }
Sean Huntc3021132010-05-05 15:23:54 +00002813
John McCalla2becad2009-10-21 00:40:46 +00002814 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2815 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002816
John McCalla2becad2009-10-21 00:40:46 +00002817 return Result;
2818}
2819
2820template<typename Derived>
2821QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002822 ExtVectorTypeLoc TL,
2823 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002824 VectorType *T = TL.getTypePtr();
2825 QualType ElementType = getDerived().TransformType(T->getElementType());
2826 if (ElementType.isNull())
2827 return QualType();
2828
2829 QualType Result = TL.getType();
2830 if (getDerived().AlwaysRebuild() ||
2831 ElementType != T->getElementType()) {
2832 Result = getDerived().RebuildExtVectorType(ElementType,
2833 T->getNumElements(),
2834 /*FIXME*/ SourceLocation());
2835 if (Result.isNull())
2836 return QualType();
2837 }
Sean Huntc3021132010-05-05 15:23:54 +00002838
John McCalla2becad2009-10-21 00:40:46 +00002839 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2840 NewTL.setNameLoc(TL.getNameLoc());
2841
2842 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002843}
Mike Stump1eb44332009-09-09 15:08:12 +00002844
2845template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002846ParmVarDecl *
2847TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2848 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2849 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2850 if (!NewDI)
2851 return 0;
2852
2853 if (NewDI == OldDI)
2854 return OldParm;
2855 else
2856 return ParmVarDecl::Create(SemaRef.Context,
2857 OldParm->getDeclContext(),
2858 OldParm->getLocation(),
2859 OldParm->getIdentifier(),
2860 NewDI->getType(),
2861 NewDI,
2862 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002863 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002864 /* DefArg */ NULL);
2865}
2866
2867template<typename Derived>
2868bool TreeTransform<Derived>::
2869 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2870 llvm::SmallVectorImpl<QualType> &PTypes,
2871 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2872 FunctionProtoType *T = TL.getTypePtr();
2873
2874 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2875 ParmVarDecl *OldParm = TL.getArg(i);
2876
2877 QualType NewType;
2878 ParmVarDecl *NewParm;
2879
2880 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002881 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2882 if (!NewParm)
2883 return true;
2884 NewType = NewParm->getType();
2885
2886 // Deal with the possibility that we don't have a parameter
2887 // declaration for this parameter.
2888 } else {
2889 NewParm = 0;
2890
2891 QualType OldType = T->getArgType(i);
2892 NewType = getDerived().TransformType(OldType);
2893 if (NewType.isNull())
2894 return true;
2895 }
2896
2897 PTypes.push_back(NewType);
2898 PVars.push_back(NewParm);
2899 }
2900
2901 return false;
2902}
2903
2904template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002905QualType
John McCalla2becad2009-10-21 00:40:46 +00002906TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002907 FunctionProtoTypeLoc TL,
2908 QualType ObjectType) {
Douglas Gregor895162d2010-04-30 18:55:50 +00002909 // Transform the parameters. We do this first for the benefit of template
2910 // instantiations, so that the ParmVarDecls get/ placed into the template
2911 // instantiation scope before we transform the function type.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002912 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002913 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall21ef0fa2010-03-11 09:03:00 +00002914 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2915 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002916
Douglas Gregor895162d2010-04-30 18:55:50 +00002917 FunctionProtoType *T = TL.getTypePtr();
2918 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2919 if (ResultType.isNull())
2920 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002921
John McCalla2becad2009-10-21 00:40:46 +00002922 QualType Result = TL.getType();
2923 if (getDerived().AlwaysRebuild() ||
2924 ResultType != T->getResultType() ||
2925 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2926 Result = getDerived().RebuildFunctionProtoType(ResultType,
2927 ParamTypes.data(),
2928 ParamTypes.size(),
2929 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00002930 T->getTypeQuals(),
2931 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00002932 if (Result.isNull())
2933 return QualType();
2934 }
Mike Stump1eb44332009-09-09 15:08:12 +00002935
John McCalla2becad2009-10-21 00:40:46 +00002936 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2937 NewTL.setLParenLoc(TL.getLParenLoc());
2938 NewTL.setRParenLoc(TL.getRParenLoc());
2939 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2940 NewTL.setArg(i, ParamDecls[i]);
2941
2942 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002943}
Mike Stump1eb44332009-09-09 15:08:12 +00002944
Douglas Gregor577f75a2009-08-04 16:50:30 +00002945template<typename Derived>
2946QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002947 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002948 FunctionNoProtoTypeLoc TL,
2949 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002950 FunctionNoProtoType *T = TL.getTypePtr();
2951 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2952 if (ResultType.isNull())
2953 return QualType();
2954
2955 QualType Result = TL.getType();
2956 if (getDerived().AlwaysRebuild() ||
2957 ResultType != T->getResultType())
2958 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2959
2960 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2961 NewTL.setLParenLoc(TL.getLParenLoc());
2962 NewTL.setRParenLoc(TL.getRParenLoc());
2963
2964 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002965}
Mike Stump1eb44332009-09-09 15:08:12 +00002966
John McCalled976492009-12-04 22:46:56 +00002967template<typename Derived> QualType
2968TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002969 UnresolvedUsingTypeLoc TL,
2970 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00002971 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002972 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00002973 if (!D)
2974 return QualType();
2975
2976 QualType Result = TL.getType();
2977 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2978 Result = getDerived().RebuildUnresolvedUsingType(D);
2979 if (Result.isNull())
2980 return QualType();
2981 }
2982
2983 // We might get an arbitrary type spec type back. We should at
2984 // least always get a type spec type, though.
2985 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2986 NewTL.setNameLoc(TL.getNameLoc());
2987
2988 return Result;
2989}
2990
Douglas Gregor577f75a2009-08-04 16:50:30 +00002991template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002992QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002993 TypedefTypeLoc TL,
2994 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002995 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002996 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002997 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2998 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002999 if (!Typedef)
3000 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003001
John McCalla2becad2009-10-21 00:40:46 +00003002 QualType Result = TL.getType();
3003 if (getDerived().AlwaysRebuild() ||
3004 Typedef != T->getDecl()) {
3005 Result = getDerived().RebuildTypedefType(Typedef);
3006 if (Result.isNull())
3007 return QualType();
3008 }
Mike Stump1eb44332009-09-09 15:08:12 +00003009
John McCalla2becad2009-10-21 00:40:46 +00003010 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3011 NewTL.setNameLoc(TL.getNameLoc());
3012
3013 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003014}
Mike Stump1eb44332009-09-09 15:08:12 +00003015
Douglas Gregor577f75a2009-08-04 16:50:30 +00003016template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003017QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003018 TypeOfExprTypeLoc TL,
3019 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003020 // typeof expressions are not potentially evaluated contexts
3021 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003022
John McCall60d7b3a2010-08-24 06:29:42 +00003023 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003024 if (E.isInvalid())
3025 return QualType();
3026
John McCalla2becad2009-10-21 00:40:46 +00003027 QualType Result = TL.getType();
3028 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003029 E.get() != TL.getUnderlyingExpr()) {
John McCall9ae2f072010-08-23 23:25:46 +00003030 Result = getDerived().RebuildTypeOfExprType(E.get());
John McCalla2becad2009-10-21 00:40:46 +00003031 if (Result.isNull())
3032 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003033 }
John McCalla2becad2009-10-21 00:40:46 +00003034 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003035
John McCalla2becad2009-10-21 00:40:46 +00003036 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003037 NewTL.setTypeofLoc(TL.getTypeofLoc());
3038 NewTL.setLParenLoc(TL.getLParenLoc());
3039 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003040
3041 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003042}
Mike Stump1eb44332009-09-09 15:08:12 +00003043
3044template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003045QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003046 TypeOfTypeLoc TL,
3047 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00003048 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3049 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3050 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003051 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003052
John McCalla2becad2009-10-21 00:40:46 +00003053 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003054 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3055 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003056 if (Result.isNull())
3057 return QualType();
3058 }
Mike Stump1eb44332009-09-09 15:08:12 +00003059
John McCalla2becad2009-10-21 00:40:46 +00003060 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003061 NewTL.setTypeofLoc(TL.getTypeofLoc());
3062 NewTL.setLParenLoc(TL.getLParenLoc());
3063 NewTL.setRParenLoc(TL.getRParenLoc());
3064 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003065
3066 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003067}
Mike Stump1eb44332009-09-09 15:08:12 +00003068
3069template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003070QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003071 DecltypeTypeLoc TL,
3072 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003073 DecltypeType *T = TL.getTypePtr();
3074
Douglas Gregor670444e2009-08-04 22:27:00 +00003075 // decltype expressions are not potentially evaluated contexts
3076 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003077
John McCall60d7b3a2010-08-24 06:29:42 +00003078 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003079 if (E.isInvalid())
3080 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003081
John McCalla2becad2009-10-21 00:40:46 +00003082 QualType Result = TL.getType();
3083 if (getDerived().AlwaysRebuild() ||
3084 E.get() != T->getUnderlyingExpr()) {
John McCall9ae2f072010-08-23 23:25:46 +00003085 Result = getDerived().RebuildDecltypeType(E.get());
John McCalla2becad2009-10-21 00:40:46 +00003086 if (Result.isNull())
3087 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003088 }
John McCalla2becad2009-10-21 00:40:46 +00003089 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003090
John McCalla2becad2009-10-21 00:40:46 +00003091 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3092 NewTL.setNameLoc(TL.getNameLoc());
3093
3094 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003095}
3096
3097template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003098QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003099 RecordTypeLoc TL,
3100 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003101 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003102 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003103 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3104 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003105 if (!Record)
3106 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003107
John McCalla2becad2009-10-21 00:40:46 +00003108 QualType Result = TL.getType();
3109 if (getDerived().AlwaysRebuild() ||
3110 Record != T->getDecl()) {
3111 Result = getDerived().RebuildRecordType(Record);
3112 if (Result.isNull())
3113 return QualType();
3114 }
Mike Stump1eb44332009-09-09 15:08:12 +00003115
John McCalla2becad2009-10-21 00:40:46 +00003116 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3117 NewTL.setNameLoc(TL.getNameLoc());
3118
3119 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003120}
Mike Stump1eb44332009-09-09 15:08:12 +00003121
3122template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003123QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003124 EnumTypeLoc TL,
3125 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003126 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003127 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003128 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3129 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003130 if (!Enum)
3131 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003132
John McCalla2becad2009-10-21 00:40:46 +00003133 QualType Result = TL.getType();
3134 if (getDerived().AlwaysRebuild() ||
3135 Enum != T->getDecl()) {
3136 Result = getDerived().RebuildEnumType(Enum);
3137 if (Result.isNull())
3138 return QualType();
3139 }
Mike Stump1eb44332009-09-09 15:08:12 +00003140
John McCalla2becad2009-10-21 00:40:46 +00003141 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3142 NewTL.setNameLoc(TL.getNameLoc());
3143
3144 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003145}
John McCall7da24312009-09-05 00:15:47 +00003146
John McCall3cb0ebd2010-03-10 03:28:59 +00003147template<typename Derived>
3148QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3149 TypeLocBuilder &TLB,
3150 InjectedClassNameTypeLoc TL,
3151 QualType ObjectType) {
3152 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3153 TL.getTypePtr()->getDecl());
3154 if (!D) return QualType();
3155
3156 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3157 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3158 return T;
3159}
3160
Mike Stump1eb44332009-09-09 15:08:12 +00003161
Douglas Gregor577f75a2009-08-04 16:50:30 +00003162template<typename Derived>
3163QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003164 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003165 TemplateTypeParmTypeLoc TL,
3166 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003167 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003168}
3169
Mike Stump1eb44332009-09-09 15:08:12 +00003170template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003171QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003172 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003173 SubstTemplateTypeParmTypeLoc TL,
3174 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003175 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003176}
3177
3178template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003179QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3180 const TemplateSpecializationType *TST,
3181 QualType ObjectType) {
3182 // FIXME: this entire method is a temporary workaround; callers
3183 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00003184
John McCall833ca992009-10-29 08:12:44 +00003185 // Fake up a TemplateSpecializationTypeLoc.
3186 TypeLocBuilder TLB;
3187 TemplateSpecializationTypeLoc TL
3188 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3189
John McCall828bff22009-10-29 18:45:58 +00003190 SourceLocation BaseLoc = getDerived().getBaseLocation();
3191
3192 TL.setTemplateNameLoc(BaseLoc);
3193 TL.setLAngleLoc(BaseLoc);
3194 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00003195 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3196 const TemplateArgument &TA = TST->getArg(i);
3197 TemplateArgumentLoc TAL;
3198 getDerived().InventTemplateArgumentLoc(TA, TAL);
3199 TL.setArgLocInfo(i, TAL.getLocInfo());
3200 }
3201
3202 TypeLocBuilder IgnoredTLB;
3203 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00003204}
Sean Huntc3021132010-05-05 15:23:54 +00003205
Douglas Gregordd62b152009-10-19 22:04:39 +00003206template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003207QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003208 TypeLocBuilder &TLB,
3209 TemplateSpecializationTypeLoc TL,
3210 QualType ObjectType) {
3211 const TemplateSpecializationType *T = TL.getTypePtr();
3212
Mike Stump1eb44332009-09-09 15:08:12 +00003213 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00003214 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003215 if (Template.isNull())
3216 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003217
John McCalld5532b62009-11-23 01:53:49 +00003218 TemplateArgumentListInfo NewTemplateArgs;
3219 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3220 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3221
3222 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3223 TemplateArgumentLoc Loc;
3224 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003225 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003226 NewTemplateArgs.addArgument(Loc);
3227 }
Mike Stump1eb44332009-09-09 15:08:12 +00003228
John McCall833ca992009-10-29 08:12:44 +00003229 // FIXME: maybe don't rebuild if all the template arguments are the same.
3230
3231 QualType Result =
3232 getDerived().RebuildTemplateSpecializationType(Template,
3233 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003234 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003235
3236 if (!Result.isNull()) {
3237 TemplateSpecializationTypeLoc NewTL
3238 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3239 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3240 NewTL.setLAngleLoc(TL.getLAngleLoc());
3241 NewTL.setRAngleLoc(TL.getRAngleLoc());
3242 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3243 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003244 }
Mike Stump1eb44332009-09-09 15:08:12 +00003245
John McCall833ca992009-10-29 08:12:44 +00003246 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003247}
Mike Stump1eb44332009-09-09 15:08:12 +00003248
3249template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003250QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003251TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3252 ElaboratedTypeLoc TL,
3253 QualType ObjectType) {
3254 ElaboratedType *T = TL.getTypePtr();
3255
3256 NestedNameSpecifier *NNS = 0;
3257 // NOTE: the qualifier in an ElaboratedType is optional.
3258 if (T->getQualifier() != 0) {
3259 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003260 TL.getQualifierRange(),
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003261 ObjectType);
3262 if (!NNS)
3263 return QualType();
3264 }
Mike Stump1eb44332009-09-09 15:08:12 +00003265
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003266 QualType NamedT;
3267 // FIXME: this test is meant to workaround a problem (failing assertion)
3268 // occurring if directly executing the code in the else branch.
3269 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3270 TemplateSpecializationTypeLoc OldNamedTL
3271 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3272 const TemplateSpecializationType* OldTST
Jim Grosbach9cbb4d82010-05-19 23:53:08 +00003273 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003274 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3275 if (NamedT.isNull())
3276 return QualType();
3277 TemplateSpecializationTypeLoc NewNamedTL
3278 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3279 NewNamedTL.copy(OldNamedTL);
3280 }
3281 else {
3282 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3283 if (NamedT.isNull())
3284 return QualType();
3285 }
Daniel Dunbara63db842010-05-14 16:34:09 +00003286
John McCalla2becad2009-10-21 00:40:46 +00003287 QualType Result = TL.getType();
3288 if (getDerived().AlwaysRebuild() ||
3289 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003290 NamedT != T->getNamedType()) {
3291 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003292 if (Result.isNull())
3293 return QualType();
3294 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003295
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003296 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003297 NewTL.setKeywordLoc(TL.getKeywordLoc());
3298 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003299
3300 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003301}
Mike Stump1eb44332009-09-09 15:08:12 +00003302
3303template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003304QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3305 DependentNameTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00003306 QualType ObjectType) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003307 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003308
Douglas Gregor577f75a2009-08-04 16:50:30 +00003309 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003310 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3311 TL.getQualifierRange(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003312 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003313 if (!NNS)
3314 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003315
John McCall33500952010-06-11 00:33:02 +00003316 QualType Result
3317 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3318 T->getIdentifier(),
3319 TL.getKeywordLoc(),
3320 TL.getQualifierRange(),
3321 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003322 if (Result.isNull())
3323 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003324
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003325 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3326 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003327 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3328
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003329 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3330 NewTL.setKeywordLoc(TL.getKeywordLoc());
3331 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003332 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003333 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3334 NewTL.setKeywordLoc(TL.getKeywordLoc());
3335 NewTL.setQualifierRange(TL.getQualifierRange());
3336 NewTL.setNameLoc(TL.getNameLoc());
3337 }
John McCalla2becad2009-10-21 00:40:46 +00003338 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003339}
Mike Stump1eb44332009-09-09 15:08:12 +00003340
Douglas Gregor577f75a2009-08-04 16:50:30 +00003341template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003342QualType TreeTransform<Derived>::
3343 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3344 DependentTemplateSpecializationTypeLoc TL,
3345 QualType ObjectType) {
3346 DependentTemplateSpecializationType *T = TL.getTypePtr();
3347
3348 NestedNameSpecifier *NNS
3349 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3350 TL.getQualifierRange(),
3351 ObjectType);
3352 if (!NNS)
3353 return QualType();
3354
3355 TemplateArgumentListInfo NewTemplateArgs;
3356 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3357 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3358
3359 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3360 TemplateArgumentLoc Loc;
3361 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3362 return QualType();
3363 NewTemplateArgs.addArgument(Loc);
3364 }
3365
3366 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3367 T->getKeyword(),
3368 NNS,
3369 T->getIdentifier(),
3370 TL.getNameLoc(),
3371 NewTemplateArgs);
3372 if (Result.isNull())
3373 return QualType();
3374
3375 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3376 QualType NamedT = ElabT->getNamedType();
3377
3378 // Copy information relevant to the template specialization.
3379 TemplateSpecializationTypeLoc NamedTL
3380 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3381 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3382 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3383 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3384 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3385
3386 // Copy information relevant to the elaborated type.
3387 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3388 NewTL.setKeywordLoc(TL.getKeywordLoc());
3389 NewTL.setQualifierRange(TL.getQualifierRange());
3390 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003391 TypeLoc NewTL(Result, TL.getOpaqueData());
3392 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003393 }
3394 return Result;
3395}
3396
3397template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003398QualType
3399TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003400 ObjCInterfaceTypeLoc TL,
3401 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003402 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003403 TLB.pushFullCopy(TL);
3404 return TL.getType();
3405}
3406
3407template<typename Derived>
3408QualType
3409TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3410 ObjCObjectTypeLoc TL,
3411 QualType ObjectType) {
3412 // ObjCObjectType is never dependent.
3413 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003414 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003415}
Mike Stump1eb44332009-09-09 15:08:12 +00003416
3417template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003418QualType
3419TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003420 ObjCObjectPointerTypeLoc TL,
3421 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003422 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003423 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003424 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003425}
3426
Douglas Gregor577f75a2009-08-04 16:50:30 +00003427//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003428// Statement transformation
3429//===----------------------------------------------------------------------===//
3430template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003431StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003432TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3433 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003434}
3435
3436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003437StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003438TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3439 return getDerived().TransformCompoundStmt(S, false);
3440}
3441
3442template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003443StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003444TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003445 bool IsStmtExpr) {
3446 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003447 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00003448 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3449 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00003450 StmtResult Result = getDerived().TransformStmt(*B);
Douglas Gregor43959a92009-08-20 07:17:43 +00003451 if (Result.isInvalid())
3452 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003453
Douglas Gregor43959a92009-08-20 07:17:43 +00003454 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3455 Statements.push_back(Result.takeAs<Stmt>());
3456 }
Mike Stump1eb44332009-09-09 15:08:12 +00003457
Douglas Gregor43959a92009-08-20 07:17:43 +00003458 if (!getDerived().AlwaysRebuild() &&
3459 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003460 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003461
3462 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3463 move_arg(Statements),
3464 S->getRBracLoc(),
3465 IsStmtExpr);
3466}
Mike Stump1eb44332009-09-09 15:08:12 +00003467
Douglas Gregor43959a92009-08-20 07:17:43 +00003468template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003469StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003470TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003471 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00003472 {
3473 // The case value expressions are not potentially evaluated.
3474 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003475
Eli Friedman264c1f82009-11-19 03:14:00 +00003476 // Transform the left-hand case value.
3477 LHS = getDerived().TransformExpr(S->getLHS());
3478 if (LHS.isInvalid())
3479 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003480
Eli Friedman264c1f82009-11-19 03:14:00 +00003481 // Transform the right-hand case value (for the GNU case-range extension).
3482 RHS = getDerived().TransformExpr(S->getRHS());
3483 if (RHS.isInvalid())
3484 return SemaRef.StmtError();
3485 }
Mike Stump1eb44332009-09-09 15:08:12 +00003486
Douglas Gregor43959a92009-08-20 07:17:43 +00003487 // Build the case statement.
3488 // Case statements are always rebuilt so that they will attached to their
3489 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003490 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003491 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003492 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003493 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003494 S->getColonLoc());
3495 if (Case.isInvalid())
3496 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003497
Douglas Gregor43959a92009-08-20 07:17:43 +00003498 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00003499 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003500 if (SubStmt.isInvalid())
3501 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003502
Douglas Gregor43959a92009-08-20 07:17:43 +00003503 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00003504 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003505}
3506
3507template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003508StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003509TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003510 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00003511 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003512 if (SubStmt.isInvalid())
3513 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003514
Douglas Gregor43959a92009-08-20 07:17:43 +00003515 // Default statements are always rebuilt
3516 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003517 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003518}
Mike Stump1eb44332009-09-09 15:08:12 +00003519
Douglas Gregor43959a92009-08-20 07:17:43 +00003520template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003521StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003522TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003523 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003524 if (SubStmt.isInvalid())
3525 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003526
Douglas Gregor43959a92009-08-20 07:17:43 +00003527 // FIXME: Pass the real colon location in.
3528 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3529 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00003530 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003531}
Mike Stump1eb44332009-09-09 15:08:12 +00003532
Douglas Gregor43959a92009-08-20 07:17:43 +00003533template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003534StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003535TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003536 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003537 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003538 VarDecl *ConditionVar = 0;
3539 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003540 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003541 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003542 getDerived().TransformDefinition(
3543 S->getConditionVariable()->getLocation(),
3544 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003545 if (!ConditionVar)
3546 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003547 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003548 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003549
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003550 if (Cond.isInvalid())
3551 return SemaRef.StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003552
3553 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003554 if (S->getCond()) {
John McCall60d7b3a2010-08-24 06:29:42 +00003555 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003556 S->getIfLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003557 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003558 if (CondE.isInvalid())
3559 return getSema().StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003560
John McCall9ae2f072010-08-23 23:25:46 +00003561 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003562 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003563 }
Sean Huntc3021132010-05-05 15:23:54 +00003564
John McCall9ae2f072010-08-23 23:25:46 +00003565 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3566 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003567 return SemaRef.StmtError();
3568
Douglas Gregor43959a92009-08-20 07:17:43 +00003569 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003570 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00003571 if (Then.isInvalid())
3572 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003573
Douglas Gregor43959a92009-08-20 07:17:43 +00003574 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003575 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00003576 if (Else.isInvalid())
3577 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003578
Douglas Gregor43959a92009-08-20 07:17:43 +00003579 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003580 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003581 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003582 Then.get() == S->getThen() &&
3583 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003584 return SemaRef.Owned(S->Retain());
3585
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003586 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCall9ae2f072010-08-23 23:25:46 +00003587 Then.get(),
3588 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003589}
3590
3591template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003592StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003593TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003594 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00003595 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00003596 VarDecl *ConditionVar = 0;
3597 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003598 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003599 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003600 getDerived().TransformDefinition(
3601 S->getConditionVariable()->getLocation(),
3602 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003603 if (!ConditionVar)
3604 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003605 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003606 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003607
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003608 if (Cond.isInvalid())
3609 return SemaRef.StmtError();
3610 }
Mike Stump1eb44332009-09-09 15:08:12 +00003611
Douglas Gregor43959a92009-08-20 07:17:43 +00003612 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003613 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00003614 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00003615 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003616 if (Switch.isInvalid())
3617 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003618
Douglas Gregor43959a92009-08-20 07:17:43 +00003619 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003620 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003621 if (Body.isInvalid())
3622 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003623
Douglas Gregor43959a92009-08-20 07:17:43 +00003624 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00003625 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3626 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003627}
Mike Stump1eb44332009-09-09 15:08:12 +00003628
Douglas Gregor43959a92009-08-20 07:17:43 +00003629template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003630StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003631TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003632 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003633 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00003634 VarDecl *ConditionVar = 0;
3635 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003636 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003637 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003638 getDerived().TransformDefinition(
3639 S->getConditionVariable()->getLocation(),
3640 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003641 if (!ConditionVar)
3642 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003643 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003644 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003645
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003646 if (Cond.isInvalid())
3647 return SemaRef.StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003648
3649 if (S->getCond()) {
3650 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003651 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003652 S->getWhileLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003653 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003654 if (CondE.isInvalid())
3655 return getSema().StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00003656 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003657 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003658 }
Mike Stump1eb44332009-09-09 15:08:12 +00003659
John McCall9ae2f072010-08-23 23:25:46 +00003660 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3661 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003662 return SemaRef.StmtError();
3663
Douglas Gregor43959a92009-08-20 07:17:43 +00003664 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003665 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003666 if (Body.isInvalid())
3667 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003668
Douglas Gregor43959a92009-08-20 07:17:43 +00003669 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003670 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003671 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003672 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00003673 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003674
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003675 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00003676 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003677}
Mike Stump1eb44332009-09-09 15:08:12 +00003678
Douglas Gregor43959a92009-08-20 07:17:43 +00003679template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003680StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003681TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003682 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003683 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003684 if (Body.isInvalid())
3685 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003686
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003687 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003688 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003689 if (Cond.isInvalid())
3690 return SemaRef.StmtError();
3691
Douglas Gregor43959a92009-08-20 07:17:43 +00003692 if (!getDerived().AlwaysRebuild() &&
3693 Cond.get() == S->getCond() &&
3694 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003695 return SemaRef.Owned(S->Retain());
3696
John McCall9ae2f072010-08-23 23:25:46 +00003697 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3698 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003699 S->getRParenLoc());
3700}
Mike Stump1eb44332009-09-09 15:08:12 +00003701
Douglas Gregor43959a92009-08-20 07:17:43 +00003702template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003703StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003704TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003705 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00003706 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00003707 if (Init.isInvalid())
3708 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003709
Douglas Gregor43959a92009-08-20 07:17:43 +00003710 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003711 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003712 VarDecl *ConditionVar = 0;
3713 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003714 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003715 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003716 getDerived().TransformDefinition(
3717 S->getConditionVariable()->getLocation(),
3718 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003719 if (!ConditionVar)
3720 return SemaRef.StmtError();
3721 } else {
3722 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003723
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003724 if (Cond.isInvalid())
3725 return SemaRef.StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003726
3727 if (S->getCond()) {
3728 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003729 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003730 S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003731 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003732 if (CondE.isInvalid())
3733 return getSema().StmtError();
3734
John McCall9ae2f072010-08-23 23:25:46 +00003735 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003736 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003737 }
Mike Stump1eb44332009-09-09 15:08:12 +00003738
John McCall9ae2f072010-08-23 23:25:46 +00003739 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3740 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003741 return SemaRef.StmtError();
3742
Douglas Gregor43959a92009-08-20 07:17:43 +00003743 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00003744 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00003745 if (Inc.isInvalid())
3746 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003747
John McCall9ae2f072010-08-23 23:25:46 +00003748 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3749 if (S->getInc() && !FullInc.get())
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003750 return SemaRef.StmtError();
3751
Douglas Gregor43959a92009-08-20 07:17:43 +00003752 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003753 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003754 if (Body.isInvalid())
3755 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003756
Douglas Gregor43959a92009-08-20 07:17:43 +00003757 if (!getDerived().AlwaysRebuild() &&
3758 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00003759 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003760 Inc.get() == S->getInc() &&
3761 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003762 return SemaRef.Owned(S->Retain());
3763
Douglas Gregor43959a92009-08-20 07:17:43 +00003764 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003765 Init.get(), FullCond, ConditionVar,
3766 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003767}
3768
3769template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003770StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003771TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003772 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003773 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003774 S->getLabel());
3775}
3776
3777template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003778StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003779TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003780 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00003781 if (Target.isInvalid())
3782 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003783
Douglas Gregor43959a92009-08-20 07:17:43 +00003784 if (!getDerived().AlwaysRebuild() &&
3785 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003786 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003787
3788 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003789 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003790}
3791
3792template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003793StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003794TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3795 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003796}
Mike Stump1eb44332009-09-09 15:08:12 +00003797
Douglas Gregor43959a92009-08-20 07:17:43 +00003798template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003799StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003800TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3801 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003802}
Mike Stump1eb44332009-09-09 15:08:12 +00003803
Douglas Gregor43959a92009-08-20 07:17:43 +00003804template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003805StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003806TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003807 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00003808 if (Result.isInvalid())
3809 return SemaRef.StmtError();
3810
Mike Stump1eb44332009-09-09 15:08:12 +00003811 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003812 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00003813 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003814}
Mike Stump1eb44332009-09-09 15:08:12 +00003815
Douglas Gregor43959a92009-08-20 07:17:43 +00003816template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003817StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003818TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003819 bool DeclChanged = false;
3820 llvm::SmallVector<Decl *, 4> Decls;
3821 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3822 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003823 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3824 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003825 if (!Transformed)
3826 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003827
Douglas Gregor43959a92009-08-20 07:17:43 +00003828 if (Transformed != *D)
3829 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003830
Douglas Gregor43959a92009-08-20 07:17:43 +00003831 Decls.push_back(Transformed);
3832 }
Mike Stump1eb44332009-09-09 15:08:12 +00003833
Douglas Gregor43959a92009-08-20 07:17:43 +00003834 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003835 return SemaRef.Owned(S->Retain());
3836
3837 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003838 S->getStartLoc(), S->getEndLoc());
3839}
Mike Stump1eb44332009-09-09 15:08:12 +00003840
Douglas Gregor43959a92009-08-20 07:17:43 +00003841template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003842StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003843TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003844 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003845 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003846}
3847
3848template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003849StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003850TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003851
John McCallca0408f2010-08-23 06:44:23 +00003852 ASTOwningVector<Expr*> Constraints(getSema());
3853 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003854 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003855
John McCall60d7b3a2010-08-24 06:29:42 +00003856 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00003857 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00003858
3859 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003860
Anders Carlsson703e3942010-01-24 05:50:09 +00003861 // Go through the outputs.
3862 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003863 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003864
Anders Carlsson703e3942010-01-24 05:50:09 +00003865 // No need to transform the constraint literal.
3866 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003867
Anders Carlsson703e3942010-01-24 05:50:09 +00003868 // Transform the output expr.
3869 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003870 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003871 if (Result.isInvalid())
3872 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003873
Anders Carlsson703e3942010-01-24 05:50:09 +00003874 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003875
John McCall9ae2f072010-08-23 23:25:46 +00003876 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003877 }
Sean Huntc3021132010-05-05 15:23:54 +00003878
Anders Carlsson703e3942010-01-24 05:50:09 +00003879 // Go through the inputs.
3880 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003881 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003882
Anders Carlsson703e3942010-01-24 05:50:09 +00003883 // No need to transform the constraint literal.
3884 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003885
Anders Carlsson703e3942010-01-24 05:50:09 +00003886 // Transform the input expr.
3887 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003888 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003889 if (Result.isInvalid())
3890 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003891
Anders Carlsson703e3942010-01-24 05:50:09 +00003892 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003893
John McCall9ae2f072010-08-23 23:25:46 +00003894 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003895 }
Sean Huntc3021132010-05-05 15:23:54 +00003896
Anders Carlsson703e3942010-01-24 05:50:09 +00003897 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3898 return SemaRef.Owned(S->Retain());
3899
3900 // Go through the clobbers.
3901 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3902 Clobbers.push_back(S->getClobber(I)->Retain());
3903
3904 // No need to transform the asm string literal.
3905 AsmString = SemaRef.Owned(S->getAsmString());
3906
3907 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3908 S->isSimple(),
3909 S->isVolatile(),
3910 S->getNumOutputs(),
3911 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003912 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003913 move_arg(Constraints),
3914 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00003915 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003916 move_arg(Clobbers),
3917 S->getRParenLoc(),
3918 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003919}
3920
3921
3922template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003923StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003924TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003925 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00003926 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003927 if (TryBody.isInvalid())
3928 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003929
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003930 // Transform the @catch statements (if present).
3931 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003932 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003933 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00003934 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003935 if (Catch.isInvalid())
3936 return SemaRef.StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003937 if (Catch.get() != S->getCatchStmt(I))
3938 AnyCatchChanged = true;
3939 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003940 }
Sean Huntc3021132010-05-05 15:23:54 +00003941
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003942 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00003943 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003944 if (S->getFinallyStmt()) {
3945 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3946 if (Finally.isInvalid())
3947 return SemaRef.StmtError();
3948 }
3949
3950 // If nothing changed, just retain this statement.
3951 if (!getDerived().AlwaysRebuild() &&
3952 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003953 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003954 Finally.get() == S->getFinallyStmt())
3955 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003956
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003957 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00003958 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
3959 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003960}
Mike Stump1eb44332009-09-09 15:08:12 +00003961
Douglas Gregor43959a92009-08-20 07:17:43 +00003962template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003963StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003964TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00003965 // Transform the @catch parameter, if there is one.
3966 VarDecl *Var = 0;
3967 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3968 TypeSourceInfo *TSInfo = 0;
3969 if (FromVar->getTypeSourceInfo()) {
3970 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3971 if (!TSInfo)
3972 return SemaRef.StmtError();
3973 }
Sean Huntc3021132010-05-05 15:23:54 +00003974
Douglas Gregorbe270a02010-04-26 17:57:08 +00003975 QualType T;
3976 if (TSInfo)
3977 T = TSInfo->getType();
3978 else {
3979 T = getDerived().TransformType(FromVar->getType());
3980 if (T.isNull())
Sean Huntc3021132010-05-05 15:23:54 +00003981 return SemaRef.StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00003982 }
Sean Huntc3021132010-05-05 15:23:54 +00003983
Douglas Gregorbe270a02010-04-26 17:57:08 +00003984 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3985 if (!Var)
3986 return SemaRef.StmtError();
3987 }
Sean Huntc3021132010-05-05 15:23:54 +00003988
John McCall60d7b3a2010-08-24 06:29:42 +00003989 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00003990 if (Body.isInvalid())
3991 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003992
3993 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00003994 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003995 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003996}
Mike Stump1eb44332009-09-09 15:08:12 +00003997
Douglas Gregor43959a92009-08-20 07:17:43 +00003998template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003999StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004000TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004001 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004002 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004003 if (Body.isInvalid())
4004 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004005
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004006 // If nothing changed, just retain this statement.
4007 if (!getDerived().AlwaysRebuild() &&
4008 Body.get() == S->getFinallyBody())
4009 return SemaRef.Owned(S->Retain());
4010
4011 // Build a new statement.
4012 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004013 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004014}
Mike Stump1eb44332009-09-09 15:08:12 +00004015
Douglas Gregor43959a92009-08-20 07:17:43 +00004016template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004017StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004018TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004019 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004020 if (S->getThrowExpr()) {
4021 Operand = getDerived().TransformExpr(S->getThrowExpr());
4022 if (Operand.isInvalid())
4023 return getSema().StmtError();
4024 }
Sean Huntc3021132010-05-05 15:23:54 +00004025
Douglas Gregord1377b22010-04-22 21:44:01 +00004026 if (!getDerived().AlwaysRebuild() &&
4027 Operand.get() == S->getThrowExpr())
4028 return getSema().Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004029
John McCall9ae2f072010-08-23 23:25:46 +00004030 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004031}
Mike Stump1eb44332009-09-09 15:08:12 +00004032
Douglas Gregor43959a92009-08-20 07:17:43 +00004033template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004034StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004035TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004036 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004037 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004038 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004039 if (Object.isInvalid())
4040 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004041
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004042 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004043 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004044 if (Body.isInvalid())
4045 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004046
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004047 // If nothing change, just retain the current statement.
4048 if (!getDerived().AlwaysRebuild() &&
4049 Object.get() == S->getSynchExpr() &&
4050 Body.get() == S->getSynchBody())
4051 return SemaRef.Owned(S->Retain());
4052
4053 // Build a new statement.
4054 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004055 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004056}
4057
4058template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004059StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004060TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004061 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004062 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004063 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004064 if (Element.isInvalid())
4065 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004066
Douglas Gregorc3203e72010-04-22 23:10:45 +00004067 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00004068 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004069 if (Collection.isInvalid())
4070 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004071
Douglas Gregorc3203e72010-04-22 23:10:45 +00004072 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004073 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004074 if (Body.isInvalid())
4075 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004076
Douglas Gregorc3203e72010-04-22 23:10:45 +00004077 // If nothing changed, just retain this statement.
4078 if (!getDerived().AlwaysRebuild() &&
4079 Element.get() == S->getElement() &&
4080 Collection.get() == S->getCollection() &&
4081 Body.get() == S->getBody())
4082 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004083
Douglas Gregorc3203e72010-04-22 23:10:45 +00004084 // Build a new statement.
4085 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4086 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004087 Element.get(),
4088 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00004089 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004090 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004091}
4092
4093
4094template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004095StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004096TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4097 // Transform the exception declaration, if any.
4098 VarDecl *Var = 0;
4099 if (S->getExceptionDecl()) {
4100 VarDecl *ExceptionDecl = S->getExceptionDecl();
4101 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4102 ExceptionDecl->getDeclName());
4103
4104 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4105 if (T.isNull())
4106 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004107
Douglas Gregor43959a92009-08-20 07:17:43 +00004108 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4109 T,
John McCalla93c9342009-12-07 02:54:59 +00004110 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004111 ExceptionDecl->getIdentifier(),
4112 ExceptionDecl->getLocation(),
4113 /*FIXME: Inaccurate*/
4114 SourceRange(ExceptionDecl->getLocation()));
Douglas Gregorff331c12010-07-25 18:17:45 +00004115 if (!Var || Var->isInvalidDecl())
Douglas Gregor43959a92009-08-20 07:17:43 +00004116 return SemaRef.StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004117 }
Mike Stump1eb44332009-09-09 15:08:12 +00004118
Douglas Gregor43959a92009-08-20 07:17:43 +00004119 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00004120 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004121 if (Handler.isInvalid())
Douglas Gregor43959a92009-08-20 07:17:43 +00004122 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004123
Douglas Gregor43959a92009-08-20 07:17:43 +00004124 if (!getDerived().AlwaysRebuild() &&
4125 !Var &&
4126 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00004127 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004128
4129 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4130 Var,
John McCall9ae2f072010-08-23 23:25:46 +00004131 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004132}
Mike Stump1eb44332009-09-09 15:08:12 +00004133
Douglas Gregor43959a92009-08-20 07:17:43 +00004134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004135StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004136TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4137 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004138 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004139 = getDerived().TransformCompoundStmt(S->getTryBlock());
4140 if (TryBlock.isInvalid())
4141 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004142
Douglas Gregor43959a92009-08-20 07:17:43 +00004143 // Transform the handlers.
4144 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004145 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00004146 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004147 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004148 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4149 if (Handler.isInvalid())
4150 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004151
Douglas Gregor43959a92009-08-20 07:17:43 +00004152 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4153 Handlers.push_back(Handler.takeAs<Stmt>());
4154 }
Mike Stump1eb44332009-09-09 15:08:12 +00004155
Douglas Gregor43959a92009-08-20 07:17:43 +00004156 if (!getDerived().AlwaysRebuild() &&
4157 TryBlock.get() == S->getTryBlock() &&
4158 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004159 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004160
John McCall9ae2f072010-08-23 23:25:46 +00004161 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00004162 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004163}
Mike Stump1eb44332009-09-09 15:08:12 +00004164
Douglas Gregor43959a92009-08-20 07:17:43 +00004165//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004166// Expression transformation
4167//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004168template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004169ExprResult
John McCall454feb92009-12-08 09:21:05 +00004170TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004171 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004172}
Mike Stump1eb44332009-09-09 15:08:12 +00004173
4174template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004175ExprResult
John McCall454feb92009-12-08 09:21:05 +00004176TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004177 NestedNameSpecifier *Qualifier = 0;
4178 if (E->getQualifier()) {
4179 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004180 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004181 if (!Qualifier)
4182 return SemaRef.ExprError();
4183 }
John McCalldbd872f2009-12-08 09:08:17 +00004184
4185 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004186 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4187 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004188 if (!ND)
4189 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004190
John McCallec8045d2010-08-17 21:27:17 +00004191 DeclarationNameInfo NameInfo = E->getNameInfo();
4192 if (NameInfo.getName()) {
4193 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4194 if (!NameInfo.getName())
4195 return SemaRef.ExprError();
4196 }
Abramo Bagnara25777432010-08-11 22:01:17 +00004197
4198 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004199 Qualifier == E->getQualifier() &&
4200 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00004201 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00004202 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004203
4204 // Mark it referenced in the new context regardless.
4205 // FIXME: this is a bit instantiation-specific.
4206 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4207
Mike Stump1eb44332009-09-09 15:08:12 +00004208 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004209 }
John McCalldbd872f2009-12-08 09:08:17 +00004210
4211 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00004212 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004213 TemplateArgs = &TransArgs;
4214 TransArgs.setLAngleLoc(E->getLAngleLoc());
4215 TransArgs.setRAngleLoc(E->getRAngleLoc());
4216 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4217 TemplateArgumentLoc Loc;
4218 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4219 return SemaRef.ExprError();
4220 TransArgs.addArgument(Loc);
4221 }
4222 }
4223
Douglas Gregora2813ce2009-10-23 18:54:35 +00004224 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004225 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004226}
Mike Stump1eb44332009-09-09 15:08:12 +00004227
Douglas Gregorb98b1992009-08-11 05:31:07 +00004228template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004229ExprResult
John McCall454feb92009-12-08 09:21:05 +00004230TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004231 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004232}
Mike Stump1eb44332009-09-09 15:08:12 +00004233
Douglas Gregorb98b1992009-08-11 05:31:07 +00004234template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004235ExprResult
John McCall454feb92009-12-08 09:21:05 +00004236TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004237 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004238}
Mike Stump1eb44332009-09-09 15:08:12 +00004239
Douglas Gregorb98b1992009-08-11 05:31:07 +00004240template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004241ExprResult
John McCall454feb92009-12-08 09:21:05 +00004242TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004243 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004244}
Mike Stump1eb44332009-09-09 15:08:12 +00004245
Douglas Gregorb98b1992009-08-11 05:31:07 +00004246template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004247ExprResult
John McCall454feb92009-12-08 09:21:05 +00004248TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004249 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004250}
Mike Stump1eb44332009-09-09 15:08:12 +00004251
Douglas Gregorb98b1992009-08-11 05:31:07 +00004252template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004253ExprResult
John McCall454feb92009-12-08 09:21:05 +00004254TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004255 return SemaRef.Owned(E->Retain());
4256}
4257
4258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004259ExprResult
John McCall454feb92009-12-08 09:21:05 +00004260TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004261 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004262 if (SubExpr.isInvalid())
4263 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004264
Douglas Gregorb98b1992009-08-11 05:31:07 +00004265 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004266 return SemaRef.Owned(E->Retain());
4267
John McCall9ae2f072010-08-23 23:25:46 +00004268 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004269 E->getRParen());
4270}
4271
Mike Stump1eb44332009-09-09 15:08:12 +00004272template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004273ExprResult
John McCall454feb92009-12-08 09:21:05 +00004274TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004275 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004276 if (SubExpr.isInvalid())
4277 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004278
Douglas Gregorb98b1992009-08-11 05:31:07 +00004279 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004280 return SemaRef.Owned(E->Retain());
4281
Douglas Gregorb98b1992009-08-11 05:31:07 +00004282 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4283 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004284 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004285}
Mike Stump1eb44332009-09-09 15:08:12 +00004286
Douglas Gregorb98b1992009-08-11 05:31:07 +00004287template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004288ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004289TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4290 // Transform the type.
4291 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4292 if (!Type)
4293 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004294
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004295 // Transform all of the components into components similar to what the
4296 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004297 // FIXME: It would be slightly more efficient in the non-dependent case to
4298 // just map FieldDecls, rather than requiring the rebuilder to look for
4299 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004300 // template code that we don't care.
4301 bool ExprChanged = false;
4302 typedef Action::OffsetOfComponent Component;
4303 typedef OffsetOfExpr::OffsetOfNode Node;
4304 llvm::SmallVector<Component, 4> Components;
4305 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4306 const Node &ON = E->getComponent(I);
4307 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004308 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004309 Comp.LocStart = ON.getRange().getBegin();
4310 Comp.LocEnd = ON.getRange().getEnd();
4311 switch (ON.getKind()) {
4312 case Node::Array: {
4313 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00004314 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004315 if (Index.isInvalid())
4316 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004317
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004318 ExprChanged = ExprChanged || Index.get() != FromIndex;
4319 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00004320 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004321 break;
4322 }
Sean Huntc3021132010-05-05 15:23:54 +00004323
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004324 case Node::Field:
4325 case Node::Identifier:
4326 Comp.isBrackets = false;
4327 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004328 if (!Comp.U.IdentInfo)
4329 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004330
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004331 break;
Sean Huntc3021132010-05-05 15:23:54 +00004332
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004333 case Node::Base:
4334 // Will be recomputed during the rebuild.
4335 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004336 }
Sean Huntc3021132010-05-05 15:23:54 +00004337
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004338 Components.push_back(Comp);
4339 }
Sean Huntc3021132010-05-05 15:23:54 +00004340
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004341 // If nothing changed, retain the existing expression.
4342 if (!getDerived().AlwaysRebuild() &&
4343 Type == E->getTypeSourceInfo() &&
4344 !ExprChanged)
4345 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004346
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004347 // Build a new offsetof expression.
4348 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4349 Components.data(), Components.size(),
4350 E->getRParenLoc());
4351}
4352
4353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004354ExprResult
John McCall454feb92009-12-08 09:21:05 +00004355TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004356 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004357 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004358
John McCalla93c9342009-12-07 02:54:59 +00004359 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004360 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004361 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004362
John McCall5ab75172009-11-04 07:28:41 +00004363 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004364 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004365
John McCall5ab75172009-11-04 07:28:41 +00004366 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004367 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004368 E->getSourceRange());
4369 }
Mike Stump1eb44332009-09-09 15:08:12 +00004370
John McCall60d7b3a2010-08-24 06:29:42 +00004371 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00004372 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004373 // C++0x [expr.sizeof]p1:
4374 // The operand is either an expression, which is an unevaluated operand
4375 // [...]
4376 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004377
Douglas Gregorb98b1992009-08-11 05:31:07 +00004378 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4379 if (SubExpr.isInvalid())
4380 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004381
Douglas Gregorb98b1992009-08-11 05:31:07 +00004382 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4383 return SemaRef.Owned(E->Retain());
4384 }
Mike Stump1eb44332009-09-09 15:08:12 +00004385
John McCall9ae2f072010-08-23 23:25:46 +00004386 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004387 E->isSizeOf(),
4388 E->getSourceRange());
4389}
Mike Stump1eb44332009-09-09 15:08:12 +00004390
Douglas Gregorb98b1992009-08-11 05:31:07 +00004391template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004392ExprResult
John McCall454feb92009-12-08 09:21:05 +00004393TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004394 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004395 if (LHS.isInvalid())
4396 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004397
John McCall60d7b3a2010-08-24 06:29:42 +00004398 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004399 if (RHS.isInvalid())
4400 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004401
4402
Douglas Gregorb98b1992009-08-11 05:31:07 +00004403 if (!getDerived().AlwaysRebuild() &&
4404 LHS.get() == E->getLHS() &&
4405 RHS.get() == E->getRHS())
4406 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004407
John McCall9ae2f072010-08-23 23:25:46 +00004408 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004409 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00004410 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004411 E->getRBracketLoc());
4412}
Mike Stump1eb44332009-09-09 15:08:12 +00004413
4414template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004415ExprResult
John McCall454feb92009-12-08 09:21:05 +00004416TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004417 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00004418 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004419 if (Callee.isInvalid())
4420 return SemaRef.ExprError();
4421
4422 // Transform arguments.
4423 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004424 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004425 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4426 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004427 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004428 if (Arg.isInvalid())
4429 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004430
Douglas Gregorb98b1992009-08-11 05:31:07 +00004431 // FIXME: Wrong source location information for the ','.
4432 FakeCommaLocs.push_back(
4433 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00004434
4435 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00004436 Args.push_back(Arg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004437 }
Mike Stump1eb44332009-09-09 15:08:12 +00004438
Douglas Gregorb98b1992009-08-11 05:31:07 +00004439 if (!getDerived().AlwaysRebuild() &&
4440 Callee.get() == E->getCallee() &&
4441 !ArgChanged)
4442 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004443
Douglas Gregorb98b1992009-08-11 05:31:07 +00004444 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004445 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004446 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00004447 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004448 move_arg(Args),
4449 FakeCommaLocs.data(),
4450 E->getRParenLoc());
4451}
Mike Stump1eb44332009-09-09 15:08:12 +00004452
4453template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004454ExprResult
John McCall454feb92009-12-08 09:21:05 +00004455TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004456 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004457 if (Base.isInvalid())
4458 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004459
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004460 NestedNameSpecifier *Qualifier = 0;
4461 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004462 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004463 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004464 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004465 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004466 return SemaRef.ExprError();
4467 }
Mike Stump1eb44332009-09-09 15:08:12 +00004468
Eli Friedmanf595cc42009-12-04 06:40:45 +00004469 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004470 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4471 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004472 if (!Member)
4473 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004474
John McCall6bb80172010-03-30 21:47:33 +00004475 NamedDecl *FoundDecl = E->getFoundDecl();
4476 if (FoundDecl == E->getMemberDecl()) {
4477 FoundDecl = Member;
4478 } else {
4479 FoundDecl = cast_or_null<NamedDecl>(
4480 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4481 if (!FoundDecl)
4482 return SemaRef.ExprError();
4483 }
4484
Douglas Gregorb98b1992009-08-11 05:31:07 +00004485 if (!getDerived().AlwaysRebuild() &&
4486 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004487 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004488 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004489 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00004490 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00004491
Anders Carlsson1f240322009-12-22 05:24:09 +00004492 // Mark it referenced in the new context regardless.
4493 // FIXME: this is a bit instantiation-specific.
4494 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00004495 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00004496 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004497
John McCalld5532b62009-11-23 01:53:49 +00004498 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00004499 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00004500 TransArgs.setLAngleLoc(E->getLAngleLoc());
4501 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004502 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004503 TemplateArgumentLoc Loc;
4504 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004505 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004506 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004507 }
4508 }
Sean Huntc3021132010-05-05 15:23:54 +00004509
Douglas Gregorb98b1992009-08-11 05:31:07 +00004510 // FIXME: Bogus source location for the operator
4511 SourceLocation FakeOperatorLoc
4512 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4513
John McCallc2233c52010-01-15 08:34:02 +00004514 // FIXME: to do this check properly, we will need to preserve the
4515 // first-qualifier-in-scope here, just in case we had a dependent
4516 // base (and therefore couldn't do the check) and a
4517 // nested-name-qualifier (and therefore could do the lookup).
4518 NamedDecl *FirstQualifierInScope = 0;
4519
John McCall9ae2f072010-08-23 23:25:46 +00004520 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004521 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004522 Qualifier,
4523 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004524 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004525 Member,
John McCall6bb80172010-03-30 21:47:33 +00004526 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00004527 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00004528 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004529 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004530}
Mike Stump1eb44332009-09-09 15:08:12 +00004531
Douglas Gregorb98b1992009-08-11 05:31:07 +00004532template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004533ExprResult
John McCall454feb92009-12-08 09:21:05 +00004534TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004535 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004536 if (LHS.isInvalid())
4537 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004538
John McCall60d7b3a2010-08-24 06:29:42 +00004539 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004540 if (RHS.isInvalid())
4541 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004542
Douglas Gregorb98b1992009-08-11 05:31:07 +00004543 if (!getDerived().AlwaysRebuild() &&
4544 LHS.get() == E->getLHS() &&
4545 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004546 return SemaRef.Owned(E->Retain());
4547
Douglas Gregorb98b1992009-08-11 05:31:07 +00004548 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004549 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004550}
4551
Mike Stump1eb44332009-09-09 15:08:12 +00004552template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004553ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004554TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004555 CompoundAssignOperator *E) {
4556 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004557}
Mike Stump1eb44332009-09-09 15:08:12 +00004558
Douglas Gregorb98b1992009-08-11 05:31:07 +00004559template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004560ExprResult
John McCall454feb92009-12-08 09:21:05 +00004561TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004562 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004563 if (Cond.isInvalid())
4564 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004565
John McCall60d7b3a2010-08-24 06:29:42 +00004566 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004567 if (LHS.isInvalid())
4568 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004569
John McCall60d7b3a2010-08-24 06:29:42 +00004570 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004571 if (RHS.isInvalid())
4572 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004573
Douglas Gregorb98b1992009-08-11 05:31:07 +00004574 if (!getDerived().AlwaysRebuild() &&
4575 Cond.get() == E->getCond() &&
4576 LHS.get() == E->getLHS() &&
4577 RHS.get() == E->getRHS())
4578 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004579
John McCall9ae2f072010-08-23 23:25:46 +00004580 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004581 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004582 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004583 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004584 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004585}
Mike Stump1eb44332009-09-09 15:08:12 +00004586
4587template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004588ExprResult
John McCall454feb92009-12-08 09:21:05 +00004589TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004590 // Implicit casts are eliminated during transformation, since they
4591 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004592 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004593}
Mike Stump1eb44332009-09-09 15:08:12 +00004594
Douglas Gregorb98b1992009-08-11 05:31:07 +00004595template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004596ExprResult
John McCall454feb92009-12-08 09:21:05 +00004597TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004598 TypeSourceInfo *OldT;
4599 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004600 {
4601 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004602 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004603 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4604 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004605
John McCall9d125032010-01-15 18:39:57 +00004606 OldT = E->getTypeInfoAsWritten();
4607 NewT = getDerived().TransformType(OldT);
4608 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004609 return SemaRef.ExprError();
4610 }
Mike Stump1eb44332009-09-09 15:08:12 +00004611
John McCall60d7b3a2010-08-24 06:29:42 +00004612 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004613 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004614 if (SubExpr.isInvalid())
4615 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004616
Douglas Gregorb98b1992009-08-11 05:31:07 +00004617 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004618 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004619 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004620 return SemaRef.Owned(E->Retain());
4621
John McCall9d125032010-01-15 18:39:57 +00004622 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4623 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004624 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004625 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004626}
Mike Stump1eb44332009-09-09 15:08:12 +00004627
Douglas Gregorb98b1992009-08-11 05:31:07 +00004628template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004629ExprResult
John McCall454feb92009-12-08 09:21:05 +00004630TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004631 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4632 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4633 if (!NewT)
4634 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004635
John McCall60d7b3a2010-08-24 06:29:42 +00004636 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004637 if (Init.isInvalid())
4638 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004639
Douglas Gregorb98b1992009-08-11 05:31:07 +00004640 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004641 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004642 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00004643 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004644
John McCall1d7d8d62010-01-19 22:33:45 +00004645 // Note: the expression type doesn't necessarily match the
4646 // type-as-written, but that's okay, because it should always be
4647 // derivable from the initializer.
4648
John McCall42f56b52010-01-18 19:35:47 +00004649 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004650 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00004651 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004652}
Mike Stump1eb44332009-09-09 15:08:12 +00004653
Douglas Gregorb98b1992009-08-11 05:31:07 +00004654template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004655ExprResult
John McCall454feb92009-12-08 09:21:05 +00004656TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004657 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004658 if (Base.isInvalid())
4659 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004660
Douglas Gregorb98b1992009-08-11 05:31:07 +00004661 if (!getDerived().AlwaysRebuild() &&
4662 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00004663 return SemaRef.Owned(E->Retain());
4664
Douglas Gregorb98b1992009-08-11 05:31:07 +00004665 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004666 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004667 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00004668 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004669 E->getAccessorLoc(),
4670 E->getAccessor());
4671}
Mike Stump1eb44332009-09-09 15:08:12 +00004672
Douglas Gregorb98b1992009-08-11 05:31:07 +00004673template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004674ExprResult
John McCall454feb92009-12-08 09:21:05 +00004675TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004676 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004677
John McCallca0408f2010-08-23 06:44:23 +00004678 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004679 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004680 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004681 if (Init.isInvalid())
4682 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004683
Douglas Gregorb98b1992009-08-11 05:31:07 +00004684 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCall9ae2f072010-08-23 23:25:46 +00004685 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004686 }
Mike Stump1eb44332009-09-09 15:08:12 +00004687
Douglas Gregorb98b1992009-08-11 05:31:07 +00004688 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004689 return SemaRef.Owned(E->Retain());
4690
Douglas Gregorb98b1992009-08-11 05:31:07 +00004691 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004692 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004693}
Mike Stump1eb44332009-09-09 15:08:12 +00004694
Douglas Gregorb98b1992009-08-11 05:31:07 +00004695template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004696ExprResult
John McCall454feb92009-12-08 09:21:05 +00004697TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004698 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004699
Douglas Gregor43959a92009-08-20 07:17:43 +00004700 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00004701 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004702 if (Init.isInvalid())
4703 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004704
Douglas Gregor43959a92009-08-20 07:17:43 +00004705 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00004706 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004707 bool ExprChanged = false;
4708 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4709 DEnd = E->designators_end();
4710 D != DEnd; ++D) {
4711 if (D->isFieldDesignator()) {
4712 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4713 D->getDotLoc(),
4714 D->getFieldLoc()));
4715 continue;
4716 }
Mike Stump1eb44332009-09-09 15:08:12 +00004717
Douglas Gregorb98b1992009-08-11 05:31:07 +00004718 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00004719 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004720 if (Index.isInvalid())
4721 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004722
4723 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004724 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004725
Douglas Gregorb98b1992009-08-11 05:31:07 +00004726 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4727 ArrayExprs.push_back(Index.release());
4728 continue;
4729 }
Mike Stump1eb44332009-09-09 15:08:12 +00004730
Douglas Gregorb98b1992009-08-11 05:31:07 +00004731 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00004732 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004733 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4734 if (Start.isInvalid())
4735 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004736
John McCall60d7b3a2010-08-24 06:29:42 +00004737 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004738 if (End.isInvalid())
4739 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004740
4741 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004742 End.get(),
4743 D->getLBracketLoc(),
4744 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004745
Douglas Gregorb98b1992009-08-11 05:31:07 +00004746 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4747 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004748
Douglas Gregorb98b1992009-08-11 05:31:07 +00004749 ArrayExprs.push_back(Start.release());
4750 ArrayExprs.push_back(End.release());
4751 }
Mike Stump1eb44332009-09-09 15:08:12 +00004752
Douglas Gregorb98b1992009-08-11 05:31:07 +00004753 if (!getDerived().AlwaysRebuild() &&
4754 Init.get() == E->getInit() &&
4755 !ExprChanged)
4756 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004757
Douglas Gregorb98b1992009-08-11 05:31:07 +00004758 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4759 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004760 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004761}
Mike Stump1eb44332009-09-09 15:08:12 +00004762
Douglas Gregorb98b1992009-08-11 05:31:07 +00004763template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004764ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004765TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004766 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004767 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004768
Douglas Gregor5557b252009-10-28 00:29:27 +00004769 // FIXME: Will we ever have proper type location here? Will we actually
4770 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004771 QualType T = getDerived().TransformType(E->getType());
4772 if (T.isNull())
4773 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004774
Douglas Gregorb98b1992009-08-11 05:31:07 +00004775 if (!getDerived().AlwaysRebuild() &&
4776 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004777 return SemaRef.Owned(E->Retain());
4778
Douglas Gregorb98b1992009-08-11 05:31:07 +00004779 return getDerived().RebuildImplicitValueInitExpr(T);
4780}
Mike Stump1eb44332009-09-09 15:08:12 +00004781
Douglas Gregorb98b1992009-08-11 05:31:07 +00004782template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004783ExprResult
John McCall454feb92009-12-08 09:21:05 +00004784TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004785 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4786 if (!TInfo)
4787 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004788
John McCall60d7b3a2010-08-24 06:29:42 +00004789 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004790 if (SubExpr.isInvalid())
4791 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004792
Douglas Gregorb98b1992009-08-11 05:31:07 +00004793 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004794 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004795 SubExpr.get() == E->getSubExpr())
4796 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004797
John McCall9ae2f072010-08-23 23:25:46 +00004798 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004799 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004800}
4801
4802template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004803ExprResult
John McCall454feb92009-12-08 09:21:05 +00004804TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004805 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004806 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004807 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004808 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004809 if (Init.isInvalid())
4810 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004811
Douglas Gregorb98b1992009-08-11 05:31:07 +00004812 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00004813 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004814 }
Mike Stump1eb44332009-09-09 15:08:12 +00004815
Douglas Gregorb98b1992009-08-11 05:31:07 +00004816 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4817 move_arg(Inits),
4818 E->getRParenLoc());
4819}
Mike Stump1eb44332009-09-09 15:08:12 +00004820
Douglas Gregorb98b1992009-08-11 05:31:07 +00004821/// \brief Transform an address-of-label expression.
4822///
4823/// By default, the transformation of an address-of-label expression always
4824/// rebuilds the expression, so that the label identifier can be resolved to
4825/// the corresponding label statement by semantic analysis.
4826template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004827ExprResult
John McCall454feb92009-12-08 09:21:05 +00004828TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004829 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4830 E->getLabel());
4831}
Mike Stump1eb44332009-09-09 15:08:12 +00004832
4833template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004834ExprResult
John McCall454feb92009-12-08 09:21:05 +00004835TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004836 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004837 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4838 if (SubStmt.isInvalid())
4839 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004840
Douglas Gregorb98b1992009-08-11 05:31:07 +00004841 if (!getDerived().AlwaysRebuild() &&
4842 SubStmt.get() == E->getSubStmt())
4843 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004844
4845 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004846 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004847 E->getRParenLoc());
4848}
Mike Stump1eb44332009-09-09 15:08:12 +00004849
Douglas Gregorb98b1992009-08-11 05:31:07 +00004850template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004851ExprResult
John McCall454feb92009-12-08 09:21:05 +00004852TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004853 TypeSourceInfo *TInfo1;
4854 TypeSourceInfo *TInfo2;
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004855
4856 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4857 if (!TInfo1)
4858 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004859
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004860 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4861 if (!TInfo2)
4862 return SemaRef.ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004863
4864 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004865 TInfo1 == E->getArgTInfo1() &&
4866 TInfo2 == E->getArgTInfo2())
Mike Stump1eb44332009-09-09 15:08:12 +00004867 return SemaRef.Owned(E->Retain());
4868
Douglas Gregorb98b1992009-08-11 05:31:07 +00004869 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004870 TInfo1, TInfo2,
4871 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004872}
Mike Stump1eb44332009-09-09 15:08:12 +00004873
Douglas Gregorb98b1992009-08-11 05:31:07 +00004874template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004875ExprResult
John McCall454feb92009-12-08 09:21:05 +00004876TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004877 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004878 if (Cond.isInvalid())
4879 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004880
John McCall60d7b3a2010-08-24 06:29:42 +00004881 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004882 if (LHS.isInvalid())
4883 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004884
John McCall60d7b3a2010-08-24 06:29:42 +00004885 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004886 if (RHS.isInvalid())
4887 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004888
Douglas Gregorb98b1992009-08-11 05:31:07 +00004889 if (!getDerived().AlwaysRebuild() &&
4890 Cond.get() == E->getCond() &&
4891 LHS.get() == E->getLHS() &&
4892 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004893 return SemaRef.Owned(E->Retain());
4894
Douglas Gregorb98b1992009-08-11 05:31:07 +00004895 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004896 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004897 E->getRParenLoc());
4898}
Mike Stump1eb44332009-09-09 15:08:12 +00004899
Douglas Gregorb98b1992009-08-11 05:31:07 +00004900template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004901ExprResult
John McCall454feb92009-12-08 09:21:05 +00004902TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004903 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004904}
4905
4906template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004907ExprResult
John McCall454feb92009-12-08 09:21:05 +00004908TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004909 switch (E->getOperator()) {
4910 case OO_New:
4911 case OO_Delete:
4912 case OO_Array_New:
4913 case OO_Array_Delete:
4914 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4915 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004916
Douglas Gregor668d6d92009-12-13 20:44:55 +00004917 case OO_Call: {
4918 // This is a call to an object's operator().
4919 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4920
4921 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004922 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00004923 if (Object.isInvalid())
4924 return SemaRef.ExprError();
4925
4926 // FIXME: Poor location information
4927 SourceLocation FakeLParenLoc
4928 = SemaRef.PP.getLocForEndOfToken(
4929 static_cast<Expr *>(Object.get())->getLocEnd());
4930
4931 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00004932 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor668d6d92009-12-13 20:44:55 +00004933 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4934 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004935 if (getDerived().DropCallArgument(E->getArg(I)))
4936 break;
Sean Huntc3021132010-05-05 15:23:54 +00004937
John McCall60d7b3a2010-08-24 06:29:42 +00004938 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor668d6d92009-12-13 20:44:55 +00004939 if (Arg.isInvalid())
4940 return SemaRef.ExprError();
4941
4942 // FIXME: Poor source location information.
4943 SourceLocation FakeCommaLoc
4944 = SemaRef.PP.getLocForEndOfToken(
4945 static_cast<Expr *>(Arg.get())->getLocEnd());
4946 FakeCommaLocs.push_back(FakeCommaLoc);
4947 Args.push_back(Arg.release());
4948 }
4949
John McCall9ae2f072010-08-23 23:25:46 +00004950 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00004951 move_arg(Args),
4952 FakeCommaLocs.data(),
4953 E->getLocEnd());
4954 }
4955
4956#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4957 case OO_##Name:
4958#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4959#include "clang/Basic/OperatorKinds.def"
4960 case OO_Subscript:
4961 // Handled below.
4962 break;
4963
4964 case OO_Conditional:
4965 llvm_unreachable("conditional operator is not actually overloadable");
4966 return SemaRef.ExprError();
4967
4968 case OO_None:
4969 case NUM_OVERLOADED_OPERATORS:
4970 llvm_unreachable("not an overloaded operator?");
4971 return SemaRef.ExprError();
4972 }
4973
John McCall60d7b3a2010-08-24 06:29:42 +00004974 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004975 if (Callee.isInvalid())
4976 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004977
John McCall60d7b3a2010-08-24 06:29:42 +00004978 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004979 if (First.isInvalid())
4980 return SemaRef.ExprError();
4981
John McCall60d7b3a2010-08-24 06:29:42 +00004982 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004983 if (E->getNumArgs() == 2) {
4984 Second = getDerived().TransformExpr(E->getArg(1));
4985 if (Second.isInvalid())
4986 return SemaRef.ExprError();
4987 }
Mike Stump1eb44332009-09-09 15:08:12 +00004988
Douglas Gregorb98b1992009-08-11 05:31:07 +00004989 if (!getDerived().AlwaysRebuild() &&
4990 Callee.get() == E->getCallee() &&
4991 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00004992 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4993 return SemaRef.Owned(E->Retain());
4994
Douglas Gregorb98b1992009-08-11 05:31:07 +00004995 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4996 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004997 Callee.get(),
4998 First.get(),
4999 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005000}
Mike Stump1eb44332009-09-09 15:08:12 +00005001
Douglas Gregorb98b1992009-08-11 05:31:07 +00005002template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005003ExprResult
John McCall454feb92009-12-08 09:21:05 +00005004TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5005 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005006}
Mike Stump1eb44332009-09-09 15:08:12 +00005007
Douglas Gregorb98b1992009-08-11 05:31:07 +00005008template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005009ExprResult
John McCall454feb92009-12-08 09:21:05 +00005010TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00005011 TypeSourceInfo *OldT;
5012 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005013 {
5014 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00005015 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005016 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5017 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005018
John McCall9d125032010-01-15 18:39:57 +00005019 OldT = E->getTypeInfoAsWritten();
5020 NewT = getDerived().TransformType(OldT);
5021 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005022 return SemaRef.ExprError();
5023 }
Mike Stump1eb44332009-09-09 15:08:12 +00005024
John McCall60d7b3a2010-08-24 06:29:42 +00005025 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005026 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005027 if (SubExpr.isInvalid())
5028 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005029
Douglas Gregorb98b1992009-08-11 05:31:07 +00005030 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00005031 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005032 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005033 return SemaRef.Owned(E->Retain());
5034
Douglas Gregorb98b1992009-08-11 05:31:07 +00005035 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005036 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005037 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5038 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5039 SourceLocation FakeRParenLoc
5040 = SemaRef.PP.getLocForEndOfToken(
5041 E->getSubExpr()->getSourceRange().getEnd());
5042 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005043 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005044 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00005045 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005046 FakeRAngleLoc,
5047 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005048 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005049 FakeRParenLoc);
5050}
Mike Stump1eb44332009-09-09 15:08:12 +00005051
Douglas Gregorb98b1992009-08-11 05:31:07 +00005052template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005053ExprResult
John McCall454feb92009-12-08 09:21:05 +00005054TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5055 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005056}
Mike Stump1eb44332009-09-09 15:08:12 +00005057
5058template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005059ExprResult
John McCall454feb92009-12-08 09:21:05 +00005060TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5061 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005062}
5063
Douglas Gregorb98b1992009-08-11 05:31:07 +00005064template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005065ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005066TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005067 CXXReinterpretCastExpr *E) {
5068 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005069}
Mike Stump1eb44332009-09-09 15:08:12 +00005070
Douglas Gregorb98b1992009-08-11 05:31:07 +00005071template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005072ExprResult
John McCall454feb92009-12-08 09:21:05 +00005073TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5074 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005075}
Mike Stump1eb44332009-09-09 15:08:12 +00005076
Douglas Gregorb98b1992009-08-11 05:31:07 +00005077template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005078ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005079TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005080 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00005081 TypeSourceInfo *OldT;
5082 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005083 {
5084 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005085
John McCall9d125032010-01-15 18:39:57 +00005086 OldT = E->getTypeInfoAsWritten();
5087 NewT = getDerived().TransformType(OldT);
5088 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005089 return SemaRef.ExprError();
5090 }
Mike Stump1eb44332009-09-09 15:08:12 +00005091
John McCall60d7b3a2010-08-24 06:29:42 +00005092 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005093 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005094 if (SubExpr.isInvalid())
5095 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005096
Douglas Gregorb98b1992009-08-11 05:31:07 +00005097 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00005098 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005099 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005100 return SemaRef.Owned(E->Retain());
5101
Douglas Gregorb98b1992009-08-11 05:31:07 +00005102 // FIXME: The end of the type's source range is wrong
5103 return getDerived().RebuildCXXFunctionalCastExpr(
5104 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall9d125032010-01-15 18:39:57 +00005105 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005106 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005107 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005108 E->getRParenLoc());
5109}
Mike Stump1eb44332009-09-09 15:08:12 +00005110
Douglas Gregorb98b1992009-08-11 05:31:07 +00005111template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005112ExprResult
John McCall454feb92009-12-08 09:21:05 +00005113TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005114 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005115 TypeSourceInfo *TInfo
5116 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5117 if (!TInfo)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005118 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005119
Douglas Gregorb98b1992009-08-11 05:31:07 +00005120 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005121 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005122 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005123
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005124 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5125 E->getLocStart(),
5126 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005127 E->getLocEnd());
5128 }
Mike Stump1eb44332009-09-09 15:08:12 +00005129
Douglas Gregorb98b1992009-08-11 05:31:07 +00005130 // We don't know whether the expression is potentially evaluated until
5131 // after we perform semantic analysis, so the expression is potentially
5132 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005133 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005134 Action::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005135
John McCall60d7b3a2010-08-24 06:29:42 +00005136 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005137 if (SubExpr.isInvalid())
5138 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005139
Douglas Gregorb98b1992009-08-11 05:31:07 +00005140 if (!getDerived().AlwaysRebuild() &&
5141 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00005142 return SemaRef.Owned(E->Retain());
5143
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005144 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5145 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005146 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005147 E->getLocEnd());
5148}
5149
5150template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005151ExprResult
John McCall454feb92009-12-08 09:21:05 +00005152TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005153 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005154}
Mike Stump1eb44332009-09-09 15:08:12 +00005155
Douglas Gregorb98b1992009-08-11 05:31:07 +00005156template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005157ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005158TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005159 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005160 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005161}
Mike Stump1eb44332009-09-09 15:08:12 +00005162
Douglas Gregorb98b1992009-08-11 05:31:07 +00005163template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005164ExprResult
John McCall454feb92009-12-08 09:21:05 +00005165TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005166 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005167
Douglas Gregorb98b1992009-08-11 05:31:07 +00005168 QualType T = getDerived().TransformType(E->getType());
5169 if (T.isNull())
5170 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005171
Douglas Gregorb98b1992009-08-11 05:31:07 +00005172 if (!getDerived().AlwaysRebuild() &&
5173 T == E->getType())
5174 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005175
Douglas Gregor828a1972010-01-07 23:12:05 +00005176 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005177}
Mike Stump1eb44332009-09-09 15:08:12 +00005178
Douglas Gregorb98b1992009-08-11 05:31:07 +00005179template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005180ExprResult
John McCall454feb92009-12-08 09:21:05 +00005181TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005182 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005183 if (SubExpr.isInvalid())
5184 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005185
Douglas Gregorb98b1992009-08-11 05:31:07 +00005186 if (!getDerived().AlwaysRebuild() &&
5187 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005188 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005189
John McCall9ae2f072010-08-23 23:25:46 +00005190 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005191}
Mike Stump1eb44332009-09-09 15:08:12 +00005192
Douglas Gregorb98b1992009-08-11 05:31:07 +00005193template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005194ExprResult
John McCall454feb92009-12-08 09:21:05 +00005195TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005196 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005197 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5198 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005199 if (!Param)
5200 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005201
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005202 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005203 Param == E->getParam())
5204 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005205
Douglas Gregor036aed12009-12-23 23:03:06 +00005206 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005207}
Mike Stump1eb44332009-09-09 15:08:12 +00005208
Douglas Gregorb98b1992009-08-11 05:31:07 +00005209template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005210ExprResult
Douglas Gregored8abf12010-07-08 06:14:04 +00005211TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005212 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5213
5214 QualType T = getDerived().TransformType(E->getType());
5215 if (T.isNull())
5216 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005217
Douglas Gregorb98b1992009-08-11 05:31:07 +00005218 if (!getDerived().AlwaysRebuild() &&
5219 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00005220 return SemaRef.Owned(E->Retain());
5221
Douglas Gregored8abf12010-07-08 06:14:04 +00005222 return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
5223 /*FIXME:*/E->getTypeBeginLoc(),
5224 T,
5225 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005226}
Mike Stump1eb44332009-09-09 15:08:12 +00005227
Douglas Gregorb98b1992009-08-11 05:31:07 +00005228template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005229ExprResult
John McCall454feb92009-12-08 09:21:05 +00005230TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005231 // Transform the type that we're allocating
5232 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5233 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5234 if (AllocType.isNull())
5235 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005236
Douglas Gregorb98b1992009-08-11 05:31:07 +00005237 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00005238 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005239 if (ArraySize.isInvalid())
5240 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005241
Douglas Gregorb98b1992009-08-11 05:31:07 +00005242 // Transform the placement arguments (if any).
5243 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005244 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005245 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005246 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005247 if (Arg.isInvalid())
5248 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005249
Douglas Gregorb98b1992009-08-11 05:31:07 +00005250 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5251 PlacementArgs.push_back(Arg.take());
5252 }
Mike Stump1eb44332009-09-09 15:08:12 +00005253
Douglas Gregor43959a92009-08-20 07:17:43 +00005254 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00005255 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005256 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005257 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5258 break;
5259
John McCall60d7b3a2010-08-24 06:29:42 +00005260 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005261 if (Arg.isInvalid())
5262 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005263
Douglas Gregorb98b1992009-08-11 05:31:07 +00005264 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5265 ConstructorArgs.push_back(Arg.take());
5266 }
Mike Stump1eb44332009-09-09 15:08:12 +00005267
Douglas Gregor1af74512010-02-26 00:38:10 +00005268 // Transform constructor, new operator, and delete operator.
5269 CXXConstructorDecl *Constructor = 0;
5270 if (E->getConstructor()) {
5271 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005272 getDerived().TransformDecl(E->getLocStart(),
5273 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005274 if (!Constructor)
5275 return SemaRef.ExprError();
5276 }
5277
5278 FunctionDecl *OperatorNew = 0;
5279 if (E->getOperatorNew()) {
5280 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005281 getDerived().TransformDecl(E->getLocStart(),
5282 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005283 if (!OperatorNew)
5284 return SemaRef.ExprError();
5285 }
5286
5287 FunctionDecl *OperatorDelete = 0;
5288 if (E->getOperatorDelete()) {
5289 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005290 getDerived().TransformDecl(E->getLocStart(),
5291 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005292 if (!OperatorDelete)
5293 return SemaRef.ExprError();
5294 }
Sean Huntc3021132010-05-05 15:23:54 +00005295
Douglas Gregorb98b1992009-08-11 05:31:07 +00005296 if (!getDerived().AlwaysRebuild() &&
5297 AllocType == E->getAllocatedType() &&
5298 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005299 Constructor == E->getConstructor() &&
5300 OperatorNew == E->getOperatorNew() &&
5301 OperatorDelete == E->getOperatorDelete() &&
5302 !ArgumentChanged) {
5303 // Mark any declarations we need as referenced.
5304 // FIXME: instantiation-specific.
5305 if (Constructor)
5306 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5307 if (OperatorNew)
5308 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5309 if (OperatorDelete)
5310 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005311 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005312 }
Mike Stump1eb44332009-09-09 15:08:12 +00005313
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005314 if (!ArraySize.get()) {
5315 // If no array size was specified, but the new expression was
5316 // instantiated with an array type (e.g., "new T" where T is
5317 // instantiated with "int[4]"), extract the outer bound from the
5318 // array type as our array size. We do this with constant and
5319 // dependently-sized array types.
5320 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5321 if (!ArrayT) {
5322 // Do nothing
5323 } else if (const ConstantArrayType *ConsArrayT
5324 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005325 ArraySize
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005326 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Sean Huntc3021132010-05-05 15:23:54 +00005327 ConsArrayT->getSize(),
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005328 SemaRef.Context.getSizeType(),
5329 /*FIXME:*/E->getLocStart()));
5330 AllocType = ConsArrayT->getElementType();
5331 } else if (const DependentSizedArrayType *DepArrayT
5332 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5333 if (DepArrayT->getSizeExpr()) {
5334 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5335 AllocType = DepArrayT->getElementType();
5336 }
5337 }
5338 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005339 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5340 E->isGlobalNew(),
5341 /*FIXME:*/E->getLocStart(),
5342 move_arg(PlacementArgs),
5343 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00005344 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005345 AllocType,
5346 /*FIXME:*/E->getLocStart(),
5347 /*FIXME:*/SourceRange(),
John McCall9ae2f072010-08-23 23:25:46 +00005348 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005349 /*FIXME:*/E->getLocStart(),
5350 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005351 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005352}
Mike Stump1eb44332009-09-09 15:08:12 +00005353
Douglas Gregorb98b1992009-08-11 05:31:07 +00005354template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005355ExprResult
John McCall454feb92009-12-08 09:21:05 +00005356TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005357 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005358 if (Operand.isInvalid())
5359 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005360
Douglas Gregor1af74512010-02-26 00:38:10 +00005361 // Transform the delete operator, if known.
5362 FunctionDecl *OperatorDelete = 0;
5363 if (E->getOperatorDelete()) {
5364 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005365 getDerived().TransformDecl(E->getLocStart(),
5366 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005367 if (!OperatorDelete)
5368 return SemaRef.ExprError();
5369 }
Sean Huntc3021132010-05-05 15:23:54 +00005370
Douglas Gregorb98b1992009-08-11 05:31:07 +00005371 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005372 Operand.get() == E->getArgument() &&
5373 OperatorDelete == E->getOperatorDelete()) {
5374 // Mark any declarations we need as referenced.
5375 // FIXME: instantiation-specific.
5376 if (OperatorDelete)
5377 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005378 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005379 }
Mike Stump1eb44332009-09-09 15:08:12 +00005380
Douglas Gregorb98b1992009-08-11 05:31:07 +00005381 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5382 E->isGlobalDelete(),
5383 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00005384 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005385}
Mike Stump1eb44332009-09-09 15:08:12 +00005386
Douglas Gregorb98b1992009-08-11 05:31:07 +00005387template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005388ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005389TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005390 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005391 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00005392 if (Base.isInvalid())
5393 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005394
John McCallb3d87482010-08-24 05:47:05 +00005395 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005396 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005397 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005398 E->getOperatorLoc(),
5399 E->isArrow()? tok::arrow : tok::period,
5400 ObjectTypePtr,
5401 MayBePseudoDestructor);
5402 if (Base.isInvalid())
5403 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005404
John McCallb3d87482010-08-24 05:47:05 +00005405 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora71d8192009-09-04 17:36:40 +00005406 NestedNameSpecifier *Qualifier
5407 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00005408 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005409 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00005410 if (E->getQualifier() && !Qualifier)
5411 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005412
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005413 PseudoDestructorTypeStorage Destroyed;
5414 if (E->getDestroyedTypeInfo()) {
5415 TypeSourceInfo *DestroyedTypeInfo
5416 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5417 if (!DestroyedTypeInfo)
5418 return SemaRef.ExprError();
5419 Destroyed = DestroyedTypeInfo;
5420 } else if (ObjectType->isDependentType()) {
5421 // We aren't likely to be able to resolve the identifier down to a type
5422 // now anyway, so just retain the identifier.
5423 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5424 E->getDestroyedTypeLoc());
5425 } else {
5426 // Look for a destructor known with the given name.
5427 CXXScopeSpec SS;
5428 if (Qualifier) {
5429 SS.setScopeRep(Qualifier);
5430 SS.setRange(E->getQualifierRange());
5431 }
Sean Huntc3021132010-05-05 15:23:54 +00005432
John McCallb3d87482010-08-24 05:47:05 +00005433 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005434 *E->getDestroyedTypeIdentifier(),
5435 E->getDestroyedTypeLoc(),
5436 /*Scope=*/0,
5437 SS, ObjectTypePtr,
5438 false);
5439 if (!T)
5440 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005441
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005442 Destroyed
5443 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5444 E->getDestroyedTypeLoc());
5445 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005446
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005447 TypeSourceInfo *ScopeTypeInfo = 0;
5448 if (E->getScopeTypeInfo()) {
Sean Huntc3021132010-05-05 15:23:54 +00005449 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005450 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005451 if (!ScopeTypeInfo)
Douglas Gregora71d8192009-09-04 17:36:40 +00005452 return SemaRef.ExprError();
5453 }
Sean Huntc3021132010-05-05 15:23:54 +00005454
John McCall9ae2f072010-08-23 23:25:46 +00005455 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005456 E->getOperatorLoc(),
5457 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005458 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005459 E->getQualifierRange(),
5460 ScopeTypeInfo,
5461 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005462 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005463 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005464}
Mike Stump1eb44332009-09-09 15:08:12 +00005465
Douglas Gregora71d8192009-09-04 17:36:40 +00005466template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005467ExprResult
John McCallba135432009-11-21 08:51:07 +00005468TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005469 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005470 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5471
5472 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5473 Sema::LookupOrdinaryName);
5474
5475 // Transform all the decls.
5476 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5477 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005478 NamedDecl *InstD = static_cast<NamedDecl*>(
5479 getDerived().TransformDecl(Old->getNameLoc(),
5480 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005481 if (!InstD) {
5482 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5483 // This can happen because of dependent hiding.
5484 if (isa<UsingShadowDecl>(*I))
5485 continue;
5486 else
5487 return SemaRef.ExprError();
5488 }
John McCallf7a1a742009-11-24 19:00:30 +00005489
5490 // Expand using declarations.
5491 if (isa<UsingDecl>(InstD)) {
5492 UsingDecl *UD = cast<UsingDecl>(InstD);
5493 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5494 E = UD->shadow_end(); I != E; ++I)
5495 R.addDecl(*I);
5496 continue;
5497 }
5498
5499 R.addDecl(InstD);
5500 }
5501
5502 // Resolve a kind, but don't do any further analysis. If it's
5503 // ambiguous, the callee needs to deal with it.
5504 R.resolveKind();
5505
5506 // Rebuild the nested-name qualifier, if present.
5507 CXXScopeSpec SS;
5508 NestedNameSpecifier *Qualifier = 0;
5509 if (Old->getQualifier()) {
5510 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005511 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005512 if (!Qualifier)
5513 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005514
John McCallf7a1a742009-11-24 19:00:30 +00005515 SS.setScopeRep(Qualifier);
5516 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005517 }
5518
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005519 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005520 CXXRecordDecl *NamingClass
5521 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5522 Old->getNameLoc(),
5523 Old->getNamingClass()));
5524 if (!NamingClass)
5525 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005526
Douglas Gregor66c45152010-04-27 16:10:10 +00005527 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005528 }
5529
5530 // If we have no template arguments, it's a normal declaration name.
5531 if (!Old->hasExplicitTemplateArgs())
5532 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5533
5534 // If we have template arguments, rebuild them, then rebuild the
5535 // templateid expression.
5536 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5537 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5538 TemplateArgumentLoc Loc;
5539 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5540 return SemaRef.ExprError();
5541 TransArgs.addArgument(Loc);
5542 }
5543
5544 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5545 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005546}
Mike Stump1eb44332009-09-09 15:08:12 +00005547
Douglas Gregorb98b1992009-08-11 05:31:07 +00005548template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005549ExprResult
John McCall454feb92009-12-08 09:21:05 +00005550TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005551 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005552
Douglas Gregorb98b1992009-08-11 05:31:07 +00005553 QualType T = getDerived().TransformType(E->getQueriedType());
5554 if (T.isNull())
5555 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005556
Douglas Gregorb98b1992009-08-11 05:31:07 +00005557 if (!getDerived().AlwaysRebuild() &&
5558 T == E->getQueriedType())
5559 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005560
Douglas Gregorb98b1992009-08-11 05:31:07 +00005561 // FIXME: Bad location information
5562 SourceLocation FakeLParenLoc
5563 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00005564
5565 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005566 E->getLocStart(),
5567 /*FIXME:*/FakeLParenLoc,
5568 T,
5569 E->getLocEnd());
5570}
Mike Stump1eb44332009-09-09 15:08:12 +00005571
Douglas Gregorb98b1992009-08-11 05:31:07 +00005572template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005573ExprResult
John McCall865d4472009-11-19 22:55:06 +00005574TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005575 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005576 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005577 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005578 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005579 if (!NNS)
5580 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005581
Abramo Bagnara25777432010-08-11 22:01:17 +00005582 DeclarationNameInfo NameInfo
5583 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5584 if (!NameInfo.getName())
Douglas Gregor81499bb2009-09-03 22:13:48 +00005585 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005586
John McCallf7a1a742009-11-24 19:00:30 +00005587 if (!E->hasExplicitTemplateArgs()) {
5588 if (!getDerived().AlwaysRebuild() &&
5589 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005590 // Note: it is sufficient to compare the Name component of NameInfo:
5591 // if name has not changed, DNLoc has not changed either.
5592 NameInfo.getName() == E->getDeclName())
John McCallf7a1a742009-11-24 19:00:30 +00005593 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005594
John McCallf7a1a742009-11-24 19:00:30 +00005595 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5596 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005597 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005598 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005599 }
John McCalld5532b62009-11-23 01:53:49 +00005600
5601 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005602 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005603 TemplateArgumentLoc Loc;
5604 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb98b1992009-08-11 05:31:07 +00005605 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005606 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005607 }
5608
John McCallf7a1a742009-11-24 19:00:30 +00005609 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5610 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005611 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005612 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005613}
5614
5615template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005616ExprResult
John McCall454feb92009-12-08 09:21:05 +00005617TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005618 // CXXConstructExprs are always implicit, so when we have a
5619 // 1-argument construction we just transform that argument.
5620 if (E->getNumArgs() == 1 ||
5621 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5622 return getDerived().TransformExpr(E->getArg(0));
5623
Douglas Gregorb98b1992009-08-11 05:31:07 +00005624 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5625
5626 QualType T = getDerived().TransformType(E->getType());
5627 if (T.isNull())
5628 return SemaRef.ExprError();
5629
5630 CXXConstructorDecl *Constructor
5631 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005632 getDerived().TransformDecl(E->getLocStart(),
5633 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005634 if (!Constructor)
5635 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005636
Douglas Gregorb98b1992009-08-11 05:31:07 +00005637 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005638 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005639 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005640 ArgEnd = E->arg_end();
5641 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005642 if (getDerived().DropCallArgument(*Arg)) {
5643 ArgumentChanged = true;
5644 break;
5645 }
5646
John McCall60d7b3a2010-08-24 06:29:42 +00005647 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005648 if (TransArg.isInvalid())
5649 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005650
Douglas Gregorb98b1992009-08-11 05:31:07 +00005651 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005652 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005653 }
5654
5655 if (!getDerived().AlwaysRebuild() &&
5656 T == E->getType() &&
5657 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005658 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005659 // Mark the constructor as referenced.
5660 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005661 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005662 return SemaRef.Owned(E->Retain());
Douglas Gregorc845aad2010-02-26 00:01:57 +00005663 }
Mike Stump1eb44332009-09-09 15:08:12 +00005664
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005665 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5666 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00005667 move_arg(Args),
5668 E->requiresZeroInitialization(),
5669 E->getConstructionKind());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005670}
Mike Stump1eb44332009-09-09 15:08:12 +00005671
Douglas Gregorb98b1992009-08-11 05:31:07 +00005672/// \brief Transform a C++ temporary-binding expression.
5673///
Douglas Gregor51326552009-12-24 18:51:59 +00005674/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5675/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005676template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005677ExprResult
John McCall454feb92009-12-08 09:21:05 +00005678TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005679 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005680}
Mike Stump1eb44332009-09-09 15:08:12 +00005681
Anders Carlssoneb60edf2010-01-29 02:39:32 +00005682/// \brief Transform a C++ reference-binding expression.
5683///
5684/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5685/// transform the subexpression and return that.
5686template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005687ExprResult
Anders Carlssoneb60edf2010-01-29 02:39:32 +00005688TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5689 return getDerived().TransformExpr(E->getSubExpr());
5690}
5691
Mike Stump1eb44332009-09-09 15:08:12 +00005692/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005693/// be destroyed after the expression is evaluated.
5694///
Douglas Gregor51326552009-12-24 18:51:59 +00005695/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5696/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005697template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005698ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005699TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005700 CXXExprWithTemporaries *E) {
5701 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005702}
Mike Stump1eb44332009-09-09 15:08:12 +00005703
Douglas Gregorb98b1992009-08-11 05:31:07 +00005704template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005705ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005706TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00005707 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005708 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5709 QualType T = getDerived().TransformType(E->getType());
5710 if (T.isNull())
5711 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005712
Douglas Gregorb98b1992009-08-11 05:31:07 +00005713 CXXConstructorDecl *Constructor
5714 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005715 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005716 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005717 if (!Constructor)
5718 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005719
Douglas Gregorb98b1992009-08-11 05:31:07 +00005720 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005721 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005722 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005723 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005724 ArgEnd = E->arg_end();
5725 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005726 if (getDerived().DropCallArgument(*Arg)) {
5727 ArgumentChanged = true;
5728 break;
5729 }
5730
John McCall60d7b3a2010-08-24 06:29:42 +00005731 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005732 if (TransArg.isInvalid())
5733 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005734
Douglas Gregorb98b1992009-08-11 05:31:07 +00005735 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5736 Args.push_back((Expr *)TransArg.release());
5737 }
Mike Stump1eb44332009-09-09 15:08:12 +00005738
Douglas Gregorb98b1992009-08-11 05:31:07 +00005739 if (!getDerived().AlwaysRebuild() &&
5740 T == E->getType() &&
5741 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005742 !ArgumentChanged) {
5743 // FIXME: Instantiation-specific
5744 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carrutha3ce8ae2010-03-31 18:34:58 +00005745 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor91be6f52010-03-02 17:18:33 +00005746 }
Mike Stump1eb44332009-09-09 15:08:12 +00005747
Douglas Gregorb98b1992009-08-11 05:31:07 +00005748 // FIXME: Bogus location information
5749 SourceLocation CommaLoc;
5750 if (Args.size() > 1) {
5751 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00005752 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005753 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5754 }
5755 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5756 T,
5757 /*FIXME:*/E->getTypeBeginLoc(),
5758 move_arg(Args),
5759 &CommaLoc,
5760 E->getLocEnd());
5761}
Mike Stump1eb44332009-09-09 15:08:12 +00005762
Douglas Gregorb98b1992009-08-11 05:31:07 +00005763template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005764ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005765TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005766 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005767 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5768 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5769 if (T.isNull())
5770 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005771
Douglas Gregorb98b1992009-08-11 05:31:07 +00005772 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005773 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005774 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5775 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5776 ArgEnd = E->arg_end();
5777 Arg != ArgEnd; ++Arg) {
John McCall60d7b3a2010-08-24 06:29:42 +00005778 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005779 if (TransArg.isInvalid())
5780 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005781
Douglas Gregorb98b1992009-08-11 05:31:07 +00005782 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5783 FakeCommaLocs.push_back(
5784 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
John McCall9ae2f072010-08-23 23:25:46 +00005785 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005786 }
Mike Stump1eb44332009-09-09 15:08:12 +00005787
Douglas Gregorb98b1992009-08-11 05:31:07 +00005788 if (!getDerived().AlwaysRebuild() &&
5789 T == E->getTypeAsWritten() &&
5790 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005791 return SemaRef.Owned(E->Retain());
5792
Douglas Gregorb98b1992009-08-11 05:31:07 +00005793 // FIXME: we're faking the locations of the commas
5794 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5795 T,
5796 E->getLParenLoc(),
5797 move_arg(Args),
5798 FakeCommaLocs.data(),
5799 E->getRParenLoc());
5800}
Mike Stump1eb44332009-09-09 15:08:12 +00005801
Douglas Gregorb98b1992009-08-11 05:31:07 +00005802template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005803ExprResult
John McCall865d4472009-11-19 22:55:06 +00005804TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005805 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005806 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005807 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005808 Expr *OldBase;
5809 QualType BaseType;
5810 QualType ObjectType;
5811 if (!E->isImplicitAccess()) {
5812 OldBase = E->getBase();
5813 Base = getDerived().TransformExpr(OldBase);
5814 if (Base.isInvalid())
5815 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005816
John McCallaa81e162009-12-01 22:10:20 +00005817 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00005818 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00005819 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005820 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005821 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005822 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005823 ObjectTy,
5824 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005825 if (Base.isInvalid())
5826 return SemaRef.ExprError();
5827
John McCallb3d87482010-08-24 05:47:05 +00005828 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00005829 BaseType = ((Expr*) Base.get())->getType();
5830 } else {
5831 OldBase = 0;
5832 BaseType = getDerived().TransformType(E->getBaseType());
5833 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5834 }
Mike Stump1eb44332009-09-09 15:08:12 +00005835
Douglas Gregor6cd21982009-10-20 05:58:46 +00005836 // Transform the first part of the nested-name-specifier that qualifies
5837 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005838 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005839 = getDerived().TransformFirstQualifierInScope(
5840 E->getFirstQualifierFoundInScope(),
5841 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005842
Douglas Gregora38c6872009-09-03 16:14:30 +00005843 NestedNameSpecifier *Qualifier = 0;
5844 if (E->getQualifier()) {
5845 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5846 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005847 ObjectType,
5848 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005849 if (!Qualifier)
5850 return SemaRef.ExprError();
5851 }
Mike Stump1eb44332009-09-09 15:08:12 +00005852
Abramo Bagnara25777432010-08-11 22:01:17 +00005853 DeclarationNameInfo NameInfo
5854 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5855 ObjectType);
5856 if (!NameInfo.getName())
Douglas Gregor81499bb2009-09-03 22:13:48 +00005857 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005858
John McCallaa81e162009-12-01 22:10:20 +00005859 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005860 // This is a reference to a member without an explicitly-specified
5861 // template argument list. Optimize for this common case.
5862 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005863 Base.get() == OldBase &&
5864 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005865 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005866 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005867 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005868 return SemaRef.Owned(E->Retain());
5869
John McCall9ae2f072010-08-23 23:25:46 +00005870 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005871 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005872 E->isArrow(),
5873 E->getOperatorLoc(),
5874 Qualifier,
5875 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005876 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005877 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005878 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005879 }
5880
John McCalld5532b62009-11-23 01:53:49 +00005881 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005882 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005883 TemplateArgumentLoc Loc;
5884 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005885 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005886 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005887 }
Mike Stump1eb44332009-09-09 15:08:12 +00005888
John McCall9ae2f072010-08-23 23:25:46 +00005889 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005890 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005891 E->isArrow(),
5892 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005893 Qualifier,
5894 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005895 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005896 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005897 &TransArgs);
5898}
5899
5900template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005901ExprResult
John McCall454feb92009-12-08 09:21:05 +00005902TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005903 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005904 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005905 QualType BaseType;
5906 if (!Old->isImplicitAccess()) {
5907 Base = getDerived().TransformExpr(Old->getBase());
5908 if (Base.isInvalid())
5909 return SemaRef.ExprError();
5910 BaseType = ((Expr*) Base.get())->getType();
5911 } else {
5912 BaseType = getDerived().TransformType(Old->getBaseType());
5913 }
John McCall129e2df2009-11-30 22:42:35 +00005914
5915 NestedNameSpecifier *Qualifier = 0;
5916 if (Old->getQualifier()) {
5917 Qualifier
5918 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005919 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005920 if (Qualifier == 0)
5921 return SemaRef.ExprError();
5922 }
5923
Abramo Bagnara25777432010-08-11 22:01:17 +00005924 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00005925 Sema::LookupOrdinaryName);
5926
5927 // Transform all the decls.
5928 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5929 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005930 NamedDecl *InstD = static_cast<NamedDecl*>(
5931 getDerived().TransformDecl(Old->getMemberLoc(),
5932 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005933 if (!InstD) {
5934 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5935 // This can happen because of dependent hiding.
5936 if (isa<UsingShadowDecl>(*I))
5937 continue;
5938 else
5939 return SemaRef.ExprError();
5940 }
John McCall129e2df2009-11-30 22:42:35 +00005941
5942 // Expand using declarations.
5943 if (isa<UsingDecl>(InstD)) {
5944 UsingDecl *UD = cast<UsingDecl>(InstD);
5945 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5946 E = UD->shadow_end(); I != E; ++I)
5947 R.addDecl(*I);
5948 continue;
5949 }
5950
5951 R.addDecl(InstD);
5952 }
5953
5954 R.resolveKind();
5955
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005956 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00005957 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00005958 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005959 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00005960 Old->getMemberLoc(),
5961 Old->getNamingClass()));
5962 if (!NamingClass)
5963 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005964
Douglas Gregor66c45152010-04-27 16:10:10 +00005965 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005966 }
Sean Huntc3021132010-05-05 15:23:54 +00005967
John McCall129e2df2009-11-30 22:42:35 +00005968 TemplateArgumentListInfo TransArgs;
5969 if (Old->hasExplicitTemplateArgs()) {
5970 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5971 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5972 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5973 TemplateArgumentLoc Loc;
5974 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5975 Loc))
5976 return SemaRef.ExprError();
5977 TransArgs.addArgument(Loc);
5978 }
5979 }
John McCallc2233c52010-01-15 08:34:02 +00005980
5981 // FIXME: to do this check properly, we will need to preserve the
5982 // first-qualifier-in-scope here, just in case we had a dependent
5983 // base (and therefore couldn't do the check) and a
5984 // nested-name-qualifier (and therefore could do the lookup).
5985 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00005986
John McCall9ae2f072010-08-23 23:25:46 +00005987 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005988 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005989 Old->getOperatorLoc(),
5990 Old->isArrow(),
5991 Qualifier,
5992 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00005993 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005994 R,
5995 (Old->hasExplicitTemplateArgs()
5996 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005997}
5998
5999template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006000ExprResult
John McCall454feb92009-12-08 09:21:05 +00006001TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +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>
John McCall60d7b3a2010-08-24 06:29:42 +00006006ExprResult
John McCall454feb92009-12-08 09:21:05 +00006007TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006008 TypeSourceInfo *EncodedTypeInfo
6009 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6010 if (!EncodedTypeInfo)
Douglas Gregorb98b1992009-08-11 05:31:07 +00006011 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006012
Douglas Gregorb98b1992009-08-11 05:31:07 +00006013 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006014 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00006015 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006016
6017 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006018 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006019 E->getRParenLoc());
6020}
Mike Stump1eb44332009-09-09 15:08:12 +00006021
Douglas Gregorb98b1992009-08-11 05:31:07 +00006022template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006023ExprResult
John McCall454feb92009-12-08 09:21:05 +00006024TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006025 // Transform arguments.
6026 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006027 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006028 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006029 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor92e986e2010-04-22 16:44:27 +00006030 if (Arg.isInvalid())
6031 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006032
Douglas Gregor92e986e2010-04-22 16:44:27 +00006033 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00006034 Args.push_back(Arg.get());
Douglas Gregor92e986e2010-04-22 16:44:27 +00006035 }
6036
6037 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6038 // Class message: transform the receiver type.
6039 TypeSourceInfo *ReceiverTypeInfo
6040 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6041 if (!ReceiverTypeInfo)
6042 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006043
Douglas Gregor92e986e2010-04-22 16:44:27 +00006044 // If nothing changed, just retain the existing message send.
6045 if (!getDerived().AlwaysRebuild() &&
6046 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6047 return SemaRef.Owned(E->Retain());
6048
6049 // Build a new class message send.
6050 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6051 E->getSelector(),
6052 E->getMethodDecl(),
6053 E->getLeftLoc(),
6054 move_arg(Args),
6055 E->getRightLoc());
6056 }
6057
6058 // Instance message: transform the receiver
6059 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6060 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006061 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006062 = getDerived().TransformExpr(E->getInstanceReceiver());
6063 if (Receiver.isInvalid())
6064 return SemaRef.ExprError();
6065
6066 // If nothing changed, just retain the existing message send.
6067 if (!getDerived().AlwaysRebuild() &&
6068 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6069 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006070
Douglas Gregor92e986e2010-04-22 16:44:27 +00006071 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006072 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006073 E->getSelector(),
6074 E->getMethodDecl(),
6075 E->getLeftLoc(),
6076 move_arg(Args),
6077 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006078}
6079
Mike Stump1eb44332009-09-09 15:08:12 +00006080template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006081ExprResult
John McCall454feb92009-12-08 09:21:05 +00006082TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006083 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006084}
6085
Mike Stump1eb44332009-09-09 15:08:12 +00006086template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006087ExprResult
John McCall454feb92009-12-08 09:21:05 +00006088TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006089 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006090}
6091
Mike Stump1eb44332009-09-09 15:08:12 +00006092template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006093ExprResult
John McCall454feb92009-12-08 09:21:05 +00006094TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006095 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006096 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006097 if (Base.isInvalid())
6098 return SemaRef.ExprError();
6099
6100 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006101
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006102 // If nothing changed, just retain the existing expression.
6103 if (!getDerived().AlwaysRebuild() &&
6104 Base.get() == E->getBase())
6105 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006106
John McCall9ae2f072010-08-23 23:25:46 +00006107 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006108 E->getLocation(),
6109 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006110}
6111
Mike Stump1eb44332009-09-09 15:08:12 +00006112template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006113ExprResult
John McCall454feb92009-12-08 09:21:05 +00006114TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregore3303542010-04-26 20:47:02 +00006115 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006116 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00006117 if (Base.isInvalid())
6118 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006119
Douglas Gregore3303542010-04-26 20:47:02 +00006120 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006121
Douglas Gregore3303542010-04-26 20:47:02 +00006122 // If nothing changed, just retain the existing expression.
6123 if (!getDerived().AlwaysRebuild() &&
6124 Base.get() == E->getBase())
6125 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006126
John McCall9ae2f072010-08-23 23:25:46 +00006127 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregore3303542010-04-26 20:47:02 +00006128 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006129}
6130
Mike Stump1eb44332009-09-09 15:08:12 +00006131template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006132ExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00006133TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00006134 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006135 // If this implicit setter/getter refers to class methods, it cannot have any
6136 // dependent parts. Just retain the existing declaration.
6137 if (E->getInterfaceDecl())
6138 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006139
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006140 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006141 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006142 if (Base.isInvalid())
6143 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006144
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006145 // We don't need to transform the getters/setters; they will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006146
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006147 // If nothing changed, just retain the existing expression.
6148 if (!getDerived().AlwaysRebuild() &&
6149 Base.get() == E->getBase())
6150 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006151
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006152 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6153 E->getGetterMethod(),
6154 E->getType(),
6155 E->getSetterMethod(),
6156 E->getLocation(),
John McCall9ae2f072010-08-23 23:25:46 +00006157 Base.get());
Sean Huntc3021132010-05-05 15:23:54 +00006158
Douglas Gregorb98b1992009-08-11 05:31:07 +00006159}
6160
Mike Stump1eb44332009-09-09 15:08:12 +00006161template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006162ExprResult
John McCall454feb92009-12-08 09:21:05 +00006163TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006164 // Can never occur in a dependent context.
Mike Stump1eb44332009-09-09 15:08:12 +00006165 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006166}
6167
Mike Stump1eb44332009-09-09 15:08:12 +00006168template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006169ExprResult
John McCall454feb92009-12-08 09:21:05 +00006170TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006171 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006172 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006173 if (Base.isInvalid())
6174 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006175
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006176 // If nothing changed, just retain the existing expression.
6177 if (!getDerived().AlwaysRebuild() &&
6178 Base.get() == E->getBase())
6179 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006180
John McCall9ae2f072010-08-23 23:25:46 +00006181 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006182 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006183}
6184
Mike Stump1eb44332009-09-09 15:08:12 +00006185template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006186ExprResult
John McCall454feb92009-12-08 09:21:05 +00006187TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006188 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006189 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006190 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006191 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006192 if (SubExpr.isInvalid())
6193 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006194
Douglas Gregorb98b1992009-08-11 05:31:07 +00006195 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00006196 SubExprs.push_back(SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006197 }
Mike Stump1eb44332009-09-09 15:08:12 +00006198
Douglas Gregorb98b1992009-08-11 05:31:07 +00006199 if (!getDerived().AlwaysRebuild() &&
6200 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00006201 return SemaRef.Owned(E->Retain());
6202
Douglas Gregorb98b1992009-08-11 05:31:07 +00006203 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6204 move_arg(SubExprs),
6205 E->getRParenLoc());
6206}
6207
Mike Stump1eb44332009-09-09 15:08:12 +00006208template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006209ExprResult
John McCall454feb92009-12-08 09:21:05 +00006210TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006211 SourceLocation CaretLoc(E->getExprLoc());
6212
6213 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6214 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6215 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6216 llvm::SmallVector<ParmVarDecl*, 4> Params;
6217 llvm::SmallVector<QualType, 4> ParamTypes;
6218
6219 // Parameter substitution.
6220 const BlockDecl *BD = E->getBlockDecl();
6221 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6222 EN = BD->param_end(); P != EN; ++P) {
6223 ParmVarDecl *OldParm = (*P);
6224 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6225 QualType NewType = NewParm->getType();
6226 Params.push_back(NewParm);
6227 ParamTypes.push_back(NewParm->getType());
6228 }
6229
6230 const FunctionType *BExprFunctionType = E->getFunctionType();
6231 QualType BExprResultType = BExprFunctionType->getResultType();
6232 if (!BExprResultType.isNull()) {
6233 if (!BExprResultType->isDependentType())
6234 CurBlock->ReturnType = BExprResultType;
6235 else if (BExprResultType != SemaRef.Context.DependentTy)
6236 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6237 }
6238
6239 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00006240 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006241 if (Body.isInvalid())
6242 return SemaRef.ExprError();
6243 // Set the parameters on the block decl.
6244 if (!Params.empty())
6245 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6246
6247 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6248 CurBlock->ReturnType,
6249 ParamTypes.data(),
6250 ParamTypes.size(),
6251 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006252 0,
6253 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006254
6255 CurBlock->FunctionType = FunctionType;
John McCall9ae2f072010-08-23 23:25:46 +00006256 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006257}
6258
Mike Stump1eb44332009-09-09 15:08:12 +00006259template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006260ExprResult
John McCall454feb92009-12-08 09:21:05 +00006261TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006262 NestedNameSpecifier *Qualifier = 0;
6263
6264 ValueDecl *ND
6265 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6266 E->getDecl()));
6267 if (!ND)
6268 return SemaRef.ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00006269
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006270 if (!getDerived().AlwaysRebuild() &&
6271 ND == E->getDecl()) {
6272 // Mark it referenced in the new context regardless.
6273 // FIXME: this is a bit instantiation-specific.
6274 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6275
6276 return SemaRef.Owned(E->Retain());
6277 }
6278
Abramo Bagnara25777432010-08-11 22:01:17 +00006279 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006280 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006281 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006282}
Mike Stump1eb44332009-09-09 15:08:12 +00006283
Douglas Gregorb98b1992009-08-11 05:31:07 +00006284//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006285// Type reconstruction
6286//===----------------------------------------------------------------------===//
6287
Mike Stump1eb44332009-09-09 15:08:12 +00006288template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006289QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6290 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006291 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006292 getDerived().getBaseEntity());
6293}
6294
Mike Stump1eb44332009-09-09 15:08:12 +00006295template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006296QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6297 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006298 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006299 getDerived().getBaseEntity());
6300}
6301
Mike Stump1eb44332009-09-09 15:08:12 +00006302template<typename Derived>
6303QualType
John McCall85737a72009-10-30 00:06:24 +00006304TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6305 bool WrittenAsLValue,
6306 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006307 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006308 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006309}
6310
6311template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006312QualType
John McCall85737a72009-10-30 00:06:24 +00006313TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6314 QualType ClassType,
6315 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006316 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006317 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006318}
6319
6320template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006321QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006322TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6323 ArrayType::ArraySizeModifier SizeMod,
6324 const llvm::APInt *Size,
6325 Expr *SizeExpr,
6326 unsigned IndexTypeQuals,
6327 SourceRange BracketsRange) {
6328 if (SizeExpr || !Size)
6329 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6330 IndexTypeQuals, BracketsRange,
6331 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006332
6333 QualType Types[] = {
6334 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6335 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6336 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006337 };
6338 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6339 QualType SizeType;
6340 for (unsigned I = 0; I != NumTypes; ++I)
6341 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6342 SizeType = Types[I];
6343 break;
6344 }
Mike Stump1eb44332009-09-09 15:08:12 +00006345
Douglas Gregor577f75a2009-08-04 16:50:30 +00006346 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006347 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006348 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006349 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006350}
Mike Stump1eb44332009-09-09 15:08:12 +00006351
Douglas Gregor577f75a2009-08-04 16:50:30 +00006352template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006353QualType
6354TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006355 ArrayType::ArraySizeModifier SizeMod,
6356 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006357 unsigned IndexTypeQuals,
6358 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006359 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006360 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006361}
6362
6363template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006364QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006365TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006366 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006367 unsigned IndexTypeQuals,
6368 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006369 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006370 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006371}
Mike Stump1eb44332009-09-09 15:08:12 +00006372
Douglas Gregor577f75a2009-08-04 16:50:30 +00006373template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006374QualType
6375TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006376 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006377 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006378 unsigned IndexTypeQuals,
6379 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006380 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006381 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006382 IndexTypeQuals, BracketsRange);
6383}
6384
6385template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006386QualType
6387TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006388 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006389 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006390 unsigned IndexTypeQuals,
6391 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006392 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006393 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006394 IndexTypeQuals, BracketsRange);
6395}
6396
6397template<typename Derived>
6398QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner788b0fd2010-06-23 06:00:24 +00006399 unsigned NumElements,
6400 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006401 // FIXME: semantic checking!
Chris Lattner788b0fd2010-06-23 06:00:24 +00006402 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006403}
Mike Stump1eb44332009-09-09 15:08:12 +00006404
Douglas Gregor577f75a2009-08-04 16:50:30 +00006405template<typename Derived>
6406QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6407 unsigned NumElements,
6408 SourceLocation AttributeLoc) {
6409 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6410 NumElements, true);
6411 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00006412 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006413 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00006414 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006415}
Mike Stump1eb44332009-09-09 15:08:12 +00006416
Douglas Gregor577f75a2009-08-04 16:50:30 +00006417template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006418QualType
6419TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00006420 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006421 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00006422 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006423}
Mike Stump1eb44332009-09-09 15:08:12 +00006424
Douglas Gregor577f75a2009-08-04 16:50:30 +00006425template<typename Derived>
6426QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006427 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006428 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006429 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00006430 unsigned Quals,
6431 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00006432 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006433 Quals,
6434 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006435 getDerived().getBaseEntity(),
6436 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006437}
Mike Stump1eb44332009-09-09 15:08:12 +00006438
Douglas Gregor577f75a2009-08-04 16:50:30 +00006439template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006440QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6441 return SemaRef.Context.getFunctionNoProtoType(T);
6442}
6443
6444template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006445QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6446 assert(D && "no decl found");
6447 if (D->isInvalidDecl()) return QualType();
6448
Douglas Gregor92e986e2010-04-22 16:44:27 +00006449 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006450 TypeDecl *Ty;
6451 if (isa<UsingDecl>(D)) {
6452 UsingDecl *Using = cast<UsingDecl>(D);
6453 assert(Using->isTypeName() &&
6454 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6455
6456 // A valid resolved using typename decl points to exactly one type decl.
6457 assert(++Using->shadow_begin() == Using->shadow_end());
6458 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006459
John McCalled976492009-12-04 22:46:56 +00006460 } else {
6461 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6462 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6463 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6464 }
6465
6466 return SemaRef.Context.getTypeDeclType(Ty);
6467}
6468
6469template<typename Derived>
John McCall9ae2f072010-08-23 23:25:46 +00006470QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E) {
6471 return SemaRef.BuildTypeofExprType(E);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006472}
6473
6474template<typename Derived>
6475QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6476 return SemaRef.Context.getTypeOfType(Underlying);
6477}
6478
6479template<typename Derived>
John McCall9ae2f072010-08-23 23:25:46 +00006480QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E) {
6481 return SemaRef.BuildDecltypeType(E);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006482}
6483
6484template<typename Derived>
6485QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006486 TemplateName Template,
6487 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006488 const TemplateArgumentListInfo &TemplateArgs) {
6489 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006490}
Mike Stump1eb44332009-09-09 15:08:12 +00006491
Douglas Gregordcee1a12009-08-06 05:28:30 +00006492template<typename Derived>
6493NestedNameSpecifier *
6494TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6495 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006496 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006497 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006498 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006499 CXXScopeSpec SS;
6500 // FIXME: The source location information is all wrong.
6501 SS.setRange(Range);
6502 SS.setScopeRep(Prefix);
6503 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006504 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006505 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006506 ObjectType,
6507 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006508 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006509}
6510
6511template<typename Derived>
6512NestedNameSpecifier *
6513TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6514 SourceRange Range,
6515 NamespaceDecl *NS) {
6516 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6517}
6518
6519template<typename Derived>
6520NestedNameSpecifier *
6521TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6522 SourceRange Range,
6523 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006524 QualType T) {
6525 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006526 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006527 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006528 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6529 T.getTypePtr());
6530 }
Mike Stump1eb44332009-09-09 15:08:12 +00006531
Douglas Gregordcee1a12009-08-06 05:28:30 +00006532 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6533 return 0;
6534}
Mike Stump1eb44332009-09-09 15:08:12 +00006535
Douglas Gregord1067e52009-08-06 06:41:21 +00006536template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006537TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006538TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6539 bool TemplateKW,
6540 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006541 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006542 Template);
6543}
6544
6545template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006546TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006547TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006548 const IdentifierInfo &II,
6549 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006550 CXXScopeSpec SS;
6551 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00006552 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006553 UnqualifiedId Name;
6554 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00006555 Sema::TemplateTy Template;
6556 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6557 /*FIXME:*/getDerived().getBaseLocation(),
6558 SS,
6559 Name,
John McCallb3d87482010-08-24 05:47:05 +00006560 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006561 /*EnteringContext=*/false,
6562 Template);
6563 return Template.template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00006564}
Mike Stump1eb44332009-09-09 15:08:12 +00006565
Douglas Gregorb98b1992009-08-11 05:31:07 +00006566template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006567TemplateName
6568TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6569 OverloadedOperatorKind Operator,
6570 QualType ObjectType) {
6571 CXXScopeSpec SS;
6572 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6573 SS.setScopeRep(Qualifier);
6574 UnqualifiedId Name;
6575 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6576 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6577 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00006578 Sema::TemplateTy Template;
6579 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006580 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006581 SS,
6582 Name,
John McCallb3d87482010-08-24 05:47:05 +00006583 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006584 /*EnteringContext=*/false,
6585 Template);
6586 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006587}
Sean Huntc3021132010-05-05 15:23:54 +00006588
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006589template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006590ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6592 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006593 Expr *OrigCallee,
6594 Expr *First,
6595 Expr *Second) {
6596 Expr *Callee = OrigCallee->IgnoreParenCasts();
6597 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006598
Douglas Gregorb98b1992009-08-11 05:31:07 +00006599 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006600 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00006601 if (!First->getType()->isOverloadableType() &&
6602 !Second->getType()->isOverloadableType())
6603 return getSema().CreateBuiltinArraySubscriptExpr(First,
6604 Callee->getLocStart(),
6605 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006606 } else if (Op == OO_Arrow) {
6607 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00006608 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6609 } else if (Second == 0 || isPostIncDec) {
6610 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006611 // The argument is not of overloadable type, so try to create a
6612 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00006613 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006615
John McCall9ae2f072010-08-23 23:25:46 +00006616 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006617 }
6618 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006619 if (!First->getType()->isOverloadableType() &&
6620 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 // Neither of the arguments is an overloadable type, so try to
6622 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00006623 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006624 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00006625 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626 if (Result.isInvalid())
6627 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006628
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629 return move(Result);
6630 }
6631 }
Mike Stump1eb44332009-09-09 15:08:12 +00006632
6633 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006635 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006636
John McCall9ae2f072010-08-23 23:25:46 +00006637 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00006638 assert(ULE->requiresADL());
6639
6640 // FIXME: Do we have to check
6641 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006642 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006643 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006644 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006645 }
Mike Stump1eb44332009-09-09 15:08:12 +00006646
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00006648 Expr *Args[2] = { First, Second };
6649 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006650
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651 // Create the overloaded operator invocation for unary operators.
6652 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00006653 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00006655 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656 }
Mike Stump1eb44332009-09-09 15:08:12 +00006657
Sebastian Redlf322ed62009-10-29 20:17:01 +00006658 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00006659 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00006660 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006661 First,
6662 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006663
Douglas Gregorb98b1992009-08-11 05:31:07 +00006664 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00006665 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006666 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6668 if (Result.isInvalid())
6669 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006670
Mike Stump1eb44332009-09-09 15:08:12 +00006671 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672}
Mike Stump1eb44332009-09-09 15:08:12 +00006673
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006674template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006675ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00006676TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006677 SourceLocation OperatorLoc,
6678 bool isArrow,
6679 NestedNameSpecifier *Qualifier,
6680 SourceRange QualifierRange,
6681 TypeSourceInfo *ScopeType,
6682 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006683 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006684 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006685 CXXScopeSpec SS;
6686 if (Qualifier) {
6687 SS.setRange(QualifierRange);
6688 SS.setScopeRep(Qualifier);
6689 }
6690
John McCall9ae2f072010-08-23 23:25:46 +00006691 QualType BaseType = Base->getType();
6692 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006693 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006694 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006695 !BaseType->getAs<PointerType>()->getPointeeType()
6696 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006697 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00006698 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006699 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006700 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006701 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006702 /*FIXME?*/true);
6703 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006704
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006705 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00006706 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6707 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6708 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6709 NameInfo.setNamedTypeInfo(DestroyedType);
6710
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006711 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00006712
John McCall9ae2f072010-08-23 23:25:46 +00006713 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006714 OperatorLoc, isArrow,
6715 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00006716 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006717 /*TemplateArgs*/ 0);
6718}
6719
Douglas Gregor577f75a2009-08-04 16:50:30 +00006720} // end namespace clang
6721
6722#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H