blob: e7bfbe6fe95524f6ba6f2b2b3c188df9d6c47f69 [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 Gregor577f75a2009-08-04 16:50:30 +000095 /// \brief Initializes a new tree transformer.
96 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +000097
Douglas Gregor577f75a2009-08-04 16:50:30 +000098 /// \brief Retrieves a reference to the derived class.
99 Derived &getDerived() { return static_cast<Derived&>(*this); }
100
101 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000102 const Derived &getDerived() const {
103 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000104 }
105
John McCall60d7b3a2010-08-24 06:29:42 +0000106 static inline ExprResult Owned(Expr *E) { return E; }
107 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000108
Douglas Gregor577f75a2009-08-04 16:50:30 +0000109 /// \brief Retrieves a reference to the semantic analysis object used for
110 /// this tree transform.
111 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000112
Douglas Gregor577f75a2009-08-04 16:50:30 +0000113 /// \brief Whether the transformation should always rebuild AST nodes, even
114 /// if none of the children have changed.
115 ///
116 /// Subclasses may override this function to specify when the transformation
117 /// should rebuild all AST nodes.
118 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000119
Douglas Gregor577f75a2009-08-04 16:50:30 +0000120 /// \brief Returns the location of the entity being transformed, if that
121 /// information was not available elsewhere in the AST.
122 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000123 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 /// provide an alternative implementation that provides better location
125 /// information.
126 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000127
Douglas Gregor577f75a2009-08-04 16:50:30 +0000128 /// \brief Returns the name of the entity being transformed, if that
129 /// information was not available elsewhere in the AST.
130 ///
131 /// By default, returns an empty name. Subclasses can provide an alternative
132 /// implementation with a more precise name.
133 DeclarationName getBaseEntity() { return DeclarationName(); }
134
Douglas Gregorb98b1992009-08-11 05:31:07 +0000135 /// \brief Sets the "base" location and entity when that
136 /// information is known based on another transformation.
137 ///
138 /// By default, the source location and entity are ignored. Subclasses can
139 /// override this function to provide a customized implementation.
140 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000141
Douglas Gregorb98b1992009-08-11 05:31:07 +0000142 /// \brief RAII object that temporarily sets the base location and entity
143 /// used for reporting diagnostics in types.
144 class TemporaryBase {
145 TreeTransform &Self;
146 SourceLocation OldLocation;
147 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000148
Douglas Gregorb98b1992009-08-11 05:31:07 +0000149 public:
150 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000151 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000152 OldLocation = Self.getDerived().getBaseLocation();
153 OldEntity = Self.getDerived().getBaseEntity();
154 Self.getDerived().setBase(Location, Entity);
155 }
Mike Stump1eb44332009-09-09 15:08:12 +0000156
Douglas Gregorb98b1992009-08-11 05:31:07 +0000157 ~TemporaryBase() {
158 Self.getDerived().setBase(OldLocation, OldEntity);
159 }
160 };
Mike Stump1eb44332009-09-09 15:08:12 +0000161
162 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000163 /// transformed.
164 ///
165 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000166 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000167 /// not change. For example, template instantiation need not traverse
168 /// non-dependent types.
169 bool AlreadyTransformed(QualType T) {
170 return T.isNull();
171 }
172
Douglas Gregor6eef5192009-12-14 19:27:10 +0000173 /// \brief Determine whether the given call argument should be dropped, e.g.,
174 /// because it is a default argument.
175 ///
176 /// Subclasses can provide an alternative implementation of this routine to
177 /// determine which kinds of call arguments get dropped. By default,
178 /// CXXDefaultArgument nodes are dropped (prior to transformation).
179 bool DropCallArgument(Expr *E) {
180 return E->isDefaultArgument();
181 }
Sean Huntc3021132010-05-05 15:23:54 +0000182
Douglas Gregor577f75a2009-08-04 16:50:30 +0000183 /// \brief Transforms the given type into another type.
184 ///
John McCalla2becad2009-10-21 00:40:46 +0000185 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000186 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000187 /// function. This is expensive, but we don't mind, because
188 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000189 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000190 ///
191 /// \returns the transformed type.
Douglas Gregor124b8782010-02-16 19:09:40 +0000192 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000193
John McCalla2becad2009-10-21 00:40:46 +0000194 /// \brief Transforms the given type-with-location into a new
195 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000196 ///
John McCalla2becad2009-10-21 00:40:46 +0000197 /// By default, this routine transforms a type by delegating to the
198 /// appropriate TransformXXXType to build a new type. Subclasses
199 /// may override this function (to take over all type
200 /// transformations) or some set of the TransformXXXType functions
201 /// to alter the transformation.
Sean Huntc3021132010-05-05 15:23:54 +0000202 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
Douglas Gregor124b8782010-02-16 19:09:40 +0000203 QualType ObjectType = QualType());
John McCalla2becad2009-10-21 00:40:46 +0000204
205 /// \brief Transform the given type-with-location into a new
206 /// type, collecting location information in the given builder
207 /// as necessary.
208 ///
Sean Huntc3021132010-05-05 15:23:54 +0000209 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +0000210 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000211
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000212 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000213 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000214 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000215 /// appropriate TransformXXXStmt function to transform a specific kind of
216 /// statement or the TransformExpr() function to transform an expression.
217 /// Subclasses may override this function to transform statements using some
218 /// other mechanism.
219 ///
220 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000221 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000222
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000223 /// \brief Transform the given expression.
224 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000225 /// By default, this routine transforms an expression by delegating to the
226 /// appropriate TransformXXXExpr function to build a new expression.
227 /// Subclasses may override this function to transform expressions using some
228 /// other mechanism.
229 ///
230 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000231 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000232
Douglas Gregor577f75a2009-08-04 16:50:30 +0000233 /// \brief Transform the given declaration, which is referenced from a type
234 /// or expression.
235 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000236 /// By default, acts as the identity function on declarations. Subclasses
237 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000238 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000239
240 /// \brief Transform the definition of the given declaration.
241 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000242 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000243 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000244 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
245 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000246 }
Mike Stump1eb44332009-09-09 15:08:12 +0000247
Douglas Gregor6cd21982009-10-20 05:58:46 +0000248 /// \brief Transform the given declaration, which was the first part of a
249 /// nested-name-specifier in a member access expression.
250 ///
Sean Huntc3021132010-05-05 15:23:54 +0000251 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000252 /// identifier in a nested-name-specifier of a member access expression, e.g.,
253 /// the \c T in \c x->T::member
254 ///
255 /// By default, invokes TransformDecl() to transform the declaration.
256 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000257 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
258 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000259 }
Sean Huntc3021132010-05-05 15:23:54 +0000260
Douglas Gregor577f75a2009-08-04 16:50:30 +0000261 /// \brief Transform the given nested-name-specifier.
262 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000263 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000264 /// nested-name-specifier. Subclasses may override this function to provide
265 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000266 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000267 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000268 QualType ObjectType = QualType(),
269 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000270
Douglas Gregor81499bb2009-09-03 22:13:48 +0000271 /// \brief Transform the given declaration name.
272 ///
273 /// By default, transforms the types of conversion function, constructor,
274 /// and destructor names and then (if needed) rebuilds the declaration name.
275 /// Identifiers and selectors are returned unmodified. Sublcasses may
276 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000277 DeclarationNameInfo
278 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
279 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000280
Douglas Gregor577f75a2009-08-04 16:50:30 +0000281 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000282 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000283 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000284 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000285 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000286 TemplateName TransformTemplateName(TemplateName Name,
287 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000288
Douglas Gregor577f75a2009-08-04 16:50:30 +0000289 /// \brief Transform the given template argument.
290 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000291 /// By default, this operation transforms the type, expression, or
292 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000293 /// new template argument from the transformed result. Subclasses may
294 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000295 ///
296 /// Returns true if there was an error.
297 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
298 TemplateArgumentLoc &Output);
299
300 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
301 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
302 TemplateArgumentLoc &ArgLoc);
303
John McCalla93c9342009-12-07 02:54:59 +0000304 /// \brief Fakes up a TypeSourceInfo for a type.
305 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
306 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000307 getDerived().getBaseLocation());
308 }
Mike Stump1eb44332009-09-09 15:08:12 +0000309
John McCalla2becad2009-10-21 00:40:46 +0000310#define ABSTRACT_TYPELOC(CLASS, PARENT)
311#define TYPELOC(CLASS, PARENT) \
Douglas Gregor124b8782010-02-16 19:09:40 +0000312 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
313 QualType ObjectType = QualType());
John McCalla2becad2009-10-21 00:40:46 +0000314#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000315
John McCall21ef0fa2010-03-11 09:03:00 +0000316 /// \brief Transforms the parameters of a function type into the
317 /// given vectors.
318 ///
319 /// The result vectors should be kept in sync; null entries in the
320 /// variables vector are acceptable.
321 ///
322 /// Return true on error.
323 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
324 llvm::SmallVectorImpl<QualType> &PTypes,
325 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
326
327 /// \brief Transforms a single function-type parameter. Return null
328 /// on error.
329 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
330
Sean Huntc3021132010-05-05 15:23:54 +0000331 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +0000332 QualType ObjectType);
John McCall85737a72009-10-30 00:06:24 +0000333
Sean Huntc3021132010-05-05 15:23:54 +0000334 QualType
Douglas Gregordd62b152009-10-19 22:04:39 +0000335 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
336 QualType ObjectType);
John McCall833ca992009-10-29 08:12:44 +0000337
John McCall60d7b3a2010-08-24 06:29:42 +0000338 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
339 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000340
Douglas Gregor43959a92009-08-20 07:17:43 +0000341#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000342 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000343#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000344 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000345#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000346#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000347
Douglas Gregor577f75a2009-08-04 16:50:30 +0000348 /// \brief Build a new pointer type given its pointee type.
349 ///
350 /// By default, performs semantic analysis when building the pointer type.
351 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000352 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000353
354 /// \brief Build a new block pointer type given its pointee type.
355 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000356 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000357 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000358 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000359
John McCall85737a72009-10-30 00:06:24 +0000360 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000361 ///
John McCall85737a72009-10-30 00:06:24 +0000362 /// By default, performs semantic analysis when building the
363 /// reference type. Subclasses may override this routine to provide
364 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000365 ///
John McCall85737a72009-10-30 00:06:24 +0000366 /// \param LValue whether the type was written with an lvalue sigil
367 /// or an rvalue sigil.
368 QualType RebuildReferenceType(QualType ReferentType,
369 bool LValue,
370 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000371
Douglas Gregor577f75a2009-08-04 16:50:30 +0000372 /// \brief Build a new member pointer type given the pointee type and the
373 /// class type it refers into.
374 ///
375 /// By default, performs semantic analysis when building the member pointer
376 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000377 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
378 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000379
Douglas Gregor577f75a2009-08-04 16:50:30 +0000380 /// \brief Build a new array type given the element type, size
381 /// modifier, size of the array (if known), size expression, and index type
382 /// qualifiers.
383 ///
384 /// By default, performs semantic analysis when building the array type.
385 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000386 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000387 QualType RebuildArrayType(QualType ElementType,
388 ArrayType::ArraySizeModifier SizeMod,
389 const llvm::APInt *Size,
390 Expr *SizeExpr,
391 unsigned IndexTypeQuals,
392 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000393
Douglas Gregor577f75a2009-08-04 16:50:30 +0000394 /// \brief Build a new constant array type given the element type, size
395 /// modifier, (known) size of the array, and index type qualifiers.
396 ///
397 /// By default, performs semantic analysis when building the array type.
398 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000399 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000400 ArrayType::ArraySizeModifier SizeMod,
401 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000402 unsigned IndexTypeQuals,
403 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000404
Douglas Gregor577f75a2009-08-04 16:50:30 +0000405 /// \brief Build a new incomplete array type given the element type, size
406 /// modifier, and index type qualifiers.
407 ///
408 /// By default, performs semantic analysis when building the array type.
409 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000410 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000411 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000412 unsigned IndexTypeQuals,
413 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000414
Mike Stump1eb44332009-09-09 15:08:12 +0000415 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000416 /// size modifier, size expression, and index type qualifiers.
417 ///
418 /// By default, performs semantic analysis when building the array type.
419 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000420 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000421 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000422 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000423 unsigned IndexTypeQuals,
424 SourceRange BracketsRange);
425
Mike Stump1eb44332009-09-09 15:08:12 +0000426 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000427 /// size modifier, size expression, and index type qualifiers.
428 ///
429 /// By default, performs semantic analysis when building the array type.
430 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000431 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000432 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000433 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000434 unsigned IndexTypeQuals,
435 SourceRange BracketsRange);
436
437 /// \brief Build a new vector type given the element type and
438 /// number of elements.
439 ///
440 /// By default, performs semantic analysis when building the vector type.
441 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000442 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Chris Lattner788b0fd2010-06-23 06:00:24 +0000443 VectorType::AltiVecSpecific AltiVecSpec);
Mike Stump1eb44332009-09-09 15:08:12 +0000444
Douglas Gregor577f75a2009-08-04 16:50:30 +0000445 /// \brief Build a new extended vector type given the element type and
446 /// number of elements.
447 ///
448 /// By default, performs semantic analysis when building the vector type.
449 /// Subclasses may override this routine to provide different behavior.
450 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
451 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000452
453 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000454 /// given the element type and number of elements.
455 ///
456 /// By default, performs semantic analysis when building the vector type.
457 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000458 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000459 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000460 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000461
Douglas Gregor577f75a2009-08-04 16:50:30 +0000462 /// \brief Build a new function type.
463 ///
464 /// By default, performs semantic analysis when building the function type.
465 /// Subclasses may override this routine to provide different behavior.
466 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000467 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000468 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000469 bool Variadic, unsigned Quals,
470 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000471
John McCalla2becad2009-10-21 00:40:46 +0000472 /// \brief Build a new unprototyped function type.
473 QualType RebuildFunctionNoProtoType(QualType ResultType);
474
John McCalled976492009-12-04 22:46:56 +0000475 /// \brief Rebuild an unresolved typename type, given the decl that
476 /// the UnresolvedUsingTypenameDecl was transformed to.
477 QualType RebuildUnresolvedUsingType(Decl *D);
478
Douglas Gregor577f75a2009-08-04 16:50:30 +0000479 /// \brief Build a new typedef type.
480 QualType RebuildTypedefType(TypedefDecl *Typedef) {
481 return SemaRef.Context.getTypeDeclType(Typedef);
482 }
483
484 /// \brief Build a new class/struct/union type.
485 QualType RebuildRecordType(RecordDecl *Record) {
486 return SemaRef.Context.getTypeDeclType(Record);
487 }
488
489 /// \brief Build a new Enum type.
490 QualType RebuildEnumType(EnumDecl *Enum) {
491 return SemaRef.Context.getTypeDeclType(Enum);
492 }
John McCall7da24312009-09-05 00:15:47 +0000493
Mike Stump1eb44332009-09-09 15:08:12 +0000494 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000495 ///
496 /// By default, performs semantic analysis when building the typeof type.
497 /// Subclasses may override this routine to provide different behavior.
John McCall9ae2f072010-08-23 23:25:46 +0000498 QualType RebuildTypeOfExprType(Expr *Underlying);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000499
Mike Stump1eb44332009-09-09 15:08:12 +0000500 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000501 ///
502 /// By default, builds a new TypeOfType with the given underlying type.
503 QualType RebuildTypeOfType(QualType Underlying);
504
Mike Stump1eb44332009-09-09 15:08:12 +0000505 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000506 ///
507 /// By default, performs semantic analysis when building the decltype type.
508 /// Subclasses may override this routine to provide different behavior.
John McCall9ae2f072010-08-23 23:25:46 +0000509 QualType RebuildDecltypeType(Expr *Underlying);
Mike Stump1eb44332009-09-09 15:08:12 +0000510
Douglas Gregor577f75a2009-08-04 16:50:30 +0000511 /// \brief Build a new template specialization type.
512 ///
513 /// By default, performs semantic analysis when building the template
514 /// specialization type. Subclasses may override this routine to provide
515 /// different behavior.
516 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000517 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000518 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000519
Douglas Gregor577f75a2009-08-04 16:50:30 +0000520 /// \brief Build a new qualified name type.
521 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000522 /// By default, builds a new ElaboratedType type from the keyword,
523 /// the nested-name-specifier and the named type.
524 /// Subclasses may override this routine to provide different behavior.
525 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
526 NestedNameSpecifier *NNS, QualType Named) {
527 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000528 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000529
530 /// \brief Build a new typename type that refers to a template-id.
531 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000532 /// By default, builds a new DependentNameType type from the
533 /// nested-name-specifier and the given type. Subclasses may override
534 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000535 QualType RebuildDependentTemplateSpecializationType(
536 ElaboratedTypeKeyword Keyword,
537 NestedNameSpecifier *NNS,
538 const IdentifierInfo *Name,
539 SourceLocation NameLoc,
540 const TemplateArgumentListInfo &Args) {
541 // Rebuild the template name.
542 // TODO: avoid TemplateName abstraction
543 TemplateName InstName =
544 getDerived().RebuildTemplateName(NNS, *Name, QualType());
545
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000546 if (InstName.isNull())
547 return QualType();
548
John McCall33500952010-06-11 00:33:02 +0000549 // If it's still dependent, make a dependent specialization.
550 if (InstName.getAsDependentTemplateName())
551 return SemaRef.Context.getDependentTemplateSpecializationType(
552 Keyword, NNS, Name, Args);
553
554 // Otherwise, make an elaborated type wrapping a non-dependent
555 // specialization.
556 QualType T =
557 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
558 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000559
Abramo Bagnara22f638a2010-08-10 13:46:45 +0000560 // NOTE: NNS is already recorded in template specialization type T.
561 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000562 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000563
564 /// \brief Build a new typename type that refers to an identifier.
565 ///
566 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000567 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000568 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000569 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000570 NestedNameSpecifier *NNS,
571 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000572 SourceLocation KeywordLoc,
573 SourceRange NNSRange,
574 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000575 CXXScopeSpec SS;
576 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000577 SS.setRange(NNSRange);
578
Douglas Gregor40336422010-03-31 22:19:08 +0000579 if (NNS->isDependent()) {
580 // If the name is still dependent, just build a new dependent name type.
581 if (!SemaRef.computeDeclContext(SS))
582 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
583 }
584
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000585 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000586 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
587 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000588
589 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
590
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000591 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000592 // into a non-dependent elaborated-type-specifier. Find the tag we're
593 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000594 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000595 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
596 if (!DC)
597 return QualType();
598
John McCall56138762010-05-27 06:40:31 +0000599 if (SemaRef.RequireCompleteDeclContext(SS, DC))
600 return QualType();
601
Douglas Gregor40336422010-03-31 22:19:08 +0000602 TagDecl *Tag = 0;
603 SemaRef.LookupQualifiedName(Result, DC);
604 switch (Result.getResultKind()) {
605 case LookupResult::NotFound:
606 case LookupResult::NotFoundInCurrentInstantiation:
607 break;
Sean Huntc3021132010-05-05 15:23:54 +0000608
Douglas Gregor40336422010-03-31 22:19:08 +0000609 case LookupResult::Found:
610 Tag = Result.getAsSingle<TagDecl>();
611 break;
Sean Huntc3021132010-05-05 15:23:54 +0000612
Douglas Gregor40336422010-03-31 22:19:08 +0000613 case LookupResult::FoundOverloaded:
614 case LookupResult::FoundUnresolvedValue:
615 llvm_unreachable("Tag lookup cannot find non-tags");
616 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000617
Douglas Gregor40336422010-03-31 22:19:08 +0000618 case LookupResult::Ambiguous:
619 // Let the LookupResult structure handle ambiguities.
620 return QualType();
621 }
622
623 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000624 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000625 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000626 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000627 return QualType();
628 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000629
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000630 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
631 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000632 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
633 return QualType();
634 }
635
636 // Build the elaborated-type-specifier type.
637 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000638 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000639 }
Mike Stump1eb44332009-09-09 15:08:12 +0000640
Douglas Gregordcee1a12009-08-06 05:28:30 +0000641 /// \brief Build a new nested-name-specifier given the prefix and an
642 /// identifier that names the next step in the nested-name-specifier.
643 ///
644 /// By default, performs semantic analysis when building the new
645 /// nested-name-specifier. Subclasses may override this routine to provide
646 /// different behavior.
647 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
648 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000649 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000650 QualType ObjectType,
651 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000652
653 /// \brief Build a new nested-name-specifier given the prefix and the
654 /// namespace named in the next step in the nested-name-specifier.
655 ///
656 /// By default, performs semantic analysis when building the new
657 /// nested-name-specifier. Subclasses may override this routine to provide
658 /// different behavior.
659 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
660 SourceRange Range,
661 NamespaceDecl *NS);
662
663 /// \brief Build a new nested-name-specifier given the prefix and the
664 /// type named in the next step in the nested-name-specifier.
665 ///
666 /// By default, performs semantic analysis when building the new
667 /// nested-name-specifier. Subclasses may override this routine to provide
668 /// different behavior.
669 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
670 SourceRange Range,
671 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000672 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000673
674 /// \brief Build a new template name given a nested name specifier, a flag
675 /// indicating whether the "template" keyword was provided, and the template
676 /// that the template name refers to.
677 ///
678 /// By default, builds the new template name directly. Subclasses may override
679 /// this routine to provide different behavior.
680 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
681 bool TemplateKW,
682 TemplateDecl *Template);
683
Douglas Gregord1067e52009-08-06 06:41:21 +0000684 /// \brief Build a new template name given a nested name specifier and the
685 /// name that is referred to as a template.
686 ///
687 /// By default, performs semantic analysis to determine whether the name can
688 /// be resolved to a specific template, then builds the appropriate kind of
689 /// template name. Subclasses may override this routine to provide different
690 /// behavior.
691 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000692 const IdentifierInfo &II,
693 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000694
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000695 /// \brief Build a new template name given a nested name specifier and the
696 /// overloaded operator name that is referred to as a template.
697 ///
698 /// By default, performs semantic analysis to determine whether the name can
699 /// be resolved to a specific template, then builds the appropriate kind of
700 /// template name. Subclasses may override this routine to provide different
701 /// behavior.
702 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
703 OverloadedOperatorKind Operator,
704 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000705
Douglas Gregor43959a92009-08-20 07:17:43 +0000706 /// \brief Build a new compound statement.
707 ///
708 /// By default, performs semantic analysis to build the new statement.
709 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000710 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000711 MultiStmtArg Statements,
712 SourceLocation RBraceLoc,
713 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000714 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000715 IsStmtExpr);
716 }
717
718 /// \brief Build a new case statement.
719 ///
720 /// By default, performs semantic analysis to build the new statement.
721 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000722 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000723 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000724 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000725 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000726 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000727 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000728 ColonLoc);
729 }
Mike Stump1eb44332009-09-09 15:08:12 +0000730
Douglas Gregor43959a92009-08-20 07:17:43 +0000731 /// \brief Attach the body to a new case statement.
732 ///
733 /// By default, performs semantic analysis to build the new statement.
734 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000735 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000736 getSema().ActOnCaseStmtBody(S, Body);
737 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000738 }
Mike Stump1eb44332009-09-09 15:08:12 +0000739
Douglas Gregor43959a92009-08-20 07:17:43 +0000740 /// \brief Build a new default statement.
741 ///
742 /// By default, performs semantic analysis to build the new statement.
743 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000744 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000745 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000746 Stmt *SubStmt) {
747 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000748 /*CurScope=*/0);
749 }
Mike Stump1eb44332009-09-09 15:08:12 +0000750
Douglas Gregor43959a92009-08-20 07:17:43 +0000751 /// \brief Build a new label statement.
752 ///
753 /// By default, performs semantic analysis to build the new statement.
754 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000755 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000756 IdentifierInfo *Id,
757 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000758 Stmt *SubStmt) {
759 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +0000760 }
Mike Stump1eb44332009-09-09 15:08:12 +0000761
Douglas Gregor43959a92009-08-20 07:17:43 +0000762 /// \brief Build a new "if" statement.
763 ///
764 /// By default, performs semantic analysis to build the new statement.
765 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000766 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCall9ae2f072010-08-23 23:25:46 +0000767 VarDecl *CondVar, Stmt *Then,
768 SourceLocation ElseLoc, Stmt *Else) {
769 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000770 }
Mike Stump1eb44332009-09-09 15:08:12 +0000771
Douglas Gregor43959a92009-08-20 07:17:43 +0000772 /// \brief Start building a new switch statement.
773 ///
774 /// By default, performs semantic analysis to build the new statement.
775 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000776 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000777 Expr *Cond, VarDecl *CondVar) {
778 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +0000779 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +0000780 }
Mike Stump1eb44332009-09-09 15:08:12 +0000781
Douglas Gregor43959a92009-08-20 07:17:43 +0000782 /// \brief Attach the body to the switch statement.
783 ///
784 /// By default, performs semantic analysis to build the new statement.
785 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000786 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000787 Stmt *Switch, Stmt *Body) {
788 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000789 }
790
791 /// \brief Build a new while statement.
792 ///
793 /// By default, performs semantic analysis to build the new statement.
794 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000795 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000796 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000797 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000798 Stmt *Body) {
799 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000800 }
Mike Stump1eb44332009-09-09 15:08:12 +0000801
Douglas Gregor43959a92009-08-20 07:17:43 +0000802 /// \brief Build a new do-while statement.
803 ///
804 /// By default, performs semantic analysis to build the new statement.
805 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000806 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregor43959a92009-08-20 07:17:43 +0000807 SourceLocation WhileLoc,
808 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000809 Expr *Cond,
Douglas Gregor43959a92009-08-20 07:17:43 +0000810 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000811 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
812 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +0000813 }
814
815 /// \brief Build a new for statement.
816 ///
817 /// By default, performs semantic analysis to build the new statement.
818 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000819 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000820 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000821 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000822 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCall9ae2f072010-08-23 23:25:46 +0000823 SourceLocation RParenLoc, Stmt *Body) {
824 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCalld226f652010-08-21 09:40:31 +0000825 CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000826 Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000827 }
Mike Stump1eb44332009-09-09 15:08:12 +0000828
Douglas Gregor43959a92009-08-20 07:17:43 +0000829 /// \brief Build a new goto statement.
830 ///
831 /// By default, performs semantic analysis to build the new statement.
832 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000833 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000834 SourceLocation LabelLoc,
835 LabelStmt *Label) {
836 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
837 }
838
839 /// \brief Build a new indirect goto statement.
840 ///
841 /// By default, performs semantic analysis to build the new statement.
842 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000843 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000844 SourceLocation StarLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000845 Expr *Target) {
846 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +0000847 }
Mike Stump1eb44332009-09-09 15:08:12 +0000848
Douglas Gregor43959a92009-08-20 07:17:43 +0000849 /// \brief Build a new return statement.
850 ///
851 /// By default, performs semantic analysis to build the new statement.
852 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000853 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000854 Expr *Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000855
John McCall9ae2f072010-08-23 23:25:46 +0000856 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +0000857 }
Mike Stump1eb44332009-09-09 15:08:12 +0000858
Douglas Gregor43959a92009-08-20 07:17:43 +0000859 /// \brief Build a new declaration statement.
860 ///
861 /// By default, performs semantic analysis to build the new statement.
862 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000863 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000864 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000865 SourceLocation EndLoc) {
866 return getSema().Owned(
867 new (getSema().Context) DeclStmt(
868 DeclGroupRef::Create(getSema().Context,
869 Decls, NumDecls),
870 StartLoc, EndLoc));
871 }
Mike Stump1eb44332009-09-09 15:08:12 +0000872
Anders Carlsson703e3942010-01-24 05:50:09 +0000873 /// \brief Build a new inline asm statement.
874 ///
875 /// By default, performs semantic analysis to build the new statement.
876 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000877 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +0000878 bool IsSimple,
879 bool IsVolatile,
880 unsigned NumOutputs,
881 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000882 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000883 MultiExprArg Constraints,
884 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +0000885 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +0000886 MultiExprArg Clobbers,
887 SourceLocation RParenLoc,
888 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000889 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000890 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +0000891 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +0000892 RParenLoc, MSAsm);
893 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000894
895 /// \brief Build a new Objective-C @try statement.
896 ///
897 /// By default, performs semantic analysis to build the new statement.
898 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000899 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000900 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000901 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +0000902 Stmt *Finally) {
903 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
904 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000905 }
906
Douglas Gregorbe270a02010-04-26 17:57:08 +0000907 /// \brief Rebuild an Objective-C exception declaration.
908 ///
909 /// By default, performs semantic analysis to build the new declaration.
910 /// Subclasses may override this routine to provide different behavior.
911 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
912 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +0000913 return getSema().BuildObjCExceptionDecl(TInfo, T,
914 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +0000915 ExceptionDecl->getLocation());
916 }
Sean Huntc3021132010-05-05 15:23:54 +0000917
Douglas Gregorbe270a02010-04-26 17:57:08 +0000918 /// \brief Build a new Objective-C @catch statement.
919 ///
920 /// By default, performs semantic analysis to build the new statement.
921 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000922 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +0000923 SourceLocation RParenLoc,
924 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +0000925 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +0000926 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000927 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +0000928 }
Sean Huntc3021132010-05-05 15:23:54 +0000929
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000930 /// \brief Build a new Objective-C @finally statement.
931 ///
932 /// By default, performs semantic analysis to build the new statement.
933 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000934 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000935 Stmt *Body) {
936 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000937 }
Sean Huntc3021132010-05-05 15:23:54 +0000938
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000939 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +0000940 ///
941 /// By default, performs semantic analysis to build the new statement.
942 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000943 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000944 Expr *Operand) {
945 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +0000946 }
Sean Huntc3021132010-05-05 15:23:54 +0000947
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000948 /// \brief Build a new Objective-C @synchronized statement.
949 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000950 /// By default, performs semantic analysis to build the new statement.
951 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000952 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000953 Expr *Object,
954 Stmt *Body) {
955 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
956 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000957 }
Douglas Gregorc3203e72010-04-22 23:10:45 +0000958
959 /// \brief Build a new Objective-C fast enumeration statement.
960 ///
961 /// By default, performs semantic analysis to build the new statement.
962 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000963 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +0000964 SourceLocation LParenLoc,
965 Stmt *Element,
966 Expr *Collection,
967 SourceLocation RParenLoc,
968 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +0000969 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000970 Element,
971 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +0000972 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000973 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +0000974 }
Sean Huntc3021132010-05-05 15:23:54 +0000975
Douglas Gregor43959a92009-08-20 07:17:43 +0000976 /// \brief Build a new C++ exception declaration.
977 ///
978 /// By default, performs semantic analysis to build the new decaration.
979 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000980 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000981 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000982 IdentifierInfo *Name,
983 SourceLocation Loc,
984 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000985 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000986 TypeRange);
987 }
988
989 /// \brief Build a new C++ catch statement.
990 ///
991 /// By default, performs semantic analysis to build the new statement.
992 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000993 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +0000994 VarDecl *ExceptionDecl,
995 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +0000996 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
997 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +0000998 }
Mike Stump1eb44332009-09-09 15:08:12 +0000999
Douglas Gregor43959a92009-08-20 07:17:43 +00001000 /// \brief Build a new C++ try statement.
1001 ///
1002 /// By default, performs semantic analysis to build the new statement.
1003 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001004 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001005 Stmt *TryBlock,
1006 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001007 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001008 }
Mike Stump1eb44332009-09-09 15:08:12 +00001009
Douglas Gregorb98b1992009-08-11 05:31:07 +00001010 /// \brief Build a new expression that references a declaration.
1011 ///
1012 /// By default, performs semantic analysis to build the new expression.
1013 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001014 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001015 LookupResult &R,
1016 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001017 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1018 }
1019
1020
1021 /// \brief Build a new expression that references a declaration.
1022 ///
1023 /// By default, performs semantic analysis to build the new expression.
1024 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001025 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001026 SourceRange QualifierRange,
1027 ValueDecl *VD,
1028 const DeclarationNameInfo &NameInfo,
1029 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001030 CXXScopeSpec SS;
1031 SS.setScopeRep(Qualifier);
1032 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001033
1034 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001035
1036 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001037 }
Mike Stump1eb44332009-09-09 15:08:12 +00001038
Douglas Gregorb98b1992009-08-11 05:31:07 +00001039 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001040 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001041 /// By default, performs semantic analysis to build the new expression.
1042 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001043 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001044 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001045 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001046 }
1047
Douglas Gregora71d8192009-09-04 17:36:40 +00001048 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001049 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001050 /// By default, performs semantic analysis to build the new expression.
1051 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001052 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001053 SourceLocation OperatorLoc,
1054 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001055 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001056 SourceRange QualifierRange,
1057 TypeSourceInfo *ScopeType,
1058 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001059 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001060 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001061
Douglas Gregorb98b1992009-08-11 05:31:07 +00001062 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001063 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001064 /// By default, performs semantic analysis to build the new expression.
1065 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001066 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001067 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001068 Expr *SubExpr) {
1069 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001070 }
Mike Stump1eb44332009-09-09 15:08:12 +00001071
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001072 /// \brief Build a new builtin offsetof expression.
1073 ///
1074 /// By default, performs semantic analysis to build the new expression.
1075 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001076 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001077 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001078 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001079 unsigned NumComponents,
1080 SourceLocation RParenLoc) {
1081 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1082 NumComponents, RParenLoc);
1083 }
Sean Huntc3021132010-05-05 15:23:54 +00001084
Douglas Gregorb98b1992009-08-11 05:31:07 +00001085 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001086 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001087 /// By default, performs semantic analysis to build the new expression.
1088 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001089 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001090 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001091 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001092 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001093 }
1094
Mike Stump1eb44332009-09-09 15:08:12 +00001095 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001096 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001097 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001098 /// By default, performs semantic analysis to build the new expression.
1099 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001100 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001101 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001102 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001103 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001104 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001105 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001106
Douglas Gregorb98b1992009-08-11 05:31:07 +00001107 return move(Result);
1108 }
Mike Stump1eb44332009-09-09 15:08:12 +00001109
Douglas Gregorb98b1992009-08-11 05:31:07 +00001110 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001111 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001112 /// By default, performs semantic analysis to build the new expression.
1113 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001114 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001115 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001116 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001117 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001118 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1119 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001120 RBracketLoc);
1121 }
1122
1123 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001124 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001125 /// By default, performs semantic analysis to build the new expression.
1126 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001127 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001128 MultiExprArg Args,
1129 SourceLocation *CommaLocs,
1130 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001131 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001132 move(Args), CommaLocs, RParenLoc);
1133 }
1134
1135 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001136 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001137 /// By default, performs semantic analysis to build the new expression.
1138 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001139 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001140 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001141 NestedNameSpecifier *Qualifier,
1142 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001143 const DeclarationNameInfo &MemberNameInfo,
Eli Friedmanf595cc42009-12-04 06:40:45 +00001144 ValueDecl *Member,
John McCall6bb80172010-03-30 21:47:33 +00001145 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001146 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +00001147 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001148 if (!Member->getDeclName()) {
1149 // We have a reference to an unnamed field.
1150 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +00001151
John McCall9ae2f072010-08-23 23:25:46 +00001152 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001153 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001154 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001155
Mike Stump1eb44332009-09-09 15:08:12 +00001156 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001157 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001158 Member, MemberNameInfo,
Anders Carlssond8b285f2009-09-01 04:26:58 +00001159 cast<FieldDecl>(Member)->getType());
1160 return getSema().Owned(ME);
1161 }
Mike Stump1eb44332009-09-09 15:08:12 +00001162
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001163 CXXScopeSpec SS;
1164 if (Qualifier) {
1165 SS.setRange(QualifierRange);
1166 SS.setScopeRep(Qualifier);
1167 }
1168
John McCall9ae2f072010-08-23 23:25:46 +00001169 getSema().DefaultFunctionArrayConversion(Base);
1170 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001171
John McCall6bb80172010-03-30 21:47:33 +00001172 // FIXME: this involves duplicating earlier analysis in a lot of
1173 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001174 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001175 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001176 R.resolveKind();
1177
John McCall9ae2f072010-08-23 23:25:46 +00001178 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001179 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001180 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001181 }
Mike Stump1eb44332009-09-09 15:08:12 +00001182
Douglas Gregorb98b1992009-08-11 05:31:07 +00001183 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001184 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001185 /// By default, performs semantic analysis to build the new expression.
1186 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001187 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001188 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001189 Expr *LHS, Expr *RHS) {
1190 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001191 }
1192
1193 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001194 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001195 /// By default, performs semantic analysis to build the new expression.
1196 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001197 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001198 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001199 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001200 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001201 Expr *RHS) {
1202 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1203 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001204 }
1205
Douglas Gregorb98b1992009-08-11 05:31:07 +00001206 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001207 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001208 /// By default, performs semantic analysis to build the new expression.
1209 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001210 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001211 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001212 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001213 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001214 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001215 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001216 }
Mike Stump1eb44332009-09-09 15:08:12 +00001217
Douglas Gregorb98b1992009-08-11 05:31:07 +00001218 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001219 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001220 /// By default, performs semantic analysis to build the new expression.
1221 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001222 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001223 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001224 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001225 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001226 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001227 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001228 }
Mike Stump1eb44332009-09-09 15:08:12 +00001229
Douglas Gregorb98b1992009-08-11 05:31:07 +00001230 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001231 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001232 /// By default, performs semantic analysis to build the new expression.
1233 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001234 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001235 SourceLocation OpLoc,
1236 SourceLocation AccessorLoc,
1237 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001238
John McCall129e2df2009-11-30 22:42:35 +00001239 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001240 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001241 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001242 OpLoc, /*IsArrow*/ false,
1243 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001244 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001245 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001246 }
Mike Stump1eb44332009-09-09 15:08:12 +00001247
Douglas Gregorb98b1992009-08-11 05:31:07 +00001248 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001249 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001250 /// By default, performs semantic analysis to build the new expression.
1251 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001252 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001253 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001254 SourceLocation RBraceLoc,
1255 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001256 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001257 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1258 if (Result.isInvalid() || ResultTy->isDependentType())
1259 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001260
Douglas Gregore48319a2009-11-09 17:16:50 +00001261 // Patch in the result type we were given, which may have been computed
1262 // when the initial InitListExpr was built.
1263 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1264 ILE->setType(ResultTy);
1265 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001266 }
Mike Stump1eb44332009-09-09 15:08:12 +00001267
Douglas Gregorb98b1992009-08-11 05:31:07 +00001268 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001269 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001270 /// By default, performs semantic analysis to build the new expression.
1271 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001272 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001273 MultiExprArg ArrayExprs,
1274 SourceLocation EqualOrColonLoc,
1275 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001276 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001277 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001278 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001279 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001280 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001281 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001282
Douglas Gregorb98b1992009-08-11 05:31:07 +00001283 ArrayExprs.release();
1284 return move(Result);
1285 }
Mike Stump1eb44332009-09-09 15:08:12 +00001286
Douglas Gregorb98b1992009-08-11 05:31:07 +00001287 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001288 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001289 /// By default, builds the implicit value initialization without performing
1290 /// any semantic analysis. Subclasses may override this routine to provide
1291 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001292 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001293 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1294 }
Mike Stump1eb44332009-09-09 15:08:12 +00001295
Douglas Gregorb98b1992009-08-11 05:31:07 +00001296 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001297 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001298 /// By default, performs semantic analysis to build the new expression.
1299 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001300 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001301 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001302 SourceLocation RParenLoc) {
1303 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001304 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001305 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001306 }
1307
1308 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001309 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001310 /// By default, performs semantic analysis to build the new expression.
1311 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001312 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001313 MultiExprArg SubExprs,
1314 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001315 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001316 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001317 }
Mike Stump1eb44332009-09-09 15:08:12 +00001318
Douglas Gregorb98b1992009-08-11 05:31:07 +00001319 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001320 ///
1321 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001322 /// rather than attempting to map the label statement itself.
1323 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001324 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001325 SourceLocation LabelLoc,
1326 LabelStmt *Label) {
1327 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1328 }
Mike Stump1eb44332009-09-09 15:08:12 +00001329
Douglas Gregorb98b1992009-08-11 05:31:07 +00001330 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001331 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001332 /// By default, performs semantic analysis to build the new expression.
1333 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001334 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001335 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001336 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001337 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001338 }
Mike Stump1eb44332009-09-09 15:08:12 +00001339
Douglas Gregorb98b1992009-08-11 05:31:07 +00001340 /// \brief Build a new __builtin_types_compatible_p expression.
1341 ///
1342 /// By default, performs semantic analysis to build the new expression.
1343 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001344 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001345 TypeSourceInfo *TInfo1,
1346 TypeSourceInfo *TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001347 SourceLocation RParenLoc) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001348 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1349 TInfo1, TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001350 RParenLoc);
1351 }
Mike Stump1eb44332009-09-09 15:08:12 +00001352
Douglas Gregorb98b1992009-08-11 05:31:07 +00001353 /// \brief Build a new __builtin_choose_expr expression.
1354 ///
1355 /// By default, performs semantic analysis to build the new expression.
1356 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001357 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001358 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001359 SourceLocation RParenLoc) {
1360 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001361 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001362 RParenLoc);
1363 }
Mike Stump1eb44332009-09-09 15:08:12 +00001364
Douglas Gregorb98b1992009-08-11 05:31:07 +00001365 /// \brief Build a new overloaded operator call expression.
1366 ///
1367 /// By default, performs semantic analysis to build the new expression.
1368 /// The semantic analysis provides the behavior of template instantiation,
1369 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001370 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001371 /// argument-dependent lookup, etc. Subclasses may override this routine to
1372 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001373 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001374 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001375 Expr *Callee,
1376 Expr *First,
1377 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001378
1379 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001380 /// reinterpret_cast.
1381 ///
1382 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001383 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001384 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001385 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001386 Stmt::StmtClass Class,
1387 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001388 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001389 SourceLocation RAngleLoc,
1390 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001391 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001392 SourceLocation RParenLoc) {
1393 switch (Class) {
1394 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001395 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001396 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001397 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001398
1399 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001400 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001401 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001402 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001403
Douglas Gregorb98b1992009-08-11 05:31:07 +00001404 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001405 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001406 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001407 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001408 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001409
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001411 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001412 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001413 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001414
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 default:
1416 assert(false && "Invalid C++ named cast");
1417 break;
1418 }
Mike Stump1eb44332009-09-09 15:08:12 +00001419
John McCallf312b1e2010-08-26 23:41:50 +00001420 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 }
Mike Stump1eb44332009-09-09 15:08:12 +00001422
Douglas Gregorb98b1992009-08-11 05:31:07 +00001423 /// \brief Build a new C++ static_cast expression.
1424 ///
1425 /// By default, performs semantic analysis to build the new expression.
1426 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001427 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001428 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001429 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001430 SourceLocation RAngleLoc,
1431 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001432 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001433 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001434 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001435 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001436 SourceRange(LAngleLoc, RAngleLoc),
1437 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001438 }
1439
1440 /// \brief Build a new C++ dynamic_cast expression.
1441 ///
1442 /// By default, performs semantic analysis to build the new expression.
1443 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001444 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001445 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001446 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001447 SourceLocation RAngleLoc,
1448 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001449 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001451 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001452 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001453 SourceRange(LAngleLoc, RAngleLoc),
1454 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001455 }
1456
1457 /// \brief Build a new C++ reinterpret_cast expression.
1458 ///
1459 /// By default, performs semantic analysis to build the new expression.
1460 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001461 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001463 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001464 SourceLocation RAngleLoc,
1465 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001466 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001468 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001469 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001470 SourceRange(LAngleLoc, RAngleLoc),
1471 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001472 }
1473
1474 /// \brief Build a new C++ const_cast expression.
1475 ///
1476 /// By default, performs semantic analysis to build the new expression.
1477 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001478 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001479 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001480 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 SourceLocation RAngleLoc,
1482 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001483 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001485 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001486 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001487 SourceRange(LAngleLoc, RAngleLoc),
1488 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 }
Mike Stump1eb44332009-09-09 15:08:12 +00001490
Douglas Gregorb98b1992009-08-11 05:31:07 +00001491 /// \brief Build a new C++ functional-style cast expression.
1492 ///
1493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001495 ExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001496 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001497 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001498 Expr *Sub,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001499 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCallb3d87482010-08-24 05:47:05 +00001501 ParsedType::make(TInfo->getType()),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001503 MultiExprArg(&Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001504 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 RParenLoc);
1506 }
Mike Stump1eb44332009-09-09 15:08:12 +00001507
Douglas Gregorb98b1992009-08-11 05:31:07 +00001508 /// \brief Build a new C++ typeid(type) expression.
1509 ///
1510 /// By default, performs semantic analysis to build the new expression.
1511 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001512 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001513 SourceLocation TypeidLoc,
1514 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001516 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001517 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 }
Mike Stump1eb44332009-09-09 15:08:12 +00001519
Douglas Gregorb98b1992009-08-11 05:31:07 +00001520 /// \brief Build a new C++ typeid(expr) expression.
1521 ///
1522 /// By default, performs semantic analysis to build the new expression.
1523 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001524 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001525 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001526 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001527 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001528 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001529 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001530 }
1531
Douglas Gregorb98b1992009-08-11 05:31:07 +00001532 /// \brief Build a new C++ "this" expression.
1533 ///
1534 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001535 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001536 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001537 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001538 QualType ThisType,
1539 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001540 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001541 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1542 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001543 }
1544
1545 /// \brief Build a new C++ throw expression.
1546 ///
1547 /// By default, performs semantic analysis to build the new expression.
1548 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001549 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001550 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 }
1552
1553 /// \brief Build a new C++ default-argument expression.
1554 ///
1555 /// By default, builds a new default-argument expression, which does not
1556 /// require any semantic analysis. Subclasses may override this routine to
1557 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001558 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001559 ParmVarDecl *Param) {
1560 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1561 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001562 }
1563
1564 /// \brief Build a new C++ zero-initialization expression.
1565 ///
1566 /// By default, performs semantic analysis to build the new expression.
1567 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001568 ExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 SourceLocation LParenLoc,
1570 QualType T,
1571 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001572 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
John McCallb3d87482010-08-24 05:47:05 +00001573 ParsedType::make(T), LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001574 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001575 0, RParenLoc);
1576 }
Mike Stump1eb44332009-09-09 15:08:12 +00001577
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 /// \brief Build a new C++ "new" expression.
1579 ///
1580 /// By default, performs semantic analysis to build the new expression.
1581 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001582 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 bool UseGlobal,
1584 SourceLocation PlacementLParen,
1585 MultiExprArg PlacementArgs,
1586 SourceLocation PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001587 SourceRange TypeIdParens,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001588 QualType AllocType,
1589 SourceLocation TypeLoc,
1590 SourceRange TypeRange,
John McCall9ae2f072010-08-23 23:25:46 +00001591 Expr *ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 SourceLocation ConstructorLParen,
1593 MultiExprArg ConstructorArgs,
1594 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001595 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 PlacementLParen,
1597 move(PlacementArgs),
1598 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001599 TypeIdParens,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 AllocType,
1601 TypeLoc,
1602 TypeRange,
John McCall9ae2f072010-08-23 23:25:46 +00001603 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 ConstructorLParen,
1605 move(ConstructorArgs),
1606 ConstructorRParen);
1607 }
Mike Stump1eb44332009-09-09 15:08:12 +00001608
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 /// \brief Build a new C++ "delete" expression.
1610 ///
1611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001613 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 bool IsGlobalDelete,
1615 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001616 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001618 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001619 }
Mike Stump1eb44332009-09-09 15:08:12 +00001620
Douglas Gregorb98b1992009-08-11 05:31:07 +00001621 /// \brief Build a new unary type trait expression.
1622 ///
1623 /// By default, performs semantic analysis to build the new expression.
1624 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001625 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001626 SourceLocation StartLoc,
1627 SourceLocation LParenLoc,
1628 QualType T,
1629 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001630 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
John McCallb3d87482010-08-24 05:47:05 +00001631 ParsedType::make(T), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 }
1633
Mike Stump1eb44332009-09-09 15:08:12 +00001634 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 /// expression.
1636 ///
1637 /// By default, performs semantic analysis to build the new expression.
1638 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001639 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001640 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001641 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001642 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001643 CXXScopeSpec SS;
1644 SS.setRange(QualifierRange);
1645 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001646
1647 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001648 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001649 *TemplateArgs);
1650
Abramo Bagnara25777432010-08-11 22:01:17 +00001651 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 }
1653
1654 /// \brief Build a new template-id expression.
1655 ///
1656 /// By default, performs semantic analysis to build the new expression.
1657 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001658 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001659 LookupResult &R,
1660 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001661 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001662 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 }
1664
1665 /// \brief Build a new object-construction expression.
1666 ///
1667 /// By default, performs semantic analysis to build the new expression.
1668 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001669 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001670 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 CXXConstructorDecl *Constructor,
1672 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001673 MultiExprArg Args,
1674 bool RequiresZeroInit,
1675 CXXConstructExpr::ConstructionKind ConstructKind) {
John McCallca0408f2010-08-23 06:44:23 +00001676 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001677 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001678 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001679 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001680
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001681 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001682 move_arg(ConvertedArgs),
1683 RequiresZeroInit, ConstructKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001684 }
1685
1686 /// \brief Build a new object-construction expression.
1687 ///
1688 /// By default, performs semantic analysis to build the new expression.
1689 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001690 ExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 QualType T,
1692 SourceLocation LParenLoc,
1693 MultiExprArg Args,
1694 SourceLocation *Commas,
1695 SourceLocation RParenLoc) {
1696 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
John McCallb3d87482010-08-24 05:47:05 +00001697 ParsedType::make(T),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 LParenLoc,
1699 move(Args),
1700 Commas,
1701 RParenLoc);
1702 }
1703
1704 /// \brief Build a new object-construction expression.
1705 ///
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001708 ExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001709 QualType T,
1710 SourceLocation LParenLoc,
1711 MultiExprArg Args,
1712 SourceLocation *Commas,
1713 SourceLocation RParenLoc) {
1714 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1715 /*FIXME*/LParenLoc),
John McCallb3d87482010-08-24 05:47:05 +00001716 ParsedType::make(T),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 LParenLoc,
1718 move(Args),
1719 Commas,
1720 RParenLoc);
1721 }
Mike Stump1eb44332009-09-09 15:08:12 +00001722
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 /// \brief Build a new member reference expression.
1724 ///
1725 /// By default, performs semantic analysis to build the new expression.
1726 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001727 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001728 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001729 bool IsArrow,
1730 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001731 NestedNameSpecifier *Qualifier,
1732 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001733 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001734 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001735 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001737 SS.setRange(QualifierRange);
1738 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001739
John McCall9ae2f072010-08-23 23:25:46 +00001740 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001741 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001742 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001743 MemberNameInfo,
1744 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 }
1746
John McCall129e2df2009-11-30 22:42:35 +00001747 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001748 ///
1749 /// By default, performs semantic analysis to build the new expression.
1750 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001751 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001752 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001753 SourceLocation OperatorLoc,
1754 bool IsArrow,
1755 NestedNameSpecifier *Qualifier,
1756 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001757 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001758 LookupResult &R,
1759 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001760 CXXScopeSpec SS;
1761 SS.setRange(QualifierRange);
1762 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001763
John McCall9ae2f072010-08-23 23:25:46 +00001764 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001765 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001766 SS, FirstQualifierInScope,
1767 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001768 }
Mike Stump1eb44332009-09-09 15:08:12 +00001769
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 /// \brief Build a new Objective-C @encode expression.
1771 ///
1772 /// By default, performs semantic analysis to build the new expression.
1773 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001774 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001775 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001776 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001777 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001778 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001779 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001780
Douglas Gregor92e986e2010-04-22 16:44:27 +00001781 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00001782 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001783 Selector Sel,
1784 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001785 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001786 MultiExprArg Args,
1787 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001788 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1789 ReceiverTypeInfo->getType(),
1790 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001791 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001792 move(Args));
1793 }
1794
1795 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00001796 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001797 Selector Sel,
1798 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001799 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001800 MultiExprArg Args,
1801 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001802 return SemaRef.BuildInstanceMessage(Receiver,
1803 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00001804 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001805 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001806 move(Args));
1807 }
1808
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001809 /// \brief Build a new Objective-C ivar reference expression.
1810 ///
1811 /// By default, performs semantic analysis to build the new expression.
1812 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001813 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001814 SourceLocation IvarLoc,
1815 bool IsArrow, bool IsFreeIvar) {
1816 // FIXME: We lose track of the IsFreeIvar bit.
1817 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001818 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001819 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1820 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001821 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001822 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00001823 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00001824 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001825 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001826 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001827
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001828 if (Result.get())
1829 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001830
John McCall9ae2f072010-08-23 23:25:46 +00001831 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001832 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001833 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001834 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001835 /*TemplateArgs=*/0);
1836 }
Douglas Gregore3303542010-04-26 20:47:02 +00001837
1838 /// \brief Build a new Objective-C property reference expression.
1839 ///
1840 /// By default, performs semantic analysis to build the new expression.
1841 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001842 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001843 ObjCPropertyDecl *Property,
1844 SourceLocation PropertyLoc) {
1845 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001846 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00001847 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1848 Sema::LookupMemberName);
1849 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00001850 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00001851 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00001852 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00001853 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001854 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001855
Douglas Gregore3303542010-04-26 20:47:02 +00001856 if (Result.get())
1857 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001858
John McCall9ae2f072010-08-23 23:25:46 +00001859 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001860 /*FIXME:*/PropertyLoc, IsArrow,
1861 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001862 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001863 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001864 /*TemplateArgs=*/0);
1865 }
Sean Huntc3021132010-05-05 15:23:54 +00001866
1867 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001868 /// expression.
1869 ///
1870 /// By default, performs semantic analysis to build the new expression.
Sean Huntc3021132010-05-05 15:23:54 +00001871 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001872 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001873 ObjCMethodDecl *Getter,
1874 QualType T,
1875 ObjCMethodDecl *Setter,
1876 SourceLocation NameLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001877 Expr *Base) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001878 // Since these expressions can only be value-dependent, we do not need to
1879 // perform semantic analysis again.
John McCall9ae2f072010-08-23 23:25:46 +00001880 return Owned(
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001881 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1882 Setter,
1883 NameLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001884 Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001885 }
1886
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001887 /// \brief Build a new Objective-C "isa" expression.
1888 ///
1889 /// By default, performs semantic analysis to build the new expression.
1890 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001891 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001892 bool IsArrow) {
1893 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001894 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001895 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1896 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001897 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001898 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00001899 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001900 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001901 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001902
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001903 if (Result.get())
1904 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001905
John McCall9ae2f072010-08-23 23:25:46 +00001906 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001907 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001908 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001909 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001910 /*TemplateArgs=*/0);
1911 }
Sean Huntc3021132010-05-05 15:23:54 +00001912
Douglas Gregorb98b1992009-08-11 05:31:07 +00001913 /// \brief Build a new shuffle vector expression.
1914 ///
1915 /// By default, performs semantic analysis to build the new expression.
1916 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001917 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001918 MultiExprArg SubExprs,
1919 SourceLocation RParenLoc) {
1920 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001921 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001922 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1923 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1924 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1925 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001926
Douglas Gregorb98b1992009-08-11 05:31:07 +00001927 // Build a reference to the __builtin_shufflevector builtin
1928 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001929 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001930 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001931 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001932 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001933
1934 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 unsigned NumSubExprs = SubExprs.size();
1936 Expr **Subs = (Expr **)SubExprs.release();
1937 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1938 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00001939 Builtin->getCallResultType(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001940 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00001941 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001942
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00001944 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001945 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001946 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001947
Douglas Gregorb98b1992009-08-11 05:31:07 +00001948 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001949 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001950 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001951};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952
Douglas Gregor43959a92009-08-20 07:17:43 +00001953template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00001954StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00001955 if (!S)
1956 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001957
Douglas Gregor43959a92009-08-20 07:17:43 +00001958 switch (S->getStmtClass()) {
1959 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001960
Douglas Gregor43959a92009-08-20 07:17:43 +00001961 // Transform individual statement nodes
1962#define STMT(Node, Parent) \
1963 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1964#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00001965#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001966
Douglas Gregor43959a92009-08-20 07:17:43 +00001967 // Transform expressions by calling TransformExpr.
1968#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00001969#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00001970#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00001971#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00001972 {
John McCall60d7b3a2010-08-24 06:29:42 +00001973 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00001974 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001975 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001976
John McCall9ae2f072010-08-23 23:25:46 +00001977 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00001978 }
Mike Stump1eb44332009-09-09 15:08:12 +00001979 }
1980
Douglas Gregor43959a92009-08-20 07:17:43 +00001981 return SemaRef.Owned(S->Retain());
1982}
Mike Stump1eb44332009-09-09 15:08:12 +00001983
1984
Douglas Gregor670444e2009-08-04 22:27:00 +00001985template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00001986ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001987 if (!E)
1988 return SemaRef.Owned(E);
1989
1990 switch (E->getStmtClass()) {
1991 case Stmt::NoStmtClass: break;
1992#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00001993#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00001994#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00001995 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00001996#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001997 }
1998
Douglas Gregorb98b1992009-08-11 05:31:07 +00001999 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002000}
2001
2002template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002003NestedNameSpecifier *
2004TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002005 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002006 QualType ObjectType,
2007 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00002008 if (!NNS)
2009 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002010
Douglas Gregor43959a92009-08-20 07:17:43 +00002011 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002012 NestedNameSpecifier *Prefix = NNS->getPrefix();
2013 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002014 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002015 ObjectType,
2016 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002017 if (!Prefix)
2018 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002019
2020 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00002021 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00002022 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00002023 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002024 }
Mike Stump1eb44332009-09-09 15:08:12 +00002025
Douglas Gregordcee1a12009-08-06 05:28:30 +00002026 switch (NNS->getKind()) {
2027 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00002028 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002029 "Identifier nested-name-specifier with no prefix or object type");
2030 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2031 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002032 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002033
2034 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002035 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002036 ObjectType,
2037 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002038
Douglas Gregordcee1a12009-08-06 05:28:30 +00002039 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002040 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002041 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002042 getDerived().TransformDecl(Range.getBegin(),
2043 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002044 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002045 Prefix == NNS->getPrefix() &&
2046 NS == NNS->getAsNamespace())
2047 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002048
Douglas Gregordcee1a12009-08-06 05:28:30 +00002049 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2050 }
Mike Stump1eb44332009-09-09 15:08:12 +00002051
Douglas Gregordcee1a12009-08-06 05:28:30 +00002052 case NestedNameSpecifier::Global:
2053 // There is no meaningful transformation that one could perform on the
2054 // global scope.
2055 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002056
Douglas Gregordcee1a12009-08-06 05:28:30 +00002057 case NestedNameSpecifier::TypeSpecWithTemplate:
2058 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002059 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00002060 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2061 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002062 if (T.isNull())
2063 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002064
Douglas Gregordcee1a12009-08-06 05:28:30 +00002065 if (!getDerived().AlwaysRebuild() &&
2066 Prefix == NNS->getPrefix() &&
2067 T == QualType(NNS->getAsType(), 0))
2068 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002069
2070 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2071 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002072 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002073 }
2074 }
Mike Stump1eb44332009-09-09 15:08:12 +00002075
Douglas Gregordcee1a12009-08-06 05:28:30 +00002076 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002077 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002078}
2079
2080template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002081DeclarationNameInfo
2082TreeTransform<Derived>
2083::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2084 QualType ObjectType) {
2085 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002086 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002087 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002088
2089 switch (Name.getNameKind()) {
2090 case DeclarationName::Identifier:
2091 case DeclarationName::ObjCZeroArgSelector:
2092 case DeclarationName::ObjCOneArgSelector:
2093 case DeclarationName::ObjCMultiArgSelector:
2094 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002095 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002096 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002097 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002098
Douglas Gregor81499bb2009-09-03 22:13:48 +00002099 case DeclarationName::CXXConstructorName:
2100 case DeclarationName::CXXDestructorName:
2101 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002102 TypeSourceInfo *NewTInfo;
2103 CanQualType NewCanTy;
2104 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2105 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2106 if (!NewTInfo)
2107 return DeclarationNameInfo();
2108 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2109 }
2110 else {
2111 NewTInfo = 0;
2112 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2113 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2114 ObjectType);
2115 if (NewT.isNull())
2116 return DeclarationNameInfo();
2117 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2118 }
Mike Stump1eb44332009-09-09 15:08:12 +00002119
Abramo Bagnara25777432010-08-11 22:01:17 +00002120 DeclarationName NewName
2121 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2122 NewCanTy);
2123 DeclarationNameInfo NewNameInfo(NameInfo);
2124 NewNameInfo.setName(NewName);
2125 NewNameInfo.setNamedTypeInfo(NewTInfo);
2126 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002127 }
Mike Stump1eb44332009-09-09 15:08:12 +00002128 }
2129
Abramo Bagnara25777432010-08-11 22:01:17 +00002130 assert(0 && "Unknown name kind.");
2131 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002132}
2133
2134template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002135TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002136TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2137 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002138 SourceLocation Loc = getDerived().getBaseLocation();
2139
Douglas Gregord1067e52009-08-06 06:41:21 +00002140 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002141 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002142 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002143 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2144 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002145 if (!NNS)
2146 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002147
Douglas Gregord1067e52009-08-06 06:41:21 +00002148 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002149 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002150 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002151 if (!TransTemplate)
2152 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002153
Douglas Gregord1067e52009-08-06 06:41:21 +00002154 if (!getDerived().AlwaysRebuild() &&
2155 NNS == QTN->getQualifier() &&
2156 TransTemplate == Template)
2157 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002158
Douglas Gregord1067e52009-08-06 06:41:21 +00002159 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2160 TransTemplate);
2161 }
Mike Stump1eb44332009-09-09 15:08:12 +00002162
John McCallf7a1a742009-11-24 19:00:30 +00002163 // These should be getting filtered out before they make it into the AST.
2164 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002165 }
Mike Stump1eb44332009-09-09 15:08:12 +00002166
Douglas Gregord1067e52009-08-06 06:41:21 +00002167 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002168 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002169 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002170 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2171 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002172 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00002173 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002174
Douglas Gregord1067e52009-08-06 06:41:21 +00002175 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002176 NNS == DTN->getQualifier() &&
2177 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002178 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002179
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002180 if (DTN->isIdentifier())
Sean Huntc3021132010-05-05 15:23:54 +00002181 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002182 ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +00002183
2184 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002185 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002186 }
Mike Stump1eb44332009-09-09 15:08:12 +00002187
Douglas Gregord1067e52009-08-06 06:41:21 +00002188 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002189 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002190 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002191 if (!TransTemplate)
2192 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002193
Douglas Gregord1067e52009-08-06 06:41:21 +00002194 if (!getDerived().AlwaysRebuild() &&
2195 TransTemplate == Template)
2196 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002197
Douglas Gregord1067e52009-08-06 06:41:21 +00002198 return TemplateName(TransTemplate);
2199 }
Mike Stump1eb44332009-09-09 15:08:12 +00002200
John McCallf7a1a742009-11-24 19:00:30 +00002201 // These should be getting filtered out before they reach the AST.
2202 assert(false && "overloaded function decl survived to here");
2203 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002204}
2205
2206template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002207void TreeTransform<Derived>::InventTemplateArgumentLoc(
2208 const TemplateArgument &Arg,
2209 TemplateArgumentLoc &Output) {
2210 SourceLocation Loc = getDerived().getBaseLocation();
2211 switch (Arg.getKind()) {
2212 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002213 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002214 break;
2215
2216 case TemplateArgument::Type:
2217 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002218 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002219
John McCall833ca992009-10-29 08:12:44 +00002220 break;
2221
Douglas Gregor788cd062009-11-11 01:00:40 +00002222 case TemplateArgument::Template:
2223 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2224 break;
Sean Huntc3021132010-05-05 15:23:54 +00002225
John McCall833ca992009-10-29 08:12:44 +00002226 case TemplateArgument::Expression:
2227 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2228 break;
2229
2230 case TemplateArgument::Declaration:
2231 case TemplateArgument::Integral:
2232 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002233 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002234 break;
2235 }
2236}
2237
2238template<typename Derived>
2239bool TreeTransform<Derived>::TransformTemplateArgument(
2240 const TemplateArgumentLoc &Input,
2241 TemplateArgumentLoc &Output) {
2242 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002243 switch (Arg.getKind()) {
2244 case TemplateArgument::Null:
2245 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002246 Output = Input;
2247 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002248
Douglas Gregor670444e2009-08-04 22:27:00 +00002249 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002250 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002251 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002252 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002253
2254 DI = getDerived().TransformType(DI);
2255 if (!DI) return true;
2256
2257 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2258 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002259 }
Mike Stump1eb44332009-09-09 15:08:12 +00002260
Douglas Gregor670444e2009-08-04 22:27:00 +00002261 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002262 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002263 DeclarationName Name;
2264 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2265 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002266 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002267 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002268 if (!D) return true;
2269
John McCall828bff22009-10-29 18:45:58 +00002270 Expr *SourceExpr = Input.getSourceDeclExpression();
2271 if (SourceExpr) {
2272 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002273 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002274 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002275 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002276 }
2277
2278 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002279 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002280 }
Mike Stump1eb44332009-09-09 15:08:12 +00002281
Douglas Gregor788cd062009-11-11 01:00:40 +00002282 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002283 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002284 TemplateName Template
2285 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2286 if (Template.isNull())
2287 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002288
Douglas Gregor788cd062009-11-11 01:00:40 +00002289 Output = TemplateArgumentLoc(TemplateArgument(Template),
2290 Input.getTemplateQualifierRange(),
2291 Input.getTemplateNameLoc());
2292 return false;
2293 }
Sean Huntc3021132010-05-05 15:23:54 +00002294
Douglas Gregor670444e2009-08-04 22:27:00 +00002295 case TemplateArgument::Expression: {
2296 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002297 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002298 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002299
John McCall833ca992009-10-29 08:12:44 +00002300 Expr *InputExpr = Input.getSourceExpression();
2301 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2302
John McCall60d7b3a2010-08-24 06:29:42 +00002303 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002304 = getDerived().TransformExpr(InputExpr);
2305 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002306 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002307 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002308 }
Mike Stump1eb44332009-09-09 15:08:12 +00002309
Douglas Gregor670444e2009-08-04 22:27:00 +00002310 case TemplateArgument::Pack: {
2311 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2312 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002313 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002314 AEnd = Arg.pack_end();
2315 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002316
John McCall833ca992009-10-29 08:12:44 +00002317 // FIXME: preserve source information here when we start
2318 // caring about parameter packs.
2319
John McCall828bff22009-10-29 18:45:58 +00002320 TemplateArgumentLoc InputArg;
2321 TemplateArgumentLoc OutputArg;
2322 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2323 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002324 return true;
2325
John McCall828bff22009-10-29 18:45:58 +00002326 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002327 }
2328 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002329 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002330 true);
John McCall828bff22009-10-29 18:45:58 +00002331 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002332 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002333 }
2334 }
Mike Stump1eb44332009-09-09 15:08:12 +00002335
Douglas Gregor670444e2009-08-04 22:27:00 +00002336 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002337 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002338}
2339
Douglas Gregor577f75a2009-08-04 16:50:30 +00002340//===----------------------------------------------------------------------===//
2341// Type transformation
2342//===----------------------------------------------------------------------===//
2343
2344template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00002345QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregor124b8782010-02-16 19:09:40 +00002346 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002347 if (getDerived().AlreadyTransformed(T))
2348 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002349
John McCalla2becad2009-10-21 00:40:46 +00002350 // Temporary workaround. All of these transformations should
2351 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002352 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002353 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002354
Douglas Gregor124b8782010-02-16 19:09:40 +00002355 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002356
John McCalla2becad2009-10-21 00:40:46 +00002357 if (!NewDI)
2358 return QualType();
2359
2360 return NewDI->getType();
2361}
2362
2363template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002364TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2365 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002366 if (getDerived().AlreadyTransformed(DI->getType()))
2367 return DI;
2368
2369 TypeLocBuilder TLB;
2370
2371 TypeLoc TL = DI->getTypeLoc();
2372 TLB.reserve(TL.getFullDataSize());
2373
Douglas Gregor124b8782010-02-16 19:09:40 +00002374 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002375 if (Result.isNull())
2376 return 0;
2377
John McCalla93c9342009-12-07 02:54:59 +00002378 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002379}
2380
2381template<typename Derived>
2382QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002383TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2384 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002385 switch (T.getTypeLocClass()) {
2386#define ABSTRACT_TYPELOC(CLASS, PARENT)
2387#define TYPELOC(CLASS, PARENT) \
2388 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002389 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2390 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002391#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002392 }
Mike Stump1eb44332009-09-09 15:08:12 +00002393
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002394 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002395 return QualType();
2396}
2397
2398/// FIXME: By default, this routine adds type qualifiers only to types
2399/// that can have qualifiers, and silently suppresses those qualifiers
2400/// that are not permitted (e.g., qualifiers on reference or function
2401/// types). This is the right thing for template instantiation, but
2402/// probably not for other clients.
2403template<typename Derived>
2404QualType
2405TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002406 QualifiedTypeLoc T,
2407 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002408 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002409
Douglas Gregor124b8782010-02-16 19:09:40 +00002410 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2411 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002412 if (Result.isNull())
2413 return QualType();
2414
2415 // Silently suppress qualifiers if the result type can't be qualified.
2416 // FIXME: this is the right thing for template instantiation, but
2417 // probably not for other clients.
2418 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002419 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002420
John McCall28654742010-06-05 06:41:15 +00002421 if (!Quals.empty()) {
2422 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2423 TLB.push<QualifiedTypeLoc>(Result);
2424 // No location information to preserve.
2425 }
John McCalla2becad2009-10-21 00:40:46 +00002426
2427 return Result;
2428}
2429
2430template <class TyLoc> static inline
2431QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2432 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2433 NewT.setNameLoc(T.getNameLoc());
2434 return T.getType();
2435}
2436
John McCalla2becad2009-10-21 00:40:46 +00002437template<typename Derived>
2438QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002439 BuiltinTypeLoc T,
2440 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002441 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2442 NewT.setBuiltinLoc(T.getBuiltinLoc());
2443 if (T.needsExtraLocalData())
2444 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2445 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002446}
Mike Stump1eb44332009-09-09 15:08:12 +00002447
Douglas Gregor577f75a2009-08-04 16:50:30 +00002448template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002449QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002450 ComplexTypeLoc T,
2451 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002452 // FIXME: recurse?
2453 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002454}
Mike Stump1eb44332009-09-09 15:08:12 +00002455
Douglas Gregor577f75a2009-08-04 16:50:30 +00002456template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002457QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Sean Huntc3021132010-05-05 15:23:54 +00002458 PointerTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00002459 QualType ObjectType) {
Sean Huntc3021132010-05-05 15:23:54 +00002460 QualType PointeeType
2461 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002462 if (PointeeType.isNull())
2463 return QualType();
2464
2465 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002466 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002467 // A dependent pointer type 'T *' has is being transformed such
2468 // that an Objective-C class type is being replaced for 'T'. The
2469 // resulting pointer type is an ObjCObjectPointerType, not a
2470 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002471 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002472
John McCallc12c5bb2010-05-15 11:32:37 +00002473 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2474 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002475 return Result;
2476 }
Sean Huntc3021132010-05-05 15:23:54 +00002477
Douglas Gregor92e986e2010-04-22 16:44:27 +00002478 if (getDerived().AlwaysRebuild() ||
2479 PointeeType != TL.getPointeeLoc().getType()) {
2480 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2481 if (Result.isNull())
2482 return QualType();
2483 }
Sean Huntc3021132010-05-05 15:23:54 +00002484
Douglas Gregor92e986e2010-04-22 16:44:27 +00002485 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2486 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002487 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002488}
Mike Stump1eb44332009-09-09 15:08:12 +00002489
2490template<typename Derived>
2491QualType
John McCalla2becad2009-10-21 00:40:46 +00002492TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002493 BlockPointerTypeLoc TL,
2494 QualType ObjectType) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002495 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002496 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2497 if (PointeeType.isNull())
2498 return QualType();
2499
2500 QualType Result = TL.getType();
2501 if (getDerived().AlwaysRebuild() ||
2502 PointeeType != TL.getPointeeLoc().getType()) {
2503 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002504 TL.getSigilLoc());
2505 if (Result.isNull())
2506 return QualType();
2507 }
2508
Douglas Gregor39968ad2010-04-22 16:50:51 +00002509 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002510 NewT.setSigilLoc(TL.getSigilLoc());
2511 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002512}
2513
John McCall85737a72009-10-30 00:06:24 +00002514/// Transforms a reference type. Note that somewhat paradoxically we
2515/// don't care whether the type itself is an l-value type or an r-value
2516/// type; we only care if the type was *written* as an l-value type
2517/// or an r-value type.
2518template<typename Derived>
2519QualType
2520TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002521 ReferenceTypeLoc TL,
2522 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002523 const ReferenceType *T = TL.getTypePtr();
2524
2525 // Note that this works with the pointee-as-written.
2526 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2527 if (PointeeType.isNull())
2528 return QualType();
2529
2530 QualType Result = TL.getType();
2531 if (getDerived().AlwaysRebuild() ||
2532 PointeeType != T->getPointeeTypeAsWritten()) {
2533 Result = getDerived().RebuildReferenceType(PointeeType,
2534 T->isSpelledAsLValue(),
2535 TL.getSigilLoc());
2536 if (Result.isNull())
2537 return QualType();
2538 }
2539
2540 // r-value references can be rebuilt as l-value references.
2541 ReferenceTypeLoc NewTL;
2542 if (isa<LValueReferenceType>(Result))
2543 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2544 else
2545 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2546 NewTL.setSigilLoc(TL.getSigilLoc());
2547
2548 return Result;
2549}
2550
Mike Stump1eb44332009-09-09 15:08:12 +00002551template<typename Derived>
2552QualType
John McCalla2becad2009-10-21 00:40:46 +00002553TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002554 LValueReferenceTypeLoc TL,
2555 QualType ObjectType) {
2556 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002557}
2558
Mike Stump1eb44332009-09-09 15:08:12 +00002559template<typename Derived>
2560QualType
John McCalla2becad2009-10-21 00:40:46 +00002561TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002562 RValueReferenceTypeLoc TL,
2563 QualType ObjectType) {
2564 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002565}
Mike Stump1eb44332009-09-09 15:08:12 +00002566
Douglas Gregor577f75a2009-08-04 16:50:30 +00002567template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002568QualType
John McCalla2becad2009-10-21 00:40:46 +00002569TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002570 MemberPointerTypeLoc TL,
2571 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002572 MemberPointerType *T = TL.getTypePtr();
2573
2574 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002575 if (PointeeType.isNull())
2576 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002577
John McCalla2becad2009-10-21 00:40:46 +00002578 // TODO: preserve source information for this.
2579 QualType ClassType
2580 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002581 if (ClassType.isNull())
2582 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002583
John McCalla2becad2009-10-21 00:40:46 +00002584 QualType Result = TL.getType();
2585 if (getDerived().AlwaysRebuild() ||
2586 PointeeType != T->getPointeeType() ||
2587 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002588 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2589 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002590 if (Result.isNull())
2591 return QualType();
2592 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002593
John McCalla2becad2009-10-21 00:40:46 +00002594 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2595 NewTL.setSigilLoc(TL.getSigilLoc());
2596
2597 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002598}
2599
Mike Stump1eb44332009-09-09 15:08:12 +00002600template<typename Derived>
2601QualType
John McCalla2becad2009-10-21 00:40:46 +00002602TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002603 ConstantArrayTypeLoc TL,
2604 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002605 ConstantArrayType *T = TL.getTypePtr();
2606 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002607 if (ElementType.isNull())
2608 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002609
John McCalla2becad2009-10-21 00:40:46 +00002610 QualType Result = TL.getType();
2611 if (getDerived().AlwaysRebuild() ||
2612 ElementType != T->getElementType()) {
2613 Result = getDerived().RebuildConstantArrayType(ElementType,
2614 T->getSizeModifier(),
2615 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002616 T->getIndexTypeCVRQualifiers(),
2617 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002618 if (Result.isNull())
2619 return QualType();
2620 }
Sean Huntc3021132010-05-05 15:23:54 +00002621
John McCalla2becad2009-10-21 00:40:46 +00002622 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2623 NewTL.setLBracketLoc(TL.getLBracketLoc());
2624 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002625
John McCalla2becad2009-10-21 00:40:46 +00002626 Expr *Size = TL.getSizeExpr();
2627 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00002628 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002629 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2630 }
2631 NewTL.setSizeExpr(Size);
2632
2633 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002634}
Mike Stump1eb44332009-09-09 15:08:12 +00002635
Douglas Gregor577f75a2009-08-04 16:50:30 +00002636template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002637QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002638 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002639 IncompleteArrayTypeLoc TL,
2640 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002641 IncompleteArrayType *T = TL.getTypePtr();
2642 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002643 if (ElementType.isNull())
2644 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002645
John McCalla2becad2009-10-21 00:40:46 +00002646 QualType Result = TL.getType();
2647 if (getDerived().AlwaysRebuild() ||
2648 ElementType != T->getElementType()) {
2649 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002650 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002651 T->getIndexTypeCVRQualifiers(),
2652 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002653 if (Result.isNull())
2654 return QualType();
2655 }
Sean Huntc3021132010-05-05 15:23:54 +00002656
John McCalla2becad2009-10-21 00:40:46 +00002657 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2658 NewTL.setLBracketLoc(TL.getLBracketLoc());
2659 NewTL.setRBracketLoc(TL.getRBracketLoc());
2660 NewTL.setSizeExpr(0);
2661
2662 return Result;
2663}
2664
2665template<typename Derived>
2666QualType
2667TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002668 VariableArrayTypeLoc TL,
2669 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002670 VariableArrayType *T = TL.getTypePtr();
2671 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2672 if (ElementType.isNull())
2673 return QualType();
2674
2675 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002676 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002677
John McCall60d7b3a2010-08-24 06:29:42 +00002678 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002679 = getDerived().TransformExpr(T->getSizeExpr());
2680 if (SizeResult.isInvalid())
2681 return QualType();
2682
John McCall9ae2f072010-08-23 23:25:46 +00002683 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00002684
2685 QualType Result = TL.getType();
2686 if (getDerived().AlwaysRebuild() ||
2687 ElementType != T->getElementType() ||
2688 Size != T->getSizeExpr()) {
2689 Result = getDerived().RebuildVariableArrayType(ElementType,
2690 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002691 Size,
John McCalla2becad2009-10-21 00:40:46 +00002692 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002693 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002694 if (Result.isNull())
2695 return QualType();
2696 }
Sean Huntc3021132010-05-05 15:23:54 +00002697
John McCalla2becad2009-10-21 00:40:46 +00002698 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2699 NewTL.setLBracketLoc(TL.getLBracketLoc());
2700 NewTL.setRBracketLoc(TL.getRBracketLoc());
2701 NewTL.setSizeExpr(Size);
2702
2703 return Result;
2704}
2705
2706template<typename Derived>
2707QualType
2708TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002709 DependentSizedArrayTypeLoc TL,
2710 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002711 DependentSizedArrayType *T = TL.getTypePtr();
2712 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2713 if (ElementType.isNull())
2714 return QualType();
2715
2716 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002717 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002718
John McCall60d7b3a2010-08-24 06:29:42 +00002719 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002720 = getDerived().TransformExpr(T->getSizeExpr());
2721 if (SizeResult.isInvalid())
2722 return QualType();
2723
2724 Expr *Size = static_cast<Expr*>(SizeResult.get());
2725
2726 QualType Result = TL.getType();
2727 if (getDerived().AlwaysRebuild() ||
2728 ElementType != T->getElementType() ||
2729 Size != T->getSizeExpr()) {
2730 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2731 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002732 Size,
John McCalla2becad2009-10-21 00:40:46 +00002733 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002734 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002735 if (Result.isNull())
2736 return QualType();
2737 }
2738 else SizeResult.take();
2739
2740 // We might have any sort of array type now, but fortunately they
2741 // all have the same location layout.
2742 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2743 NewTL.setLBracketLoc(TL.getLBracketLoc());
2744 NewTL.setRBracketLoc(TL.getRBracketLoc());
2745 NewTL.setSizeExpr(Size);
2746
2747 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002748}
Mike Stump1eb44332009-09-09 15:08:12 +00002749
2750template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002751QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002752 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002753 DependentSizedExtVectorTypeLoc TL,
2754 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002755 DependentSizedExtVectorType *T = TL.getTypePtr();
2756
2757 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002758 QualType ElementType = getDerived().TransformType(T->getElementType());
2759 if (ElementType.isNull())
2760 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002761
Douglas Gregor670444e2009-08-04 22:27:00 +00002762 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002763 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00002764
John McCall60d7b3a2010-08-24 06:29:42 +00002765 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002766 if (Size.isInvalid())
2767 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002768
John McCalla2becad2009-10-21 00:40:46 +00002769 QualType Result = TL.getType();
2770 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002771 ElementType != T->getElementType() ||
2772 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002773 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00002774 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00002775 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002776 if (Result.isNull())
2777 return QualType();
2778 }
John McCalla2becad2009-10-21 00:40:46 +00002779
2780 // Result might be dependent or not.
2781 if (isa<DependentSizedExtVectorType>(Result)) {
2782 DependentSizedExtVectorTypeLoc NewTL
2783 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2784 NewTL.setNameLoc(TL.getNameLoc());
2785 } else {
2786 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2787 NewTL.setNameLoc(TL.getNameLoc());
2788 }
2789
2790 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002791}
Mike Stump1eb44332009-09-09 15:08:12 +00002792
2793template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002794QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002795 VectorTypeLoc TL,
2796 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002797 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002798 QualType ElementType = getDerived().TransformType(T->getElementType());
2799 if (ElementType.isNull())
2800 return QualType();
2801
John McCalla2becad2009-10-21 00:40:46 +00002802 QualType Result = TL.getType();
2803 if (getDerived().AlwaysRebuild() ||
2804 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002805 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner788b0fd2010-06-23 06:00:24 +00002806 T->getAltiVecSpecific());
John McCalla2becad2009-10-21 00:40:46 +00002807 if (Result.isNull())
2808 return QualType();
2809 }
Sean Huntc3021132010-05-05 15:23:54 +00002810
John McCalla2becad2009-10-21 00:40:46 +00002811 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2812 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002813
John McCalla2becad2009-10-21 00:40:46 +00002814 return Result;
2815}
2816
2817template<typename Derived>
2818QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002819 ExtVectorTypeLoc TL,
2820 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002821 VectorType *T = TL.getTypePtr();
2822 QualType ElementType = getDerived().TransformType(T->getElementType());
2823 if (ElementType.isNull())
2824 return QualType();
2825
2826 QualType Result = TL.getType();
2827 if (getDerived().AlwaysRebuild() ||
2828 ElementType != T->getElementType()) {
2829 Result = getDerived().RebuildExtVectorType(ElementType,
2830 T->getNumElements(),
2831 /*FIXME*/ SourceLocation());
2832 if (Result.isNull())
2833 return QualType();
2834 }
Sean Huntc3021132010-05-05 15:23:54 +00002835
John McCalla2becad2009-10-21 00:40:46 +00002836 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2837 NewTL.setNameLoc(TL.getNameLoc());
2838
2839 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002840}
Mike Stump1eb44332009-09-09 15:08:12 +00002841
2842template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002843ParmVarDecl *
2844TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2845 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2846 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2847 if (!NewDI)
2848 return 0;
2849
2850 if (NewDI == OldDI)
2851 return OldParm;
2852 else
2853 return ParmVarDecl::Create(SemaRef.Context,
2854 OldParm->getDeclContext(),
2855 OldParm->getLocation(),
2856 OldParm->getIdentifier(),
2857 NewDI->getType(),
2858 NewDI,
2859 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002860 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002861 /* DefArg */ NULL);
2862}
2863
2864template<typename Derived>
2865bool TreeTransform<Derived>::
2866 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2867 llvm::SmallVectorImpl<QualType> &PTypes,
2868 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2869 FunctionProtoType *T = TL.getTypePtr();
2870
2871 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2872 ParmVarDecl *OldParm = TL.getArg(i);
2873
2874 QualType NewType;
2875 ParmVarDecl *NewParm;
2876
2877 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002878 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2879 if (!NewParm)
2880 return true;
2881 NewType = NewParm->getType();
2882
2883 // Deal with the possibility that we don't have a parameter
2884 // declaration for this parameter.
2885 } else {
2886 NewParm = 0;
2887
2888 QualType OldType = T->getArgType(i);
2889 NewType = getDerived().TransformType(OldType);
2890 if (NewType.isNull())
2891 return true;
2892 }
2893
2894 PTypes.push_back(NewType);
2895 PVars.push_back(NewParm);
2896 }
2897
2898 return false;
2899}
2900
2901template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002902QualType
John McCalla2becad2009-10-21 00:40:46 +00002903TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002904 FunctionProtoTypeLoc TL,
2905 QualType ObjectType) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00002906 // Transform the parameters and return type.
2907 //
2908 // We instantiate in source order, with the return type first followed by
2909 // the parameters, because users tend to expect this (even if they shouldn't
2910 // rely on it!).
2911 //
2912 // FIXME: When we implement late-specified return types, we'll need to
2913 // instantiate the return tpe *after* the parameter types in that case,
2914 // since the return type can then refer to the parameters themselves (via
2915 // decltype, sizeof, etc.).
Douglas Gregor577f75a2009-08-04 16:50:30 +00002916 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002917 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor895162d2010-04-30 18:55:50 +00002918 FunctionProtoType *T = TL.getTypePtr();
2919 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2920 if (ResultType.isNull())
2921 return QualType();
Douglas Gregor7e010a02010-08-31 00:26:14 +00002922
2923 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2924 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002925
John McCalla2becad2009-10-21 00:40:46 +00002926 QualType Result = TL.getType();
2927 if (getDerived().AlwaysRebuild() ||
2928 ResultType != T->getResultType() ||
2929 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2930 Result = getDerived().RebuildFunctionProtoType(ResultType,
2931 ParamTypes.data(),
2932 ParamTypes.size(),
2933 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00002934 T->getTypeQuals(),
2935 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00002936 if (Result.isNull())
2937 return QualType();
2938 }
Mike Stump1eb44332009-09-09 15:08:12 +00002939
John McCalla2becad2009-10-21 00:40:46 +00002940 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2941 NewTL.setLParenLoc(TL.getLParenLoc());
2942 NewTL.setRParenLoc(TL.getRParenLoc());
2943 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2944 NewTL.setArg(i, ParamDecls[i]);
2945
2946 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002947}
Mike Stump1eb44332009-09-09 15:08:12 +00002948
Douglas Gregor577f75a2009-08-04 16:50:30 +00002949template<typename Derived>
2950QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002951 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002952 FunctionNoProtoTypeLoc TL,
2953 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002954 FunctionNoProtoType *T = TL.getTypePtr();
2955 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2956 if (ResultType.isNull())
2957 return QualType();
2958
2959 QualType Result = TL.getType();
2960 if (getDerived().AlwaysRebuild() ||
2961 ResultType != T->getResultType())
2962 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2963
2964 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2965 NewTL.setLParenLoc(TL.getLParenLoc());
2966 NewTL.setRParenLoc(TL.getRParenLoc());
2967
2968 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002969}
Mike Stump1eb44332009-09-09 15:08:12 +00002970
John McCalled976492009-12-04 22:46:56 +00002971template<typename Derived> QualType
2972TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002973 UnresolvedUsingTypeLoc TL,
2974 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00002975 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002976 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00002977 if (!D)
2978 return QualType();
2979
2980 QualType Result = TL.getType();
2981 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2982 Result = getDerived().RebuildUnresolvedUsingType(D);
2983 if (Result.isNull())
2984 return QualType();
2985 }
2986
2987 // We might get an arbitrary type spec type back. We should at
2988 // least always get a type spec type, though.
2989 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2990 NewTL.setNameLoc(TL.getNameLoc());
2991
2992 return Result;
2993}
2994
Douglas Gregor577f75a2009-08-04 16:50:30 +00002995template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002996QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002997 TypedefTypeLoc TL,
2998 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002999 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003000 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003001 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3002 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003003 if (!Typedef)
3004 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003005
John McCalla2becad2009-10-21 00:40:46 +00003006 QualType Result = TL.getType();
3007 if (getDerived().AlwaysRebuild() ||
3008 Typedef != T->getDecl()) {
3009 Result = getDerived().RebuildTypedefType(Typedef);
3010 if (Result.isNull())
3011 return QualType();
3012 }
Mike Stump1eb44332009-09-09 15:08:12 +00003013
John McCalla2becad2009-10-21 00:40:46 +00003014 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3015 NewTL.setNameLoc(TL.getNameLoc());
3016
3017 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003018}
Mike Stump1eb44332009-09-09 15:08:12 +00003019
Douglas Gregor577f75a2009-08-04 16:50:30 +00003020template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003021QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003022 TypeOfExprTypeLoc TL,
3023 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003024 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003025 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003026
John McCall60d7b3a2010-08-24 06:29:42 +00003027 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003028 if (E.isInvalid())
3029 return QualType();
3030
John McCalla2becad2009-10-21 00:40:46 +00003031 QualType Result = TL.getType();
3032 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003033 E.get() != TL.getUnderlyingExpr()) {
John McCall9ae2f072010-08-23 23:25:46 +00003034 Result = getDerived().RebuildTypeOfExprType(E.get());
John McCalla2becad2009-10-21 00:40:46 +00003035 if (Result.isNull())
3036 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003037 }
John McCalla2becad2009-10-21 00:40:46 +00003038 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003039
John McCalla2becad2009-10-21 00:40:46 +00003040 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003041 NewTL.setTypeofLoc(TL.getTypeofLoc());
3042 NewTL.setLParenLoc(TL.getLParenLoc());
3043 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003044
3045 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003046}
Mike Stump1eb44332009-09-09 15:08:12 +00003047
3048template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003049QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003050 TypeOfTypeLoc TL,
3051 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00003052 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3053 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3054 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003055 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003056
John McCalla2becad2009-10-21 00:40:46 +00003057 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003058 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3059 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003060 if (Result.isNull())
3061 return QualType();
3062 }
Mike Stump1eb44332009-09-09 15:08:12 +00003063
John McCalla2becad2009-10-21 00:40:46 +00003064 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003065 NewTL.setTypeofLoc(TL.getTypeofLoc());
3066 NewTL.setLParenLoc(TL.getLParenLoc());
3067 NewTL.setRParenLoc(TL.getRParenLoc());
3068 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003069
3070 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003071}
Mike Stump1eb44332009-09-09 15:08:12 +00003072
3073template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003074QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003075 DecltypeTypeLoc TL,
3076 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003077 DecltypeType *T = TL.getTypePtr();
3078
Douglas Gregor670444e2009-08-04 22:27:00 +00003079 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003080 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003081
John McCall60d7b3a2010-08-24 06:29:42 +00003082 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003083 if (E.isInvalid())
3084 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003085
John McCalla2becad2009-10-21 00:40:46 +00003086 QualType Result = TL.getType();
3087 if (getDerived().AlwaysRebuild() ||
3088 E.get() != T->getUnderlyingExpr()) {
John McCall9ae2f072010-08-23 23:25:46 +00003089 Result = getDerived().RebuildDecltypeType(E.get());
John McCalla2becad2009-10-21 00:40:46 +00003090 if (Result.isNull())
3091 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003092 }
John McCalla2becad2009-10-21 00:40:46 +00003093 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003094
John McCalla2becad2009-10-21 00:40:46 +00003095 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3096 NewTL.setNameLoc(TL.getNameLoc());
3097
3098 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003099}
3100
3101template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003102QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003103 RecordTypeLoc TL,
3104 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003105 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003106 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003107 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3108 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003109 if (!Record)
3110 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003111
John McCalla2becad2009-10-21 00:40:46 +00003112 QualType Result = TL.getType();
3113 if (getDerived().AlwaysRebuild() ||
3114 Record != T->getDecl()) {
3115 Result = getDerived().RebuildRecordType(Record);
3116 if (Result.isNull())
3117 return QualType();
3118 }
Mike Stump1eb44332009-09-09 15:08:12 +00003119
John McCalla2becad2009-10-21 00:40:46 +00003120 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3121 NewTL.setNameLoc(TL.getNameLoc());
3122
3123 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003124}
Mike Stump1eb44332009-09-09 15:08:12 +00003125
3126template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003127QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003128 EnumTypeLoc TL,
3129 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003130 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003131 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003132 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3133 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003134 if (!Enum)
3135 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003136
John McCalla2becad2009-10-21 00:40:46 +00003137 QualType Result = TL.getType();
3138 if (getDerived().AlwaysRebuild() ||
3139 Enum != T->getDecl()) {
3140 Result = getDerived().RebuildEnumType(Enum);
3141 if (Result.isNull())
3142 return QualType();
3143 }
Mike Stump1eb44332009-09-09 15:08:12 +00003144
John McCalla2becad2009-10-21 00:40:46 +00003145 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3146 NewTL.setNameLoc(TL.getNameLoc());
3147
3148 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003149}
John McCall7da24312009-09-05 00:15:47 +00003150
John McCall3cb0ebd2010-03-10 03:28:59 +00003151template<typename Derived>
3152QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3153 TypeLocBuilder &TLB,
3154 InjectedClassNameTypeLoc TL,
3155 QualType ObjectType) {
3156 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3157 TL.getTypePtr()->getDecl());
3158 if (!D) return QualType();
3159
3160 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3161 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3162 return T;
3163}
3164
Mike Stump1eb44332009-09-09 15:08:12 +00003165
Douglas Gregor577f75a2009-08-04 16:50:30 +00003166template<typename Derived>
3167QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003168 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003169 TemplateTypeParmTypeLoc TL,
3170 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003171 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003172}
3173
Mike Stump1eb44332009-09-09 15:08:12 +00003174template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003175QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003176 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003177 SubstTemplateTypeParmTypeLoc TL,
3178 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003179 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003180}
3181
3182template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003183QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3184 const TemplateSpecializationType *TST,
3185 QualType ObjectType) {
3186 // FIXME: this entire method is a temporary workaround; callers
3187 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00003188
John McCall833ca992009-10-29 08:12:44 +00003189 // Fake up a TemplateSpecializationTypeLoc.
3190 TypeLocBuilder TLB;
3191 TemplateSpecializationTypeLoc TL
3192 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3193
John McCall828bff22009-10-29 18:45:58 +00003194 SourceLocation BaseLoc = getDerived().getBaseLocation();
3195
3196 TL.setTemplateNameLoc(BaseLoc);
3197 TL.setLAngleLoc(BaseLoc);
3198 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00003199 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3200 const TemplateArgument &TA = TST->getArg(i);
3201 TemplateArgumentLoc TAL;
3202 getDerived().InventTemplateArgumentLoc(TA, TAL);
3203 TL.setArgLocInfo(i, TAL.getLocInfo());
3204 }
3205
3206 TypeLocBuilder IgnoredTLB;
3207 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00003208}
Sean Huntc3021132010-05-05 15:23:54 +00003209
Douglas Gregordd62b152009-10-19 22:04:39 +00003210template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003211QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003212 TypeLocBuilder &TLB,
3213 TemplateSpecializationTypeLoc TL,
3214 QualType ObjectType) {
3215 const TemplateSpecializationType *T = TL.getTypePtr();
3216
Mike Stump1eb44332009-09-09 15:08:12 +00003217 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00003218 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003219 if (Template.isNull())
3220 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003221
John McCalld5532b62009-11-23 01:53:49 +00003222 TemplateArgumentListInfo NewTemplateArgs;
3223 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3224 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3225
3226 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3227 TemplateArgumentLoc Loc;
3228 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003229 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003230 NewTemplateArgs.addArgument(Loc);
3231 }
Mike Stump1eb44332009-09-09 15:08:12 +00003232
John McCall833ca992009-10-29 08:12:44 +00003233 // FIXME: maybe don't rebuild if all the template arguments are the same.
3234
3235 QualType Result =
3236 getDerived().RebuildTemplateSpecializationType(Template,
3237 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003238 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003239
3240 if (!Result.isNull()) {
3241 TemplateSpecializationTypeLoc NewTL
3242 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3243 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3244 NewTL.setLAngleLoc(TL.getLAngleLoc());
3245 NewTL.setRAngleLoc(TL.getRAngleLoc());
3246 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3247 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003248 }
Mike Stump1eb44332009-09-09 15:08:12 +00003249
John McCall833ca992009-10-29 08:12:44 +00003250 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003251}
Mike Stump1eb44332009-09-09 15:08:12 +00003252
3253template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003254QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003255TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3256 ElaboratedTypeLoc TL,
3257 QualType ObjectType) {
3258 ElaboratedType *T = TL.getTypePtr();
3259
3260 NestedNameSpecifier *NNS = 0;
3261 // NOTE: the qualifier in an ElaboratedType is optional.
3262 if (T->getQualifier() != 0) {
3263 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003264 TL.getQualifierRange(),
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003265 ObjectType);
3266 if (!NNS)
3267 return QualType();
3268 }
Mike Stump1eb44332009-09-09 15:08:12 +00003269
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003270 QualType NamedT;
3271 // FIXME: this test is meant to workaround a problem (failing assertion)
3272 // occurring if directly executing the code in the else branch.
3273 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3274 TemplateSpecializationTypeLoc OldNamedTL
3275 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3276 const TemplateSpecializationType* OldTST
Jim Grosbach9cbb4d82010-05-19 23:53:08 +00003277 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003278 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3279 if (NamedT.isNull())
3280 return QualType();
3281 TemplateSpecializationTypeLoc NewNamedTL
3282 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3283 NewNamedTL.copy(OldNamedTL);
3284 }
3285 else {
3286 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3287 if (NamedT.isNull())
3288 return QualType();
3289 }
Daniel Dunbara63db842010-05-14 16:34:09 +00003290
John McCalla2becad2009-10-21 00:40:46 +00003291 QualType Result = TL.getType();
3292 if (getDerived().AlwaysRebuild() ||
3293 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003294 NamedT != T->getNamedType()) {
3295 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003296 if (Result.isNull())
3297 return QualType();
3298 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003299
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003300 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003301 NewTL.setKeywordLoc(TL.getKeywordLoc());
3302 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003303
3304 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003305}
Mike Stump1eb44332009-09-09 15:08:12 +00003306
3307template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003308QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3309 DependentNameTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00003310 QualType ObjectType) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003311 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003312
Douglas Gregor577f75a2009-08-04 16:50:30 +00003313 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003314 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3315 TL.getQualifierRange(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003316 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003317 if (!NNS)
3318 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003319
John McCall33500952010-06-11 00:33:02 +00003320 QualType Result
3321 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3322 T->getIdentifier(),
3323 TL.getKeywordLoc(),
3324 TL.getQualifierRange(),
3325 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003326 if (Result.isNull())
3327 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003328
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003329 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3330 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003331 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3332
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003333 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3334 NewTL.setKeywordLoc(TL.getKeywordLoc());
3335 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003336 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003337 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3338 NewTL.setKeywordLoc(TL.getKeywordLoc());
3339 NewTL.setQualifierRange(TL.getQualifierRange());
3340 NewTL.setNameLoc(TL.getNameLoc());
3341 }
John McCalla2becad2009-10-21 00:40:46 +00003342 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003343}
Mike Stump1eb44332009-09-09 15:08:12 +00003344
Douglas Gregor577f75a2009-08-04 16:50:30 +00003345template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003346QualType TreeTransform<Derived>::
3347 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3348 DependentTemplateSpecializationTypeLoc TL,
3349 QualType ObjectType) {
3350 DependentTemplateSpecializationType *T = TL.getTypePtr();
3351
3352 NestedNameSpecifier *NNS
3353 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3354 TL.getQualifierRange(),
3355 ObjectType);
3356 if (!NNS)
3357 return QualType();
3358
3359 TemplateArgumentListInfo NewTemplateArgs;
3360 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3361 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3362
3363 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3364 TemplateArgumentLoc Loc;
3365 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3366 return QualType();
3367 NewTemplateArgs.addArgument(Loc);
3368 }
3369
3370 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3371 T->getKeyword(),
3372 NNS,
3373 T->getIdentifier(),
3374 TL.getNameLoc(),
3375 NewTemplateArgs);
3376 if (Result.isNull())
3377 return QualType();
3378
3379 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3380 QualType NamedT = ElabT->getNamedType();
3381
3382 // Copy information relevant to the template specialization.
3383 TemplateSpecializationTypeLoc NamedTL
3384 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3385 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3386 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3387 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3388 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3389
3390 // Copy information relevant to the elaborated type.
3391 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3392 NewTL.setKeywordLoc(TL.getKeywordLoc());
3393 NewTL.setQualifierRange(TL.getQualifierRange());
3394 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003395 TypeLoc NewTL(Result, TL.getOpaqueData());
3396 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003397 }
3398 return Result;
3399}
3400
3401template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003402QualType
3403TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003404 ObjCInterfaceTypeLoc TL,
3405 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003406 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003407 TLB.pushFullCopy(TL);
3408 return TL.getType();
3409}
3410
3411template<typename Derived>
3412QualType
3413TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3414 ObjCObjectTypeLoc TL,
3415 QualType ObjectType) {
3416 // ObjCObjectType is never dependent.
3417 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003418 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003419}
Mike Stump1eb44332009-09-09 15:08:12 +00003420
3421template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003422QualType
3423TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003424 ObjCObjectPointerTypeLoc TL,
3425 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003426 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003427 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003428 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003429}
3430
Douglas Gregor577f75a2009-08-04 16:50:30 +00003431//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003432// Statement transformation
3433//===----------------------------------------------------------------------===//
3434template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003435StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003436TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3437 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003438}
3439
3440template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003441StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003442TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3443 return getDerived().TransformCompoundStmt(S, false);
3444}
3445
3446template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003447StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003448TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003449 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00003450 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00003451 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003452 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00003453 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3454 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00003455 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00003456 if (Result.isInvalid()) {
3457 // Immediately fail if this was a DeclStmt, since it's very
3458 // likely that this will cause problems for future statements.
3459 if (isa<DeclStmt>(*B))
3460 return StmtError();
3461
3462 // Otherwise, just keep processing substatements and fail later.
3463 SubStmtInvalid = true;
3464 continue;
3465 }
Mike Stump1eb44332009-09-09 15:08:12 +00003466
Douglas Gregor43959a92009-08-20 07:17:43 +00003467 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3468 Statements.push_back(Result.takeAs<Stmt>());
3469 }
Mike Stump1eb44332009-09-09 15:08:12 +00003470
John McCall7114cba2010-08-27 19:56:05 +00003471 if (SubStmtInvalid)
3472 return StmtError();
3473
Douglas Gregor43959a92009-08-20 07:17:43 +00003474 if (!getDerived().AlwaysRebuild() &&
3475 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003476 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003477
3478 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3479 move_arg(Statements),
3480 S->getRBracLoc(),
3481 IsStmtExpr);
3482}
Mike Stump1eb44332009-09-09 15:08:12 +00003483
Douglas Gregor43959a92009-08-20 07:17:43 +00003484template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003485StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003486TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003487 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00003488 {
3489 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00003490 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003491
Eli Friedman264c1f82009-11-19 03:14:00 +00003492 // Transform the left-hand case value.
3493 LHS = getDerived().TransformExpr(S->getLHS());
3494 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003495 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003496
Eli Friedman264c1f82009-11-19 03:14:00 +00003497 // Transform the right-hand case value (for the GNU case-range extension).
3498 RHS = getDerived().TransformExpr(S->getRHS());
3499 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003500 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00003501 }
Mike Stump1eb44332009-09-09 15:08:12 +00003502
Douglas Gregor43959a92009-08-20 07:17:43 +00003503 // Build the case statement.
3504 // Case statements are always rebuilt so that they will attached to their
3505 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003506 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003507 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003508 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003509 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003510 S->getColonLoc());
3511 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003512 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003513
Douglas Gregor43959a92009-08-20 07:17:43 +00003514 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00003515 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003516 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003517 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003518
Douglas Gregor43959a92009-08-20 07:17:43 +00003519 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00003520 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003521}
3522
3523template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003524StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003525TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003526 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00003527 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003528 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003529 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003530
Douglas Gregor43959a92009-08-20 07:17:43 +00003531 // Default statements are always rebuilt
3532 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003533 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003534}
Mike Stump1eb44332009-09-09 15:08:12 +00003535
Douglas Gregor43959a92009-08-20 07:17:43 +00003536template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003537StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003538TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003539 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003540 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003541 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003542
Douglas Gregor43959a92009-08-20 07:17:43 +00003543 // FIXME: Pass the real colon location in.
3544 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3545 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00003546 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003547}
Mike Stump1eb44332009-09-09 15:08:12 +00003548
Douglas Gregor43959a92009-08-20 07:17:43 +00003549template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003550StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003551TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003552 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003553 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003554 VarDecl *ConditionVar = 0;
3555 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003556 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003557 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003558 getDerived().TransformDefinition(
3559 S->getConditionVariable()->getLocation(),
3560 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003561 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003562 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003563 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003564 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003565
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003566 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003567 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003568
3569 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003570 if (S->getCond()) {
John McCall60d7b3a2010-08-24 06:29:42 +00003571 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003572 S->getIfLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003573 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003574 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003575 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003576
John McCall9ae2f072010-08-23 23:25:46 +00003577 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003578 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003579 }
Sean Huntc3021132010-05-05 15:23:54 +00003580
John McCall9ae2f072010-08-23 23:25:46 +00003581 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3582 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003583 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003584
Douglas Gregor43959a92009-08-20 07:17:43 +00003585 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003586 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00003587 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003588 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003589
Douglas Gregor43959a92009-08-20 07:17:43 +00003590 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003591 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00003592 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003593 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003594
Douglas Gregor43959a92009-08-20 07:17:43 +00003595 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003596 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003597 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003598 Then.get() == S->getThen() &&
3599 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003600 return SemaRef.Owned(S->Retain());
3601
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003602 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCall9ae2f072010-08-23 23:25:46 +00003603 Then.get(),
3604 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003605}
3606
3607template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003608StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003609TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003610 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00003611 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00003612 VarDecl *ConditionVar = 0;
3613 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003614 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003615 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003616 getDerived().TransformDefinition(
3617 S->getConditionVariable()->getLocation(),
3618 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003619 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003620 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003621 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003622 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003623
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003624 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003625 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003626 }
Mike Stump1eb44332009-09-09 15:08:12 +00003627
Douglas Gregor43959a92009-08-20 07:17:43 +00003628 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003629 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00003630 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00003631 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003632 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003633 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003634
Douglas Gregor43959a92009-08-20 07:17:43 +00003635 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003636 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003637 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003638 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003639
Douglas Gregor43959a92009-08-20 07:17:43 +00003640 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00003641 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3642 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003643}
Mike Stump1eb44332009-09-09 15:08:12 +00003644
Douglas Gregor43959a92009-08-20 07:17:43 +00003645template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003646StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003647TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003648 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003649 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00003650 VarDecl *ConditionVar = 0;
3651 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003652 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003653 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003654 getDerived().TransformDefinition(
3655 S->getConditionVariable()->getLocation(),
3656 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003657 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003658 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003659 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003660 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003661
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003662 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003663 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003664
3665 if (S->getCond()) {
3666 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003667 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003668 S->getWhileLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003669 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003670 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003671 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00003672 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003673 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003674 }
Mike Stump1eb44332009-09-09 15:08:12 +00003675
John McCall9ae2f072010-08-23 23:25:46 +00003676 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3677 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003678 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003679
Douglas Gregor43959a92009-08-20 07:17:43 +00003680 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003681 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003682 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003683 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003684
Douglas Gregor43959a92009-08-20 07:17:43 +00003685 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003686 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003687 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003688 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00003689 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003690
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003691 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00003692 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003693}
Mike Stump1eb44332009-09-09 15:08:12 +00003694
Douglas Gregor43959a92009-08-20 07:17:43 +00003695template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003696StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003697TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003698 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003699 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003700 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003701 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003702
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003703 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003704 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003705 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003706 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003707
Douglas Gregor43959a92009-08-20 07:17:43 +00003708 if (!getDerived().AlwaysRebuild() &&
3709 Cond.get() == S->getCond() &&
3710 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003711 return SemaRef.Owned(S->Retain());
3712
John McCall9ae2f072010-08-23 23:25:46 +00003713 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3714 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003715 S->getRParenLoc());
3716}
Mike Stump1eb44332009-09-09 15:08:12 +00003717
Douglas Gregor43959a92009-08-20 07:17:43 +00003718template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003719StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003720TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003721 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00003722 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00003723 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003724 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003725
Douglas Gregor43959a92009-08-20 07:17:43 +00003726 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003727 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003728 VarDecl *ConditionVar = 0;
3729 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003730 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003731 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003732 getDerived().TransformDefinition(
3733 S->getConditionVariable()->getLocation(),
3734 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003735 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003736 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003737 } else {
3738 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003739
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003740 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003741 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003742
3743 if (S->getCond()) {
3744 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003745 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003746 S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003747 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003748 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003749 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003750
John McCall9ae2f072010-08-23 23:25:46 +00003751 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003752 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003753 }
Mike Stump1eb44332009-09-09 15:08:12 +00003754
John McCall9ae2f072010-08-23 23:25:46 +00003755 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3756 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003757 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003758
Douglas Gregor43959a92009-08-20 07:17:43 +00003759 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00003760 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00003761 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003762 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003763
John McCall9ae2f072010-08-23 23:25:46 +00003764 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3765 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00003766 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003767
Douglas Gregor43959a92009-08-20 07:17:43 +00003768 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003769 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003770 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003771 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003772
Douglas Gregor43959a92009-08-20 07:17:43 +00003773 if (!getDerived().AlwaysRebuild() &&
3774 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00003775 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003776 Inc.get() == S->getInc() &&
3777 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003778 return SemaRef.Owned(S->Retain());
3779
Douglas Gregor43959a92009-08-20 07:17:43 +00003780 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003781 Init.get(), FullCond, ConditionVar,
3782 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003783}
3784
3785template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003786StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003787TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003788 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003789 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003790 S->getLabel());
3791}
3792
3793template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003794StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003795TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003796 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00003797 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003798 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003799
Douglas Gregor43959a92009-08-20 07:17:43 +00003800 if (!getDerived().AlwaysRebuild() &&
3801 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003802 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003803
3804 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003805 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003806}
3807
3808template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003809StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003810TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3811 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003812}
Mike Stump1eb44332009-09-09 15:08:12 +00003813
Douglas Gregor43959a92009-08-20 07:17:43 +00003814template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003815StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003816TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3817 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003818}
Mike Stump1eb44332009-09-09 15:08:12 +00003819
Douglas Gregor43959a92009-08-20 07:17:43 +00003820template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003821StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003822TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003823 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00003824 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003825 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00003826
Mike Stump1eb44332009-09-09 15:08:12 +00003827 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003828 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00003829 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003830}
Mike Stump1eb44332009-09-09 15:08:12 +00003831
Douglas Gregor43959a92009-08-20 07:17:43 +00003832template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003833StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003834TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003835 bool DeclChanged = false;
3836 llvm::SmallVector<Decl *, 4> Decls;
3837 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3838 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003839 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3840 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003841 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00003842 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003843
Douglas Gregor43959a92009-08-20 07:17:43 +00003844 if (Transformed != *D)
3845 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003846
Douglas Gregor43959a92009-08-20 07:17:43 +00003847 Decls.push_back(Transformed);
3848 }
Mike Stump1eb44332009-09-09 15:08:12 +00003849
Douglas Gregor43959a92009-08-20 07:17:43 +00003850 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003851 return SemaRef.Owned(S->Retain());
3852
3853 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003854 S->getStartLoc(), S->getEndLoc());
3855}
Mike Stump1eb44332009-09-09 15:08:12 +00003856
Douglas Gregor43959a92009-08-20 07:17:43 +00003857template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003858StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003859TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003860 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003861 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003862}
3863
3864template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003865StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003866TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003867
John McCallca0408f2010-08-23 06:44:23 +00003868 ASTOwningVector<Expr*> Constraints(getSema());
3869 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003870 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003871
John McCall60d7b3a2010-08-24 06:29:42 +00003872 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00003873 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00003874
3875 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003876
Anders Carlsson703e3942010-01-24 05:50:09 +00003877 // Go through the outputs.
3878 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003879 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003880
Anders Carlsson703e3942010-01-24 05:50:09 +00003881 // No need to transform the constraint literal.
3882 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003883
Anders Carlsson703e3942010-01-24 05:50:09 +00003884 // Transform the output expr.
3885 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003886 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003887 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003888 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003889
Anders Carlsson703e3942010-01-24 05:50:09 +00003890 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003891
John McCall9ae2f072010-08-23 23:25:46 +00003892 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003893 }
Sean Huntc3021132010-05-05 15:23:54 +00003894
Anders Carlsson703e3942010-01-24 05:50:09 +00003895 // Go through the inputs.
3896 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003897 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003898
Anders Carlsson703e3942010-01-24 05:50:09 +00003899 // No need to transform the constraint literal.
3900 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003901
Anders Carlsson703e3942010-01-24 05:50:09 +00003902 // Transform the input expr.
3903 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003904 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003905 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003906 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003907
Anders Carlsson703e3942010-01-24 05:50:09 +00003908 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003909
John McCall9ae2f072010-08-23 23:25:46 +00003910 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003911 }
Sean Huntc3021132010-05-05 15:23:54 +00003912
Anders Carlsson703e3942010-01-24 05:50:09 +00003913 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3914 return SemaRef.Owned(S->Retain());
3915
3916 // Go through the clobbers.
3917 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3918 Clobbers.push_back(S->getClobber(I)->Retain());
3919
3920 // No need to transform the asm string literal.
3921 AsmString = SemaRef.Owned(S->getAsmString());
3922
3923 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3924 S->isSimple(),
3925 S->isVolatile(),
3926 S->getNumOutputs(),
3927 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003928 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003929 move_arg(Constraints),
3930 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00003931 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003932 move_arg(Clobbers),
3933 S->getRParenLoc(),
3934 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003935}
3936
3937
3938template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003939StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003940TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003941 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00003942 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003943 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003944 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003945
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003946 // Transform the @catch statements (if present).
3947 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003948 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003949 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00003950 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003951 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003952 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003953 if (Catch.get() != S->getCatchStmt(I))
3954 AnyCatchChanged = true;
3955 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003956 }
Sean Huntc3021132010-05-05 15:23:54 +00003957
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003958 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00003959 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003960 if (S->getFinallyStmt()) {
3961 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3962 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003963 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003964 }
3965
3966 // If nothing changed, just retain this statement.
3967 if (!getDerived().AlwaysRebuild() &&
3968 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003969 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003970 Finally.get() == S->getFinallyStmt())
3971 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003972
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003973 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00003974 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
3975 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003976}
Mike Stump1eb44332009-09-09 15:08:12 +00003977
Douglas Gregor43959a92009-08-20 07:17:43 +00003978template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003979StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003980TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00003981 // Transform the @catch parameter, if there is one.
3982 VarDecl *Var = 0;
3983 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3984 TypeSourceInfo *TSInfo = 0;
3985 if (FromVar->getTypeSourceInfo()) {
3986 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3987 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00003988 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00003989 }
Sean Huntc3021132010-05-05 15:23:54 +00003990
Douglas Gregorbe270a02010-04-26 17:57:08 +00003991 QualType T;
3992 if (TSInfo)
3993 T = TSInfo->getType();
3994 else {
3995 T = getDerived().TransformType(FromVar->getType());
3996 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00003997 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00003998 }
Sean Huntc3021132010-05-05 15:23:54 +00003999
Douglas Gregorbe270a02010-04-26 17:57:08 +00004000 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4001 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004002 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004003 }
Sean Huntc3021132010-05-05 15:23:54 +00004004
John McCall60d7b3a2010-08-24 06:29:42 +00004005 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004006 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004007 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004008
4009 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004010 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004011 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004012}
Mike Stump1eb44332009-09-09 15:08:12 +00004013
Douglas Gregor43959a92009-08-20 07:17:43 +00004014template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004015StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004016TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004017 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004018 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004019 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004020 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004021
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004022 // If nothing changed, just retain this statement.
4023 if (!getDerived().AlwaysRebuild() &&
4024 Body.get() == S->getFinallyBody())
4025 return SemaRef.Owned(S->Retain());
4026
4027 // Build a new statement.
4028 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004029 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004030}
Mike Stump1eb44332009-09-09 15:08:12 +00004031
Douglas Gregor43959a92009-08-20 07:17:43 +00004032template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004033StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004034TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004035 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004036 if (S->getThrowExpr()) {
4037 Operand = getDerived().TransformExpr(S->getThrowExpr());
4038 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004039 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004040 }
Sean Huntc3021132010-05-05 15:23:54 +00004041
Douglas Gregord1377b22010-04-22 21:44:01 +00004042 if (!getDerived().AlwaysRebuild() &&
4043 Operand.get() == S->getThrowExpr())
4044 return getSema().Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004045
John McCall9ae2f072010-08-23 23:25:46 +00004046 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004047}
Mike Stump1eb44332009-09-09 15:08:12 +00004048
Douglas Gregor43959a92009-08-20 07:17:43 +00004049template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004050StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004051TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004052 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004053 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004054 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004055 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004056 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004057
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004058 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004059 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004060 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004061 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004062
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004063 // If nothing change, just retain the current statement.
4064 if (!getDerived().AlwaysRebuild() &&
4065 Object.get() == S->getSynchExpr() &&
4066 Body.get() == S->getSynchBody())
4067 return SemaRef.Owned(S->Retain());
4068
4069 // Build a new statement.
4070 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004071 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004072}
4073
4074template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004075StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004076TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004077 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004078 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004079 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004080 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004081 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004082
Douglas Gregorc3203e72010-04-22 23:10:45 +00004083 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00004084 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004085 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004086 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004087
Douglas Gregorc3203e72010-04-22 23:10:45 +00004088 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004089 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004090 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004091 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004092
Douglas Gregorc3203e72010-04-22 23:10:45 +00004093 // If nothing changed, just retain this statement.
4094 if (!getDerived().AlwaysRebuild() &&
4095 Element.get() == S->getElement() &&
4096 Collection.get() == S->getCollection() &&
4097 Body.get() == S->getBody())
4098 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004099
Douglas Gregorc3203e72010-04-22 23:10:45 +00004100 // Build a new statement.
4101 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4102 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004103 Element.get(),
4104 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00004105 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004106 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004107}
4108
4109
4110template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004111StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004112TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4113 // Transform the exception declaration, if any.
4114 VarDecl *Var = 0;
4115 if (S->getExceptionDecl()) {
4116 VarDecl *ExceptionDecl = S->getExceptionDecl();
4117 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4118 ExceptionDecl->getDeclName());
4119
4120 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4121 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004122 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004123
Douglas Gregor43959a92009-08-20 07:17:43 +00004124 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4125 T,
John McCalla93c9342009-12-07 02:54:59 +00004126 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004127 ExceptionDecl->getIdentifier(),
4128 ExceptionDecl->getLocation(),
4129 /*FIXME: Inaccurate*/
4130 SourceRange(ExceptionDecl->getLocation()));
Douglas Gregorff331c12010-07-25 18:17:45 +00004131 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00004132 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004133 }
Mike Stump1eb44332009-09-09 15:08:12 +00004134
Douglas Gregor43959a92009-08-20 07:17:43 +00004135 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00004136 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004137 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004138 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004139
Douglas Gregor43959a92009-08-20 07:17:43 +00004140 if (!getDerived().AlwaysRebuild() &&
4141 !Var &&
4142 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00004143 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004144
4145 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4146 Var,
John McCall9ae2f072010-08-23 23:25:46 +00004147 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004148}
Mike Stump1eb44332009-09-09 15:08:12 +00004149
Douglas Gregor43959a92009-08-20 07:17:43 +00004150template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004151StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004152TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4153 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004154 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004155 = getDerived().TransformCompoundStmt(S->getTryBlock());
4156 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004157 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004158
Douglas Gregor43959a92009-08-20 07:17:43 +00004159 // Transform the handlers.
4160 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004161 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00004162 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004163 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004164 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4165 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004166 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004167
Douglas Gregor43959a92009-08-20 07:17:43 +00004168 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4169 Handlers.push_back(Handler.takeAs<Stmt>());
4170 }
Mike Stump1eb44332009-09-09 15:08:12 +00004171
Douglas Gregor43959a92009-08-20 07:17:43 +00004172 if (!getDerived().AlwaysRebuild() &&
4173 TryBlock.get() == S->getTryBlock() &&
4174 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004175 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004176
John McCall9ae2f072010-08-23 23:25:46 +00004177 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00004178 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004179}
Mike Stump1eb44332009-09-09 15:08:12 +00004180
Douglas Gregor43959a92009-08-20 07:17:43 +00004181//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004182// Expression transformation
4183//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004184template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004185ExprResult
John McCall454feb92009-12-08 09:21:05 +00004186TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004187 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004188}
Mike Stump1eb44332009-09-09 15:08:12 +00004189
4190template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004191ExprResult
John McCall454feb92009-12-08 09:21:05 +00004192TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004193 NestedNameSpecifier *Qualifier = 0;
4194 if (E->getQualifier()) {
4195 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004196 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004197 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00004198 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00004199 }
John McCalldbd872f2009-12-08 09:08:17 +00004200
4201 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004202 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4203 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004204 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00004205 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004206
John McCallec8045d2010-08-17 21:27:17 +00004207 DeclarationNameInfo NameInfo = E->getNameInfo();
4208 if (NameInfo.getName()) {
4209 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4210 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00004211 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00004212 }
Abramo Bagnara25777432010-08-11 22:01:17 +00004213
4214 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004215 Qualifier == E->getQualifier() &&
4216 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00004217 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00004218 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004219
4220 // Mark it referenced in the new context regardless.
4221 // FIXME: this is a bit instantiation-specific.
4222 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4223
Mike Stump1eb44332009-09-09 15:08:12 +00004224 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004225 }
John McCalldbd872f2009-12-08 09:08:17 +00004226
4227 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00004228 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004229 TemplateArgs = &TransArgs;
4230 TransArgs.setLAngleLoc(E->getLAngleLoc());
4231 TransArgs.setRAngleLoc(E->getRAngleLoc());
4232 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4233 TemplateArgumentLoc Loc;
4234 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004235 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00004236 TransArgs.addArgument(Loc);
4237 }
4238 }
4239
Douglas Gregora2813ce2009-10-23 18:54:35 +00004240 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004241 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004242}
Mike Stump1eb44332009-09-09 15:08:12 +00004243
Douglas Gregorb98b1992009-08-11 05:31:07 +00004244template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004245ExprResult
John McCall454feb92009-12-08 09:21:05 +00004246TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004247 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004248}
Mike Stump1eb44332009-09-09 15:08:12 +00004249
Douglas Gregorb98b1992009-08-11 05:31:07 +00004250template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004251ExprResult
John McCall454feb92009-12-08 09:21:05 +00004252TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004253 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004254}
Mike Stump1eb44332009-09-09 15:08:12 +00004255
Douglas Gregorb98b1992009-08-11 05:31:07 +00004256template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004257ExprResult
John McCall454feb92009-12-08 09:21:05 +00004258TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004259 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004260}
Mike Stump1eb44332009-09-09 15:08:12 +00004261
Douglas Gregorb98b1992009-08-11 05:31:07 +00004262template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004263ExprResult
John McCall454feb92009-12-08 09:21:05 +00004264TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004265 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004266}
Mike Stump1eb44332009-09-09 15:08:12 +00004267
Douglas Gregorb98b1992009-08-11 05:31:07 +00004268template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004269ExprResult
John McCall454feb92009-12-08 09:21:05 +00004270TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004271 return SemaRef.Owned(E->Retain());
4272}
4273
4274template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004275ExprResult
John McCall454feb92009-12-08 09:21:05 +00004276TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004277 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004278 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004279 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004280
Douglas Gregorb98b1992009-08-11 05:31:07 +00004281 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004282 return SemaRef.Owned(E->Retain());
4283
John McCall9ae2f072010-08-23 23:25:46 +00004284 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004285 E->getRParen());
4286}
4287
Mike Stump1eb44332009-09-09 15:08:12 +00004288template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004289ExprResult
John McCall454feb92009-12-08 09:21:05 +00004290TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004291 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004292 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004293 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004294
Douglas Gregorb98b1992009-08-11 05:31:07 +00004295 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004296 return SemaRef.Owned(E->Retain());
4297
Douglas Gregorb98b1992009-08-11 05:31:07 +00004298 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4299 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004300 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004301}
Mike Stump1eb44332009-09-09 15:08:12 +00004302
Douglas Gregorb98b1992009-08-11 05:31:07 +00004303template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004304ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004305TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4306 // Transform the type.
4307 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4308 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00004309 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004310
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004311 // Transform all of the components into components similar to what the
4312 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004313 // FIXME: It would be slightly more efficient in the non-dependent case to
4314 // just map FieldDecls, rather than requiring the rebuilder to look for
4315 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004316 // template code that we don't care.
4317 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00004318 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004319 typedef OffsetOfExpr::OffsetOfNode Node;
4320 llvm::SmallVector<Component, 4> Components;
4321 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4322 const Node &ON = E->getComponent(I);
4323 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004324 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004325 Comp.LocStart = ON.getRange().getBegin();
4326 Comp.LocEnd = ON.getRange().getEnd();
4327 switch (ON.getKind()) {
4328 case Node::Array: {
4329 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00004330 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004331 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004332 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004333
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004334 ExprChanged = ExprChanged || Index.get() != FromIndex;
4335 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00004336 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004337 break;
4338 }
Sean Huntc3021132010-05-05 15:23:54 +00004339
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004340 case Node::Field:
4341 case Node::Identifier:
4342 Comp.isBrackets = false;
4343 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004344 if (!Comp.U.IdentInfo)
4345 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004346
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004347 break;
Sean Huntc3021132010-05-05 15:23:54 +00004348
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004349 case Node::Base:
4350 // Will be recomputed during the rebuild.
4351 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004352 }
Sean Huntc3021132010-05-05 15:23:54 +00004353
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004354 Components.push_back(Comp);
4355 }
Sean Huntc3021132010-05-05 15:23:54 +00004356
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004357 // If nothing changed, retain the existing expression.
4358 if (!getDerived().AlwaysRebuild() &&
4359 Type == E->getTypeSourceInfo() &&
4360 !ExprChanged)
4361 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004362
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004363 // Build a new offsetof expression.
4364 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4365 Components.data(), Components.size(),
4366 E->getRParenLoc());
4367}
4368
4369template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004370ExprResult
John McCall454feb92009-12-08 09:21:05 +00004371TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004372 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004373 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004374
John McCalla93c9342009-12-07 02:54:59 +00004375 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004376 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004377 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004378
John McCall5ab75172009-11-04 07:28:41 +00004379 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004380 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004381
John McCall5ab75172009-11-04 07:28:41 +00004382 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004383 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004384 E->getSourceRange());
4385 }
Mike Stump1eb44332009-09-09 15:08:12 +00004386
John McCall60d7b3a2010-08-24 06:29:42 +00004387 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00004388 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004389 // C++0x [expr.sizeof]p1:
4390 // The operand is either an expression, which is an unevaluated operand
4391 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00004392 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004393
Douglas Gregorb98b1992009-08-11 05:31:07 +00004394 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4395 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004396 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004397
Douglas Gregorb98b1992009-08-11 05:31:07 +00004398 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4399 return SemaRef.Owned(E->Retain());
4400 }
Mike Stump1eb44332009-09-09 15:08:12 +00004401
John McCall9ae2f072010-08-23 23:25:46 +00004402 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004403 E->isSizeOf(),
4404 E->getSourceRange());
4405}
Mike Stump1eb44332009-09-09 15:08:12 +00004406
Douglas Gregorb98b1992009-08-11 05:31:07 +00004407template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004408ExprResult
John McCall454feb92009-12-08 09:21:05 +00004409TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004410 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004411 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004412 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004413
John McCall60d7b3a2010-08-24 06:29:42 +00004414 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004415 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004416 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004417
4418
Douglas Gregorb98b1992009-08-11 05:31:07 +00004419 if (!getDerived().AlwaysRebuild() &&
4420 LHS.get() == E->getLHS() &&
4421 RHS.get() == E->getRHS())
4422 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004423
John McCall9ae2f072010-08-23 23:25:46 +00004424 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004425 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00004426 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004427 E->getRBracketLoc());
4428}
Mike Stump1eb44332009-09-09 15:08:12 +00004429
4430template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004431ExprResult
John McCall454feb92009-12-08 09:21:05 +00004432TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004433 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00004434 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004435 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004436 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004437
4438 // Transform arguments.
4439 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004440 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004441 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4442 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004443 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004444 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004445 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004446
Douglas Gregorb98b1992009-08-11 05:31:07 +00004447 // FIXME: Wrong source location information for the ','.
4448 FakeCommaLocs.push_back(
4449 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00004450
4451 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00004452 Args.push_back(Arg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004453 }
Mike Stump1eb44332009-09-09 15:08:12 +00004454
Douglas Gregorb98b1992009-08-11 05:31:07 +00004455 if (!getDerived().AlwaysRebuild() &&
4456 Callee.get() == E->getCallee() &&
4457 !ArgChanged)
4458 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004459
Douglas Gregorb98b1992009-08-11 05:31:07 +00004460 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004461 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004462 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00004463 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004464 move_arg(Args),
4465 FakeCommaLocs.data(),
4466 E->getRParenLoc());
4467}
Mike Stump1eb44332009-09-09 15:08:12 +00004468
4469template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004470ExprResult
John McCall454feb92009-12-08 09:21:05 +00004471TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004472 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004473 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004474 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004475
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004476 NestedNameSpecifier *Qualifier = 0;
4477 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004478 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004479 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004480 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004481 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00004482 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004483 }
Mike Stump1eb44332009-09-09 15:08:12 +00004484
Eli Friedmanf595cc42009-12-04 06:40:45 +00004485 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004486 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4487 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004488 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00004489 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004490
John McCall6bb80172010-03-30 21:47:33 +00004491 NamedDecl *FoundDecl = E->getFoundDecl();
4492 if (FoundDecl == E->getMemberDecl()) {
4493 FoundDecl = Member;
4494 } else {
4495 FoundDecl = cast_or_null<NamedDecl>(
4496 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4497 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00004498 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00004499 }
4500
Douglas Gregorb98b1992009-08-11 05:31:07 +00004501 if (!getDerived().AlwaysRebuild() &&
4502 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004503 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004504 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004505 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00004506 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00004507
Anders Carlsson1f240322009-12-22 05:24:09 +00004508 // Mark it referenced in the new context regardless.
4509 // FIXME: this is a bit instantiation-specific.
4510 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00004511 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00004512 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004513
John McCalld5532b62009-11-23 01:53:49 +00004514 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00004515 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00004516 TransArgs.setLAngleLoc(E->getLAngleLoc());
4517 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004518 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004519 TemplateArgumentLoc Loc;
4520 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004521 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004522 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004523 }
4524 }
Sean Huntc3021132010-05-05 15:23:54 +00004525
Douglas Gregorb98b1992009-08-11 05:31:07 +00004526 // FIXME: Bogus source location for the operator
4527 SourceLocation FakeOperatorLoc
4528 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4529
John McCallc2233c52010-01-15 08:34:02 +00004530 // FIXME: to do this check properly, we will need to preserve the
4531 // first-qualifier-in-scope here, just in case we had a dependent
4532 // base (and therefore couldn't do the check) and a
4533 // nested-name-qualifier (and therefore could do the lookup).
4534 NamedDecl *FirstQualifierInScope = 0;
4535
John McCall9ae2f072010-08-23 23:25:46 +00004536 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004537 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004538 Qualifier,
4539 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004540 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004541 Member,
John McCall6bb80172010-03-30 21:47:33 +00004542 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00004543 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00004544 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004545 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004546}
Mike Stump1eb44332009-09-09 15:08:12 +00004547
Douglas Gregorb98b1992009-08-11 05:31:07 +00004548template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004549ExprResult
John McCall454feb92009-12-08 09:21:05 +00004550TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004551 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004552 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004553 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004554
John McCall60d7b3a2010-08-24 06:29:42 +00004555 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004556 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004557 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004558
Douglas Gregorb98b1992009-08-11 05:31:07 +00004559 if (!getDerived().AlwaysRebuild() &&
4560 LHS.get() == E->getLHS() &&
4561 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004562 return SemaRef.Owned(E->Retain());
4563
Douglas Gregorb98b1992009-08-11 05:31:07 +00004564 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004565 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004566}
4567
Mike Stump1eb44332009-09-09 15:08:12 +00004568template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004569ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004570TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004571 CompoundAssignOperator *E) {
4572 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004573}
Mike Stump1eb44332009-09-09 15:08:12 +00004574
Douglas Gregorb98b1992009-08-11 05:31:07 +00004575template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004576ExprResult
John McCall454feb92009-12-08 09:21:05 +00004577TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004578 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004579 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004580 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004581
John McCall60d7b3a2010-08-24 06:29:42 +00004582 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004583 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004584 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004585
John McCall60d7b3a2010-08-24 06:29:42 +00004586 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004587 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004588 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004589
Douglas Gregorb98b1992009-08-11 05:31:07 +00004590 if (!getDerived().AlwaysRebuild() &&
4591 Cond.get() == E->getCond() &&
4592 LHS.get() == E->getLHS() &&
4593 RHS.get() == E->getRHS())
4594 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004595
John McCall9ae2f072010-08-23 23:25:46 +00004596 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004597 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004598 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004599 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004600 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004601}
Mike Stump1eb44332009-09-09 15:08:12 +00004602
4603template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004604ExprResult
John McCall454feb92009-12-08 09:21:05 +00004605TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004606 // Implicit casts are eliminated during transformation, since they
4607 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004608 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004609}
Mike Stump1eb44332009-09-09 15:08:12 +00004610
Douglas Gregorb98b1992009-08-11 05:31:07 +00004611template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004612ExprResult
John McCall454feb92009-12-08 09:21:05 +00004613TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004614 TypeSourceInfo *OldT;
4615 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004616 {
4617 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004618 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004619 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4620 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004621
John McCall9d125032010-01-15 18:39:57 +00004622 OldT = E->getTypeInfoAsWritten();
4623 NewT = getDerived().TransformType(OldT);
4624 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004625 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004626 }
Mike Stump1eb44332009-09-09 15:08:12 +00004627
John McCall60d7b3a2010-08-24 06:29:42 +00004628 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004629 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004630 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004631 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004632
Douglas Gregorb98b1992009-08-11 05:31:07 +00004633 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004634 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004635 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004636 return SemaRef.Owned(E->Retain());
4637
John McCall9d125032010-01-15 18:39:57 +00004638 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4639 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004640 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004641 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004642}
Mike Stump1eb44332009-09-09 15:08:12 +00004643
Douglas Gregorb98b1992009-08-11 05:31:07 +00004644template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004645ExprResult
John McCall454feb92009-12-08 09:21:05 +00004646TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004647 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4648 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4649 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004650 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004651
John McCall60d7b3a2010-08-24 06:29:42 +00004652 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004653 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004654 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004655
Douglas Gregorb98b1992009-08-11 05:31:07 +00004656 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004657 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004658 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00004659 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004660
John McCall1d7d8d62010-01-19 22:33:45 +00004661 // Note: the expression type doesn't necessarily match the
4662 // type-as-written, but that's okay, because it should always be
4663 // derivable from the initializer.
4664
John McCall42f56b52010-01-18 19:35:47 +00004665 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004666 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00004667 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004668}
Mike Stump1eb44332009-09-09 15:08:12 +00004669
Douglas Gregorb98b1992009-08-11 05:31:07 +00004670template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004671ExprResult
John McCall454feb92009-12-08 09:21:05 +00004672TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004673 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004674 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004675 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004676
Douglas Gregorb98b1992009-08-11 05:31:07 +00004677 if (!getDerived().AlwaysRebuild() &&
4678 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00004679 return SemaRef.Owned(E->Retain());
4680
Douglas Gregorb98b1992009-08-11 05:31:07 +00004681 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004682 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004683 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00004684 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004685 E->getAccessorLoc(),
4686 E->getAccessor());
4687}
Mike Stump1eb44332009-09-09 15:08:12 +00004688
Douglas Gregorb98b1992009-08-11 05:31:07 +00004689template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004690ExprResult
John McCall454feb92009-12-08 09:21:05 +00004691TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004692 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004693
John McCallca0408f2010-08-23 06:44:23 +00004694 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004695 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004696 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004697 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004698 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004699
Douglas Gregorb98b1992009-08-11 05:31:07 +00004700 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCall9ae2f072010-08-23 23:25:46 +00004701 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004702 }
Mike Stump1eb44332009-09-09 15:08:12 +00004703
Douglas Gregorb98b1992009-08-11 05:31:07 +00004704 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004705 return SemaRef.Owned(E->Retain());
4706
Douglas Gregorb98b1992009-08-11 05:31:07 +00004707 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004708 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004709}
Mike Stump1eb44332009-09-09 15:08:12 +00004710
Douglas Gregorb98b1992009-08-11 05:31:07 +00004711template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004712ExprResult
John McCall454feb92009-12-08 09:21:05 +00004713TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004714 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004715
Douglas Gregor43959a92009-08-20 07:17:43 +00004716 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00004717 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004718 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004719 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004720
Douglas Gregor43959a92009-08-20 07:17:43 +00004721 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00004722 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004723 bool ExprChanged = false;
4724 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4725 DEnd = E->designators_end();
4726 D != DEnd; ++D) {
4727 if (D->isFieldDesignator()) {
4728 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4729 D->getDotLoc(),
4730 D->getFieldLoc()));
4731 continue;
4732 }
Mike Stump1eb44332009-09-09 15:08:12 +00004733
Douglas Gregorb98b1992009-08-11 05:31:07 +00004734 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00004735 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004736 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004737 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004738
4739 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004740 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004741
Douglas Gregorb98b1992009-08-11 05:31:07 +00004742 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4743 ArrayExprs.push_back(Index.release());
4744 continue;
4745 }
Mike Stump1eb44332009-09-09 15:08:12 +00004746
Douglas Gregorb98b1992009-08-11 05:31:07 +00004747 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00004748 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004749 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4750 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004751 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004752
John McCall60d7b3a2010-08-24 06:29:42 +00004753 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004754 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004755 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004756
4757 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004758 End.get(),
4759 D->getLBracketLoc(),
4760 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004761
Douglas Gregorb98b1992009-08-11 05:31:07 +00004762 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4763 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004764
Douglas Gregorb98b1992009-08-11 05:31:07 +00004765 ArrayExprs.push_back(Start.release());
4766 ArrayExprs.push_back(End.release());
4767 }
Mike Stump1eb44332009-09-09 15:08:12 +00004768
Douglas Gregorb98b1992009-08-11 05:31:07 +00004769 if (!getDerived().AlwaysRebuild() &&
4770 Init.get() == E->getInit() &&
4771 !ExprChanged)
4772 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004773
Douglas Gregorb98b1992009-08-11 05:31:07 +00004774 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4775 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004776 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004777}
Mike Stump1eb44332009-09-09 15:08:12 +00004778
Douglas Gregorb98b1992009-08-11 05:31:07 +00004779template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004780ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004781TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004782 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004783 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004784
Douglas Gregor5557b252009-10-28 00:29:27 +00004785 // FIXME: Will we ever have proper type location here? Will we actually
4786 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004787 QualType T = getDerived().TransformType(E->getType());
4788 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004789 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004790
Douglas Gregorb98b1992009-08-11 05:31:07 +00004791 if (!getDerived().AlwaysRebuild() &&
4792 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004793 return SemaRef.Owned(E->Retain());
4794
Douglas Gregorb98b1992009-08-11 05:31:07 +00004795 return getDerived().RebuildImplicitValueInitExpr(T);
4796}
Mike Stump1eb44332009-09-09 15:08:12 +00004797
Douglas Gregorb98b1992009-08-11 05:31:07 +00004798template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004799ExprResult
John McCall454feb92009-12-08 09:21:05 +00004800TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004801 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4802 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004803 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004804
John McCall60d7b3a2010-08-24 06:29:42 +00004805 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004806 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004807 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004808
Douglas Gregorb98b1992009-08-11 05:31:07 +00004809 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004810 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004811 SubExpr.get() == E->getSubExpr())
4812 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004813
John McCall9ae2f072010-08-23 23:25:46 +00004814 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004815 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004816}
4817
4818template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004819ExprResult
John McCall454feb92009-12-08 09:21:05 +00004820TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004821 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004822 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004823 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004824 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004825 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004826 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004827
Douglas Gregorb98b1992009-08-11 05:31:07 +00004828 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00004829 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004830 }
Mike Stump1eb44332009-09-09 15:08:12 +00004831
Douglas Gregorb98b1992009-08-11 05:31:07 +00004832 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4833 move_arg(Inits),
4834 E->getRParenLoc());
4835}
Mike Stump1eb44332009-09-09 15:08:12 +00004836
Douglas Gregorb98b1992009-08-11 05:31:07 +00004837/// \brief Transform an address-of-label expression.
4838///
4839/// By default, the transformation of an address-of-label expression always
4840/// rebuilds the expression, so that the label identifier can be resolved to
4841/// the corresponding label statement by semantic analysis.
4842template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004843ExprResult
John McCall454feb92009-12-08 09:21:05 +00004844TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004845 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4846 E->getLabel());
4847}
Mike Stump1eb44332009-09-09 15:08:12 +00004848
4849template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004850ExprResult
John McCall454feb92009-12-08 09:21:05 +00004851TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004852 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004853 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4854 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004855 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004856
Douglas Gregorb98b1992009-08-11 05:31:07 +00004857 if (!getDerived().AlwaysRebuild() &&
4858 SubStmt.get() == E->getSubStmt())
4859 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004860
4861 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004862 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004863 E->getRParenLoc());
4864}
Mike Stump1eb44332009-09-09 15:08:12 +00004865
Douglas Gregorb98b1992009-08-11 05:31:07 +00004866template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004867ExprResult
John McCall454feb92009-12-08 09:21:05 +00004868TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004869 TypeSourceInfo *TInfo1;
4870 TypeSourceInfo *TInfo2;
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004871
4872 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4873 if (!TInfo1)
John McCallf312b1e2010-08-26 23:41:50 +00004874 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004875
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004876 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4877 if (!TInfo2)
John McCallf312b1e2010-08-26 23:41:50 +00004878 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004879
4880 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004881 TInfo1 == E->getArgTInfo1() &&
4882 TInfo2 == E->getArgTInfo2())
Mike Stump1eb44332009-09-09 15:08:12 +00004883 return SemaRef.Owned(E->Retain());
4884
Douglas Gregorb98b1992009-08-11 05:31:07 +00004885 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004886 TInfo1, TInfo2,
4887 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004888}
Mike Stump1eb44332009-09-09 15:08:12 +00004889
Douglas Gregorb98b1992009-08-11 05:31:07 +00004890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004891ExprResult
John McCall454feb92009-12-08 09:21:05 +00004892TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004893 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004894 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004895 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004896
John McCall60d7b3a2010-08-24 06:29:42 +00004897 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004898 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004899 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004900
John McCall60d7b3a2010-08-24 06:29:42 +00004901 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004902 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004903 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004904
Douglas Gregorb98b1992009-08-11 05:31:07 +00004905 if (!getDerived().AlwaysRebuild() &&
4906 Cond.get() == E->getCond() &&
4907 LHS.get() == E->getLHS() &&
4908 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004909 return SemaRef.Owned(E->Retain());
4910
Douglas Gregorb98b1992009-08-11 05:31:07 +00004911 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004912 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004913 E->getRParenLoc());
4914}
Mike Stump1eb44332009-09-09 15:08:12 +00004915
Douglas Gregorb98b1992009-08-11 05:31:07 +00004916template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004917ExprResult
John McCall454feb92009-12-08 09:21:05 +00004918TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004919 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004920}
4921
4922template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004923ExprResult
John McCall454feb92009-12-08 09:21:05 +00004924TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004925 switch (E->getOperator()) {
4926 case OO_New:
4927 case OO_Delete:
4928 case OO_Array_New:
4929 case OO_Array_Delete:
4930 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00004931 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004932
Douglas Gregor668d6d92009-12-13 20:44:55 +00004933 case OO_Call: {
4934 // This is a call to an object's operator().
4935 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4936
4937 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004938 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00004939 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004940 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004941
4942 // FIXME: Poor location information
4943 SourceLocation FakeLParenLoc
4944 = SemaRef.PP.getLocForEndOfToken(
4945 static_cast<Expr *>(Object.get())->getLocEnd());
4946
4947 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00004948 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor668d6d92009-12-13 20:44:55 +00004949 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4950 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004951 if (getDerived().DropCallArgument(E->getArg(I)))
4952 break;
Sean Huntc3021132010-05-05 15:23:54 +00004953
John McCall60d7b3a2010-08-24 06:29:42 +00004954 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor668d6d92009-12-13 20:44:55 +00004955 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004956 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004957
4958 // FIXME: Poor source location information.
4959 SourceLocation FakeCommaLoc
4960 = SemaRef.PP.getLocForEndOfToken(
4961 static_cast<Expr *>(Arg.get())->getLocEnd());
4962 FakeCommaLocs.push_back(FakeCommaLoc);
4963 Args.push_back(Arg.release());
4964 }
4965
John McCall9ae2f072010-08-23 23:25:46 +00004966 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00004967 move_arg(Args),
4968 FakeCommaLocs.data(),
4969 E->getLocEnd());
4970 }
4971
4972#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4973 case OO_##Name:
4974#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4975#include "clang/Basic/OperatorKinds.def"
4976 case OO_Subscript:
4977 // Handled below.
4978 break;
4979
4980 case OO_Conditional:
4981 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00004982 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004983
4984 case OO_None:
4985 case NUM_OVERLOADED_OPERATORS:
4986 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00004987 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004988 }
4989
John McCall60d7b3a2010-08-24 06:29:42 +00004990 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004991 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004992 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004993
John McCall60d7b3a2010-08-24 06:29:42 +00004994 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004995 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004996 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004997
John McCall60d7b3a2010-08-24 06:29:42 +00004998 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004999 if (E->getNumArgs() == 2) {
5000 Second = getDerived().TransformExpr(E->getArg(1));
5001 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005002 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005003 }
Mike Stump1eb44332009-09-09 15:08:12 +00005004
Douglas Gregorb98b1992009-08-11 05:31:07 +00005005 if (!getDerived().AlwaysRebuild() &&
5006 Callee.get() == E->getCallee() &&
5007 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005008 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5009 return SemaRef.Owned(E->Retain());
5010
Douglas Gregorb98b1992009-08-11 05:31:07 +00005011 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5012 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005013 Callee.get(),
5014 First.get(),
5015 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005016}
Mike Stump1eb44332009-09-09 15:08:12 +00005017
Douglas Gregorb98b1992009-08-11 05:31:07 +00005018template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005019ExprResult
John McCall454feb92009-12-08 09:21:05 +00005020TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5021 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005022}
Mike Stump1eb44332009-09-09 15:08:12 +00005023
Douglas Gregorb98b1992009-08-11 05:31:07 +00005024template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005025ExprResult
John McCall454feb92009-12-08 09:21:05 +00005026TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00005027 TypeSourceInfo *OldT;
5028 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005029 {
5030 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00005031 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005032 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5033 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005034
John McCall9d125032010-01-15 18:39:57 +00005035 OldT = E->getTypeInfoAsWritten();
5036 NewT = getDerived().TransformType(OldT);
5037 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005038 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005039 }
Mike Stump1eb44332009-09-09 15:08:12 +00005040
John McCall60d7b3a2010-08-24 06:29:42 +00005041 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005042 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005043 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005044 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005045
Douglas Gregorb98b1992009-08-11 05:31:07 +00005046 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00005047 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005048 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005049 return SemaRef.Owned(E->Retain());
5050
Douglas Gregorb98b1992009-08-11 05:31:07 +00005051 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005052 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005053 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5054 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5055 SourceLocation FakeRParenLoc
5056 = SemaRef.PP.getLocForEndOfToken(
5057 E->getSubExpr()->getSourceRange().getEnd());
5058 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005059 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005060 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00005061 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005062 FakeRAngleLoc,
5063 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005064 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005065 FakeRParenLoc);
5066}
Mike Stump1eb44332009-09-09 15:08:12 +00005067
Douglas Gregorb98b1992009-08-11 05:31:07 +00005068template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005069ExprResult
John McCall454feb92009-12-08 09:21:05 +00005070TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5071 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005072}
Mike Stump1eb44332009-09-09 15:08:12 +00005073
5074template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005075ExprResult
John McCall454feb92009-12-08 09:21:05 +00005076TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5077 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005078}
5079
Douglas Gregorb98b1992009-08-11 05:31:07 +00005080template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005081ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005082TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005083 CXXReinterpretCastExpr *E) {
5084 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005085}
Mike Stump1eb44332009-09-09 15:08:12 +00005086
Douglas Gregorb98b1992009-08-11 05:31:07 +00005087template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005088ExprResult
John McCall454feb92009-12-08 09:21:05 +00005089TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5090 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005091}
Mike Stump1eb44332009-09-09 15:08:12 +00005092
Douglas Gregorb98b1992009-08-11 05:31:07 +00005093template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005094ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005095TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005096 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00005097 TypeSourceInfo *OldT;
5098 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005099 {
5100 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005101
John McCall9d125032010-01-15 18:39:57 +00005102 OldT = E->getTypeInfoAsWritten();
5103 NewT = getDerived().TransformType(OldT);
5104 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005105 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005106 }
Mike Stump1eb44332009-09-09 15:08:12 +00005107
John McCall60d7b3a2010-08-24 06:29:42 +00005108 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005109 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005110 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005111 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005112
Douglas Gregorb98b1992009-08-11 05:31:07 +00005113 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00005114 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005115 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005116 return SemaRef.Owned(E->Retain());
5117
Douglas Gregorb98b1992009-08-11 05:31:07 +00005118 // FIXME: The end of the type's source range is wrong
5119 return getDerived().RebuildCXXFunctionalCastExpr(
5120 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall9d125032010-01-15 18:39:57 +00005121 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005122 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005123 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005124 E->getRParenLoc());
5125}
Mike Stump1eb44332009-09-09 15:08:12 +00005126
Douglas Gregorb98b1992009-08-11 05:31:07 +00005127template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005128ExprResult
John McCall454feb92009-12-08 09:21:05 +00005129TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005130 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005131 TypeSourceInfo *TInfo
5132 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5133 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005134 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005135
Douglas Gregorb98b1992009-08-11 05:31:07 +00005136 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005137 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005138 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005139
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005140 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5141 E->getLocStart(),
5142 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005143 E->getLocEnd());
5144 }
Mike Stump1eb44332009-09-09 15:08:12 +00005145
Douglas Gregorb98b1992009-08-11 05:31:07 +00005146 // We don't know whether the expression is potentially evaluated until
5147 // after we perform semantic analysis, so the expression is potentially
5148 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005149 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00005150 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005151
John McCall60d7b3a2010-08-24 06:29:42 +00005152 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005153 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005154 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005155
Douglas Gregorb98b1992009-08-11 05:31:07 +00005156 if (!getDerived().AlwaysRebuild() &&
5157 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00005158 return SemaRef.Owned(E->Retain());
5159
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005160 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5161 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005162 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005163 E->getLocEnd());
5164}
5165
5166template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005167ExprResult
John McCall454feb92009-12-08 09:21:05 +00005168TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005169 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005170}
Mike Stump1eb44332009-09-09 15:08:12 +00005171
Douglas Gregorb98b1992009-08-11 05:31:07 +00005172template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005173ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005174TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005175 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005176 return SemaRef.Owned(E->Retain());
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>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005182 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005183
Douglas Gregorb98b1992009-08-11 05:31:07 +00005184 QualType T = getDerived().TransformType(E->getType());
5185 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005186 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005187
Douglas Gregorb98b1992009-08-11 05:31:07 +00005188 if (!getDerived().AlwaysRebuild() &&
5189 T == E->getType())
5190 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005191
Douglas Gregor828a1972010-01-07 23:12:05 +00005192 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005193}
Mike Stump1eb44332009-09-09 15:08:12 +00005194
Douglas Gregorb98b1992009-08-11 05:31:07 +00005195template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005196ExprResult
John McCall454feb92009-12-08 09:21:05 +00005197TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005198 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005199 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005200 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005201
Douglas Gregorb98b1992009-08-11 05:31:07 +00005202 if (!getDerived().AlwaysRebuild() &&
5203 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005204 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005205
John McCall9ae2f072010-08-23 23:25:46 +00005206 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
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
John McCall454feb92009-12-08 09:21:05 +00005211TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005212 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005213 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5214 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005215 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00005216 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005217
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005218 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005219 Param == E->getParam())
5220 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005221
Douglas Gregor036aed12009-12-23 23:03:06 +00005222 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005223}
Mike Stump1eb44332009-09-09 15:08:12 +00005224
Douglas Gregorb98b1992009-08-11 05:31:07 +00005225template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005226ExprResult
Douglas Gregored8abf12010-07-08 06:14:04 +00005227TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005228 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5229
5230 QualType T = getDerived().TransformType(E->getType());
5231 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005232 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005233
Douglas Gregorb98b1992009-08-11 05:31:07 +00005234 if (!getDerived().AlwaysRebuild() &&
5235 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00005236 return SemaRef.Owned(E->Retain());
5237
Douglas Gregored8abf12010-07-08 06:14:04 +00005238 return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
5239 /*FIXME:*/E->getTypeBeginLoc(),
5240 T,
5241 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005242}
Mike Stump1eb44332009-09-09 15:08:12 +00005243
Douglas Gregorb98b1992009-08-11 05:31:07 +00005244template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005245ExprResult
John McCall454feb92009-12-08 09:21:05 +00005246TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005247 // Transform the type that we're allocating
5248 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5249 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5250 if (AllocType.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005251 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005252
Douglas Gregorb98b1992009-08-11 05:31:07 +00005253 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00005254 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005255 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005256 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005257
Douglas Gregorb98b1992009-08-11 05:31:07 +00005258 // Transform the placement arguments (if any).
5259 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005260 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005261 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005262 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005263 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005264 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005265
Douglas Gregorb98b1992009-08-11 05:31:07 +00005266 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5267 PlacementArgs.push_back(Arg.take());
5268 }
Mike Stump1eb44332009-09-09 15:08:12 +00005269
Douglas Gregor43959a92009-08-20 07:17:43 +00005270 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00005271 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005272 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005273 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5274 break;
5275
John McCall60d7b3a2010-08-24 06:29:42 +00005276 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005277 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005278 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005279
Douglas Gregorb98b1992009-08-11 05:31:07 +00005280 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5281 ConstructorArgs.push_back(Arg.take());
5282 }
Mike Stump1eb44332009-09-09 15:08:12 +00005283
Douglas Gregor1af74512010-02-26 00:38:10 +00005284 // Transform constructor, new operator, and delete operator.
5285 CXXConstructorDecl *Constructor = 0;
5286 if (E->getConstructor()) {
5287 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005288 getDerived().TransformDecl(E->getLocStart(),
5289 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005290 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005291 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005292 }
5293
5294 FunctionDecl *OperatorNew = 0;
5295 if (E->getOperatorNew()) {
5296 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005297 getDerived().TransformDecl(E->getLocStart(),
5298 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005299 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00005300 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005301 }
5302
5303 FunctionDecl *OperatorDelete = 0;
5304 if (E->getOperatorDelete()) {
5305 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005306 getDerived().TransformDecl(E->getLocStart(),
5307 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005308 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005309 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005310 }
Sean Huntc3021132010-05-05 15:23:54 +00005311
Douglas Gregorb98b1992009-08-11 05:31:07 +00005312 if (!getDerived().AlwaysRebuild() &&
5313 AllocType == E->getAllocatedType() &&
5314 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005315 Constructor == E->getConstructor() &&
5316 OperatorNew == E->getOperatorNew() &&
5317 OperatorDelete == E->getOperatorDelete() &&
5318 !ArgumentChanged) {
5319 // Mark any declarations we need as referenced.
5320 // FIXME: instantiation-specific.
5321 if (Constructor)
5322 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5323 if (OperatorNew)
5324 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5325 if (OperatorDelete)
5326 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005327 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005328 }
Mike Stump1eb44332009-09-09 15:08:12 +00005329
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005330 if (!ArraySize.get()) {
5331 // If no array size was specified, but the new expression was
5332 // instantiated with an array type (e.g., "new T" where T is
5333 // instantiated with "int[4]"), extract the outer bound from the
5334 // array type as our array size. We do this with constant and
5335 // dependently-sized array types.
5336 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5337 if (!ArrayT) {
5338 // Do nothing
5339 } else if (const ConstantArrayType *ConsArrayT
5340 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005341 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00005342 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5343 ConsArrayT->getSize(),
5344 SemaRef.Context.getSizeType(),
5345 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005346 AllocType = ConsArrayT->getElementType();
5347 } else if (const DependentSizedArrayType *DepArrayT
5348 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5349 if (DepArrayT->getSizeExpr()) {
5350 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5351 AllocType = DepArrayT->getElementType();
5352 }
5353 }
5354 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005355 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5356 E->isGlobalNew(),
5357 /*FIXME:*/E->getLocStart(),
5358 move_arg(PlacementArgs),
5359 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00005360 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005361 AllocType,
5362 /*FIXME:*/E->getLocStart(),
5363 /*FIXME:*/SourceRange(),
John McCall9ae2f072010-08-23 23:25:46 +00005364 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005365 /*FIXME:*/E->getLocStart(),
5366 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005367 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005368}
Mike Stump1eb44332009-09-09 15:08:12 +00005369
Douglas Gregorb98b1992009-08-11 05:31:07 +00005370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005371ExprResult
John McCall454feb92009-12-08 09:21:05 +00005372TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005373 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005374 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005375 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005376
Douglas Gregor1af74512010-02-26 00:38:10 +00005377 // Transform the delete operator, if known.
5378 FunctionDecl *OperatorDelete = 0;
5379 if (E->getOperatorDelete()) {
5380 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005381 getDerived().TransformDecl(E->getLocStart(),
5382 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005383 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005384 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005385 }
Sean Huntc3021132010-05-05 15:23:54 +00005386
Douglas Gregorb98b1992009-08-11 05:31:07 +00005387 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005388 Operand.get() == E->getArgument() &&
5389 OperatorDelete == E->getOperatorDelete()) {
5390 // Mark any declarations we need as referenced.
5391 // FIXME: instantiation-specific.
5392 if (OperatorDelete)
5393 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005394 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005395 }
Mike Stump1eb44332009-09-09 15:08:12 +00005396
Douglas Gregorb98b1992009-08-11 05:31:07 +00005397 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5398 E->isGlobalDelete(),
5399 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00005400 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005401}
Mike Stump1eb44332009-09-09 15:08:12 +00005402
Douglas Gregorb98b1992009-08-11 05:31:07 +00005403template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005404ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005405TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005406 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005407 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00005408 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005409 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005410
John McCallb3d87482010-08-24 05:47:05 +00005411 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005412 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005413 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005414 E->getOperatorLoc(),
5415 E->isArrow()? tok::arrow : tok::period,
5416 ObjectTypePtr,
5417 MayBePseudoDestructor);
5418 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005419 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005420
John McCallb3d87482010-08-24 05:47:05 +00005421 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora71d8192009-09-04 17:36:40 +00005422 NestedNameSpecifier *Qualifier
5423 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00005424 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005425 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00005426 if (E->getQualifier() && !Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005427 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005428
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005429 PseudoDestructorTypeStorage Destroyed;
5430 if (E->getDestroyedTypeInfo()) {
5431 TypeSourceInfo *DestroyedTypeInfo
5432 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5433 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005434 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005435 Destroyed = DestroyedTypeInfo;
5436 } else if (ObjectType->isDependentType()) {
5437 // We aren't likely to be able to resolve the identifier down to a type
5438 // now anyway, so just retain the identifier.
5439 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5440 E->getDestroyedTypeLoc());
5441 } else {
5442 // Look for a destructor known with the given name.
5443 CXXScopeSpec SS;
5444 if (Qualifier) {
5445 SS.setScopeRep(Qualifier);
5446 SS.setRange(E->getQualifierRange());
5447 }
Sean Huntc3021132010-05-05 15:23:54 +00005448
John McCallb3d87482010-08-24 05:47:05 +00005449 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005450 *E->getDestroyedTypeIdentifier(),
5451 E->getDestroyedTypeLoc(),
5452 /*Scope=*/0,
5453 SS, ObjectTypePtr,
5454 false);
5455 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005456 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005457
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005458 Destroyed
5459 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5460 E->getDestroyedTypeLoc());
5461 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005462
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005463 TypeSourceInfo *ScopeTypeInfo = 0;
5464 if (E->getScopeTypeInfo()) {
Sean Huntc3021132010-05-05 15:23:54 +00005465 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005466 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005467 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005468 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00005469 }
Sean Huntc3021132010-05-05 15:23:54 +00005470
John McCall9ae2f072010-08-23 23:25:46 +00005471 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005472 E->getOperatorLoc(),
5473 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005474 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005475 E->getQualifierRange(),
5476 ScopeTypeInfo,
5477 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005478 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005479 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005480}
Mike Stump1eb44332009-09-09 15:08:12 +00005481
Douglas Gregora71d8192009-09-04 17:36:40 +00005482template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005483ExprResult
John McCallba135432009-11-21 08:51:07 +00005484TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005485 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005486 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5487
5488 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5489 Sema::LookupOrdinaryName);
5490
5491 // Transform all the decls.
5492 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5493 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005494 NamedDecl *InstD = static_cast<NamedDecl*>(
5495 getDerived().TransformDecl(Old->getNameLoc(),
5496 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005497 if (!InstD) {
5498 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5499 // This can happen because of dependent hiding.
5500 if (isa<UsingShadowDecl>(*I))
5501 continue;
5502 else
John McCallf312b1e2010-08-26 23:41:50 +00005503 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005504 }
John McCallf7a1a742009-11-24 19:00:30 +00005505
5506 // Expand using declarations.
5507 if (isa<UsingDecl>(InstD)) {
5508 UsingDecl *UD = cast<UsingDecl>(InstD);
5509 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5510 E = UD->shadow_end(); I != E; ++I)
5511 R.addDecl(*I);
5512 continue;
5513 }
5514
5515 R.addDecl(InstD);
5516 }
5517
5518 // Resolve a kind, but don't do any further analysis. If it's
5519 // ambiguous, the callee needs to deal with it.
5520 R.resolveKind();
5521
5522 // Rebuild the nested-name qualifier, if present.
5523 CXXScopeSpec SS;
5524 NestedNameSpecifier *Qualifier = 0;
5525 if (Old->getQualifier()) {
5526 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005527 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005528 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005529 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005530
John McCallf7a1a742009-11-24 19:00:30 +00005531 SS.setScopeRep(Qualifier);
5532 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005533 }
5534
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005535 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005536 CXXRecordDecl *NamingClass
5537 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5538 Old->getNameLoc(),
5539 Old->getNamingClass()));
5540 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00005541 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005542
Douglas Gregor66c45152010-04-27 16:10:10 +00005543 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005544 }
5545
5546 // If we have no template arguments, it's a normal declaration name.
5547 if (!Old->hasExplicitTemplateArgs())
5548 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5549
5550 // If we have template arguments, rebuild them, then rebuild the
5551 // templateid expression.
5552 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5553 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5554 TemplateArgumentLoc Loc;
5555 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005556 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00005557 TransArgs.addArgument(Loc);
5558 }
5559
5560 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5561 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005562}
Mike Stump1eb44332009-09-09 15:08:12 +00005563
Douglas Gregorb98b1992009-08-11 05:31:07 +00005564template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005565ExprResult
John McCall454feb92009-12-08 09:21:05 +00005566TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005567 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005568
Douglas Gregorb98b1992009-08-11 05:31:07 +00005569 QualType T = getDerived().TransformType(E->getQueriedType());
5570 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005571 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005572
Douglas Gregorb98b1992009-08-11 05:31:07 +00005573 if (!getDerived().AlwaysRebuild() &&
5574 T == E->getQueriedType())
5575 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005576
Douglas Gregorb98b1992009-08-11 05:31:07 +00005577 // FIXME: Bad location information
5578 SourceLocation FakeLParenLoc
5579 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00005580
5581 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005582 E->getLocStart(),
5583 /*FIXME:*/FakeLParenLoc,
5584 T,
5585 E->getLocEnd());
5586}
Mike Stump1eb44332009-09-09 15:08:12 +00005587
Douglas Gregorb98b1992009-08-11 05:31:07 +00005588template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005589ExprResult
John McCall865d4472009-11-19 22:55:06 +00005590TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005591 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005592 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005593 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005594 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005595 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00005596 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005597
Abramo Bagnara25777432010-08-11 22:01:17 +00005598 DeclarationNameInfo NameInfo
5599 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5600 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005601 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005602
John McCallf7a1a742009-11-24 19:00:30 +00005603 if (!E->hasExplicitTemplateArgs()) {
5604 if (!getDerived().AlwaysRebuild() &&
5605 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005606 // Note: it is sufficient to compare the Name component of NameInfo:
5607 // if name has not changed, DNLoc has not changed either.
5608 NameInfo.getName() == E->getDeclName())
John McCallf7a1a742009-11-24 19:00:30 +00005609 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005610
John McCallf7a1a742009-11-24 19:00:30 +00005611 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5612 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005613 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005614 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005615 }
John McCalld5532b62009-11-23 01:53:49 +00005616
5617 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005618 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005619 TemplateArgumentLoc Loc;
5620 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005621 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005622 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005623 }
5624
John McCallf7a1a742009-11-24 19:00:30 +00005625 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5626 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005627 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005628 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005629}
5630
5631template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005632ExprResult
John McCall454feb92009-12-08 09:21:05 +00005633TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005634 // CXXConstructExprs are always implicit, so when we have a
5635 // 1-argument construction we just transform that argument.
5636 if (E->getNumArgs() == 1 ||
5637 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5638 return getDerived().TransformExpr(E->getArg(0));
5639
Douglas Gregorb98b1992009-08-11 05:31:07 +00005640 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5641
5642 QualType T = getDerived().TransformType(E->getType());
5643 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005644 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005645
5646 CXXConstructorDecl *Constructor
5647 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005648 getDerived().TransformDecl(E->getLocStart(),
5649 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005650 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005651 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005652
Douglas Gregorb98b1992009-08-11 05:31:07 +00005653 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005654 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005655 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005656 ArgEnd = E->arg_end();
5657 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005658 if (getDerived().DropCallArgument(*Arg)) {
5659 ArgumentChanged = true;
5660 break;
5661 }
5662
John McCall60d7b3a2010-08-24 06:29:42 +00005663 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005664 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005665 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005666
Douglas Gregorb98b1992009-08-11 05:31:07 +00005667 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005668 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005669 }
5670
5671 if (!getDerived().AlwaysRebuild() &&
5672 T == E->getType() &&
5673 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005674 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005675 // Mark the constructor as referenced.
5676 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005677 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005678 return SemaRef.Owned(E->Retain());
Douglas Gregorc845aad2010-02-26 00:01:57 +00005679 }
Mike Stump1eb44332009-09-09 15:08:12 +00005680
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005681 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5682 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00005683 move_arg(Args),
5684 E->requiresZeroInitialization(),
5685 E->getConstructionKind());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005686}
Mike Stump1eb44332009-09-09 15:08:12 +00005687
Douglas Gregorb98b1992009-08-11 05:31:07 +00005688/// \brief Transform a C++ temporary-binding expression.
5689///
Douglas Gregor51326552009-12-24 18:51:59 +00005690/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5691/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005692template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005693ExprResult
John McCall454feb92009-12-08 09:21:05 +00005694TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005695 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005696}
Mike Stump1eb44332009-09-09 15:08:12 +00005697
5698/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005699/// be destroyed after the expression is evaluated.
5700///
Douglas Gregor51326552009-12-24 18:51:59 +00005701/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5702/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005703template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005704ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005705TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005706 CXXExprWithTemporaries *E) {
5707 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005708}
Mike Stump1eb44332009-09-09 15:08:12 +00005709
Douglas Gregorb98b1992009-08-11 05:31:07 +00005710template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005711ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005712TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00005713 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005714 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5715 QualType T = getDerived().TransformType(E->getType());
5716 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005717 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005718
Douglas Gregorb98b1992009-08-11 05:31:07 +00005719 CXXConstructorDecl *Constructor
5720 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005721 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005722 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005723 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005724 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005725
Douglas Gregorb98b1992009-08-11 05:31:07 +00005726 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005727 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005728 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005729 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005730 ArgEnd = E->arg_end();
5731 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005732 if (getDerived().DropCallArgument(*Arg)) {
5733 ArgumentChanged = true;
5734 break;
5735 }
5736
John McCall60d7b3a2010-08-24 06:29:42 +00005737 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005738 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005739 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005740
Douglas Gregorb98b1992009-08-11 05:31:07 +00005741 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5742 Args.push_back((Expr *)TransArg.release());
5743 }
Mike Stump1eb44332009-09-09 15:08:12 +00005744
Douglas Gregorb98b1992009-08-11 05:31:07 +00005745 if (!getDerived().AlwaysRebuild() &&
5746 T == E->getType() &&
5747 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005748 !ArgumentChanged) {
5749 // FIXME: Instantiation-specific
5750 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carrutha3ce8ae2010-03-31 18:34:58 +00005751 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor91be6f52010-03-02 17:18:33 +00005752 }
Mike Stump1eb44332009-09-09 15:08:12 +00005753
Douglas Gregorb98b1992009-08-11 05:31:07 +00005754 // FIXME: Bogus location information
5755 SourceLocation CommaLoc;
5756 if (Args.size() > 1) {
5757 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00005758 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005759 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5760 }
5761 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5762 T,
5763 /*FIXME:*/E->getTypeBeginLoc(),
5764 move_arg(Args),
5765 &CommaLoc,
5766 E->getLocEnd());
5767}
Mike Stump1eb44332009-09-09 15:08:12 +00005768
Douglas Gregorb98b1992009-08-11 05:31:07 +00005769template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005770ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005771TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005772 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005773 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5774 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5775 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005776 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005777
Douglas Gregorb98b1992009-08-11 05:31:07 +00005778 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005779 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005780 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5781 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5782 ArgEnd = E->arg_end();
5783 Arg != ArgEnd; ++Arg) {
John McCall60d7b3a2010-08-24 06:29:42 +00005784 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005785 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005786 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005787
Douglas Gregorb98b1992009-08-11 05:31:07 +00005788 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5789 FakeCommaLocs.push_back(
5790 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
John McCall9ae2f072010-08-23 23:25:46 +00005791 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005792 }
Mike Stump1eb44332009-09-09 15:08:12 +00005793
Douglas Gregorb98b1992009-08-11 05:31:07 +00005794 if (!getDerived().AlwaysRebuild() &&
5795 T == E->getTypeAsWritten() &&
5796 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005797 return SemaRef.Owned(E->Retain());
5798
Douglas Gregorb98b1992009-08-11 05:31:07 +00005799 // FIXME: we're faking the locations of the commas
5800 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5801 T,
5802 E->getLParenLoc(),
5803 move_arg(Args),
5804 FakeCommaLocs.data(),
5805 E->getRParenLoc());
5806}
Mike Stump1eb44332009-09-09 15:08:12 +00005807
Douglas Gregorb98b1992009-08-11 05:31:07 +00005808template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005809ExprResult
John McCall865d4472009-11-19 22:55:06 +00005810TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005811 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005812 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005813 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005814 Expr *OldBase;
5815 QualType BaseType;
5816 QualType ObjectType;
5817 if (!E->isImplicitAccess()) {
5818 OldBase = E->getBase();
5819 Base = getDerived().TransformExpr(OldBase);
5820 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005821 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005822
John McCallaa81e162009-12-01 22:10:20 +00005823 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00005824 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00005825 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005826 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005827 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005828 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005829 ObjectTy,
5830 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005831 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005832 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005833
John McCallb3d87482010-08-24 05:47:05 +00005834 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00005835 BaseType = ((Expr*) Base.get())->getType();
5836 } else {
5837 OldBase = 0;
5838 BaseType = getDerived().TransformType(E->getBaseType());
5839 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5840 }
Mike Stump1eb44332009-09-09 15:08:12 +00005841
Douglas Gregor6cd21982009-10-20 05:58:46 +00005842 // Transform the first part of the nested-name-specifier that qualifies
5843 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005844 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005845 = getDerived().TransformFirstQualifierInScope(
5846 E->getFirstQualifierFoundInScope(),
5847 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005848
Douglas Gregora38c6872009-09-03 16:14:30 +00005849 NestedNameSpecifier *Qualifier = 0;
5850 if (E->getQualifier()) {
5851 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5852 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005853 ObjectType,
5854 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005855 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005856 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00005857 }
Mike Stump1eb44332009-09-09 15:08:12 +00005858
Abramo Bagnara25777432010-08-11 22:01:17 +00005859 DeclarationNameInfo NameInfo
5860 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5861 ObjectType);
5862 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005863 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005864
John McCallaa81e162009-12-01 22:10:20 +00005865 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005866 // This is a reference to a member without an explicitly-specified
5867 // template argument list. Optimize for this common case.
5868 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005869 Base.get() == OldBase &&
5870 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005871 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005872 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005873 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005874 return SemaRef.Owned(E->Retain());
5875
John McCall9ae2f072010-08-23 23:25:46 +00005876 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005877 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005878 E->isArrow(),
5879 E->getOperatorLoc(),
5880 Qualifier,
5881 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005882 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005883 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005884 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005885 }
5886
John McCalld5532b62009-11-23 01:53:49 +00005887 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005888 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005889 TemplateArgumentLoc Loc;
5890 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005891 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005892 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005893 }
Mike Stump1eb44332009-09-09 15:08:12 +00005894
John McCall9ae2f072010-08-23 23:25:46 +00005895 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005896 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005897 E->isArrow(),
5898 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005899 Qualifier,
5900 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005901 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005902 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005903 &TransArgs);
5904}
5905
5906template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005907ExprResult
John McCall454feb92009-12-08 09:21:05 +00005908TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005909 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005910 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005911 QualType BaseType;
5912 if (!Old->isImplicitAccess()) {
5913 Base = getDerived().TransformExpr(Old->getBase());
5914 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005915 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005916 BaseType = ((Expr*) Base.get())->getType();
5917 } else {
5918 BaseType = getDerived().TransformType(Old->getBaseType());
5919 }
John McCall129e2df2009-11-30 22:42:35 +00005920
5921 NestedNameSpecifier *Qualifier = 0;
5922 if (Old->getQualifier()) {
5923 Qualifier
5924 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005925 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005926 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00005927 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00005928 }
5929
Abramo Bagnara25777432010-08-11 22:01:17 +00005930 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00005931 Sema::LookupOrdinaryName);
5932
5933 // Transform all the decls.
5934 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5935 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005936 NamedDecl *InstD = static_cast<NamedDecl*>(
5937 getDerived().TransformDecl(Old->getMemberLoc(),
5938 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005939 if (!InstD) {
5940 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5941 // This can happen because of dependent hiding.
5942 if (isa<UsingShadowDecl>(*I))
5943 continue;
5944 else
John McCallf312b1e2010-08-26 23:41:50 +00005945 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005946 }
John McCall129e2df2009-11-30 22:42:35 +00005947
5948 // Expand using declarations.
5949 if (isa<UsingDecl>(InstD)) {
5950 UsingDecl *UD = cast<UsingDecl>(InstD);
5951 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5952 E = UD->shadow_end(); I != E; ++I)
5953 R.addDecl(*I);
5954 continue;
5955 }
5956
5957 R.addDecl(InstD);
5958 }
5959
5960 R.resolveKind();
5961
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005962 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00005963 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00005964 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005965 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00005966 Old->getMemberLoc(),
5967 Old->getNamingClass()));
5968 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00005969 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005970
Douglas Gregor66c45152010-04-27 16:10:10 +00005971 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005972 }
Sean Huntc3021132010-05-05 15:23:54 +00005973
John McCall129e2df2009-11-30 22:42:35 +00005974 TemplateArgumentListInfo TransArgs;
5975 if (Old->hasExplicitTemplateArgs()) {
5976 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5977 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5978 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5979 TemplateArgumentLoc Loc;
5980 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5981 Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005982 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00005983 TransArgs.addArgument(Loc);
5984 }
5985 }
John McCallc2233c52010-01-15 08:34:02 +00005986
5987 // FIXME: to do this check properly, we will need to preserve the
5988 // first-qualifier-in-scope here, just in case we had a dependent
5989 // base (and therefore couldn't do the check) and a
5990 // nested-name-qualifier (and therefore could do the lookup).
5991 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00005992
John McCall9ae2f072010-08-23 23:25:46 +00005993 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005994 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005995 Old->getOperatorLoc(),
5996 Old->isArrow(),
5997 Qualifier,
5998 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00005999 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006000 R,
6001 (Old->hasExplicitTemplateArgs()
6002 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006003}
6004
6005template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006006ExprResult
John McCall454feb92009-12-08 09:21:05 +00006007TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006008 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006009}
6010
Mike Stump1eb44332009-09-09 15:08:12 +00006011template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006012ExprResult
John McCall454feb92009-12-08 09:21:05 +00006013TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006014 TypeSourceInfo *EncodedTypeInfo
6015 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6016 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006017 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006018
Douglas Gregorb98b1992009-08-11 05:31:07 +00006019 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006020 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00006021 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006022
6023 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006024 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006025 E->getRParenLoc());
6026}
Mike Stump1eb44332009-09-09 15:08:12 +00006027
Douglas Gregorb98b1992009-08-11 05:31:07 +00006028template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006029ExprResult
John McCall454feb92009-12-08 09:21:05 +00006030TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006031 // Transform arguments.
6032 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006033 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006034 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006035 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor92e986e2010-04-22 16:44:27 +00006036 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006037 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006038
Douglas Gregor92e986e2010-04-22 16:44:27 +00006039 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00006040 Args.push_back(Arg.get());
Douglas Gregor92e986e2010-04-22 16:44:27 +00006041 }
6042
6043 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6044 // Class message: transform the receiver type.
6045 TypeSourceInfo *ReceiverTypeInfo
6046 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6047 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006048 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006049
Douglas Gregor92e986e2010-04-22 16:44:27 +00006050 // If nothing changed, just retain the existing message send.
6051 if (!getDerived().AlwaysRebuild() &&
6052 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6053 return SemaRef.Owned(E->Retain());
6054
6055 // Build a new class message send.
6056 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6057 E->getSelector(),
6058 E->getMethodDecl(),
6059 E->getLeftLoc(),
6060 move_arg(Args),
6061 E->getRightLoc());
6062 }
6063
6064 // Instance message: transform the receiver
6065 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6066 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006067 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006068 = getDerived().TransformExpr(E->getInstanceReceiver());
6069 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006070 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006071
6072 // If nothing changed, just retain the existing message send.
6073 if (!getDerived().AlwaysRebuild() &&
6074 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6075 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006076
Douglas Gregor92e986e2010-04-22 16:44:27 +00006077 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006078 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006079 E->getSelector(),
6080 E->getMethodDecl(),
6081 E->getLeftLoc(),
6082 move_arg(Args),
6083 E->getRightLoc());
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>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +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>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006095 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006096}
6097
Mike Stump1eb44332009-09-09 15:08:12 +00006098template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006099ExprResult
John McCall454feb92009-12-08 09:21:05 +00006100TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006101 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006102 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006103 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006104 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006105
6106 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006107
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006108 // If nothing changed, just retain the existing expression.
6109 if (!getDerived().AlwaysRebuild() &&
6110 Base.get() == E->getBase())
6111 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006112
John McCall9ae2f072010-08-23 23:25:46 +00006113 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006114 E->getLocation(),
6115 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006116}
6117
Mike Stump1eb44332009-09-09 15:08:12 +00006118template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006119ExprResult
John McCall454feb92009-12-08 09:21:05 +00006120TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregore3303542010-04-26 20:47:02 +00006121 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006122 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00006123 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006124 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006125
Douglas Gregore3303542010-04-26 20:47:02 +00006126 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006127
Douglas Gregore3303542010-04-26 20:47:02 +00006128 // If nothing changed, just retain the existing expression.
6129 if (!getDerived().AlwaysRebuild() &&
6130 Base.get() == E->getBase())
6131 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006132
John McCall9ae2f072010-08-23 23:25:46 +00006133 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregore3303542010-04-26 20:47:02 +00006134 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006135}
6136
Mike Stump1eb44332009-09-09 15:08:12 +00006137template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006138ExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00006139TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00006140 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006141 // If this implicit setter/getter refers to class methods, it cannot have any
6142 // dependent parts. Just retain the existing declaration.
6143 if (E->getInterfaceDecl())
6144 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006145
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006146 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006147 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006148 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006149 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006150
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006151 // We don't need to transform the getters/setters; they will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006152
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006153 // If nothing changed, just retain the existing expression.
6154 if (!getDerived().AlwaysRebuild() &&
6155 Base.get() == E->getBase())
6156 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006157
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006158 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6159 E->getGetterMethod(),
6160 E->getType(),
6161 E->getSetterMethod(),
6162 E->getLocation(),
John McCall9ae2f072010-08-23 23:25:46 +00006163 Base.get());
Sean Huntc3021132010-05-05 15:23:54 +00006164
Douglas Gregorb98b1992009-08-11 05:31:07 +00006165}
6166
Mike Stump1eb44332009-09-09 15:08:12 +00006167template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006168ExprResult
John McCall454feb92009-12-08 09:21:05 +00006169TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006170 // Can never occur in a dependent context.
Mike Stump1eb44332009-09-09 15:08:12 +00006171 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006172}
6173
Mike Stump1eb44332009-09-09 15:08:12 +00006174template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006175ExprResult
John McCall454feb92009-12-08 09:21:05 +00006176TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006177 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006178 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006179 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006180 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006181
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006182 // If nothing changed, just retain the existing expression.
6183 if (!getDerived().AlwaysRebuild() &&
6184 Base.get() == E->getBase())
6185 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006186
John McCall9ae2f072010-08-23 23:25:46 +00006187 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006188 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006189}
6190
Mike Stump1eb44332009-09-09 15:08:12 +00006191template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006192ExprResult
John McCall454feb92009-12-08 09:21:05 +00006193TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006194 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006195 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006196 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006197 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006198 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006199 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006200
Douglas Gregorb98b1992009-08-11 05:31:07 +00006201 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00006202 SubExprs.push_back(SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006203 }
Mike Stump1eb44332009-09-09 15:08:12 +00006204
Douglas Gregorb98b1992009-08-11 05:31:07 +00006205 if (!getDerived().AlwaysRebuild() &&
6206 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00006207 return SemaRef.Owned(E->Retain());
6208
Douglas Gregorb98b1992009-08-11 05:31:07 +00006209 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6210 move_arg(SubExprs),
6211 E->getRParenLoc());
6212}
6213
Mike Stump1eb44332009-09-09 15:08:12 +00006214template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006215ExprResult
John McCall454feb92009-12-08 09:21:05 +00006216TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006217 SourceLocation CaretLoc(E->getExprLoc());
6218
6219 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6220 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6221 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6222 llvm::SmallVector<ParmVarDecl*, 4> Params;
6223 llvm::SmallVector<QualType, 4> ParamTypes;
6224
6225 // Parameter substitution.
6226 const BlockDecl *BD = E->getBlockDecl();
6227 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6228 EN = BD->param_end(); P != EN; ++P) {
6229 ParmVarDecl *OldParm = (*P);
6230 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6231 QualType NewType = NewParm->getType();
6232 Params.push_back(NewParm);
6233 ParamTypes.push_back(NewParm->getType());
6234 }
6235
6236 const FunctionType *BExprFunctionType = E->getFunctionType();
6237 QualType BExprResultType = BExprFunctionType->getResultType();
6238 if (!BExprResultType.isNull()) {
6239 if (!BExprResultType->isDependentType())
6240 CurBlock->ReturnType = BExprResultType;
6241 else if (BExprResultType != SemaRef.Context.DependentTy)
6242 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6243 }
6244
6245 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00006246 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006247 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006248 return ExprError();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006249 // Set the parameters on the block decl.
6250 if (!Params.empty())
6251 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6252
6253 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6254 CurBlock->ReturnType,
6255 ParamTypes.data(),
6256 ParamTypes.size(),
6257 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006258 0,
6259 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006260
6261 CurBlock->FunctionType = FunctionType;
John McCall9ae2f072010-08-23 23:25:46 +00006262 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006263}
6264
Mike Stump1eb44332009-09-09 15:08:12 +00006265template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006266ExprResult
John McCall454feb92009-12-08 09:21:05 +00006267TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006268 NestedNameSpecifier *Qualifier = 0;
6269
6270 ValueDecl *ND
6271 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6272 E->getDecl()));
6273 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006274 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00006275
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006276 if (!getDerived().AlwaysRebuild() &&
6277 ND == E->getDecl()) {
6278 // Mark it referenced in the new context regardless.
6279 // FIXME: this is a bit instantiation-specific.
6280 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6281
6282 return SemaRef.Owned(E->Retain());
6283 }
6284
Abramo Bagnara25777432010-08-11 22:01:17 +00006285 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006286 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006287 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006288}
Mike Stump1eb44332009-09-09 15:08:12 +00006289
Douglas Gregorb98b1992009-08-11 05:31:07 +00006290//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006291// Type reconstruction
6292//===----------------------------------------------------------------------===//
6293
Mike Stump1eb44332009-09-09 15:08:12 +00006294template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006295QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6296 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006297 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006298 getDerived().getBaseEntity());
6299}
6300
Mike Stump1eb44332009-09-09 15:08:12 +00006301template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006302QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6303 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006304 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006305 getDerived().getBaseEntity());
6306}
6307
Mike Stump1eb44332009-09-09 15:08:12 +00006308template<typename Derived>
6309QualType
John McCall85737a72009-10-30 00:06:24 +00006310TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6311 bool WrittenAsLValue,
6312 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006313 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006314 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006315}
6316
6317template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006318QualType
John McCall85737a72009-10-30 00:06:24 +00006319TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6320 QualType ClassType,
6321 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006322 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006323 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006324}
6325
6326template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006327QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006328TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6329 ArrayType::ArraySizeModifier SizeMod,
6330 const llvm::APInt *Size,
6331 Expr *SizeExpr,
6332 unsigned IndexTypeQuals,
6333 SourceRange BracketsRange) {
6334 if (SizeExpr || !Size)
6335 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6336 IndexTypeQuals, BracketsRange,
6337 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006338
6339 QualType Types[] = {
6340 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6341 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6342 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006343 };
6344 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6345 QualType SizeType;
6346 for (unsigned I = 0; I != NumTypes; ++I)
6347 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6348 SizeType = Types[I];
6349 break;
6350 }
Mike Stump1eb44332009-09-09 15:08:12 +00006351
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006352 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6353 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006354 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006355 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006356 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006357}
Mike Stump1eb44332009-09-09 15:08:12 +00006358
Douglas Gregor577f75a2009-08-04 16:50:30 +00006359template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006360QualType
6361TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006362 ArrayType::ArraySizeModifier SizeMod,
6363 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006364 unsigned IndexTypeQuals,
6365 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006366 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006367 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006368}
6369
6370template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006371QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006372TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006373 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006374 unsigned IndexTypeQuals,
6375 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006376 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006377 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006378}
Mike Stump1eb44332009-09-09 15:08:12 +00006379
Douglas Gregor577f75a2009-08-04 16:50:30 +00006380template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006381QualType
6382TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006383 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006384 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006385 unsigned IndexTypeQuals,
6386 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006387 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006388 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006389 IndexTypeQuals, BracketsRange);
6390}
6391
6392template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006393QualType
6394TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006395 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006396 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006397 unsigned IndexTypeQuals,
6398 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006399 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006400 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006401 IndexTypeQuals, BracketsRange);
6402}
6403
6404template<typename Derived>
6405QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner788b0fd2010-06-23 06:00:24 +00006406 unsigned NumElements,
6407 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006408 // FIXME: semantic checking!
Chris Lattner788b0fd2010-06-23 06:00:24 +00006409 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006410}
Mike Stump1eb44332009-09-09 15:08:12 +00006411
Douglas Gregor577f75a2009-08-04 16:50:30 +00006412template<typename Derived>
6413QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6414 unsigned NumElements,
6415 SourceLocation AttributeLoc) {
6416 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6417 NumElements, true);
6418 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006419 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6420 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00006421 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006422}
Mike Stump1eb44332009-09-09 15:08:12 +00006423
Douglas Gregor577f75a2009-08-04 16:50:30 +00006424template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006425QualType
6426TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00006427 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006428 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00006429 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006430}
Mike Stump1eb44332009-09-09 15:08:12 +00006431
Douglas Gregor577f75a2009-08-04 16:50:30 +00006432template<typename Derived>
6433QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006434 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006435 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006436 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00006437 unsigned Quals,
6438 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00006439 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006440 Quals,
6441 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006442 getDerived().getBaseEntity(),
6443 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006444}
Mike Stump1eb44332009-09-09 15:08:12 +00006445
Douglas Gregor577f75a2009-08-04 16:50:30 +00006446template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006447QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6448 return SemaRef.Context.getFunctionNoProtoType(T);
6449}
6450
6451template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006452QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6453 assert(D && "no decl found");
6454 if (D->isInvalidDecl()) return QualType();
6455
Douglas Gregor92e986e2010-04-22 16:44:27 +00006456 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006457 TypeDecl *Ty;
6458 if (isa<UsingDecl>(D)) {
6459 UsingDecl *Using = cast<UsingDecl>(D);
6460 assert(Using->isTypeName() &&
6461 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6462
6463 // A valid resolved using typename decl points to exactly one type decl.
6464 assert(++Using->shadow_begin() == Using->shadow_end());
6465 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006466
John McCalled976492009-12-04 22:46:56 +00006467 } else {
6468 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6469 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6470 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6471 }
6472
6473 return SemaRef.Context.getTypeDeclType(Ty);
6474}
6475
6476template<typename Derived>
John McCall9ae2f072010-08-23 23:25:46 +00006477QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E) {
6478 return SemaRef.BuildTypeofExprType(E);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006479}
6480
6481template<typename Derived>
6482QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6483 return SemaRef.Context.getTypeOfType(Underlying);
6484}
6485
6486template<typename Derived>
John McCall9ae2f072010-08-23 23:25:46 +00006487QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E) {
6488 return SemaRef.BuildDecltypeType(E);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006489}
6490
6491template<typename Derived>
6492QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006493 TemplateName Template,
6494 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006495 const TemplateArgumentListInfo &TemplateArgs) {
6496 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006497}
Mike Stump1eb44332009-09-09 15:08:12 +00006498
Douglas Gregordcee1a12009-08-06 05:28:30 +00006499template<typename Derived>
6500NestedNameSpecifier *
6501TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6502 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006503 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006504 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006505 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006506 CXXScopeSpec SS;
6507 // FIXME: The source location information is all wrong.
6508 SS.setRange(Range);
6509 SS.setScopeRep(Prefix);
6510 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006511 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006512 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006513 ObjectType,
6514 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006515 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006516}
6517
6518template<typename Derived>
6519NestedNameSpecifier *
6520TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6521 SourceRange Range,
6522 NamespaceDecl *NS) {
6523 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6524}
6525
6526template<typename Derived>
6527NestedNameSpecifier *
6528TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6529 SourceRange Range,
6530 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006531 QualType T) {
6532 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006533 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006534 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006535 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6536 T.getTypePtr());
6537 }
Mike Stump1eb44332009-09-09 15:08:12 +00006538
Douglas Gregordcee1a12009-08-06 05:28:30 +00006539 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6540 return 0;
6541}
Mike Stump1eb44332009-09-09 15:08:12 +00006542
Douglas Gregord1067e52009-08-06 06:41:21 +00006543template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006544TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006545TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6546 bool TemplateKW,
6547 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006548 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006549 Template);
6550}
6551
6552template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006553TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006554TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006555 const IdentifierInfo &II,
6556 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006557 CXXScopeSpec SS;
6558 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00006559 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006560 UnqualifiedId Name;
6561 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00006562 Sema::TemplateTy Template;
6563 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6564 /*FIXME:*/getDerived().getBaseLocation(),
6565 SS,
6566 Name,
John McCallb3d87482010-08-24 05:47:05 +00006567 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006568 /*EnteringContext=*/false,
6569 Template);
6570 return Template.template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00006571}
Mike Stump1eb44332009-09-09 15:08:12 +00006572
Douglas Gregorb98b1992009-08-11 05:31:07 +00006573template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006574TemplateName
6575TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6576 OverloadedOperatorKind Operator,
6577 QualType ObjectType) {
6578 CXXScopeSpec SS;
6579 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6580 SS.setScopeRep(Qualifier);
6581 UnqualifiedId Name;
6582 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6583 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6584 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00006585 Sema::TemplateTy Template;
6586 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006587 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006588 SS,
6589 Name,
John McCallb3d87482010-08-24 05:47:05 +00006590 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006591 /*EnteringContext=*/false,
6592 Template);
6593 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006594}
Sean Huntc3021132010-05-05 15:23:54 +00006595
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006596template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006597ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006598TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6599 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006600 Expr *OrigCallee,
6601 Expr *First,
6602 Expr *Second) {
6603 Expr *Callee = OrigCallee->IgnoreParenCasts();
6604 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006605
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006607 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00006608 if (!First->getType()->isOverloadableType() &&
6609 !Second->getType()->isOverloadableType())
6610 return getSema().CreateBuiltinArraySubscriptExpr(First,
6611 Callee->getLocStart(),
6612 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006613 } else if (Op == OO_Arrow) {
6614 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00006615 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6616 } else if (Second == 0 || isPostIncDec) {
6617 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618 // The argument is not of overloadable type, so try to create a
6619 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00006620 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006622
John McCall9ae2f072010-08-23 23:25:46 +00006623 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624 }
6625 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006626 if (!First->getType()->isOverloadableType() &&
6627 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628 // Neither of the arguments is an overloadable type, so try to
6629 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00006630 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006631 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00006632 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006634 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006635
Douglas Gregorb98b1992009-08-11 05:31:07 +00006636 return move(Result);
6637 }
6638 }
Mike Stump1eb44332009-09-09 15:08:12 +00006639
6640 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006642 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006643
John McCall9ae2f072010-08-23 23:25:46 +00006644 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00006645 assert(ULE->requiresADL());
6646
6647 // FIXME: Do we have to check
6648 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006649 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006650 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006651 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006652 }
Mike Stump1eb44332009-09-09 15:08:12 +00006653
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00006655 Expr *Args[2] = { First, Second };
6656 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006657
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658 // Create the overloaded operator invocation for unary operators.
6659 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00006660 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00006662 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663 }
Mike Stump1eb44332009-09-09 15:08:12 +00006664
Sebastian Redlf322ed62009-10-29 20:17:01 +00006665 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00006666 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00006667 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006668 First,
6669 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006670
Douglas Gregorb98b1992009-08-11 05:31:07 +00006671 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00006672 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006673 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6675 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006676 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006677
Mike Stump1eb44332009-09-09 15:08:12 +00006678 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006679}
Mike Stump1eb44332009-09-09 15:08:12 +00006680
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006681template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006682ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00006683TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006684 SourceLocation OperatorLoc,
6685 bool isArrow,
6686 NestedNameSpecifier *Qualifier,
6687 SourceRange QualifierRange,
6688 TypeSourceInfo *ScopeType,
6689 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006690 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006691 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006692 CXXScopeSpec SS;
6693 if (Qualifier) {
6694 SS.setRange(QualifierRange);
6695 SS.setScopeRep(Qualifier);
6696 }
6697
John McCall9ae2f072010-08-23 23:25:46 +00006698 QualType BaseType = Base->getType();
6699 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006700 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006701 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006702 !BaseType->getAs<PointerType>()->getPointeeType()
6703 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006704 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00006705 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006706 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006707 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006708 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006709 /*FIXME?*/true);
6710 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006711
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006712 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00006713 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6714 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6715 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6716 NameInfo.setNamedTypeInfo(DestroyedType);
6717
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006718 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00006719
John McCall9ae2f072010-08-23 23:25:46 +00006720 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006721 OperatorLoc, isArrow,
6722 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00006723 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006724 /*TemplateArgs*/ 0);
6725}
6726
Douglas Gregor577f75a2009-08-04 16:50:30 +00006727} // end namespace clang
6728
6729#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H