blob: 15143dd416277a602ed35144b3c4d6dc98e94112 [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,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000537 NestedNameSpecifier *Qualifier,
538 SourceRange QualifierRange,
John McCall33500952010-06-11 00:33:02 +0000539 const IdentifierInfo *Name,
540 SourceLocation NameLoc,
541 const TemplateArgumentListInfo &Args) {
542 // Rebuild the template name.
543 // TODO: avoid TemplateName abstraction
544 TemplateName InstName =
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000545 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
546 QualType());
John McCall33500952010-06-11 00:33:02 +0000547
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000548 if (InstName.isNull())
549 return QualType();
550
John McCall33500952010-06-11 00:33:02 +0000551 // If it's still dependent, make a dependent specialization.
552 if (InstName.getAsDependentTemplateName())
553 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000554 Keyword, Qualifier, Name, Args);
John McCall33500952010-06-11 00:33:02 +0000555
556 // Otherwise, make an elaborated type wrapping a non-dependent
557 // specialization.
558 QualType T =
559 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
560 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000561
Abramo Bagnara22f638a2010-08-10 13:46:45 +0000562 // NOTE: NNS is already recorded in template specialization type T.
563 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000564 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000565
566 /// \brief Build a new typename type that refers to an identifier.
567 ///
568 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000569 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000570 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000571 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000572 NestedNameSpecifier *NNS,
573 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000574 SourceLocation KeywordLoc,
575 SourceRange NNSRange,
576 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000577 CXXScopeSpec SS;
578 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000579 SS.setRange(NNSRange);
580
Douglas Gregor40336422010-03-31 22:19:08 +0000581 if (NNS->isDependent()) {
582 // If the name is still dependent, just build a new dependent name type.
583 if (!SemaRef.computeDeclContext(SS))
584 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
585 }
586
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000587 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000588 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
589 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000590
591 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
592
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000593 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000594 // into a non-dependent elaborated-type-specifier. Find the tag we're
595 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000596 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000597 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
598 if (!DC)
599 return QualType();
600
John McCall56138762010-05-27 06:40:31 +0000601 if (SemaRef.RequireCompleteDeclContext(SS, DC))
602 return QualType();
603
Douglas Gregor40336422010-03-31 22:19:08 +0000604 TagDecl *Tag = 0;
605 SemaRef.LookupQualifiedName(Result, DC);
606 switch (Result.getResultKind()) {
607 case LookupResult::NotFound:
608 case LookupResult::NotFoundInCurrentInstantiation:
609 break;
Sean Huntc3021132010-05-05 15:23:54 +0000610
Douglas Gregor40336422010-03-31 22:19:08 +0000611 case LookupResult::Found:
612 Tag = Result.getAsSingle<TagDecl>();
613 break;
Sean Huntc3021132010-05-05 15:23:54 +0000614
Douglas Gregor40336422010-03-31 22:19:08 +0000615 case LookupResult::FoundOverloaded:
616 case LookupResult::FoundUnresolvedValue:
617 llvm_unreachable("Tag lookup cannot find non-tags");
618 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000619
Douglas Gregor40336422010-03-31 22:19:08 +0000620 case LookupResult::Ambiguous:
621 // Let the LookupResult structure handle ambiguities.
622 return QualType();
623 }
624
625 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000626 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000627 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000628 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000629 return QualType();
630 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000631
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000632 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
633 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000634 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
635 return QualType();
636 }
637
638 // Build the elaborated-type-specifier type.
639 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000640 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000641 }
Mike Stump1eb44332009-09-09 15:08:12 +0000642
Douglas Gregordcee1a12009-08-06 05:28:30 +0000643 /// \brief Build a new nested-name-specifier given the prefix and an
644 /// identifier that names the next step in the nested-name-specifier.
645 ///
646 /// By default, performs semantic analysis when building the new
647 /// nested-name-specifier. Subclasses may override this routine to provide
648 /// different behavior.
649 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
650 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000651 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000652 QualType ObjectType,
653 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000654
655 /// \brief Build a new nested-name-specifier given the prefix and the
656 /// namespace named in the next step in the nested-name-specifier.
657 ///
658 /// By default, performs semantic analysis when building the new
659 /// nested-name-specifier. Subclasses may override this routine to provide
660 /// different behavior.
661 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
662 SourceRange Range,
663 NamespaceDecl *NS);
664
665 /// \brief Build a new nested-name-specifier given the prefix and the
666 /// type named in the next step in the nested-name-specifier.
667 ///
668 /// By default, performs semantic analysis when building the new
669 /// nested-name-specifier. Subclasses may override this routine to provide
670 /// different behavior.
671 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
672 SourceRange Range,
673 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000674 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000675
676 /// \brief Build a new template name given a nested name specifier, a flag
677 /// indicating whether the "template" keyword was provided, and the template
678 /// that the template name refers to.
679 ///
680 /// By default, builds the new template name directly. Subclasses may override
681 /// this routine to provide different behavior.
682 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
683 bool TemplateKW,
684 TemplateDecl *Template);
685
Douglas Gregord1067e52009-08-06 06:41:21 +0000686 /// \brief Build a new template name given a nested name specifier and the
687 /// name that is referred to as a template.
688 ///
689 /// By default, performs semantic analysis to determine whether the name can
690 /// be resolved to a specific template, then builds the appropriate kind of
691 /// template name. Subclasses may override this routine to provide different
692 /// behavior.
693 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000694 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000695 const IdentifierInfo &II,
696 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000697
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000698 /// \brief Build a new template name given a nested name specifier and the
699 /// overloaded operator name that is referred to as a template.
700 ///
701 /// By default, performs semantic analysis to determine whether the name can
702 /// be resolved to a specific template, then builds the appropriate kind of
703 /// template name. Subclasses may override this routine to provide different
704 /// behavior.
705 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
706 OverloadedOperatorKind Operator,
707 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000708
Douglas Gregor43959a92009-08-20 07:17:43 +0000709 /// \brief Build a new compound statement.
710 ///
711 /// By default, performs semantic analysis to build the new statement.
712 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000713 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000714 MultiStmtArg Statements,
715 SourceLocation RBraceLoc,
716 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000717 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000718 IsStmtExpr);
719 }
720
721 /// \brief Build a new case statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000725 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000726 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000727 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000728 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000729 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000730 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000731 ColonLoc);
732 }
Mike Stump1eb44332009-09-09 15:08:12 +0000733
Douglas Gregor43959a92009-08-20 07:17:43 +0000734 /// \brief Attach the body to a new case statement.
735 ///
736 /// By default, performs semantic analysis to build the new statement.
737 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000738 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000739 getSema().ActOnCaseStmtBody(S, Body);
740 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000741 }
Mike Stump1eb44332009-09-09 15:08:12 +0000742
Douglas Gregor43959a92009-08-20 07:17:43 +0000743 /// \brief Build a new default statement.
744 ///
745 /// By default, performs semantic analysis to build the new statement.
746 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000747 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000748 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000749 Stmt *SubStmt) {
750 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000751 /*CurScope=*/0);
752 }
Mike Stump1eb44332009-09-09 15:08:12 +0000753
Douglas Gregor43959a92009-08-20 07:17:43 +0000754 /// \brief Build a new label statement.
755 ///
756 /// By default, performs semantic analysis to build the new statement.
757 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000758 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000759 IdentifierInfo *Id,
760 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000761 Stmt *SubStmt) {
762 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +0000763 }
Mike Stump1eb44332009-09-09 15:08:12 +0000764
Douglas Gregor43959a92009-08-20 07:17:43 +0000765 /// \brief Build a new "if" statement.
766 ///
767 /// By default, performs semantic analysis to build the new statement.
768 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000769 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCall9ae2f072010-08-23 23:25:46 +0000770 VarDecl *CondVar, Stmt *Then,
771 SourceLocation ElseLoc, Stmt *Else) {
772 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000773 }
Mike Stump1eb44332009-09-09 15:08:12 +0000774
Douglas Gregor43959a92009-08-20 07:17:43 +0000775 /// \brief Start building a new switch statement.
776 ///
777 /// By default, performs semantic analysis to build the new statement.
778 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000779 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000780 Expr *Cond, VarDecl *CondVar) {
781 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +0000782 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +0000783 }
Mike Stump1eb44332009-09-09 15:08:12 +0000784
Douglas Gregor43959a92009-08-20 07:17:43 +0000785 /// \brief Attach the body to the switch statement.
786 ///
787 /// By default, performs semantic analysis to build the new statement.
788 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000789 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000790 Stmt *Switch, Stmt *Body) {
791 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000792 }
793
794 /// \brief Build a new while statement.
795 ///
796 /// By default, performs semantic analysis to build the new statement.
797 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000798 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000799 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000800 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000801 Stmt *Body) {
802 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000803 }
Mike Stump1eb44332009-09-09 15:08:12 +0000804
Douglas Gregor43959a92009-08-20 07:17:43 +0000805 /// \brief Build a new do-while statement.
806 ///
807 /// By default, performs semantic analysis to build the new statement.
808 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000809 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregor43959a92009-08-20 07:17:43 +0000810 SourceLocation WhileLoc,
811 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000812 Expr *Cond,
Douglas Gregor43959a92009-08-20 07:17:43 +0000813 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000814 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
815 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +0000816 }
817
818 /// \brief Build a new for statement.
819 ///
820 /// By default, performs semantic analysis to build the new statement.
821 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000822 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000823 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000824 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000825 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCall9ae2f072010-08-23 23:25:46 +0000826 SourceLocation RParenLoc, Stmt *Body) {
827 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCalld226f652010-08-21 09:40:31 +0000828 CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000829 Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000830 }
Mike Stump1eb44332009-09-09 15:08:12 +0000831
Douglas Gregor43959a92009-08-20 07:17:43 +0000832 /// \brief Build a new goto statement.
833 ///
834 /// By default, performs semantic analysis to build the new statement.
835 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000836 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000837 SourceLocation LabelLoc,
838 LabelStmt *Label) {
839 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
840 }
841
842 /// \brief Build a new indirect goto statement.
843 ///
844 /// By default, performs semantic analysis to build the new statement.
845 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000846 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000847 SourceLocation StarLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000848 Expr *Target) {
849 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +0000850 }
Mike Stump1eb44332009-09-09 15:08:12 +0000851
Douglas Gregor43959a92009-08-20 07:17:43 +0000852 /// \brief Build a new return statement.
853 ///
854 /// By default, performs semantic analysis to build the new statement.
855 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000856 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000857 Expr *Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000858
John McCall9ae2f072010-08-23 23:25:46 +0000859 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +0000860 }
Mike Stump1eb44332009-09-09 15:08:12 +0000861
Douglas Gregor43959a92009-08-20 07:17:43 +0000862 /// \brief Build a new declaration statement.
863 ///
864 /// By default, performs semantic analysis to build the new statement.
865 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000866 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000867 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000868 SourceLocation EndLoc) {
869 return getSema().Owned(
870 new (getSema().Context) DeclStmt(
871 DeclGroupRef::Create(getSema().Context,
872 Decls, NumDecls),
873 StartLoc, EndLoc));
874 }
Mike Stump1eb44332009-09-09 15:08:12 +0000875
Anders Carlsson703e3942010-01-24 05:50:09 +0000876 /// \brief Build a new inline asm statement.
877 ///
878 /// By default, performs semantic analysis to build the new statement.
879 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000880 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +0000881 bool IsSimple,
882 bool IsVolatile,
883 unsigned NumOutputs,
884 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000885 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000886 MultiExprArg Constraints,
887 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +0000888 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +0000889 MultiExprArg Clobbers,
890 SourceLocation RParenLoc,
891 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000892 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000893 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +0000894 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +0000895 RParenLoc, MSAsm);
896 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000897
898 /// \brief Build a new Objective-C @try statement.
899 ///
900 /// By default, performs semantic analysis to build the new statement.
901 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000902 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000903 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000904 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +0000905 Stmt *Finally) {
906 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
907 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000908 }
909
Douglas Gregorbe270a02010-04-26 17:57:08 +0000910 /// \brief Rebuild an Objective-C exception declaration.
911 ///
912 /// By default, performs semantic analysis to build the new declaration.
913 /// Subclasses may override this routine to provide different behavior.
914 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
915 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +0000916 return getSema().BuildObjCExceptionDecl(TInfo, T,
917 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +0000918 ExceptionDecl->getLocation());
919 }
Sean Huntc3021132010-05-05 15:23:54 +0000920
Douglas Gregorbe270a02010-04-26 17:57:08 +0000921 /// \brief Build a new Objective-C @catch statement.
922 ///
923 /// By default, performs semantic analysis to build the new statement.
924 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000925 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +0000926 SourceLocation RParenLoc,
927 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +0000928 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +0000929 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000930 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +0000931 }
Sean Huntc3021132010-05-05 15:23:54 +0000932
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000933 /// \brief Build a new Objective-C @finally statement.
934 ///
935 /// By default, performs semantic analysis to build the new statement.
936 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000937 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000938 Stmt *Body) {
939 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000940 }
Sean Huntc3021132010-05-05 15:23:54 +0000941
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000942 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +0000943 ///
944 /// By default, performs semantic analysis to build the new statement.
945 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000946 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000947 Expr *Operand) {
948 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +0000949 }
Sean Huntc3021132010-05-05 15:23:54 +0000950
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000951 /// \brief Build a new Objective-C @synchronized statement.
952 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000953 /// By default, performs semantic analysis to build the new statement.
954 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000955 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000956 Expr *Object,
957 Stmt *Body) {
958 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
959 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000960 }
Douglas Gregorc3203e72010-04-22 23:10:45 +0000961
962 /// \brief Build a new Objective-C fast enumeration statement.
963 ///
964 /// By default, performs semantic analysis to build the new statement.
965 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000966 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +0000967 SourceLocation LParenLoc,
968 Stmt *Element,
969 Expr *Collection,
970 SourceLocation RParenLoc,
971 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +0000972 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000973 Element,
974 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +0000975 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000976 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +0000977 }
Sean Huntc3021132010-05-05 15:23:54 +0000978
Douglas Gregor43959a92009-08-20 07:17:43 +0000979 /// \brief Build a new C++ exception declaration.
980 ///
981 /// By default, performs semantic analysis to build the new decaration.
982 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000983 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000984 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000985 IdentifierInfo *Name,
986 SourceLocation Loc,
987 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000988 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000989 TypeRange);
990 }
991
992 /// \brief Build a new C++ catch statement.
993 ///
994 /// By default, performs semantic analysis to build the new statement.
995 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000996 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +0000997 VarDecl *ExceptionDecl,
998 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +0000999 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1000 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001001 }
Mike Stump1eb44332009-09-09 15:08:12 +00001002
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 /// \brief Build a new C++ try statement.
1004 ///
1005 /// By default, performs semantic analysis to build the new statement.
1006 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001007 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001008 Stmt *TryBlock,
1009 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001010 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001011 }
Mike Stump1eb44332009-09-09 15:08:12 +00001012
Douglas Gregorb98b1992009-08-11 05:31:07 +00001013 /// \brief Build a new expression that references a declaration.
1014 ///
1015 /// By default, performs semantic analysis to build the new expression.
1016 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001017 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001018 LookupResult &R,
1019 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001020 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1021 }
1022
1023
1024 /// \brief Build a new expression that references a declaration.
1025 ///
1026 /// By default, performs semantic analysis to build the new expression.
1027 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001028 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001029 SourceRange QualifierRange,
1030 ValueDecl *VD,
1031 const DeclarationNameInfo &NameInfo,
1032 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001033 CXXScopeSpec SS;
1034 SS.setScopeRep(Qualifier);
1035 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001036
1037 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001038
1039 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001040 }
Mike Stump1eb44332009-09-09 15:08:12 +00001041
Douglas Gregorb98b1992009-08-11 05:31:07 +00001042 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001043 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001044 /// By default, performs semantic analysis to build the new expression.
1045 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001046 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001047 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001048 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001049 }
1050
Douglas Gregora71d8192009-09-04 17:36:40 +00001051 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001052 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001053 /// By default, performs semantic analysis to build the new expression.
1054 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001055 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001056 SourceLocation OperatorLoc,
1057 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001058 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001059 SourceRange QualifierRange,
1060 TypeSourceInfo *ScopeType,
1061 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001062 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001063 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001064
Douglas Gregorb98b1992009-08-11 05:31:07 +00001065 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001066 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001067 /// By default, performs semantic analysis to build the new expression.
1068 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001069 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001070 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001071 Expr *SubExpr) {
1072 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001073 }
Mike Stump1eb44332009-09-09 15:08:12 +00001074
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001075 /// \brief Build a new builtin offsetof expression.
1076 ///
1077 /// By default, performs semantic analysis to build the new expression.
1078 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001079 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001080 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001081 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001082 unsigned NumComponents,
1083 SourceLocation RParenLoc) {
1084 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1085 NumComponents, RParenLoc);
1086 }
Sean Huntc3021132010-05-05 15:23:54 +00001087
Douglas Gregorb98b1992009-08-11 05:31:07 +00001088 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001089 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001090 /// By default, performs semantic analysis to build the new expression.
1091 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001092 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001093 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001094 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001095 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001096 }
1097
Mike Stump1eb44332009-09-09 15:08:12 +00001098 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001099 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001100 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001101 /// By default, performs semantic analysis to build the new expression.
1102 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001103 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001104 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001105 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001106 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001107 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001108 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001109
Douglas Gregorb98b1992009-08-11 05:31:07 +00001110 return move(Result);
1111 }
Mike Stump1eb44332009-09-09 15:08:12 +00001112
Douglas Gregorb98b1992009-08-11 05:31:07 +00001113 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001114 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001115 /// By default, performs semantic analysis to build the new expression.
1116 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001117 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001118 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001119 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001120 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001121 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1122 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001123 RBracketLoc);
1124 }
1125
1126 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001127 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001128 /// By default, performs semantic analysis to build the new expression.
1129 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001130 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001131 MultiExprArg Args,
1132 SourceLocation *CommaLocs,
1133 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001134 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001135 move(Args), CommaLocs, RParenLoc);
1136 }
1137
1138 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001139 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001140 /// By default, performs semantic analysis to build the new expression.
1141 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001142 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001143 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001144 NestedNameSpecifier *Qualifier,
1145 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001146 const DeclarationNameInfo &MemberNameInfo,
Eli Friedmanf595cc42009-12-04 06:40:45 +00001147 ValueDecl *Member,
John McCall6bb80172010-03-30 21:47:33 +00001148 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001149 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +00001150 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001151 if (!Member->getDeclName()) {
1152 // We have a reference to an unnamed field.
1153 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +00001154
John McCall9ae2f072010-08-23 23:25:46 +00001155 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001156 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001157 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001158
Mike Stump1eb44332009-09-09 15:08:12 +00001159 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001160 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001161 Member, MemberNameInfo,
Anders Carlssond8b285f2009-09-01 04:26:58 +00001162 cast<FieldDecl>(Member)->getType());
1163 return getSema().Owned(ME);
1164 }
Mike Stump1eb44332009-09-09 15:08:12 +00001165
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001166 CXXScopeSpec SS;
1167 if (Qualifier) {
1168 SS.setRange(QualifierRange);
1169 SS.setScopeRep(Qualifier);
1170 }
1171
John McCall9ae2f072010-08-23 23:25:46 +00001172 getSema().DefaultFunctionArrayConversion(Base);
1173 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001174
John McCall6bb80172010-03-30 21:47:33 +00001175 // FIXME: this involves duplicating earlier analysis in a lot of
1176 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001177 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001178 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001179 R.resolveKind();
1180
John McCall9ae2f072010-08-23 23:25:46 +00001181 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001182 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001183 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001184 }
Mike Stump1eb44332009-09-09 15:08:12 +00001185
Douglas Gregorb98b1992009-08-11 05:31:07 +00001186 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001187 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001188 /// By default, performs semantic analysis to build the new expression.
1189 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001190 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001191 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001192 Expr *LHS, Expr *RHS) {
1193 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001194 }
1195
1196 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001197 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001198 /// By default, performs semantic analysis to build the new expression.
1199 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001200 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001201 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001202 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001203 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001204 Expr *RHS) {
1205 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1206 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001207 }
1208
Douglas Gregorb98b1992009-08-11 05:31:07 +00001209 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001210 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001211 /// By default, performs semantic analysis to build the new expression.
1212 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001213 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001214 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001215 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001216 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001217 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001218 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001219 }
Mike Stump1eb44332009-09-09 15:08:12 +00001220
Douglas Gregorb98b1992009-08-11 05:31:07 +00001221 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001222 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001223 /// By default, performs semantic analysis to build the new expression.
1224 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001225 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001226 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001227 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001228 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001229 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001230 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001231 }
Mike Stump1eb44332009-09-09 15:08:12 +00001232
Douglas Gregorb98b1992009-08-11 05:31:07 +00001233 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001234 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001235 /// By default, performs semantic analysis to build the new expression.
1236 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001237 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001238 SourceLocation OpLoc,
1239 SourceLocation AccessorLoc,
1240 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001241
John McCall129e2df2009-11-30 22:42:35 +00001242 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001243 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001244 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001245 OpLoc, /*IsArrow*/ false,
1246 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001247 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001248 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001249 }
Mike Stump1eb44332009-09-09 15:08:12 +00001250
Douglas Gregorb98b1992009-08-11 05:31:07 +00001251 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001252 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001253 /// By default, performs semantic analysis to build the new expression.
1254 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001255 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001256 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001257 SourceLocation RBraceLoc,
1258 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001259 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001260 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1261 if (Result.isInvalid() || ResultTy->isDependentType())
1262 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001263
Douglas Gregore48319a2009-11-09 17:16:50 +00001264 // Patch in the result type we were given, which may have been computed
1265 // when the initial InitListExpr was built.
1266 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1267 ILE->setType(ResultTy);
1268 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001269 }
Mike Stump1eb44332009-09-09 15:08:12 +00001270
Douglas Gregorb98b1992009-08-11 05:31:07 +00001271 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001272 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001273 /// By default, performs semantic analysis to build the new expression.
1274 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001275 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001276 MultiExprArg ArrayExprs,
1277 SourceLocation EqualOrColonLoc,
1278 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001279 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001280 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001281 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001282 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001283 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001284 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001285
Douglas Gregorb98b1992009-08-11 05:31:07 +00001286 ArrayExprs.release();
1287 return move(Result);
1288 }
Mike Stump1eb44332009-09-09 15:08:12 +00001289
Douglas Gregorb98b1992009-08-11 05:31:07 +00001290 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001291 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001292 /// By default, builds the implicit value initialization without performing
1293 /// any semantic analysis. Subclasses may override this routine to provide
1294 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001295 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001296 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1297 }
Mike Stump1eb44332009-09-09 15:08:12 +00001298
Douglas Gregorb98b1992009-08-11 05:31:07 +00001299 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001300 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001301 /// By default, performs semantic analysis to build the new expression.
1302 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001303 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001304 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001305 SourceLocation RParenLoc) {
1306 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001307 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001308 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001309 }
1310
1311 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001312 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001313 /// By default, performs semantic analysis to build the new expression.
1314 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001315 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001316 MultiExprArg SubExprs,
1317 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001318 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001319 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001320 }
Mike Stump1eb44332009-09-09 15:08:12 +00001321
Douglas Gregorb98b1992009-08-11 05:31:07 +00001322 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001323 ///
1324 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001325 /// rather than attempting to map the label statement itself.
1326 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001327 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001328 SourceLocation LabelLoc,
1329 LabelStmt *Label) {
1330 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1331 }
Mike Stump1eb44332009-09-09 15:08:12 +00001332
Douglas Gregorb98b1992009-08-11 05:31:07 +00001333 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001334 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001335 /// By default, performs semantic analysis to build the new expression.
1336 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001337 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001338 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001339 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001340 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001341 }
Mike Stump1eb44332009-09-09 15:08:12 +00001342
Douglas Gregorb98b1992009-08-11 05:31:07 +00001343 /// \brief Build a new __builtin_types_compatible_p expression.
1344 ///
1345 /// By default, performs semantic analysis to build the new expression.
1346 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001347 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001348 TypeSourceInfo *TInfo1,
1349 TypeSourceInfo *TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001350 SourceLocation RParenLoc) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001351 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1352 TInfo1, TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001353 RParenLoc);
1354 }
Mike Stump1eb44332009-09-09 15:08:12 +00001355
Douglas Gregorb98b1992009-08-11 05:31:07 +00001356 /// \brief Build a new __builtin_choose_expr expression.
1357 ///
1358 /// By default, performs semantic analysis to build the new expression.
1359 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001360 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001361 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001362 SourceLocation RParenLoc) {
1363 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001364 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001365 RParenLoc);
1366 }
Mike Stump1eb44332009-09-09 15:08:12 +00001367
Douglas Gregorb98b1992009-08-11 05:31:07 +00001368 /// \brief Build a new overloaded operator call expression.
1369 ///
1370 /// By default, performs semantic analysis to build the new expression.
1371 /// The semantic analysis provides the behavior of template instantiation,
1372 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001373 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001374 /// argument-dependent lookup, etc. Subclasses may override this routine to
1375 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001376 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001377 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001378 Expr *Callee,
1379 Expr *First,
1380 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001381
1382 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001383 /// reinterpret_cast.
1384 ///
1385 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001386 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001387 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001388 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001389 Stmt::StmtClass Class,
1390 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001391 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001392 SourceLocation RAngleLoc,
1393 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001394 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001395 SourceLocation RParenLoc) {
1396 switch (Class) {
1397 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001398 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001399 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001400 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001401
1402 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001403 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001404 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001405 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001406
Douglas Gregorb98b1992009-08-11 05:31:07 +00001407 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001408 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001409 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001410 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001411 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001412
Douglas Gregorb98b1992009-08-11 05:31:07 +00001413 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001414 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001415 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001416 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001417
Douglas Gregorb98b1992009-08-11 05:31:07 +00001418 default:
1419 assert(false && "Invalid C++ named cast");
1420 break;
1421 }
Mike Stump1eb44332009-09-09 15:08:12 +00001422
John McCallf312b1e2010-08-26 23:41:50 +00001423 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001424 }
Mike Stump1eb44332009-09-09 15:08:12 +00001425
Douglas Gregorb98b1992009-08-11 05:31:07 +00001426 /// \brief Build a new C++ static_cast expression.
1427 ///
1428 /// By default, performs semantic analysis to build the new expression.
1429 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001430 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001432 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001433 SourceLocation RAngleLoc,
1434 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001435 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001437 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001438 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001439 SourceRange(LAngleLoc, RAngleLoc),
1440 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001441 }
1442
1443 /// \brief Build a new C++ dynamic_cast expression.
1444 ///
1445 /// By default, performs semantic analysis to build the new expression.
1446 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001447 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001448 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001449 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 SourceLocation RAngleLoc,
1451 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001452 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001453 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001454 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001455 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001456 SourceRange(LAngleLoc, RAngleLoc),
1457 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001458 }
1459
1460 /// \brief Build a new C++ reinterpret_cast expression.
1461 ///
1462 /// By default, performs semantic analysis to build the new expression.
1463 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001464 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001465 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001466 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 SourceLocation RAngleLoc,
1468 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001469 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001471 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001472 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001473 SourceRange(LAngleLoc, RAngleLoc),
1474 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 }
1476
1477 /// \brief Build a new C++ const_cast expression.
1478 ///
1479 /// By default, performs semantic analysis to build the new expression.
1480 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001481 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001483 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 SourceLocation RAngleLoc,
1485 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001486 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001488 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001489 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001490 SourceRange(LAngleLoc, RAngleLoc),
1491 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 }
Mike Stump1eb44332009-09-09 15:08:12 +00001493
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 /// \brief Build a new C++ functional-style cast expression.
1495 ///
1496 /// By default, performs semantic analysis to build the new expression.
1497 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001498 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1499 SourceLocation LParenLoc,
1500 Expr *Sub,
1501 SourceLocation RParenLoc) {
1502 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001503 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 RParenLoc);
1505 }
Mike Stump1eb44332009-09-09 15:08:12 +00001506
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 /// \brief Build a new C++ typeid(type) expression.
1508 ///
1509 /// By default, performs semantic analysis to build the new expression.
1510 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001511 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001512 SourceLocation TypeidLoc,
1513 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001515 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001516 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 }
Mike Stump1eb44332009-09-09 15:08:12 +00001518
Francois Pichet01b7c302010-09-08 12:20:18 +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
Francois Pichet01b7c302010-09-08 12:20:18 +00001532 /// \brief Build a new C++ __uuidof(type) expression.
1533 ///
1534 /// By default, performs semantic analysis to build the new expression.
1535 /// Subclasses may override this routine to provide different behavior.
1536 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1537 SourceLocation TypeidLoc,
1538 TypeSourceInfo *Operand,
1539 SourceLocation RParenLoc) {
1540 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1541 RParenLoc);
1542 }
1543
1544 /// \brief Build a new C++ __uuidof(expr) expression.
1545 ///
1546 /// By default, performs semantic analysis to build the new expression.
1547 /// Subclasses may override this routine to provide different behavior.
1548 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1549 SourceLocation TypeidLoc,
1550 Expr *Operand,
1551 SourceLocation RParenLoc) {
1552 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1553 RParenLoc);
1554 }
1555
Douglas Gregorb98b1992009-08-11 05:31:07 +00001556 /// \brief Build a new C++ "this" expression.
1557 ///
1558 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001559 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001560 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001561 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001562 QualType ThisType,
1563 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001564 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001565 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1566 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 }
1568
1569 /// \brief Build a new C++ throw expression.
1570 ///
1571 /// By default, performs semantic analysis to build the new expression.
1572 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001573 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001574 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001575 }
1576
1577 /// \brief Build a new C++ default-argument expression.
1578 ///
1579 /// By default, builds a new default-argument expression, which does not
1580 /// require any semantic analysis. Subclasses may override this routine to
1581 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001582 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001583 ParmVarDecl *Param) {
1584 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1585 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 }
1587
1588 /// \brief Build a new C++ zero-initialization expression.
1589 ///
1590 /// By default, performs semantic analysis to build the new expression.
1591 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001592 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1593 SourceLocation LParenLoc,
1594 SourceLocation RParenLoc) {
1595 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001596 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001597 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 }
Mike Stump1eb44332009-09-09 15:08:12 +00001599
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 /// \brief Build a new C++ "new" expression.
1601 ///
1602 /// By default, performs semantic analysis to build the new expression.
1603 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001604 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001605 bool UseGlobal,
1606 SourceLocation PlacementLParen,
1607 MultiExprArg PlacementArgs,
1608 SourceLocation PlacementRParen,
1609 SourceRange TypeIdParens,
1610 QualType AllocatedType,
1611 TypeSourceInfo *AllocatedTypeInfo,
1612 Expr *ArraySize,
1613 SourceLocation ConstructorLParen,
1614 MultiExprArg ConstructorArgs,
1615 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001616 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 PlacementLParen,
1618 move(PlacementArgs),
1619 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001620 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001621 AllocatedType,
1622 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001623 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 ConstructorLParen,
1625 move(ConstructorArgs),
1626 ConstructorRParen);
1627 }
Mike Stump1eb44332009-09-09 15:08:12 +00001628
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 /// \brief Build a new C++ "delete" expression.
1630 ///
1631 /// By default, performs semantic analysis to build the new expression.
1632 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001633 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001634 bool IsGlobalDelete,
1635 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001636 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001638 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 }
Mike Stump1eb44332009-09-09 15:08:12 +00001640
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 /// \brief Build a new unary type trait expression.
1642 ///
1643 /// By default, performs semantic analysis to build the new expression.
1644 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001645 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 SourceLocation StartLoc,
1647 SourceLocation LParenLoc,
1648 QualType T,
1649 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001650 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
John McCallb3d87482010-08-24 05:47:05 +00001651 ParsedType::make(T), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 }
1653
Mike Stump1eb44332009-09-09 15:08:12 +00001654 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 /// expression.
1656 ///
1657 /// By default, performs semantic analysis to build the new expression.
1658 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001659 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001661 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001662 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 CXXScopeSpec SS;
1664 SS.setRange(QualifierRange);
1665 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001666
1667 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001668 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001669 *TemplateArgs);
1670
Abramo Bagnara25777432010-08-11 22:01:17 +00001671 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 }
1673
1674 /// \brief Build a new template-id expression.
1675 ///
1676 /// By default, performs semantic analysis to build the new expression.
1677 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001678 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001679 LookupResult &R,
1680 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001681 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001682 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 }
1684
1685 /// \brief Build a new object-construction expression.
1686 ///
1687 /// By default, performs semantic analysis to build the new expression.
1688 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001689 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001690 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 CXXConstructorDecl *Constructor,
1692 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001693 MultiExprArg Args,
1694 bool RequiresZeroInit,
1695 CXXConstructExpr::ConstructionKind ConstructKind) {
John McCallca0408f2010-08-23 06:44:23 +00001696 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001697 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001698 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001699 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001700
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001701 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001702 move_arg(ConvertedArgs),
1703 RequiresZeroInit, ConstructKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 }
1705
1706 /// \brief Build a new object-construction expression.
1707 ///
1708 /// By default, performs semantic analysis to build the new expression.
1709 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001710 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1711 SourceLocation LParenLoc,
1712 MultiExprArg Args,
1713 SourceLocation RParenLoc) {
1714 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001715 LParenLoc,
1716 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 RParenLoc);
1718 }
1719
1720 /// \brief Build a new object-construction expression.
1721 ///
1722 /// By default, performs semantic analysis to build the new expression.
1723 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001724 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1725 SourceLocation LParenLoc,
1726 MultiExprArg Args,
1727 SourceLocation RParenLoc) {
1728 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001729 LParenLoc,
1730 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001731 RParenLoc);
1732 }
Mike Stump1eb44332009-09-09 15:08:12 +00001733
Douglas Gregorb98b1992009-08-11 05:31:07 +00001734 /// \brief Build a new member reference expression.
1735 ///
1736 /// By default, performs semantic analysis to build the new expression.
1737 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001738 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001739 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001740 bool IsArrow,
1741 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001742 NestedNameSpecifier *Qualifier,
1743 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001744 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001745 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001746 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001747 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001748 SS.setRange(QualifierRange);
1749 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001750
John McCall9ae2f072010-08-23 23:25:46 +00001751 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001752 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001753 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001754 MemberNameInfo,
1755 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 }
1757
John McCall129e2df2009-11-30 22:42:35 +00001758 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001759 ///
1760 /// By default, performs semantic analysis to build the new expression.
1761 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001762 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001763 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001764 SourceLocation OperatorLoc,
1765 bool IsArrow,
1766 NestedNameSpecifier *Qualifier,
1767 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001768 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001769 LookupResult &R,
1770 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001771 CXXScopeSpec SS;
1772 SS.setRange(QualifierRange);
1773 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001774
John McCall9ae2f072010-08-23 23:25:46 +00001775 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001776 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001777 SS, FirstQualifierInScope,
1778 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001779 }
Mike Stump1eb44332009-09-09 15:08:12 +00001780
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 /// \brief Build a new Objective-C @encode expression.
1782 ///
1783 /// By default, performs semantic analysis to build the new expression.
1784 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001785 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001786 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001788 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001790 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791
Douglas Gregor92e986e2010-04-22 16:44:27 +00001792 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00001793 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001794 Selector Sel,
1795 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001796 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001797 MultiExprArg Args,
1798 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001799 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1800 ReceiverTypeInfo->getType(),
1801 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001802 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001803 move(Args));
1804 }
1805
1806 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00001807 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001808 Selector Sel,
1809 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001810 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001811 MultiExprArg Args,
1812 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001813 return SemaRef.BuildInstanceMessage(Receiver,
1814 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00001815 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001816 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001817 move(Args));
1818 }
1819
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001820 /// \brief Build a new Objective-C ivar reference expression.
1821 ///
1822 /// By default, performs semantic analysis to build the new expression.
1823 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001824 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001825 SourceLocation IvarLoc,
1826 bool IsArrow, bool IsFreeIvar) {
1827 // FIXME: We lose track of the IsFreeIvar bit.
1828 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001829 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001830 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1831 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001832 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001833 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00001834 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00001835 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001836 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001837 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001838
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001839 if (Result.get())
1840 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001841
John McCall9ae2f072010-08-23 23:25:46 +00001842 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001843 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001844 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001845 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001846 /*TemplateArgs=*/0);
1847 }
Douglas Gregore3303542010-04-26 20:47:02 +00001848
1849 /// \brief Build a new Objective-C property reference expression.
1850 ///
1851 /// By default, performs semantic analysis to build the new expression.
1852 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001853 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001854 ObjCPropertyDecl *Property,
1855 SourceLocation PropertyLoc) {
1856 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001857 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00001858 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1859 Sema::LookupMemberName);
1860 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00001861 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00001862 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00001863 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00001864 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001865 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001866
Douglas Gregore3303542010-04-26 20:47:02 +00001867 if (Result.get())
1868 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001869
John McCall9ae2f072010-08-23 23:25:46 +00001870 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001871 /*FIXME:*/PropertyLoc, IsArrow,
1872 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001873 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001874 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001875 /*TemplateArgs=*/0);
1876 }
Sean Huntc3021132010-05-05 15:23:54 +00001877
1878 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001879 /// expression.
1880 ///
1881 /// By default, performs semantic analysis to build the new expression.
Sean Huntc3021132010-05-05 15:23:54 +00001882 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001883 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001884 ObjCMethodDecl *Getter,
1885 QualType T,
1886 ObjCMethodDecl *Setter,
1887 SourceLocation NameLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001888 Expr *Base) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001889 // Since these expressions can only be value-dependent, we do not need to
1890 // perform semantic analysis again.
John McCall9ae2f072010-08-23 23:25:46 +00001891 return Owned(
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001892 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1893 Setter,
1894 NameLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001895 Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001896 }
1897
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001898 /// \brief Build a new Objective-C "isa" expression.
1899 ///
1900 /// By default, performs semantic analysis to build the new expression.
1901 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001902 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001903 bool IsArrow) {
1904 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001905 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001906 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1907 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001908 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001909 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00001910 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001911 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001912 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001913
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001914 if (Result.get())
1915 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001916
John McCall9ae2f072010-08-23 23:25:46 +00001917 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001918 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001919 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001920 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001921 /*TemplateArgs=*/0);
1922 }
Sean Huntc3021132010-05-05 15:23:54 +00001923
Douglas Gregorb98b1992009-08-11 05:31:07 +00001924 /// \brief Build a new shuffle vector expression.
1925 ///
1926 /// By default, performs semantic analysis to build the new expression.
1927 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001928 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001929 MultiExprArg SubExprs,
1930 SourceLocation RParenLoc) {
1931 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001932 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001933 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1934 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1935 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1936 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001937
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 // Build a reference to the __builtin_shufflevector builtin
1939 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001940 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001941 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001942 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001944
1945 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946 unsigned NumSubExprs = SubExprs.size();
1947 Expr **Subs = (Expr **)SubExprs.release();
1948 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1949 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00001950 Builtin->getCallResultType(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001951 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00001952 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001953
Douglas Gregorb98b1992009-08-11 05:31:07 +00001954 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00001955 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001956 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001957 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001958
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001960 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001961 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001962};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963
Douglas Gregor43959a92009-08-20 07:17:43 +00001964template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00001965StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00001966 if (!S)
1967 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001968
Douglas Gregor43959a92009-08-20 07:17:43 +00001969 switch (S->getStmtClass()) {
1970 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001971
Douglas Gregor43959a92009-08-20 07:17:43 +00001972 // Transform individual statement nodes
1973#define STMT(Node, Parent) \
1974 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1975#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00001976#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001977
Douglas Gregor43959a92009-08-20 07:17:43 +00001978 // Transform expressions by calling TransformExpr.
1979#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00001980#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00001981#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00001982#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00001983 {
John McCall60d7b3a2010-08-24 06:29:42 +00001984 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00001985 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001986 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001987
John McCall9ae2f072010-08-23 23:25:46 +00001988 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00001989 }
Mike Stump1eb44332009-09-09 15:08:12 +00001990 }
1991
Douglas Gregor43959a92009-08-20 07:17:43 +00001992 return SemaRef.Owned(S->Retain());
1993}
Mike Stump1eb44332009-09-09 15:08:12 +00001994
1995
Douglas Gregor670444e2009-08-04 22:27:00 +00001996template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00001997ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001998 if (!E)
1999 return SemaRef.Owned(E);
2000
2001 switch (E->getStmtClass()) {
2002 case Stmt::NoStmtClass: break;
2003#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002004#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002005#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002006 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002007#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002008 }
2009
Douglas Gregorb98b1992009-08-11 05:31:07 +00002010 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002011}
2012
2013template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002014NestedNameSpecifier *
2015TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002016 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002017 QualType ObjectType,
2018 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00002019 if (!NNS)
2020 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002021
Douglas Gregor43959a92009-08-20 07:17:43 +00002022 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002023 NestedNameSpecifier *Prefix = NNS->getPrefix();
2024 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002025 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002026 ObjectType,
2027 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002028 if (!Prefix)
2029 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002030
2031 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00002032 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00002033 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00002034 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002035 }
Mike Stump1eb44332009-09-09 15:08:12 +00002036
Douglas Gregordcee1a12009-08-06 05:28:30 +00002037 switch (NNS->getKind()) {
2038 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00002039 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002040 "Identifier nested-name-specifier with no prefix or object type");
2041 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2042 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002043 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002044
2045 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002046 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002047 ObjectType,
2048 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002049
Douglas Gregordcee1a12009-08-06 05:28:30 +00002050 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002051 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002052 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002053 getDerived().TransformDecl(Range.getBegin(),
2054 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002055 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002056 Prefix == NNS->getPrefix() &&
2057 NS == NNS->getAsNamespace())
2058 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002059
Douglas Gregordcee1a12009-08-06 05:28:30 +00002060 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2061 }
Mike Stump1eb44332009-09-09 15:08:12 +00002062
Douglas Gregordcee1a12009-08-06 05:28:30 +00002063 case NestedNameSpecifier::Global:
2064 // There is no meaningful transformation that one could perform on the
2065 // global scope.
2066 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002067
Douglas Gregordcee1a12009-08-06 05:28:30 +00002068 case NestedNameSpecifier::TypeSpecWithTemplate:
2069 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002070 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00002071 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2072 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002073 if (T.isNull())
2074 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002075
Douglas Gregordcee1a12009-08-06 05:28:30 +00002076 if (!getDerived().AlwaysRebuild() &&
2077 Prefix == NNS->getPrefix() &&
2078 T == QualType(NNS->getAsType(), 0))
2079 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002080
2081 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2082 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002083 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002084 }
2085 }
Mike Stump1eb44332009-09-09 15:08:12 +00002086
Douglas Gregordcee1a12009-08-06 05:28:30 +00002087 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002088 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002089}
2090
2091template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002092DeclarationNameInfo
2093TreeTransform<Derived>
2094::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2095 QualType ObjectType) {
2096 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002097 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002098 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002099
2100 switch (Name.getNameKind()) {
2101 case DeclarationName::Identifier:
2102 case DeclarationName::ObjCZeroArgSelector:
2103 case DeclarationName::ObjCOneArgSelector:
2104 case DeclarationName::ObjCMultiArgSelector:
2105 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002106 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002107 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002108 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002109
Douglas Gregor81499bb2009-09-03 22:13:48 +00002110 case DeclarationName::CXXConstructorName:
2111 case DeclarationName::CXXDestructorName:
2112 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002113 TypeSourceInfo *NewTInfo;
2114 CanQualType NewCanTy;
2115 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2116 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2117 if (!NewTInfo)
2118 return DeclarationNameInfo();
2119 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2120 }
2121 else {
2122 NewTInfo = 0;
2123 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2124 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2125 ObjectType);
2126 if (NewT.isNull())
2127 return DeclarationNameInfo();
2128 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2129 }
Mike Stump1eb44332009-09-09 15:08:12 +00002130
Abramo Bagnara25777432010-08-11 22:01:17 +00002131 DeclarationName NewName
2132 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2133 NewCanTy);
2134 DeclarationNameInfo NewNameInfo(NameInfo);
2135 NewNameInfo.setName(NewName);
2136 NewNameInfo.setNamedTypeInfo(NewTInfo);
2137 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002138 }
Mike Stump1eb44332009-09-09 15:08:12 +00002139 }
2140
Abramo Bagnara25777432010-08-11 22:01:17 +00002141 assert(0 && "Unknown name kind.");
2142 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002143}
2144
2145template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002146TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002147TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2148 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002149 SourceLocation Loc = getDerived().getBaseLocation();
2150
Douglas Gregord1067e52009-08-06 06:41:21 +00002151 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002152 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002153 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002154 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2155 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002156 if (!NNS)
2157 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002158
Douglas Gregord1067e52009-08-06 06:41:21 +00002159 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002160 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002161 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002162 if (!TransTemplate)
2163 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002164
Douglas Gregord1067e52009-08-06 06:41:21 +00002165 if (!getDerived().AlwaysRebuild() &&
2166 NNS == QTN->getQualifier() &&
2167 TransTemplate == Template)
2168 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002169
Douglas Gregord1067e52009-08-06 06:41:21 +00002170 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2171 TransTemplate);
2172 }
Mike Stump1eb44332009-09-09 15:08:12 +00002173
John McCallf7a1a742009-11-24 19:00:30 +00002174 // These should be getting filtered out before they make it into the AST.
2175 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002176 }
Mike Stump1eb44332009-09-09 15:08:12 +00002177
Douglas Gregord1067e52009-08-06 06:41:21 +00002178 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002179 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002180 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002181 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2182 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002183 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00002184 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002185
Douglas Gregord1067e52009-08-06 06:41:21 +00002186 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002187 NNS == DTN->getQualifier() &&
2188 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002189 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002190
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002191 if (DTN->isIdentifier()) {
2192 // FIXME: Bad range
2193 SourceRange QualifierRange(getDerived().getBaseLocation());
2194 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2195 *DTN->getIdentifier(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002196 ObjectType);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002197 }
Sean Huntc3021132010-05-05 15:23:54 +00002198
2199 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002200 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002201 }
Mike Stump1eb44332009-09-09 15:08:12 +00002202
Douglas Gregord1067e52009-08-06 06:41:21 +00002203 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002204 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002205 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002206 if (!TransTemplate)
2207 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002208
Douglas Gregord1067e52009-08-06 06:41:21 +00002209 if (!getDerived().AlwaysRebuild() &&
2210 TransTemplate == Template)
2211 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002212
Douglas Gregord1067e52009-08-06 06:41:21 +00002213 return TemplateName(TransTemplate);
2214 }
Mike Stump1eb44332009-09-09 15:08:12 +00002215
John McCallf7a1a742009-11-24 19:00:30 +00002216 // These should be getting filtered out before they reach the AST.
2217 assert(false && "overloaded function decl survived to here");
2218 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002219}
2220
2221template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002222void TreeTransform<Derived>::InventTemplateArgumentLoc(
2223 const TemplateArgument &Arg,
2224 TemplateArgumentLoc &Output) {
2225 SourceLocation Loc = getDerived().getBaseLocation();
2226 switch (Arg.getKind()) {
2227 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002228 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002229 break;
2230
2231 case TemplateArgument::Type:
2232 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002233 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002234
John McCall833ca992009-10-29 08:12:44 +00002235 break;
2236
Douglas Gregor788cd062009-11-11 01:00:40 +00002237 case TemplateArgument::Template:
2238 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2239 break;
Sean Huntc3021132010-05-05 15:23:54 +00002240
John McCall833ca992009-10-29 08:12:44 +00002241 case TemplateArgument::Expression:
2242 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2243 break;
2244
2245 case TemplateArgument::Declaration:
2246 case TemplateArgument::Integral:
2247 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002248 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002249 break;
2250 }
2251}
2252
2253template<typename Derived>
2254bool TreeTransform<Derived>::TransformTemplateArgument(
2255 const TemplateArgumentLoc &Input,
2256 TemplateArgumentLoc &Output) {
2257 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002258 switch (Arg.getKind()) {
2259 case TemplateArgument::Null:
2260 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002261 Output = Input;
2262 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002263
Douglas Gregor670444e2009-08-04 22:27:00 +00002264 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002265 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002266 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002267 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002268
2269 DI = getDerived().TransformType(DI);
2270 if (!DI) return true;
2271
2272 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2273 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002274 }
Mike Stump1eb44332009-09-09 15:08:12 +00002275
Douglas Gregor670444e2009-08-04 22:27:00 +00002276 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002277 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002278 DeclarationName Name;
2279 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2280 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002281 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002282 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002283 if (!D) return true;
2284
John McCall828bff22009-10-29 18:45:58 +00002285 Expr *SourceExpr = Input.getSourceDeclExpression();
2286 if (SourceExpr) {
2287 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002288 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002289 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002290 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002291 }
2292
2293 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002294 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002295 }
Mike Stump1eb44332009-09-09 15:08:12 +00002296
Douglas Gregor788cd062009-11-11 01:00:40 +00002297 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002298 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002299 TemplateName Template
2300 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2301 if (Template.isNull())
2302 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002303
Douglas Gregor788cd062009-11-11 01:00:40 +00002304 Output = TemplateArgumentLoc(TemplateArgument(Template),
2305 Input.getTemplateQualifierRange(),
2306 Input.getTemplateNameLoc());
2307 return false;
2308 }
Sean Huntc3021132010-05-05 15:23:54 +00002309
Douglas Gregor670444e2009-08-04 22:27:00 +00002310 case TemplateArgument::Expression: {
2311 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002312 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002313 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002314
John McCall833ca992009-10-29 08:12:44 +00002315 Expr *InputExpr = Input.getSourceExpression();
2316 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2317
John McCall60d7b3a2010-08-24 06:29:42 +00002318 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002319 = getDerived().TransformExpr(InputExpr);
2320 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002321 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002322 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002323 }
Mike Stump1eb44332009-09-09 15:08:12 +00002324
Douglas Gregor670444e2009-08-04 22:27:00 +00002325 case TemplateArgument::Pack: {
2326 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2327 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002328 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002329 AEnd = Arg.pack_end();
2330 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002331
John McCall833ca992009-10-29 08:12:44 +00002332 // FIXME: preserve source information here when we start
2333 // caring about parameter packs.
2334
John McCall828bff22009-10-29 18:45:58 +00002335 TemplateArgumentLoc InputArg;
2336 TemplateArgumentLoc OutputArg;
2337 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2338 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002339 return true;
2340
John McCall828bff22009-10-29 18:45:58 +00002341 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002342 }
2343 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002344 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002345 true);
John McCall828bff22009-10-29 18:45:58 +00002346 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002347 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002348 }
2349 }
Mike Stump1eb44332009-09-09 15:08:12 +00002350
Douglas Gregor670444e2009-08-04 22:27:00 +00002351 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002352 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002353}
2354
Douglas Gregor577f75a2009-08-04 16:50:30 +00002355//===----------------------------------------------------------------------===//
2356// Type transformation
2357//===----------------------------------------------------------------------===//
2358
2359template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00002360QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregor124b8782010-02-16 19:09:40 +00002361 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002362 if (getDerived().AlreadyTransformed(T))
2363 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002364
John McCalla2becad2009-10-21 00:40:46 +00002365 // Temporary workaround. All of these transformations should
2366 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002367 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002368 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002369
Douglas Gregor124b8782010-02-16 19:09:40 +00002370 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002371
John McCalla2becad2009-10-21 00:40:46 +00002372 if (!NewDI)
2373 return QualType();
2374
2375 return NewDI->getType();
2376}
2377
2378template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002379TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2380 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002381 if (getDerived().AlreadyTransformed(DI->getType()))
2382 return DI;
2383
2384 TypeLocBuilder TLB;
2385
2386 TypeLoc TL = DI->getTypeLoc();
2387 TLB.reserve(TL.getFullDataSize());
2388
Douglas Gregor124b8782010-02-16 19:09:40 +00002389 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002390 if (Result.isNull())
2391 return 0;
2392
John McCalla93c9342009-12-07 02:54:59 +00002393 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002394}
2395
2396template<typename Derived>
2397QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002398TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2399 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002400 switch (T.getTypeLocClass()) {
2401#define ABSTRACT_TYPELOC(CLASS, PARENT)
2402#define TYPELOC(CLASS, PARENT) \
2403 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002404 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2405 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002406#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002407 }
Mike Stump1eb44332009-09-09 15:08:12 +00002408
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002409 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002410 return QualType();
2411}
2412
2413/// FIXME: By default, this routine adds type qualifiers only to types
2414/// that can have qualifiers, and silently suppresses those qualifiers
2415/// that are not permitted (e.g., qualifiers on reference or function
2416/// types). This is the right thing for template instantiation, but
2417/// probably not for other clients.
2418template<typename Derived>
2419QualType
2420TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002421 QualifiedTypeLoc T,
2422 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002423 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002424
Douglas Gregor124b8782010-02-16 19:09:40 +00002425 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2426 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002427 if (Result.isNull())
2428 return QualType();
2429
2430 // Silently suppress qualifiers if the result type can't be qualified.
2431 // FIXME: this is the right thing for template instantiation, but
2432 // probably not for other clients.
2433 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002434 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002435
John McCall28654742010-06-05 06:41:15 +00002436 if (!Quals.empty()) {
2437 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2438 TLB.push<QualifiedTypeLoc>(Result);
2439 // No location information to preserve.
2440 }
John McCalla2becad2009-10-21 00:40:46 +00002441
2442 return Result;
2443}
2444
2445template <class TyLoc> static inline
2446QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2447 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2448 NewT.setNameLoc(T.getNameLoc());
2449 return T.getType();
2450}
2451
John McCalla2becad2009-10-21 00:40:46 +00002452template<typename Derived>
2453QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002454 BuiltinTypeLoc T,
2455 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002456 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2457 NewT.setBuiltinLoc(T.getBuiltinLoc());
2458 if (T.needsExtraLocalData())
2459 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2460 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002461}
Mike Stump1eb44332009-09-09 15:08:12 +00002462
Douglas Gregor577f75a2009-08-04 16:50:30 +00002463template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002464QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002465 ComplexTypeLoc T,
2466 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002467 // FIXME: recurse?
2468 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002469}
Mike Stump1eb44332009-09-09 15:08:12 +00002470
Douglas Gregor577f75a2009-08-04 16:50:30 +00002471template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002472QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Sean Huntc3021132010-05-05 15:23:54 +00002473 PointerTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00002474 QualType ObjectType) {
Sean Huntc3021132010-05-05 15:23:54 +00002475 QualType PointeeType
2476 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002477 if (PointeeType.isNull())
2478 return QualType();
2479
2480 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002481 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002482 // A dependent pointer type 'T *' has is being transformed such
2483 // that an Objective-C class type is being replaced for 'T'. The
2484 // resulting pointer type is an ObjCObjectPointerType, not a
2485 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002486 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002487
John McCallc12c5bb2010-05-15 11:32:37 +00002488 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2489 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002490 return Result;
2491 }
Sean Huntc3021132010-05-05 15:23:54 +00002492
Douglas Gregor92e986e2010-04-22 16:44:27 +00002493 if (getDerived().AlwaysRebuild() ||
2494 PointeeType != TL.getPointeeLoc().getType()) {
2495 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2496 if (Result.isNull())
2497 return QualType();
2498 }
Sean Huntc3021132010-05-05 15:23:54 +00002499
Douglas Gregor92e986e2010-04-22 16:44:27 +00002500 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2501 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002502 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002503}
Mike Stump1eb44332009-09-09 15:08:12 +00002504
2505template<typename Derived>
2506QualType
John McCalla2becad2009-10-21 00:40:46 +00002507TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002508 BlockPointerTypeLoc TL,
2509 QualType ObjectType) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002510 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002511 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2512 if (PointeeType.isNull())
2513 return QualType();
2514
2515 QualType Result = TL.getType();
2516 if (getDerived().AlwaysRebuild() ||
2517 PointeeType != TL.getPointeeLoc().getType()) {
2518 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002519 TL.getSigilLoc());
2520 if (Result.isNull())
2521 return QualType();
2522 }
2523
Douglas Gregor39968ad2010-04-22 16:50:51 +00002524 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002525 NewT.setSigilLoc(TL.getSigilLoc());
2526 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002527}
2528
John McCall85737a72009-10-30 00:06:24 +00002529/// Transforms a reference type. Note that somewhat paradoxically we
2530/// don't care whether the type itself is an l-value type or an r-value
2531/// type; we only care if the type was *written* as an l-value type
2532/// or an r-value type.
2533template<typename Derived>
2534QualType
2535TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002536 ReferenceTypeLoc TL,
2537 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002538 const ReferenceType *T = TL.getTypePtr();
2539
2540 // Note that this works with the pointee-as-written.
2541 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2542 if (PointeeType.isNull())
2543 return QualType();
2544
2545 QualType Result = TL.getType();
2546 if (getDerived().AlwaysRebuild() ||
2547 PointeeType != T->getPointeeTypeAsWritten()) {
2548 Result = getDerived().RebuildReferenceType(PointeeType,
2549 T->isSpelledAsLValue(),
2550 TL.getSigilLoc());
2551 if (Result.isNull())
2552 return QualType();
2553 }
2554
2555 // r-value references can be rebuilt as l-value references.
2556 ReferenceTypeLoc NewTL;
2557 if (isa<LValueReferenceType>(Result))
2558 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2559 else
2560 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2561 NewTL.setSigilLoc(TL.getSigilLoc());
2562
2563 return Result;
2564}
2565
Mike Stump1eb44332009-09-09 15:08:12 +00002566template<typename Derived>
2567QualType
John McCalla2becad2009-10-21 00:40:46 +00002568TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002569 LValueReferenceTypeLoc TL,
2570 QualType ObjectType) {
2571 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002572}
2573
Mike Stump1eb44332009-09-09 15:08:12 +00002574template<typename Derived>
2575QualType
John McCalla2becad2009-10-21 00:40:46 +00002576TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002577 RValueReferenceTypeLoc TL,
2578 QualType ObjectType) {
2579 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002580}
Mike Stump1eb44332009-09-09 15:08:12 +00002581
Douglas Gregor577f75a2009-08-04 16:50:30 +00002582template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002583QualType
John McCalla2becad2009-10-21 00:40:46 +00002584TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002585 MemberPointerTypeLoc TL,
2586 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002587 MemberPointerType *T = TL.getTypePtr();
2588
2589 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002590 if (PointeeType.isNull())
2591 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002592
John McCalla2becad2009-10-21 00:40:46 +00002593 // TODO: preserve source information for this.
2594 QualType ClassType
2595 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002596 if (ClassType.isNull())
2597 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002598
John McCalla2becad2009-10-21 00:40:46 +00002599 QualType Result = TL.getType();
2600 if (getDerived().AlwaysRebuild() ||
2601 PointeeType != T->getPointeeType() ||
2602 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002603 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2604 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002605 if (Result.isNull())
2606 return QualType();
2607 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002608
John McCalla2becad2009-10-21 00:40:46 +00002609 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2610 NewTL.setSigilLoc(TL.getSigilLoc());
2611
2612 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002613}
2614
Mike Stump1eb44332009-09-09 15:08:12 +00002615template<typename Derived>
2616QualType
John McCalla2becad2009-10-21 00:40:46 +00002617TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002618 ConstantArrayTypeLoc TL,
2619 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002620 ConstantArrayType *T = TL.getTypePtr();
2621 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002622 if (ElementType.isNull())
2623 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002624
John McCalla2becad2009-10-21 00:40:46 +00002625 QualType Result = TL.getType();
2626 if (getDerived().AlwaysRebuild() ||
2627 ElementType != T->getElementType()) {
2628 Result = getDerived().RebuildConstantArrayType(ElementType,
2629 T->getSizeModifier(),
2630 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002631 T->getIndexTypeCVRQualifiers(),
2632 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002633 if (Result.isNull())
2634 return QualType();
2635 }
Sean Huntc3021132010-05-05 15:23:54 +00002636
John McCalla2becad2009-10-21 00:40:46 +00002637 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2638 NewTL.setLBracketLoc(TL.getLBracketLoc());
2639 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002640
John McCalla2becad2009-10-21 00:40:46 +00002641 Expr *Size = TL.getSizeExpr();
2642 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00002643 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002644 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2645 }
2646 NewTL.setSizeExpr(Size);
2647
2648 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002649}
Mike Stump1eb44332009-09-09 15:08:12 +00002650
Douglas Gregor577f75a2009-08-04 16:50:30 +00002651template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002652QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002653 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002654 IncompleteArrayTypeLoc TL,
2655 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002656 IncompleteArrayType *T = TL.getTypePtr();
2657 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002658 if (ElementType.isNull())
2659 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002660
John McCalla2becad2009-10-21 00:40:46 +00002661 QualType Result = TL.getType();
2662 if (getDerived().AlwaysRebuild() ||
2663 ElementType != T->getElementType()) {
2664 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002665 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002666 T->getIndexTypeCVRQualifiers(),
2667 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002668 if (Result.isNull())
2669 return QualType();
2670 }
Sean Huntc3021132010-05-05 15:23:54 +00002671
John McCalla2becad2009-10-21 00:40:46 +00002672 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2673 NewTL.setLBracketLoc(TL.getLBracketLoc());
2674 NewTL.setRBracketLoc(TL.getRBracketLoc());
2675 NewTL.setSizeExpr(0);
2676
2677 return Result;
2678}
2679
2680template<typename Derived>
2681QualType
2682TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002683 VariableArrayTypeLoc TL,
2684 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002685 VariableArrayType *T = TL.getTypePtr();
2686 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2687 if (ElementType.isNull())
2688 return QualType();
2689
2690 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002691 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002692
John McCall60d7b3a2010-08-24 06:29:42 +00002693 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002694 = getDerived().TransformExpr(T->getSizeExpr());
2695 if (SizeResult.isInvalid())
2696 return QualType();
2697
John McCall9ae2f072010-08-23 23:25:46 +00002698 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00002699
2700 QualType Result = TL.getType();
2701 if (getDerived().AlwaysRebuild() ||
2702 ElementType != T->getElementType() ||
2703 Size != T->getSizeExpr()) {
2704 Result = getDerived().RebuildVariableArrayType(ElementType,
2705 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002706 Size,
John McCalla2becad2009-10-21 00:40:46 +00002707 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002708 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002709 if (Result.isNull())
2710 return QualType();
2711 }
Sean Huntc3021132010-05-05 15:23:54 +00002712
John McCalla2becad2009-10-21 00:40:46 +00002713 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2714 NewTL.setLBracketLoc(TL.getLBracketLoc());
2715 NewTL.setRBracketLoc(TL.getRBracketLoc());
2716 NewTL.setSizeExpr(Size);
2717
2718 return Result;
2719}
2720
2721template<typename Derived>
2722QualType
2723TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002724 DependentSizedArrayTypeLoc TL,
2725 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002726 DependentSizedArrayType *T = TL.getTypePtr();
2727 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2728 if (ElementType.isNull())
2729 return QualType();
2730
2731 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002732 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002733
John McCall60d7b3a2010-08-24 06:29:42 +00002734 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002735 = getDerived().TransformExpr(T->getSizeExpr());
2736 if (SizeResult.isInvalid())
2737 return QualType();
2738
2739 Expr *Size = static_cast<Expr*>(SizeResult.get());
2740
2741 QualType Result = TL.getType();
2742 if (getDerived().AlwaysRebuild() ||
2743 ElementType != T->getElementType() ||
2744 Size != T->getSizeExpr()) {
2745 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2746 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002747 Size,
John McCalla2becad2009-10-21 00:40:46 +00002748 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002749 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002750 if (Result.isNull())
2751 return QualType();
2752 }
2753 else SizeResult.take();
2754
2755 // We might have any sort of array type now, but fortunately they
2756 // all have the same location layout.
2757 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2758 NewTL.setLBracketLoc(TL.getLBracketLoc());
2759 NewTL.setRBracketLoc(TL.getRBracketLoc());
2760 NewTL.setSizeExpr(Size);
2761
2762 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002763}
Mike Stump1eb44332009-09-09 15:08:12 +00002764
2765template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002766QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002767 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002768 DependentSizedExtVectorTypeLoc TL,
2769 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002770 DependentSizedExtVectorType *T = TL.getTypePtr();
2771
2772 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002773 QualType ElementType = getDerived().TransformType(T->getElementType());
2774 if (ElementType.isNull())
2775 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002776
Douglas Gregor670444e2009-08-04 22:27:00 +00002777 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002778 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00002779
John McCall60d7b3a2010-08-24 06:29:42 +00002780 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002781 if (Size.isInvalid())
2782 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002783
John McCalla2becad2009-10-21 00:40:46 +00002784 QualType Result = TL.getType();
2785 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002786 ElementType != T->getElementType() ||
2787 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002788 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00002789 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00002790 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002791 if (Result.isNull())
2792 return QualType();
2793 }
John McCalla2becad2009-10-21 00:40:46 +00002794
2795 // Result might be dependent or not.
2796 if (isa<DependentSizedExtVectorType>(Result)) {
2797 DependentSizedExtVectorTypeLoc NewTL
2798 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2799 NewTL.setNameLoc(TL.getNameLoc());
2800 } else {
2801 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2802 NewTL.setNameLoc(TL.getNameLoc());
2803 }
2804
2805 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002806}
Mike Stump1eb44332009-09-09 15:08:12 +00002807
2808template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002809QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002810 VectorTypeLoc TL,
2811 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002812 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002813 QualType ElementType = getDerived().TransformType(T->getElementType());
2814 if (ElementType.isNull())
2815 return QualType();
2816
John McCalla2becad2009-10-21 00:40:46 +00002817 QualType Result = TL.getType();
2818 if (getDerived().AlwaysRebuild() ||
2819 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002820 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner788b0fd2010-06-23 06:00:24 +00002821 T->getAltiVecSpecific());
John McCalla2becad2009-10-21 00:40:46 +00002822 if (Result.isNull())
2823 return QualType();
2824 }
Sean Huntc3021132010-05-05 15:23:54 +00002825
John McCalla2becad2009-10-21 00:40:46 +00002826 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2827 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002828
John McCalla2becad2009-10-21 00:40:46 +00002829 return Result;
2830}
2831
2832template<typename Derived>
2833QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002834 ExtVectorTypeLoc TL,
2835 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002836 VectorType *T = TL.getTypePtr();
2837 QualType ElementType = getDerived().TransformType(T->getElementType());
2838 if (ElementType.isNull())
2839 return QualType();
2840
2841 QualType Result = TL.getType();
2842 if (getDerived().AlwaysRebuild() ||
2843 ElementType != T->getElementType()) {
2844 Result = getDerived().RebuildExtVectorType(ElementType,
2845 T->getNumElements(),
2846 /*FIXME*/ SourceLocation());
2847 if (Result.isNull())
2848 return QualType();
2849 }
Sean Huntc3021132010-05-05 15:23:54 +00002850
John McCalla2becad2009-10-21 00:40:46 +00002851 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2852 NewTL.setNameLoc(TL.getNameLoc());
2853
2854 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002855}
Mike Stump1eb44332009-09-09 15:08:12 +00002856
2857template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002858ParmVarDecl *
2859TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2860 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2861 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2862 if (!NewDI)
2863 return 0;
2864
2865 if (NewDI == OldDI)
2866 return OldParm;
2867 else
2868 return ParmVarDecl::Create(SemaRef.Context,
2869 OldParm->getDeclContext(),
2870 OldParm->getLocation(),
2871 OldParm->getIdentifier(),
2872 NewDI->getType(),
2873 NewDI,
2874 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002875 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002876 /* DefArg */ NULL);
2877}
2878
2879template<typename Derived>
2880bool TreeTransform<Derived>::
2881 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2882 llvm::SmallVectorImpl<QualType> &PTypes,
2883 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2884 FunctionProtoType *T = TL.getTypePtr();
2885
2886 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2887 ParmVarDecl *OldParm = TL.getArg(i);
2888
2889 QualType NewType;
2890 ParmVarDecl *NewParm;
2891
2892 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002893 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2894 if (!NewParm)
2895 return true;
2896 NewType = NewParm->getType();
2897
2898 // Deal with the possibility that we don't have a parameter
2899 // declaration for this parameter.
2900 } else {
2901 NewParm = 0;
2902
2903 QualType OldType = T->getArgType(i);
2904 NewType = getDerived().TransformType(OldType);
2905 if (NewType.isNull())
2906 return true;
2907 }
2908
2909 PTypes.push_back(NewType);
2910 PVars.push_back(NewParm);
2911 }
2912
2913 return false;
2914}
2915
2916template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002917QualType
John McCalla2becad2009-10-21 00:40:46 +00002918TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002919 FunctionProtoTypeLoc TL,
2920 QualType ObjectType) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00002921 // Transform the parameters and return type.
2922 //
2923 // We instantiate in source order, with the return type first followed by
2924 // the parameters, because users tend to expect this (even if they shouldn't
2925 // rely on it!).
2926 //
2927 // FIXME: When we implement late-specified return types, we'll need to
2928 // instantiate the return tpe *after* the parameter types in that case,
2929 // since the return type can then refer to the parameters themselves (via
2930 // decltype, sizeof, etc.).
Douglas Gregor577f75a2009-08-04 16:50:30 +00002931 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002932 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor895162d2010-04-30 18:55:50 +00002933 FunctionProtoType *T = TL.getTypePtr();
2934 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2935 if (ResultType.isNull())
2936 return QualType();
Douglas Gregor7e010a02010-08-31 00:26:14 +00002937
2938 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2939 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002940
John McCalla2becad2009-10-21 00:40:46 +00002941 QualType Result = TL.getType();
2942 if (getDerived().AlwaysRebuild() ||
2943 ResultType != T->getResultType() ||
2944 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2945 Result = getDerived().RebuildFunctionProtoType(ResultType,
2946 ParamTypes.data(),
2947 ParamTypes.size(),
2948 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00002949 T->getTypeQuals(),
2950 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00002951 if (Result.isNull())
2952 return QualType();
2953 }
Mike Stump1eb44332009-09-09 15:08:12 +00002954
John McCalla2becad2009-10-21 00:40:46 +00002955 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2956 NewTL.setLParenLoc(TL.getLParenLoc());
2957 NewTL.setRParenLoc(TL.getRParenLoc());
2958 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2959 NewTL.setArg(i, ParamDecls[i]);
2960
2961 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002962}
Mike Stump1eb44332009-09-09 15:08:12 +00002963
Douglas Gregor577f75a2009-08-04 16:50:30 +00002964template<typename Derived>
2965QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002966 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002967 FunctionNoProtoTypeLoc TL,
2968 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002969 FunctionNoProtoType *T = TL.getTypePtr();
2970 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2971 if (ResultType.isNull())
2972 return QualType();
2973
2974 QualType Result = TL.getType();
2975 if (getDerived().AlwaysRebuild() ||
2976 ResultType != T->getResultType())
2977 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2978
2979 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2980 NewTL.setLParenLoc(TL.getLParenLoc());
2981 NewTL.setRParenLoc(TL.getRParenLoc());
2982
2983 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002984}
Mike Stump1eb44332009-09-09 15:08:12 +00002985
John McCalled976492009-12-04 22:46:56 +00002986template<typename Derived> QualType
2987TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002988 UnresolvedUsingTypeLoc TL,
2989 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00002990 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002991 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00002992 if (!D)
2993 return QualType();
2994
2995 QualType Result = TL.getType();
2996 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2997 Result = getDerived().RebuildUnresolvedUsingType(D);
2998 if (Result.isNull())
2999 return QualType();
3000 }
3001
3002 // We might get an arbitrary type spec type back. We should at
3003 // least always get a type spec type, though.
3004 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3005 NewTL.setNameLoc(TL.getNameLoc());
3006
3007 return Result;
3008}
3009
Douglas Gregor577f75a2009-08-04 16:50:30 +00003010template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003011QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003012 TypedefTypeLoc TL,
3013 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003014 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003015 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003016 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3017 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003018 if (!Typedef)
3019 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003020
John McCalla2becad2009-10-21 00:40:46 +00003021 QualType Result = TL.getType();
3022 if (getDerived().AlwaysRebuild() ||
3023 Typedef != T->getDecl()) {
3024 Result = getDerived().RebuildTypedefType(Typedef);
3025 if (Result.isNull())
3026 return QualType();
3027 }
Mike Stump1eb44332009-09-09 15:08:12 +00003028
John McCalla2becad2009-10-21 00:40:46 +00003029 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3030 NewTL.setNameLoc(TL.getNameLoc());
3031
3032 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003033}
Mike Stump1eb44332009-09-09 15:08:12 +00003034
Douglas Gregor577f75a2009-08-04 16:50:30 +00003035template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003036QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003037 TypeOfExprTypeLoc TL,
3038 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003039 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003040 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003041
John McCall60d7b3a2010-08-24 06:29:42 +00003042 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003043 if (E.isInvalid())
3044 return QualType();
3045
John McCalla2becad2009-10-21 00:40:46 +00003046 QualType Result = TL.getType();
3047 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003048 E.get() != TL.getUnderlyingExpr()) {
John McCall9ae2f072010-08-23 23:25:46 +00003049 Result = getDerived().RebuildTypeOfExprType(E.get());
John McCalla2becad2009-10-21 00:40:46 +00003050 if (Result.isNull())
3051 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003052 }
John McCalla2becad2009-10-21 00:40:46 +00003053 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003054
John McCalla2becad2009-10-21 00:40:46 +00003055 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003056 NewTL.setTypeofLoc(TL.getTypeofLoc());
3057 NewTL.setLParenLoc(TL.getLParenLoc());
3058 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003059
3060 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003061}
Mike Stump1eb44332009-09-09 15:08:12 +00003062
3063template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003064QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003065 TypeOfTypeLoc TL,
3066 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00003067 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3068 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3069 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003070 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003071
John McCalla2becad2009-10-21 00:40:46 +00003072 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003073 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3074 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003075 if (Result.isNull())
3076 return QualType();
3077 }
Mike Stump1eb44332009-09-09 15:08:12 +00003078
John McCalla2becad2009-10-21 00:40:46 +00003079 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003080 NewTL.setTypeofLoc(TL.getTypeofLoc());
3081 NewTL.setLParenLoc(TL.getLParenLoc());
3082 NewTL.setRParenLoc(TL.getRParenLoc());
3083 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003084
3085 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003086}
Mike Stump1eb44332009-09-09 15:08:12 +00003087
3088template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003089QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003090 DecltypeTypeLoc TL,
3091 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003092 DecltypeType *T = TL.getTypePtr();
3093
Douglas Gregor670444e2009-08-04 22:27:00 +00003094 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003095 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003096
John McCall60d7b3a2010-08-24 06:29:42 +00003097 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003098 if (E.isInvalid())
3099 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003100
John McCalla2becad2009-10-21 00:40:46 +00003101 QualType Result = TL.getType();
3102 if (getDerived().AlwaysRebuild() ||
3103 E.get() != T->getUnderlyingExpr()) {
John McCall9ae2f072010-08-23 23:25:46 +00003104 Result = getDerived().RebuildDecltypeType(E.get());
John McCalla2becad2009-10-21 00:40:46 +00003105 if (Result.isNull())
3106 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003107 }
John McCalla2becad2009-10-21 00:40:46 +00003108 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003109
John McCalla2becad2009-10-21 00:40:46 +00003110 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3111 NewTL.setNameLoc(TL.getNameLoc());
3112
3113 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003114}
3115
3116template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003117QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003118 RecordTypeLoc TL,
3119 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003120 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003121 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003122 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3123 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003124 if (!Record)
3125 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003126
John McCalla2becad2009-10-21 00:40:46 +00003127 QualType Result = TL.getType();
3128 if (getDerived().AlwaysRebuild() ||
3129 Record != T->getDecl()) {
3130 Result = getDerived().RebuildRecordType(Record);
3131 if (Result.isNull())
3132 return QualType();
3133 }
Mike Stump1eb44332009-09-09 15:08:12 +00003134
John McCalla2becad2009-10-21 00:40:46 +00003135 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3136 NewTL.setNameLoc(TL.getNameLoc());
3137
3138 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003139}
Mike Stump1eb44332009-09-09 15:08:12 +00003140
3141template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003142QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003143 EnumTypeLoc TL,
3144 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003145 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003146 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003147 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3148 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003149 if (!Enum)
3150 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003151
John McCalla2becad2009-10-21 00:40:46 +00003152 QualType Result = TL.getType();
3153 if (getDerived().AlwaysRebuild() ||
3154 Enum != T->getDecl()) {
3155 Result = getDerived().RebuildEnumType(Enum);
3156 if (Result.isNull())
3157 return QualType();
3158 }
Mike Stump1eb44332009-09-09 15:08:12 +00003159
John McCalla2becad2009-10-21 00:40:46 +00003160 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3161 NewTL.setNameLoc(TL.getNameLoc());
3162
3163 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003164}
John McCall7da24312009-09-05 00:15:47 +00003165
John McCall3cb0ebd2010-03-10 03:28:59 +00003166template<typename Derived>
3167QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3168 TypeLocBuilder &TLB,
3169 InjectedClassNameTypeLoc TL,
3170 QualType ObjectType) {
3171 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3172 TL.getTypePtr()->getDecl());
3173 if (!D) return QualType();
3174
3175 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3176 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3177 return T;
3178}
3179
Mike Stump1eb44332009-09-09 15:08:12 +00003180
Douglas Gregor577f75a2009-08-04 16:50:30 +00003181template<typename Derived>
3182QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003183 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003184 TemplateTypeParmTypeLoc TL,
3185 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003186 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003187}
3188
Mike Stump1eb44332009-09-09 15:08:12 +00003189template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003190QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003191 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003192 SubstTemplateTypeParmTypeLoc TL,
3193 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003194 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003195}
3196
3197template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003198QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3199 const TemplateSpecializationType *TST,
3200 QualType ObjectType) {
3201 // FIXME: this entire method is a temporary workaround; callers
3202 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00003203
John McCall833ca992009-10-29 08:12:44 +00003204 // Fake up a TemplateSpecializationTypeLoc.
3205 TypeLocBuilder TLB;
3206 TemplateSpecializationTypeLoc TL
3207 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3208
John McCall828bff22009-10-29 18:45:58 +00003209 SourceLocation BaseLoc = getDerived().getBaseLocation();
3210
3211 TL.setTemplateNameLoc(BaseLoc);
3212 TL.setLAngleLoc(BaseLoc);
3213 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00003214 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3215 const TemplateArgument &TA = TST->getArg(i);
3216 TemplateArgumentLoc TAL;
3217 getDerived().InventTemplateArgumentLoc(TA, TAL);
3218 TL.setArgLocInfo(i, TAL.getLocInfo());
3219 }
3220
3221 TypeLocBuilder IgnoredTLB;
3222 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00003223}
Sean Huntc3021132010-05-05 15:23:54 +00003224
Douglas Gregordd62b152009-10-19 22:04:39 +00003225template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003226QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003227 TypeLocBuilder &TLB,
3228 TemplateSpecializationTypeLoc TL,
3229 QualType ObjectType) {
3230 const TemplateSpecializationType *T = TL.getTypePtr();
3231
Mike Stump1eb44332009-09-09 15:08:12 +00003232 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00003233 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003234 if (Template.isNull())
3235 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003236
John McCalld5532b62009-11-23 01:53:49 +00003237 TemplateArgumentListInfo NewTemplateArgs;
3238 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3239 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3240
3241 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3242 TemplateArgumentLoc Loc;
3243 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003244 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003245 NewTemplateArgs.addArgument(Loc);
3246 }
Mike Stump1eb44332009-09-09 15:08:12 +00003247
John McCall833ca992009-10-29 08:12:44 +00003248 // FIXME: maybe don't rebuild if all the template arguments are the same.
3249
3250 QualType Result =
3251 getDerived().RebuildTemplateSpecializationType(Template,
3252 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003253 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003254
3255 if (!Result.isNull()) {
3256 TemplateSpecializationTypeLoc NewTL
3257 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3258 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3259 NewTL.setLAngleLoc(TL.getLAngleLoc());
3260 NewTL.setRAngleLoc(TL.getRAngleLoc());
3261 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3262 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003263 }
Mike Stump1eb44332009-09-09 15:08:12 +00003264
John McCall833ca992009-10-29 08:12:44 +00003265 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003266}
Mike Stump1eb44332009-09-09 15:08:12 +00003267
3268template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003269QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003270TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3271 ElaboratedTypeLoc TL,
3272 QualType ObjectType) {
3273 ElaboratedType *T = TL.getTypePtr();
3274
3275 NestedNameSpecifier *NNS = 0;
3276 // NOTE: the qualifier in an ElaboratedType is optional.
3277 if (T->getQualifier() != 0) {
3278 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003279 TL.getQualifierRange(),
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003280 ObjectType);
3281 if (!NNS)
3282 return QualType();
3283 }
Mike Stump1eb44332009-09-09 15:08:12 +00003284
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003285 QualType NamedT;
3286 // FIXME: this test is meant to workaround a problem (failing assertion)
3287 // occurring if directly executing the code in the else branch.
3288 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3289 TemplateSpecializationTypeLoc OldNamedTL
3290 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3291 const TemplateSpecializationType* OldTST
Jim Grosbach9cbb4d82010-05-19 23:53:08 +00003292 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003293 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3294 if (NamedT.isNull())
3295 return QualType();
3296 TemplateSpecializationTypeLoc NewNamedTL
3297 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3298 NewNamedTL.copy(OldNamedTL);
3299 }
3300 else {
3301 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3302 if (NamedT.isNull())
3303 return QualType();
3304 }
Daniel Dunbara63db842010-05-14 16:34:09 +00003305
John McCalla2becad2009-10-21 00:40:46 +00003306 QualType Result = TL.getType();
3307 if (getDerived().AlwaysRebuild() ||
3308 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003309 NamedT != T->getNamedType()) {
3310 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003311 if (Result.isNull())
3312 return QualType();
3313 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003314
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003315 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003316 NewTL.setKeywordLoc(TL.getKeywordLoc());
3317 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003318
3319 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003320}
Mike Stump1eb44332009-09-09 15:08:12 +00003321
3322template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003323QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3324 DependentNameTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00003325 QualType ObjectType) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003326 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003327
Douglas Gregor577f75a2009-08-04 16:50:30 +00003328 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003329 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3330 TL.getQualifierRange(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003331 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003332 if (!NNS)
3333 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003334
John McCall33500952010-06-11 00:33:02 +00003335 QualType Result
3336 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3337 T->getIdentifier(),
3338 TL.getKeywordLoc(),
3339 TL.getQualifierRange(),
3340 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003341 if (Result.isNull())
3342 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003343
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003344 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3345 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003346 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3347
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003348 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3349 NewTL.setKeywordLoc(TL.getKeywordLoc());
3350 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003351 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003352 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3353 NewTL.setKeywordLoc(TL.getKeywordLoc());
3354 NewTL.setQualifierRange(TL.getQualifierRange());
3355 NewTL.setNameLoc(TL.getNameLoc());
3356 }
John McCalla2becad2009-10-21 00:40:46 +00003357 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003358}
Mike Stump1eb44332009-09-09 15:08:12 +00003359
Douglas Gregor577f75a2009-08-04 16:50:30 +00003360template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003361QualType TreeTransform<Derived>::
3362 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3363 DependentTemplateSpecializationTypeLoc TL,
3364 QualType ObjectType) {
3365 DependentTemplateSpecializationType *T = TL.getTypePtr();
3366
3367 NestedNameSpecifier *NNS
3368 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3369 TL.getQualifierRange(),
3370 ObjectType);
3371 if (!NNS)
3372 return QualType();
3373
3374 TemplateArgumentListInfo NewTemplateArgs;
3375 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3376 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3377
3378 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3379 TemplateArgumentLoc Loc;
3380 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3381 return QualType();
3382 NewTemplateArgs.addArgument(Loc);
3383 }
3384
Douglas Gregor1efb6c72010-09-08 23:56:00 +00003385 QualType Result
3386 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3387 NNS,
3388 TL.getQualifierRange(),
3389 T->getIdentifier(),
3390 TL.getNameLoc(),
3391 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00003392 if (Result.isNull())
3393 return QualType();
3394
3395 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3396 QualType NamedT = ElabT->getNamedType();
3397
3398 // Copy information relevant to the template specialization.
3399 TemplateSpecializationTypeLoc NamedTL
3400 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3401 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3402 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3403 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3404 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3405
3406 // Copy information relevant to the elaborated type.
3407 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3408 NewTL.setKeywordLoc(TL.getKeywordLoc());
3409 NewTL.setQualifierRange(TL.getQualifierRange());
3410 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003411 TypeLoc NewTL(Result, TL.getOpaqueData());
3412 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003413 }
3414 return Result;
3415}
3416
3417template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003418QualType
3419TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003420 ObjCInterfaceTypeLoc TL,
3421 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003422 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003423 TLB.pushFullCopy(TL);
3424 return TL.getType();
3425}
3426
3427template<typename Derived>
3428QualType
3429TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3430 ObjCObjectTypeLoc TL,
3431 QualType ObjectType) {
3432 // ObjCObjectType is never dependent.
3433 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003434 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003435}
Mike Stump1eb44332009-09-09 15:08:12 +00003436
3437template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003438QualType
3439TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003440 ObjCObjectPointerTypeLoc TL,
3441 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003442 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003443 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003444 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003445}
3446
Douglas Gregor577f75a2009-08-04 16:50:30 +00003447//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003448// Statement transformation
3449//===----------------------------------------------------------------------===//
3450template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003451StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003452TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3453 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003454}
3455
3456template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003457StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003458TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3459 return getDerived().TransformCompoundStmt(S, false);
3460}
3461
3462template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003463StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003464TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003465 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00003466 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00003467 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003468 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00003469 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3470 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00003471 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00003472 if (Result.isInvalid()) {
3473 // Immediately fail if this was a DeclStmt, since it's very
3474 // likely that this will cause problems for future statements.
3475 if (isa<DeclStmt>(*B))
3476 return StmtError();
3477
3478 // Otherwise, just keep processing substatements and fail later.
3479 SubStmtInvalid = true;
3480 continue;
3481 }
Mike Stump1eb44332009-09-09 15:08:12 +00003482
Douglas Gregor43959a92009-08-20 07:17:43 +00003483 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3484 Statements.push_back(Result.takeAs<Stmt>());
3485 }
Mike Stump1eb44332009-09-09 15:08:12 +00003486
John McCall7114cba2010-08-27 19:56:05 +00003487 if (SubStmtInvalid)
3488 return StmtError();
3489
Douglas Gregor43959a92009-08-20 07:17:43 +00003490 if (!getDerived().AlwaysRebuild() &&
3491 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003492 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003493
3494 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3495 move_arg(Statements),
3496 S->getRBracLoc(),
3497 IsStmtExpr);
3498}
Mike Stump1eb44332009-09-09 15:08:12 +00003499
Douglas Gregor43959a92009-08-20 07:17:43 +00003500template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003501StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003502TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003503 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00003504 {
3505 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00003506 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003507
Eli Friedman264c1f82009-11-19 03:14:00 +00003508 // Transform the left-hand case value.
3509 LHS = getDerived().TransformExpr(S->getLHS());
3510 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003511 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003512
Eli Friedman264c1f82009-11-19 03:14:00 +00003513 // Transform the right-hand case value (for the GNU case-range extension).
3514 RHS = getDerived().TransformExpr(S->getRHS());
3515 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003516 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00003517 }
Mike Stump1eb44332009-09-09 15:08:12 +00003518
Douglas Gregor43959a92009-08-20 07:17:43 +00003519 // Build the case statement.
3520 // Case statements are always rebuilt so that they will attached to their
3521 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003522 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003523 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003524 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003525 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003526 S->getColonLoc());
3527 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003528 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003529
Douglas Gregor43959a92009-08-20 07:17:43 +00003530 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00003531 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003532 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003533 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003534
Douglas Gregor43959a92009-08-20 07:17:43 +00003535 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00003536 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003537}
3538
3539template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003540StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003541TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003542 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00003543 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003544 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003545 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003546
Douglas Gregor43959a92009-08-20 07:17:43 +00003547 // Default statements are always rebuilt
3548 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003549 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003550}
Mike Stump1eb44332009-09-09 15:08:12 +00003551
Douglas Gregor43959a92009-08-20 07:17:43 +00003552template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003553StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003554TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003555 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003556 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003557 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003558
Douglas Gregor43959a92009-08-20 07:17:43 +00003559 // FIXME: Pass the real colon location in.
3560 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3561 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00003562 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003563}
Mike Stump1eb44332009-09-09 15:08:12 +00003564
Douglas Gregor43959a92009-08-20 07:17:43 +00003565template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003566StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003567TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003568 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003569 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003570 VarDecl *ConditionVar = 0;
3571 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003572 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003573 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003574 getDerived().TransformDefinition(
3575 S->getConditionVariable()->getLocation(),
3576 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003577 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003578 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003579 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003580 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003581
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003582 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003583 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003584
3585 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003586 if (S->getCond()) {
John McCall60d7b3a2010-08-24 06:29:42 +00003587 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003588 S->getIfLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003589 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003590 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003591 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003592
John McCall9ae2f072010-08-23 23:25:46 +00003593 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003594 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003595 }
Sean Huntc3021132010-05-05 15:23:54 +00003596
John McCall9ae2f072010-08-23 23:25:46 +00003597 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3598 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003599 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003600
Douglas Gregor43959a92009-08-20 07:17:43 +00003601 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003602 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00003603 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003604 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003605
Douglas Gregor43959a92009-08-20 07:17:43 +00003606 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003607 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00003608 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003609 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003610
Douglas Gregor43959a92009-08-20 07:17:43 +00003611 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003612 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003613 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003614 Then.get() == S->getThen() &&
3615 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003616 return SemaRef.Owned(S->Retain());
3617
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003618 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCall9ae2f072010-08-23 23:25:46 +00003619 Then.get(),
3620 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003621}
3622
3623template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003624StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003625TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003626 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00003627 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00003628 VarDecl *ConditionVar = 0;
3629 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003630 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003631 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003632 getDerived().TransformDefinition(
3633 S->getConditionVariable()->getLocation(),
3634 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003635 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003636 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003637 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003638 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003639
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003640 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003641 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003642 }
Mike Stump1eb44332009-09-09 15:08:12 +00003643
Douglas Gregor43959a92009-08-20 07:17:43 +00003644 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003645 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00003646 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00003647 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003648 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003649 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003650
Douglas Gregor43959a92009-08-20 07:17:43 +00003651 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003652 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003653 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003654 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003655
Douglas Gregor43959a92009-08-20 07:17:43 +00003656 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00003657 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3658 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003659}
Mike Stump1eb44332009-09-09 15:08:12 +00003660
Douglas Gregor43959a92009-08-20 07:17:43 +00003661template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003662StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003663TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003664 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003665 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00003666 VarDecl *ConditionVar = 0;
3667 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003668 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003669 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003670 getDerived().TransformDefinition(
3671 S->getConditionVariable()->getLocation(),
3672 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003673 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003674 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003675 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003676 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003677
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003678 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003679 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003680
3681 if (S->getCond()) {
3682 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003683 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003684 S->getWhileLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003685 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003686 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003687 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00003688 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003689 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003690 }
Mike Stump1eb44332009-09-09 15:08:12 +00003691
John McCall9ae2f072010-08-23 23:25:46 +00003692 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3693 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003694 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003695
Douglas Gregor43959a92009-08-20 07:17:43 +00003696 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003697 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003698 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003699 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003700
Douglas Gregor43959a92009-08-20 07:17:43 +00003701 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003702 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003703 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003704 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00003705 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003706
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003707 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00003708 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003709}
Mike Stump1eb44332009-09-09 15:08:12 +00003710
Douglas Gregor43959a92009-08-20 07:17:43 +00003711template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003712StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003713TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003714 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003715 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003716 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003717 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003718
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003719 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003720 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003721 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003722 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003723
Douglas Gregor43959a92009-08-20 07:17:43 +00003724 if (!getDerived().AlwaysRebuild() &&
3725 Cond.get() == S->getCond() &&
3726 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003727 return SemaRef.Owned(S->Retain());
3728
John McCall9ae2f072010-08-23 23:25:46 +00003729 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3730 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003731 S->getRParenLoc());
3732}
Mike Stump1eb44332009-09-09 15:08:12 +00003733
Douglas Gregor43959a92009-08-20 07:17:43 +00003734template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003735StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003736TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003737 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00003738 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00003739 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003740 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003741
Douglas Gregor43959a92009-08-20 07:17:43 +00003742 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003743 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003744 VarDecl *ConditionVar = 0;
3745 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003746 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003747 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003748 getDerived().TransformDefinition(
3749 S->getConditionVariable()->getLocation(),
3750 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003751 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003752 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003753 } else {
3754 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003755
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003756 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003757 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003758
3759 if (S->getCond()) {
3760 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003761 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003762 S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003763 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003764 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003765 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003766
John McCall9ae2f072010-08-23 23:25:46 +00003767 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003768 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003769 }
Mike Stump1eb44332009-09-09 15:08:12 +00003770
John McCall9ae2f072010-08-23 23:25:46 +00003771 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3772 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003773 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003774
Douglas Gregor43959a92009-08-20 07:17:43 +00003775 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00003776 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00003777 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003778 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003779
John McCall9ae2f072010-08-23 23:25:46 +00003780 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3781 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00003782 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003783
Douglas Gregor43959a92009-08-20 07:17:43 +00003784 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003785 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003786 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003787 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003788
Douglas Gregor43959a92009-08-20 07:17:43 +00003789 if (!getDerived().AlwaysRebuild() &&
3790 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00003791 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003792 Inc.get() == S->getInc() &&
3793 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003794 return SemaRef.Owned(S->Retain());
3795
Douglas Gregor43959a92009-08-20 07:17:43 +00003796 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003797 Init.get(), FullCond, ConditionVar,
3798 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003799}
3800
3801template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003802StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003803TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003804 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003805 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003806 S->getLabel());
3807}
3808
3809template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003810StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003811TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003812 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00003813 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003814 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003815
Douglas Gregor43959a92009-08-20 07:17:43 +00003816 if (!getDerived().AlwaysRebuild() &&
3817 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003818 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003819
3820 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003821 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003822}
3823
3824template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003825StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003826TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3827 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003828}
Mike Stump1eb44332009-09-09 15:08:12 +00003829
Douglas Gregor43959a92009-08-20 07:17:43 +00003830template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003831StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003832TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3833 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003834}
Mike Stump1eb44332009-09-09 15:08:12 +00003835
Douglas Gregor43959a92009-08-20 07:17:43 +00003836template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003837StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003838TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003839 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00003840 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003841 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00003842
Mike Stump1eb44332009-09-09 15:08:12 +00003843 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003844 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00003845 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003846}
Mike Stump1eb44332009-09-09 15:08:12 +00003847
Douglas Gregor43959a92009-08-20 07:17:43 +00003848template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003849StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003850TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003851 bool DeclChanged = false;
3852 llvm::SmallVector<Decl *, 4> Decls;
3853 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3854 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003855 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3856 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003857 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00003858 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003859
Douglas Gregor43959a92009-08-20 07:17:43 +00003860 if (Transformed != *D)
3861 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003862
Douglas Gregor43959a92009-08-20 07:17:43 +00003863 Decls.push_back(Transformed);
3864 }
Mike Stump1eb44332009-09-09 15:08:12 +00003865
Douglas Gregor43959a92009-08-20 07:17:43 +00003866 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003867 return SemaRef.Owned(S->Retain());
3868
3869 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003870 S->getStartLoc(), S->getEndLoc());
3871}
Mike Stump1eb44332009-09-09 15:08:12 +00003872
Douglas Gregor43959a92009-08-20 07:17:43 +00003873template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003874StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003875TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003876 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003877 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003878}
3879
3880template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003881StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003882TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003883
John McCallca0408f2010-08-23 06:44:23 +00003884 ASTOwningVector<Expr*> Constraints(getSema());
3885 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003886 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003887
John McCall60d7b3a2010-08-24 06:29:42 +00003888 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00003889 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00003890
3891 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003892
Anders Carlsson703e3942010-01-24 05:50:09 +00003893 // Go through the outputs.
3894 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003895 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003896
Anders Carlsson703e3942010-01-24 05:50:09 +00003897 // No need to transform the constraint literal.
3898 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003899
Anders Carlsson703e3942010-01-24 05:50:09 +00003900 // Transform the output expr.
3901 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003902 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003903 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003904 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003905
Anders Carlsson703e3942010-01-24 05:50:09 +00003906 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003907
John McCall9ae2f072010-08-23 23:25:46 +00003908 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003909 }
Sean Huntc3021132010-05-05 15:23:54 +00003910
Anders Carlsson703e3942010-01-24 05:50:09 +00003911 // Go through the inputs.
3912 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003913 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003914
Anders Carlsson703e3942010-01-24 05:50:09 +00003915 // No need to transform the constraint literal.
3916 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003917
Anders Carlsson703e3942010-01-24 05:50:09 +00003918 // Transform the input expr.
3919 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003920 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003921 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003922 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003923
Anders Carlsson703e3942010-01-24 05:50:09 +00003924 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003925
John McCall9ae2f072010-08-23 23:25:46 +00003926 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003927 }
Sean Huntc3021132010-05-05 15:23:54 +00003928
Anders Carlsson703e3942010-01-24 05:50:09 +00003929 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3930 return SemaRef.Owned(S->Retain());
3931
3932 // Go through the clobbers.
3933 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3934 Clobbers.push_back(S->getClobber(I)->Retain());
3935
3936 // No need to transform the asm string literal.
3937 AsmString = SemaRef.Owned(S->getAsmString());
3938
3939 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3940 S->isSimple(),
3941 S->isVolatile(),
3942 S->getNumOutputs(),
3943 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003944 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003945 move_arg(Constraints),
3946 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00003947 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003948 move_arg(Clobbers),
3949 S->getRParenLoc(),
3950 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003951}
3952
3953
3954template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003955StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003956TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003957 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00003958 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003959 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003960 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003961
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003962 // Transform the @catch statements (if present).
3963 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003964 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003965 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00003966 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003967 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003968 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003969 if (Catch.get() != S->getCatchStmt(I))
3970 AnyCatchChanged = true;
3971 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003972 }
Sean Huntc3021132010-05-05 15:23:54 +00003973
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003974 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00003975 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003976 if (S->getFinallyStmt()) {
3977 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3978 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003979 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003980 }
3981
3982 // If nothing changed, just retain this statement.
3983 if (!getDerived().AlwaysRebuild() &&
3984 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003985 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003986 Finally.get() == S->getFinallyStmt())
3987 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003988
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003989 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00003990 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
3991 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003992}
Mike Stump1eb44332009-09-09 15:08:12 +00003993
Douglas Gregor43959a92009-08-20 07:17:43 +00003994template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003995StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003996TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00003997 // Transform the @catch parameter, if there is one.
3998 VarDecl *Var = 0;
3999 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4000 TypeSourceInfo *TSInfo = 0;
4001 if (FromVar->getTypeSourceInfo()) {
4002 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4003 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004004 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004005 }
Sean Huntc3021132010-05-05 15:23:54 +00004006
Douglas Gregorbe270a02010-04-26 17:57:08 +00004007 QualType T;
4008 if (TSInfo)
4009 T = TSInfo->getType();
4010 else {
4011 T = getDerived().TransformType(FromVar->getType());
4012 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004013 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004014 }
Sean Huntc3021132010-05-05 15:23:54 +00004015
Douglas Gregorbe270a02010-04-26 17:57:08 +00004016 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4017 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004018 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004019 }
Sean Huntc3021132010-05-05 15:23:54 +00004020
John McCall60d7b3a2010-08-24 06:29:42 +00004021 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004022 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004023 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004024
4025 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004026 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004027 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004028}
Mike Stump1eb44332009-09-09 15:08:12 +00004029
Douglas Gregor43959a92009-08-20 07:17:43 +00004030template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004031StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004032TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004033 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004034 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004035 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004036 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004037
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004038 // If nothing changed, just retain this statement.
4039 if (!getDerived().AlwaysRebuild() &&
4040 Body.get() == S->getFinallyBody())
4041 return SemaRef.Owned(S->Retain());
4042
4043 // Build a new statement.
4044 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004045 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004046}
Mike Stump1eb44332009-09-09 15:08:12 +00004047
Douglas Gregor43959a92009-08-20 07:17:43 +00004048template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004049StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004050TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004051 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004052 if (S->getThrowExpr()) {
4053 Operand = getDerived().TransformExpr(S->getThrowExpr());
4054 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004055 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004056 }
Sean Huntc3021132010-05-05 15:23:54 +00004057
Douglas Gregord1377b22010-04-22 21:44:01 +00004058 if (!getDerived().AlwaysRebuild() &&
4059 Operand.get() == S->getThrowExpr())
4060 return getSema().Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004061
John McCall9ae2f072010-08-23 23:25:46 +00004062 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004063}
Mike Stump1eb44332009-09-09 15:08:12 +00004064
Douglas Gregor43959a92009-08-20 07:17:43 +00004065template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004066StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004067TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004068 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004069 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004070 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004071 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004072 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004073
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004074 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004075 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004076 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004077 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004078
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004079 // If nothing change, just retain the current statement.
4080 if (!getDerived().AlwaysRebuild() &&
4081 Object.get() == S->getSynchExpr() &&
4082 Body.get() == S->getSynchBody())
4083 return SemaRef.Owned(S->Retain());
4084
4085 // Build a new statement.
4086 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004087 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004088}
4089
4090template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004091StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004092TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004093 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004094 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004095 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004096 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004097 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004098
Douglas Gregorc3203e72010-04-22 23:10:45 +00004099 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00004100 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004101 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004102 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004103
Douglas Gregorc3203e72010-04-22 23:10:45 +00004104 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004105 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004106 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004107 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004108
Douglas Gregorc3203e72010-04-22 23:10:45 +00004109 // If nothing changed, just retain this statement.
4110 if (!getDerived().AlwaysRebuild() &&
4111 Element.get() == S->getElement() &&
4112 Collection.get() == S->getCollection() &&
4113 Body.get() == S->getBody())
4114 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004115
Douglas Gregorc3203e72010-04-22 23:10:45 +00004116 // Build a new statement.
4117 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4118 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004119 Element.get(),
4120 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00004121 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004122 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004123}
4124
4125
4126template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004127StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004128TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4129 // Transform the exception declaration, if any.
4130 VarDecl *Var = 0;
4131 if (S->getExceptionDecl()) {
4132 VarDecl *ExceptionDecl = S->getExceptionDecl();
4133 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4134 ExceptionDecl->getDeclName());
4135
4136 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4137 if (T.isNull())
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 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4141 T,
John McCalla93c9342009-12-07 02:54:59 +00004142 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004143 ExceptionDecl->getIdentifier(),
4144 ExceptionDecl->getLocation(),
4145 /*FIXME: Inaccurate*/
4146 SourceRange(ExceptionDecl->getLocation()));
Douglas Gregorff331c12010-07-25 18:17:45 +00004147 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00004148 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004149 }
Mike Stump1eb44332009-09-09 15:08:12 +00004150
Douglas Gregor43959a92009-08-20 07:17:43 +00004151 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00004152 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004153 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004154 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004155
Douglas Gregor43959a92009-08-20 07:17:43 +00004156 if (!getDerived().AlwaysRebuild() &&
4157 !Var &&
4158 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00004159 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004160
4161 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4162 Var,
John McCall9ae2f072010-08-23 23:25:46 +00004163 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004164}
Mike Stump1eb44332009-09-09 15:08:12 +00004165
Douglas Gregor43959a92009-08-20 07:17:43 +00004166template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004167StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004168TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4169 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004170 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004171 = getDerived().TransformCompoundStmt(S->getTryBlock());
4172 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004173 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004174
Douglas Gregor43959a92009-08-20 07:17:43 +00004175 // Transform the handlers.
4176 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004177 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00004178 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004179 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004180 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4181 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004182 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004183
Douglas Gregor43959a92009-08-20 07:17:43 +00004184 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4185 Handlers.push_back(Handler.takeAs<Stmt>());
4186 }
Mike Stump1eb44332009-09-09 15:08:12 +00004187
Douglas Gregor43959a92009-08-20 07:17:43 +00004188 if (!getDerived().AlwaysRebuild() &&
4189 TryBlock.get() == S->getTryBlock() &&
4190 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004191 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004192
John McCall9ae2f072010-08-23 23:25:46 +00004193 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00004194 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004195}
Mike Stump1eb44332009-09-09 15:08:12 +00004196
Douglas Gregor43959a92009-08-20 07:17:43 +00004197//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004198// Expression transformation
4199//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004200template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004201ExprResult
John McCall454feb92009-12-08 09:21:05 +00004202TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004203 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004204}
Mike Stump1eb44332009-09-09 15:08:12 +00004205
4206template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004207ExprResult
John McCall454feb92009-12-08 09:21:05 +00004208TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004209 NestedNameSpecifier *Qualifier = 0;
4210 if (E->getQualifier()) {
4211 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004212 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004213 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00004214 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00004215 }
John McCalldbd872f2009-12-08 09:08:17 +00004216
4217 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004218 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4219 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004220 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00004221 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004222
John McCallec8045d2010-08-17 21:27:17 +00004223 DeclarationNameInfo NameInfo = E->getNameInfo();
4224 if (NameInfo.getName()) {
4225 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4226 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00004227 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00004228 }
Abramo Bagnara25777432010-08-11 22:01:17 +00004229
4230 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004231 Qualifier == E->getQualifier() &&
4232 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00004233 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00004234 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004235
4236 // Mark it referenced in the new context regardless.
4237 // FIXME: this is a bit instantiation-specific.
4238 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4239
Mike Stump1eb44332009-09-09 15:08:12 +00004240 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004241 }
John McCalldbd872f2009-12-08 09:08:17 +00004242
4243 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00004244 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004245 TemplateArgs = &TransArgs;
4246 TransArgs.setLAngleLoc(E->getLAngleLoc());
4247 TransArgs.setRAngleLoc(E->getRAngleLoc());
4248 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4249 TemplateArgumentLoc Loc;
4250 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004251 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00004252 TransArgs.addArgument(Loc);
4253 }
4254 }
4255
Douglas Gregora2813ce2009-10-23 18:54:35 +00004256 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004257 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004258}
Mike Stump1eb44332009-09-09 15:08:12 +00004259
Douglas Gregorb98b1992009-08-11 05:31:07 +00004260template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004261ExprResult
John McCall454feb92009-12-08 09:21:05 +00004262TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004263 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004264}
Mike Stump1eb44332009-09-09 15:08:12 +00004265
Douglas Gregorb98b1992009-08-11 05:31:07 +00004266template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004267ExprResult
John McCall454feb92009-12-08 09:21:05 +00004268TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004269 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004270}
Mike Stump1eb44332009-09-09 15:08:12 +00004271
Douglas Gregorb98b1992009-08-11 05:31:07 +00004272template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004273ExprResult
John McCall454feb92009-12-08 09:21:05 +00004274TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004275 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004276}
Mike Stump1eb44332009-09-09 15:08:12 +00004277
Douglas Gregorb98b1992009-08-11 05:31:07 +00004278template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004279ExprResult
John McCall454feb92009-12-08 09:21:05 +00004280TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004281 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004282}
Mike Stump1eb44332009-09-09 15:08:12 +00004283
Douglas Gregorb98b1992009-08-11 05:31:07 +00004284template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004285ExprResult
John McCall454feb92009-12-08 09:21:05 +00004286TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004287 return SemaRef.Owned(E->Retain());
4288}
4289
4290template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004291ExprResult
John McCall454feb92009-12-08 09:21:05 +00004292TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004293 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004294 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004295 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004296
Douglas Gregorb98b1992009-08-11 05:31:07 +00004297 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004298 return SemaRef.Owned(E->Retain());
4299
John McCall9ae2f072010-08-23 23:25:46 +00004300 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004301 E->getRParen());
4302}
4303
Mike Stump1eb44332009-09-09 15:08:12 +00004304template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004305ExprResult
John McCall454feb92009-12-08 09:21:05 +00004306TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004307 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004308 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004309 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004310
Douglas Gregorb98b1992009-08-11 05:31:07 +00004311 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004312 return SemaRef.Owned(E->Retain());
4313
Douglas Gregorb98b1992009-08-11 05:31:07 +00004314 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4315 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004316 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004317}
Mike Stump1eb44332009-09-09 15:08:12 +00004318
Douglas Gregorb98b1992009-08-11 05:31:07 +00004319template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004320ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004321TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4322 // Transform the type.
4323 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4324 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00004325 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004326
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004327 // Transform all of the components into components similar to what the
4328 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004329 // FIXME: It would be slightly more efficient in the non-dependent case to
4330 // just map FieldDecls, rather than requiring the rebuilder to look for
4331 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004332 // template code that we don't care.
4333 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00004334 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004335 typedef OffsetOfExpr::OffsetOfNode Node;
4336 llvm::SmallVector<Component, 4> Components;
4337 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4338 const Node &ON = E->getComponent(I);
4339 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004340 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004341 Comp.LocStart = ON.getRange().getBegin();
4342 Comp.LocEnd = ON.getRange().getEnd();
4343 switch (ON.getKind()) {
4344 case Node::Array: {
4345 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00004346 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004347 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004348 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004349
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004350 ExprChanged = ExprChanged || Index.get() != FromIndex;
4351 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00004352 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004353 break;
4354 }
Sean Huntc3021132010-05-05 15:23:54 +00004355
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004356 case Node::Field:
4357 case Node::Identifier:
4358 Comp.isBrackets = false;
4359 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004360 if (!Comp.U.IdentInfo)
4361 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004362
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004363 break;
Sean Huntc3021132010-05-05 15:23:54 +00004364
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004365 case Node::Base:
4366 // Will be recomputed during the rebuild.
4367 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004368 }
Sean Huntc3021132010-05-05 15:23:54 +00004369
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004370 Components.push_back(Comp);
4371 }
Sean Huntc3021132010-05-05 15:23:54 +00004372
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004373 // If nothing changed, retain the existing expression.
4374 if (!getDerived().AlwaysRebuild() &&
4375 Type == E->getTypeSourceInfo() &&
4376 !ExprChanged)
4377 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004378
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004379 // Build a new offsetof expression.
4380 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4381 Components.data(), Components.size(),
4382 E->getRParenLoc());
4383}
4384
4385template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004386ExprResult
John McCall454feb92009-12-08 09:21:05 +00004387TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004388 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004389 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004390
John McCalla93c9342009-12-07 02:54:59 +00004391 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004392 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004393 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004394
John McCall5ab75172009-11-04 07:28:41 +00004395 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004396 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004397
John McCall5ab75172009-11-04 07:28:41 +00004398 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004399 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004400 E->getSourceRange());
4401 }
Mike Stump1eb44332009-09-09 15:08:12 +00004402
John McCall60d7b3a2010-08-24 06:29:42 +00004403 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00004404 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004405 // C++0x [expr.sizeof]p1:
4406 // The operand is either an expression, which is an unevaluated operand
4407 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00004408 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004409
Douglas Gregorb98b1992009-08-11 05:31:07 +00004410 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4411 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004412 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004413
Douglas Gregorb98b1992009-08-11 05:31:07 +00004414 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4415 return SemaRef.Owned(E->Retain());
4416 }
Mike Stump1eb44332009-09-09 15:08:12 +00004417
John McCall9ae2f072010-08-23 23:25:46 +00004418 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004419 E->isSizeOf(),
4420 E->getSourceRange());
4421}
Mike Stump1eb44332009-09-09 15:08:12 +00004422
Douglas Gregorb98b1992009-08-11 05:31:07 +00004423template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004424ExprResult
John McCall454feb92009-12-08 09:21:05 +00004425TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004426 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004427 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004428 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004429
John McCall60d7b3a2010-08-24 06:29:42 +00004430 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004431 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004432 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004433
4434
Douglas Gregorb98b1992009-08-11 05:31:07 +00004435 if (!getDerived().AlwaysRebuild() &&
4436 LHS.get() == E->getLHS() &&
4437 RHS.get() == E->getRHS())
4438 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004439
John McCall9ae2f072010-08-23 23:25:46 +00004440 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004441 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00004442 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004443 E->getRBracketLoc());
4444}
Mike Stump1eb44332009-09-09 15:08:12 +00004445
4446template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004447ExprResult
John McCall454feb92009-12-08 09:21:05 +00004448TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004449 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00004450 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004451 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004452 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004453
4454 // Transform arguments.
4455 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004456 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004457 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4458 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004459 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004460 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004461 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004462
Douglas Gregorb98b1992009-08-11 05:31:07 +00004463 // FIXME: Wrong source location information for the ','.
4464 FakeCommaLocs.push_back(
4465 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00004466
4467 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00004468 Args.push_back(Arg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004469 }
Mike Stump1eb44332009-09-09 15:08:12 +00004470
Douglas Gregorb98b1992009-08-11 05:31:07 +00004471 if (!getDerived().AlwaysRebuild() &&
4472 Callee.get() == E->getCallee() &&
4473 !ArgChanged)
4474 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004475
Douglas Gregorb98b1992009-08-11 05:31:07 +00004476 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004477 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004478 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00004479 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004480 move_arg(Args),
4481 FakeCommaLocs.data(),
4482 E->getRParenLoc());
4483}
Mike Stump1eb44332009-09-09 15:08:12 +00004484
4485template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004486ExprResult
John McCall454feb92009-12-08 09:21:05 +00004487TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004488 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004489 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004490 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004491
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004492 NestedNameSpecifier *Qualifier = 0;
4493 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004494 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004495 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004496 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004497 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00004498 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004499 }
Mike Stump1eb44332009-09-09 15:08:12 +00004500
Eli Friedmanf595cc42009-12-04 06:40:45 +00004501 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004502 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4503 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004504 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00004505 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004506
John McCall6bb80172010-03-30 21:47:33 +00004507 NamedDecl *FoundDecl = E->getFoundDecl();
4508 if (FoundDecl == E->getMemberDecl()) {
4509 FoundDecl = Member;
4510 } else {
4511 FoundDecl = cast_or_null<NamedDecl>(
4512 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4513 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00004514 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00004515 }
4516
Douglas Gregorb98b1992009-08-11 05:31:07 +00004517 if (!getDerived().AlwaysRebuild() &&
4518 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004519 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004520 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004521 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00004522 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00004523
Anders Carlsson1f240322009-12-22 05:24:09 +00004524 // Mark it referenced in the new context regardless.
4525 // FIXME: this is a bit instantiation-specific.
4526 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00004527 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00004528 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004529
John McCalld5532b62009-11-23 01:53:49 +00004530 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00004531 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00004532 TransArgs.setLAngleLoc(E->getLAngleLoc());
4533 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004534 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004535 TemplateArgumentLoc Loc;
4536 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004537 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004538 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004539 }
4540 }
Sean Huntc3021132010-05-05 15:23:54 +00004541
Douglas Gregorb98b1992009-08-11 05:31:07 +00004542 // FIXME: Bogus source location for the operator
4543 SourceLocation FakeOperatorLoc
4544 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4545
John McCallc2233c52010-01-15 08:34:02 +00004546 // FIXME: to do this check properly, we will need to preserve the
4547 // first-qualifier-in-scope here, just in case we had a dependent
4548 // base (and therefore couldn't do the check) and a
4549 // nested-name-qualifier (and therefore could do the lookup).
4550 NamedDecl *FirstQualifierInScope = 0;
4551
John McCall9ae2f072010-08-23 23:25:46 +00004552 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004553 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004554 Qualifier,
4555 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004556 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004557 Member,
John McCall6bb80172010-03-30 21:47:33 +00004558 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00004559 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00004560 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004561 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004562}
Mike Stump1eb44332009-09-09 15:08:12 +00004563
Douglas Gregorb98b1992009-08-11 05:31:07 +00004564template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004565ExprResult
John McCall454feb92009-12-08 09:21:05 +00004566TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004567 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004568 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004569 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004570
John McCall60d7b3a2010-08-24 06:29:42 +00004571 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004572 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004573 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004574
Douglas Gregorb98b1992009-08-11 05:31:07 +00004575 if (!getDerived().AlwaysRebuild() &&
4576 LHS.get() == E->getLHS() &&
4577 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004578 return SemaRef.Owned(E->Retain());
4579
Douglas Gregorb98b1992009-08-11 05:31:07 +00004580 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004581 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004582}
4583
Mike Stump1eb44332009-09-09 15:08:12 +00004584template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004585ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004586TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004587 CompoundAssignOperator *E) {
4588 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004589}
Mike Stump1eb44332009-09-09 15:08:12 +00004590
Douglas Gregorb98b1992009-08-11 05:31:07 +00004591template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004592ExprResult
John McCall454feb92009-12-08 09:21:05 +00004593TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004594 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004595 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004596 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004597
John McCall60d7b3a2010-08-24 06:29:42 +00004598 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004599 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004600 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004601
John McCall60d7b3a2010-08-24 06:29:42 +00004602 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004603 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004604 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004605
Douglas Gregorb98b1992009-08-11 05:31:07 +00004606 if (!getDerived().AlwaysRebuild() &&
4607 Cond.get() == E->getCond() &&
4608 LHS.get() == E->getLHS() &&
4609 RHS.get() == E->getRHS())
4610 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004611
John McCall9ae2f072010-08-23 23:25:46 +00004612 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004613 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004614 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004615 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004616 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004617}
Mike Stump1eb44332009-09-09 15:08:12 +00004618
4619template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004620ExprResult
John McCall454feb92009-12-08 09:21:05 +00004621TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004622 // Implicit casts are eliminated during transformation, since they
4623 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004624 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004625}
Mike Stump1eb44332009-09-09 15:08:12 +00004626
Douglas Gregorb98b1992009-08-11 05:31:07 +00004627template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004628ExprResult
John McCall454feb92009-12-08 09:21:05 +00004629TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004630 TypeSourceInfo *OldT;
4631 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004632 {
4633 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004634 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004635 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4636 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004637
John McCall9d125032010-01-15 18:39:57 +00004638 OldT = E->getTypeInfoAsWritten();
4639 NewT = getDerived().TransformType(OldT);
4640 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004641 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004642 }
Mike Stump1eb44332009-09-09 15:08:12 +00004643
John McCall60d7b3a2010-08-24 06:29:42 +00004644 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004645 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004646 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004647 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004648
Douglas Gregorb98b1992009-08-11 05:31:07 +00004649 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004650 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004651 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004652 return SemaRef.Owned(E->Retain());
4653
John McCall9d125032010-01-15 18:39:57 +00004654 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4655 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004656 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004657 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004658}
Mike Stump1eb44332009-09-09 15:08:12 +00004659
Douglas Gregorb98b1992009-08-11 05:31:07 +00004660template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004661ExprResult
John McCall454feb92009-12-08 09:21:05 +00004662TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004663 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4664 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4665 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004666 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004667
John McCall60d7b3a2010-08-24 06:29:42 +00004668 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004669 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004670 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004671
Douglas Gregorb98b1992009-08-11 05:31:07 +00004672 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004673 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004674 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00004675 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004676
John McCall1d7d8d62010-01-19 22:33:45 +00004677 // Note: the expression type doesn't necessarily match the
4678 // type-as-written, but that's okay, because it should always be
4679 // derivable from the initializer.
4680
John McCall42f56b52010-01-18 19:35:47 +00004681 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004682 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00004683 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004684}
Mike Stump1eb44332009-09-09 15:08:12 +00004685
Douglas Gregorb98b1992009-08-11 05:31:07 +00004686template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004687ExprResult
John McCall454feb92009-12-08 09:21:05 +00004688TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004689 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004690 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004691 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004692
Douglas Gregorb98b1992009-08-11 05:31:07 +00004693 if (!getDerived().AlwaysRebuild() &&
4694 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00004695 return SemaRef.Owned(E->Retain());
4696
Douglas Gregorb98b1992009-08-11 05:31:07 +00004697 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004698 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004699 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00004700 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004701 E->getAccessorLoc(),
4702 E->getAccessor());
4703}
Mike Stump1eb44332009-09-09 15:08:12 +00004704
Douglas Gregorb98b1992009-08-11 05:31:07 +00004705template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004706ExprResult
John McCall454feb92009-12-08 09:21:05 +00004707TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004708 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004709
John McCallca0408f2010-08-23 06:44:23 +00004710 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004711 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004712 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004713 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004714 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004715
Douglas Gregorb98b1992009-08-11 05:31:07 +00004716 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCall9ae2f072010-08-23 23:25:46 +00004717 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004718 }
Mike Stump1eb44332009-09-09 15:08:12 +00004719
Douglas Gregorb98b1992009-08-11 05:31:07 +00004720 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004721 return SemaRef.Owned(E->Retain());
4722
Douglas Gregorb98b1992009-08-11 05:31:07 +00004723 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004724 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004725}
Mike Stump1eb44332009-09-09 15:08:12 +00004726
Douglas Gregorb98b1992009-08-11 05:31:07 +00004727template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004728ExprResult
John McCall454feb92009-12-08 09:21:05 +00004729TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004730 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004731
Douglas Gregor43959a92009-08-20 07:17:43 +00004732 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00004733 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004734 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004735 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004736
Douglas Gregor43959a92009-08-20 07:17:43 +00004737 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00004738 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004739 bool ExprChanged = false;
4740 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4741 DEnd = E->designators_end();
4742 D != DEnd; ++D) {
4743 if (D->isFieldDesignator()) {
4744 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4745 D->getDotLoc(),
4746 D->getFieldLoc()));
4747 continue;
4748 }
Mike Stump1eb44332009-09-09 15:08:12 +00004749
Douglas Gregorb98b1992009-08-11 05:31:07 +00004750 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00004751 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004752 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004753 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004754
4755 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004756 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004757
Douglas Gregorb98b1992009-08-11 05:31:07 +00004758 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4759 ArrayExprs.push_back(Index.release());
4760 continue;
4761 }
Mike Stump1eb44332009-09-09 15:08:12 +00004762
Douglas Gregorb98b1992009-08-11 05:31:07 +00004763 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00004764 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004765 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4766 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004767 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004768
John McCall60d7b3a2010-08-24 06:29:42 +00004769 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004770 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004771 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004772
4773 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004774 End.get(),
4775 D->getLBracketLoc(),
4776 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004777
Douglas Gregorb98b1992009-08-11 05:31:07 +00004778 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4779 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004780
Douglas Gregorb98b1992009-08-11 05:31:07 +00004781 ArrayExprs.push_back(Start.release());
4782 ArrayExprs.push_back(End.release());
4783 }
Mike Stump1eb44332009-09-09 15:08:12 +00004784
Douglas Gregorb98b1992009-08-11 05:31:07 +00004785 if (!getDerived().AlwaysRebuild() &&
4786 Init.get() == E->getInit() &&
4787 !ExprChanged)
4788 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004789
Douglas Gregorb98b1992009-08-11 05:31:07 +00004790 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4791 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004792 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004793}
Mike Stump1eb44332009-09-09 15:08:12 +00004794
Douglas Gregorb98b1992009-08-11 05:31:07 +00004795template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004796ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004797TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004798 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004799 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004800
Douglas Gregor5557b252009-10-28 00:29:27 +00004801 // FIXME: Will we ever have proper type location here? Will we actually
4802 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004803 QualType T = getDerived().TransformType(E->getType());
4804 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004805 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004806
Douglas Gregorb98b1992009-08-11 05:31:07 +00004807 if (!getDerived().AlwaysRebuild() &&
4808 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004809 return SemaRef.Owned(E->Retain());
4810
Douglas Gregorb98b1992009-08-11 05:31:07 +00004811 return getDerived().RebuildImplicitValueInitExpr(T);
4812}
Mike Stump1eb44332009-09-09 15:08:12 +00004813
Douglas Gregorb98b1992009-08-11 05:31:07 +00004814template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004815ExprResult
John McCall454feb92009-12-08 09:21:05 +00004816TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004817 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4818 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004819 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004820
John McCall60d7b3a2010-08-24 06:29:42 +00004821 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004822 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004823 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004824
Douglas Gregorb98b1992009-08-11 05:31:07 +00004825 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004826 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004827 SubExpr.get() == E->getSubExpr())
4828 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004829
John McCall9ae2f072010-08-23 23:25:46 +00004830 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004831 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004832}
4833
4834template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004835ExprResult
John McCall454feb92009-12-08 09:21:05 +00004836TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004837 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004838 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004839 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004840 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004841 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004842 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004843
Douglas Gregorb98b1992009-08-11 05:31:07 +00004844 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00004845 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004846 }
Mike Stump1eb44332009-09-09 15:08:12 +00004847
Douglas Gregorb98b1992009-08-11 05:31:07 +00004848 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4849 move_arg(Inits),
4850 E->getRParenLoc());
4851}
Mike Stump1eb44332009-09-09 15:08:12 +00004852
Douglas Gregorb98b1992009-08-11 05:31:07 +00004853/// \brief Transform an address-of-label expression.
4854///
4855/// By default, the transformation of an address-of-label expression always
4856/// rebuilds the expression, so that the label identifier can be resolved to
4857/// the corresponding label statement by semantic analysis.
4858template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004859ExprResult
John McCall454feb92009-12-08 09:21:05 +00004860TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004861 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4862 E->getLabel());
4863}
Mike Stump1eb44332009-09-09 15:08:12 +00004864
4865template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004866ExprResult
John McCall454feb92009-12-08 09:21:05 +00004867TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004868 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004869 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4870 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004871 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004872
Douglas Gregorb98b1992009-08-11 05:31:07 +00004873 if (!getDerived().AlwaysRebuild() &&
4874 SubStmt.get() == E->getSubStmt())
4875 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004876
4877 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004878 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004879 E->getRParenLoc());
4880}
Mike Stump1eb44332009-09-09 15:08:12 +00004881
Douglas Gregorb98b1992009-08-11 05:31:07 +00004882template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004883ExprResult
John McCall454feb92009-12-08 09:21:05 +00004884TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004885 TypeSourceInfo *TInfo1;
4886 TypeSourceInfo *TInfo2;
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004887
4888 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4889 if (!TInfo1)
John McCallf312b1e2010-08-26 23:41:50 +00004890 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004891
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004892 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4893 if (!TInfo2)
John McCallf312b1e2010-08-26 23:41:50 +00004894 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004895
4896 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004897 TInfo1 == E->getArgTInfo1() &&
4898 TInfo2 == E->getArgTInfo2())
Mike Stump1eb44332009-09-09 15:08:12 +00004899 return SemaRef.Owned(E->Retain());
4900
Douglas Gregorb98b1992009-08-11 05:31:07 +00004901 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004902 TInfo1, TInfo2,
4903 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004904}
Mike Stump1eb44332009-09-09 15:08:12 +00004905
Douglas Gregorb98b1992009-08-11 05:31:07 +00004906template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004907ExprResult
John McCall454feb92009-12-08 09:21:05 +00004908TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004909 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004910 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004911 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004912
John McCall60d7b3a2010-08-24 06:29:42 +00004913 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004914 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004915 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004916
John McCall60d7b3a2010-08-24 06:29:42 +00004917 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004918 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004919 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004920
Douglas Gregorb98b1992009-08-11 05:31:07 +00004921 if (!getDerived().AlwaysRebuild() &&
4922 Cond.get() == E->getCond() &&
4923 LHS.get() == E->getLHS() &&
4924 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004925 return SemaRef.Owned(E->Retain());
4926
Douglas Gregorb98b1992009-08-11 05:31:07 +00004927 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004928 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004929 E->getRParenLoc());
4930}
Mike Stump1eb44332009-09-09 15:08:12 +00004931
Douglas Gregorb98b1992009-08-11 05:31:07 +00004932template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004933ExprResult
John McCall454feb92009-12-08 09:21:05 +00004934TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004935 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004936}
4937
4938template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004939ExprResult
John McCall454feb92009-12-08 09:21:05 +00004940TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004941 switch (E->getOperator()) {
4942 case OO_New:
4943 case OO_Delete:
4944 case OO_Array_New:
4945 case OO_Array_Delete:
4946 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00004947 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004948
Douglas Gregor668d6d92009-12-13 20:44:55 +00004949 case OO_Call: {
4950 // This is a call to an object's operator().
4951 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4952
4953 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004954 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00004955 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004956 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004957
4958 // FIXME: Poor location information
4959 SourceLocation FakeLParenLoc
4960 = SemaRef.PP.getLocForEndOfToken(
4961 static_cast<Expr *>(Object.get())->getLocEnd());
4962
4963 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00004964 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor668d6d92009-12-13 20:44:55 +00004965 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4966 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004967 if (getDerived().DropCallArgument(E->getArg(I)))
4968 break;
Sean Huntc3021132010-05-05 15:23:54 +00004969
John McCall60d7b3a2010-08-24 06:29:42 +00004970 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor668d6d92009-12-13 20:44:55 +00004971 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004972 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004973
4974 // FIXME: Poor source location information.
4975 SourceLocation FakeCommaLoc
4976 = SemaRef.PP.getLocForEndOfToken(
4977 static_cast<Expr *>(Arg.get())->getLocEnd());
4978 FakeCommaLocs.push_back(FakeCommaLoc);
4979 Args.push_back(Arg.release());
4980 }
4981
John McCall9ae2f072010-08-23 23:25:46 +00004982 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00004983 move_arg(Args),
4984 FakeCommaLocs.data(),
4985 E->getLocEnd());
4986 }
4987
4988#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4989 case OO_##Name:
4990#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4991#include "clang/Basic/OperatorKinds.def"
4992 case OO_Subscript:
4993 // Handled below.
4994 break;
4995
4996 case OO_Conditional:
4997 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00004998 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004999
5000 case OO_None:
5001 case NUM_OVERLOADED_OPERATORS:
5002 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00005003 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005004 }
5005
John McCall60d7b3a2010-08-24 06:29:42 +00005006 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005007 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005008 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005009
John McCall60d7b3a2010-08-24 06:29:42 +00005010 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005011 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005012 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005013
John McCall60d7b3a2010-08-24 06:29:42 +00005014 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005015 if (E->getNumArgs() == 2) {
5016 Second = getDerived().TransformExpr(E->getArg(1));
5017 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005018 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005019 }
Mike Stump1eb44332009-09-09 15:08:12 +00005020
Douglas Gregorb98b1992009-08-11 05:31:07 +00005021 if (!getDerived().AlwaysRebuild() &&
5022 Callee.get() == E->getCallee() &&
5023 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005024 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5025 return SemaRef.Owned(E->Retain());
5026
Douglas Gregorb98b1992009-08-11 05:31:07 +00005027 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5028 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005029 Callee.get(),
5030 First.get(),
5031 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005032}
Mike Stump1eb44332009-09-09 15:08:12 +00005033
Douglas Gregorb98b1992009-08-11 05:31:07 +00005034template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005035ExprResult
John McCall454feb92009-12-08 09:21:05 +00005036TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5037 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005038}
Mike Stump1eb44332009-09-09 15:08:12 +00005039
Douglas Gregorb98b1992009-08-11 05:31:07 +00005040template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005041ExprResult
John McCall454feb92009-12-08 09:21:05 +00005042TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00005043 TypeSourceInfo *OldT;
5044 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005045 {
5046 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00005047 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005048 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5049 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005050
John McCall9d125032010-01-15 18:39:57 +00005051 OldT = E->getTypeInfoAsWritten();
5052 NewT = getDerived().TransformType(OldT);
5053 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005054 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005055 }
Mike Stump1eb44332009-09-09 15:08:12 +00005056
John McCall60d7b3a2010-08-24 06:29:42 +00005057 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005058 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005059 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005060 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005061
Douglas Gregorb98b1992009-08-11 05:31:07 +00005062 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00005063 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005064 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005065 return SemaRef.Owned(E->Retain());
5066
Douglas Gregorb98b1992009-08-11 05:31:07 +00005067 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005068 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005069 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5070 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5071 SourceLocation FakeRParenLoc
5072 = SemaRef.PP.getLocForEndOfToken(
5073 E->getSubExpr()->getSourceRange().getEnd());
5074 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005075 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005076 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00005077 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005078 FakeRAngleLoc,
5079 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005080 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005081 FakeRParenLoc);
5082}
Mike Stump1eb44332009-09-09 15:08:12 +00005083
Douglas Gregorb98b1992009-08-11 05:31:07 +00005084template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005085ExprResult
John McCall454feb92009-12-08 09:21:05 +00005086TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5087 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005088}
Mike Stump1eb44332009-09-09 15:08:12 +00005089
5090template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005091ExprResult
John McCall454feb92009-12-08 09:21:05 +00005092TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5093 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005094}
5095
Douglas Gregorb98b1992009-08-11 05:31:07 +00005096template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005097ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005098TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005099 CXXReinterpretCastExpr *E) {
5100 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005101}
Mike Stump1eb44332009-09-09 15:08:12 +00005102
Douglas Gregorb98b1992009-08-11 05:31:07 +00005103template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005104ExprResult
John McCall454feb92009-12-08 09:21:05 +00005105TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5106 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005107}
Mike Stump1eb44332009-09-09 15:08:12 +00005108
Douglas Gregorb98b1992009-08-11 05:31:07 +00005109template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005110ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005111TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005112 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00005113 TypeSourceInfo *OldT;
5114 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005115 {
5116 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005117
John McCall9d125032010-01-15 18:39:57 +00005118 OldT = E->getTypeInfoAsWritten();
5119 NewT = getDerived().TransformType(OldT);
5120 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005121 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005122 }
Mike Stump1eb44332009-09-09 15:08:12 +00005123
John McCall60d7b3a2010-08-24 06:29:42 +00005124 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005125 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005126 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005127 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005128
Douglas Gregorb98b1992009-08-11 05:31:07 +00005129 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00005130 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005131 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005132 return SemaRef.Owned(E->Retain());
5133
Douglas Gregorab6677e2010-09-08 00:15:04 +00005134 return getDerived().RebuildCXXFunctionalCastExpr(NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005135 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005136 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005137 E->getRParenLoc());
5138}
Mike Stump1eb44332009-09-09 15:08:12 +00005139
Douglas Gregorb98b1992009-08-11 05:31:07 +00005140template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005141ExprResult
John McCall454feb92009-12-08 09:21:05 +00005142TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005143 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005144 TypeSourceInfo *TInfo
5145 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5146 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005147 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005148
Douglas Gregorb98b1992009-08-11 05:31:07 +00005149 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005150 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005151 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005152
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005153 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5154 E->getLocStart(),
5155 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005156 E->getLocEnd());
5157 }
Mike Stump1eb44332009-09-09 15:08:12 +00005158
Douglas Gregorb98b1992009-08-11 05:31:07 +00005159 // We don't know whether the expression is potentially evaluated until
5160 // after we perform semantic analysis, so the expression is potentially
5161 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005162 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00005163 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005164
John McCall60d7b3a2010-08-24 06:29:42 +00005165 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005166 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005167 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005168
Douglas Gregorb98b1992009-08-11 05:31:07 +00005169 if (!getDerived().AlwaysRebuild() &&
5170 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00005171 return SemaRef.Owned(E->Retain());
5172
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005173 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5174 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005175 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005176 E->getLocEnd());
5177}
5178
5179template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005180ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00005181TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5182 if (E->isTypeOperand()) {
5183 TypeSourceInfo *TInfo
5184 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5185 if (!TInfo)
5186 return ExprError();
5187
5188 if (!getDerived().AlwaysRebuild() &&
5189 TInfo == E->getTypeOperandSourceInfo())
5190 return SemaRef.Owned(E->Retain());
5191
5192 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5193 E->getLocStart(),
5194 TInfo,
5195 E->getLocEnd());
5196 }
5197
5198 // We don't know whether the expression is potentially evaluated until
5199 // after we perform semantic analysis, so the expression is potentially
5200 // potentially evaluated.
5201 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5202
5203 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5204 if (SubExpr.isInvalid())
5205 return ExprError();
5206
5207 if (!getDerived().AlwaysRebuild() &&
5208 SubExpr.get() == E->getExprOperand())
5209 return SemaRef.Owned(E->Retain());
5210
5211 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5212 E->getLocStart(),
5213 SubExpr.get(),
5214 E->getLocEnd());
5215}
5216
5217template<typename Derived>
5218ExprResult
John McCall454feb92009-12-08 09:21:05 +00005219TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005220 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005221}
Mike Stump1eb44332009-09-09 15:08:12 +00005222
Douglas Gregorb98b1992009-08-11 05:31:07 +00005223template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005224ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005225TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005226 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005227 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005228}
Mike Stump1eb44332009-09-09 15:08:12 +00005229
Douglas Gregorb98b1992009-08-11 05:31:07 +00005230template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005231ExprResult
John McCall454feb92009-12-08 09:21:05 +00005232TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005233 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005234
Douglas Gregorb98b1992009-08-11 05:31:07 +00005235 QualType T = getDerived().TransformType(E->getType());
5236 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005237 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005238
Douglas Gregorb98b1992009-08-11 05:31:07 +00005239 if (!getDerived().AlwaysRebuild() &&
5240 T == E->getType())
5241 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005242
Douglas Gregor828a1972010-01-07 23:12:05 +00005243 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005244}
Mike Stump1eb44332009-09-09 15:08:12 +00005245
Douglas Gregorb98b1992009-08-11 05:31:07 +00005246template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005247ExprResult
John McCall454feb92009-12-08 09:21:05 +00005248TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005249 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005250 if (SubExpr.isInvalid())
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 if (!getDerived().AlwaysRebuild() &&
5254 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005255 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005256
John McCall9ae2f072010-08-23 23:25:46 +00005257 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005258}
Mike Stump1eb44332009-09-09 15:08:12 +00005259
Douglas Gregorb98b1992009-08-11 05:31:07 +00005260template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005261ExprResult
John McCall454feb92009-12-08 09:21:05 +00005262TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005263 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005264 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5265 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005266 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00005267 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005268
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005269 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005270 Param == E->getParam())
5271 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005272
Douglas Gregor036aed12009-12-23 23:03:06 +00005273 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005274}
Mike Stump1eb44332009-09-09 15:08:12 +00005275
Douglas Gregorb98b1992009-08-11 05:31:07 +00005276template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005277ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00005278TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5279 CXXScalarValueInitExpr *E) {
5280 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5281 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005282 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00005283
Douglas Gregorb98b1992009-08-11 05:31:07 +00005284 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005285 T == E->getTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00005286 return SemaRef.Owned(E->Retain());
5287
Douglas Gregorab6677e2010-09-08 00:15:04 +00005288 return getDerived().RebuildCXXScalarValueInitExpr(T,
5289 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00005290 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005291}
Mike Stump1eb44332009-09-09 15:08:12 +00005292
Douglas Gregorb98b1992009-08-11 05:31:07 +00005293template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005294ExprResult
John McCall454feb92009-12-08 09:21:05 +00005295TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005296 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005297 TypeSourceInfo *AllocTypeInfo
5298 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5299 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005300 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005301
Douglas Gregorb98b1992009-08-11 05:31:07 +00005302 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00005303 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005304 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005305 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005306
Douglas Gregorb98b1992009-08-11 05:31:07 +00005307 // Transform the placement arguments (if any).
5308 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005309 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005310 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005311 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005312 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005313 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005314
Douglas Gregorb98b1992009-08-11 05:31:07 +00005315 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5316 PlacementArgs.push_back(Arg.take());
5317 }
Mike Stump1eb44332009-09-09 15:08:12 +00005318
Douglas Gregor43959a92009-08-20 07:17:43 +00005319 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00005320 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005321 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005322 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5323 break;
5324
John McCall60d7b3a2010-08-24 06:29:42 +00005325 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005326 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005327 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005328
Douglas Gregorb98b1992009-08-11 05:31:07 +00005329 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5330 ConstructorArgs.push_back(Arg.take());
5331 }
Mike Stump1eb44332009-09-09 15:08:12 +00005332
Douglas Gregor1af74512010-02-26 00:38:10 +00005333 // Transform constructor, new operator, and delete operator.
5334 CXXConstructorDecl *Constructor = 0;
5335 if (E->getConstructor()) {
5336 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005337 getDerived().TransformDecl(E->getLocStart(),
5338 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005339 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005340 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005341 }
5342
5343 FunctionDecl *OperatorNew = 0;
5344 if (E->getOperatorNew()) {
5345 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005346 getDerived().TransformDecl(E->getLocStart(),
5347 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005348 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00005349 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005350 }
5351
5352 FunctionDecl *OperatorDelete = 0;
5353 if (E->getOperatorDelete()) {
5354 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005355 getDerived().TransformDecl(E->getLocStart(),
5356 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005357 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005358 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005359 }
Sean Huntc3021132010-05-05 15:23:54 +00005360
Douglas Gregorb98b1992009-08-11 05:31:07 +00005361 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005362 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005363 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005364 Constructor == E->getConstructor() &&
5365 OperatorNew == E->getOperatorNew() &&
5366 OperatorDelete == E->getOperatorDelete() &&
5367 !ArgumentChanged) {
5368 // Mark any declarations we need as referenced.
5369 // FIXME: instantiation-specific.
5370 if (Constructor)
5371 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5372 if (OperatorNew)
5373 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5374 if (OperatorDelete)
5375 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005376 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005377 }
Mike Stump1eb44332009-09-09 15:08:12 +00005378
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005379 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005380 if (!ArraySize.get()) {
5381 // If no array size was specified, but the new expression was
5382 // instantiated with an array type (e.g., "new T" where T is
5383 // instantiated with "int[4]"), extract the outer bound from the
5384 // array type as our array size. We do this with constant and
5385 // dependently-sized array types.
5386 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5387 if (!ArrayT) {
5388 // Do nothing
5389 } else if (const ConstantArrayType *ConsArrayT
5390 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005391 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00005392 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5393 ConsArrayT->getSize(),
5394 SemaRef.Context.getSizeType(),
5395 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005396 AllocType = ConsArrayT->getElementType();
5397 } else if (const DependentSizedArrayType *DepArrayT
5398 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5399 if (DepArrayT->getSizeExpr()) {
5400 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5401 AllocType = DepArrayT->getElementType();
5402 }
5403 }
5404 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005405
Douglas Gregorb98b1992009-08-11 05:31:07 +00005406 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5407 E->isGlobalNew(),
5408 /*FIXME:*/E->getLocStart(),
5409 move_arg(PlacementArgs),
5410 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00005411 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005412 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005413 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00005414 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005415 /*FIXME:*/E->getLocStart(),
5416 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005417 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005418}
Mike Stump1eb44332009-09-09 15:08:12 +00005419
Douglas Gregorb98b1992009-08-11 05:31:07 +00005420template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005421ExprResult
John McCall454feb92009-12-08 09:21:05 +00005422TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005423 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005424 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005425 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005426
Douglas Gregor1af74512010-02-26 00:38:10 +00005427 // Transform the delete operator, if known.
5428 FunctionDecl *OperatorDelete = 0;
5429 if (E->getOperatorDelete()) {
5430 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005431 getDerived().TransformDecl(E->getLocStart(),
5432 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005433 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005434 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005435 }
Sean Huntc3021132010-05-05 15:23:54 +00005436
Douglas Gregorb98b1992009-08-11 05:31:07 +00005437 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005438 Operand.get() == E->getArgument() &&
5439 OperatorDelete == E->getOperatorDelete()) {
5440 // Mark any declarations we need as referenced.
5441 // FIXME: instantiation-specific.
5442 if (OperatorDelete)
5443 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005444 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005445 }
Mike Stump1eb44332009-09-09 15:08:12 +00005446
Douglas Gregorb98b1992009-08-11 05:31:07 +00005447 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5448 E->isGlobalDelete(),
5449 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00005450 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005451}
Mike Stump1eb44332009-09-09 15:08:12 +00005452
Douglas Gregorb98b1992009-08-11 05:31:07 +00005453template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005454ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005455TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005456 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005457 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00005458 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005459 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005460
John McCallb3d87482010-08-24 05:47:05 +00005461 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005462 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005463 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005464 E->getOperatorLoc(),
5465 E->isArrow()? tok::arrow : tok::period,
5466 ObjectTypePtr,
5467 MayBePseudoDestructor);
5468 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005469 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005470
John McCallb3d87482010-08-24 05:47:05 +00005471 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora71d8192009-09-04 17:36:40 +00005472 NestedNameSpecifier *Qualifier
5473 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00005474 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005475 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00005476 if (E->getQualifier() && !Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005477 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005478
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005479 PseudoDestructorTypeStorage Destroyed;
5480 if (E->getDestroyedTypeInfo()) {
5481 TypeSourceInfo *DestroyedTypeInfo
5482 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5483 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005484 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005485 Destroyed = DestroyedTypeInfo;
5486 } else if (ObjectType->isDependentType()) {
5487 // We aren't likely to be able to resolve the identifier down to a type
5488 // now anyway, so just retain the identifier.
5489 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5490 E->getDestroyedTypeLoc());
5491 } else {
5492 // Look for a destructor known with the given name.
5493 CXXScopeSpec SS;
5494 if (Qualifier) {
5495 SS.setScopeRep(Qualifier);
5496 SS.setRange(E->getQualifierRange());
5497 }
Sean Huntc3021132010-05-05 15:23:54 +00005498
John McCallb3d87482010-08-24 05:47:05 +00005499 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005500 *E->getDestroyedTypeIdentifier(),
5501 E->getDestroyedTypeLoc(),
5502 /*Scope=*/0,
5503 SS, ObjectTypePtr,
5504 false);
5505 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005506 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005507
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005508 Destroyed
5509 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5510 E->getDestroyedTypeLoc());
5511 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005512
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005513 TypeSourceInfo *ScopeTypeInfo = 0;
5514 if (E->getScopeTypeInfo()) {
Sean Huntc3021132010-05-05 15:23:54 +00005515 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005516 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005517 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005518 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00005519 }
Sean Huntc3021132010-05-05 15:23:54 +00005520
John McCall9ae2f072010-08-23 23:25:46 +00005521 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005522 E->getOperatorLoc(),
5523 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005524 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005525 E->getQualifierRange(),
5526 ScopeTypeInfo,
5527 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005528 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005529 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005530}
Mike Stump1eb44332009-09-09 15:08:12 +00005531
Douglas Gregora71d8192009-09-04 17:36:40 +00005532template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005533ExprResult
John McCallba135432009-11-21 08:51:07 +00005534TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005535 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005536 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5537
5538 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5539 Sema::LookupOrdinaryName);
5540
5541 // Transform all the decls.
5542 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5543 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005544 NamedDecl *InstD = static_cast<NamedDecl*>(
5545 getDerived().TransformDecl(Old->getNameLoc(),
5546 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005547 if (!InstD) {
5548 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5549 // This can happen because of dependent hiding.
5550 if (isa<UsingShadowDecl>(*I))
5551 continue;
5552 else
John McCallf312b1e2010-08-26 23:41:50 +00005553 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005554 }
John McCallf7a1a742009-11-24 19:00:30 +00005555
5556 // Expand using declarations.
5557 if (isa<UsingDecl>(InstD)) {
5558 UsingDecl *UD = cast<UsingDecl>(InstD);
5559 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5560 E = UD->shadow_end(); I != E; ++I)
5561 R.addDecl(*I);
5562 continue;
5563 }
5564
5565 R.addDecl(InstD);
5566 }
5567
5568 // Resolve a kind, but don't do any further analysis. If it's
5569 // ambiguous, the callee needs to deal with it.
5570 R.resolveKind();
5571
5572 // Rebuild the nested-name qualifier, if present.
5573 CXXScopeSpec SS;
5574 NestedNameSpecifier *Qualifier = 0;
5575 if (Old->getQualifier()) {
5576 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005577 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005578 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005579 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005580
John McCallf7a1a742009-11-24 19:00:30 +00005581 SS.setScopeRep(Qualifier);
5582 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005583 }
5584
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005585 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005586 CXXRecordDecl *NamingClass
5587 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5588 Old->getNameLoc(),
5589 Old->getNamingClass()));
5590 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00005591 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005592
Douglas Gregor66c45152010-04-27 16:10:10 +00005593 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005594 }
5595
5596 // If we have no template arguments, it's a normal declaration name.
5597 if (!Old->hasExplicitTemplateArgs())
5598 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5599
5600 // If we have template arguments, rebuild them, then rebuild the
5601 // templateid expression.
5602 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5603 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5604 TemplateArgumentLoc Loc;
5605 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005606 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00005607 TransArgs.addArgument(Loc);
5608 }
5609
5610 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5611 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005612}
Mike Stump1eb44332009-09-09 15:08:12 +00005613
Douglas Gregorb98b1992009-08-11 05:31:07 +00005614template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005615ExprResult
John McCall454feb92009-12-08 09:21:05 +00005616TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005617 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005618
Douglas Gregorb98b1992009-08-11 05:31:07 +00005619 QualType T = getDerived().TransformType(E->getQueriedType());
5620 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005621 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005622
Douglas Gregorb98b1992009-08-11 05:31:07 +00005623 if (!getDerived().AlwaysRebuild() &&
5624 T == E->getQueriedType())
5625 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005626
Douglas Gregorb98b1992009-08-11 05:31:07 +00005627 // FIXME: Bad location information
5628 SourceLocation FakeLParenLoc
5629 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00005630
5631 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005632 E->getLocStart(),
5633 /*FIXME:*/FakeLParenLoc,
5634 T,
5635 E->getLocEnd());
5636}
Mike Stump1eb44332009-09-09 15:08:12 +00005637
Douglas Gregorb98b1992009-08-11 05:31:07 +00005638template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005639ExprResult
John McCall865d4472009-11-19 22:55:06 +00005640TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005641 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005642 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005643 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005644 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005645 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00005646 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005647
Abramo Bagnara25777432010-08-11 22:01:17 +00005648 DeclarationNameInfo NameInfo
5649 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5650 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005651 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005652
John McCallf7a1a742009-11-24 19:00:30 +00005653 if (!E->hasExplicitTemplateArgs()) {
5654 if (!getDerived().AlwaysRebuild() &&
5655 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005656 // Note: it is sufficient to compare the Name component of NameInfo:
5657 // if name has not changed, DNLoc has not changed either.
5658 NameInfo.getName() == E->getDeclName())
John McCallf7a1a742009-11-24 19:00:30 +00005659 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005660
John McCallf7a1a742009-11-24 19:00:30 +00005661 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5662 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005663 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005664 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005665 }
John McCalld5532b62009-11-23 01:53:49 +00005666
5667 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005668 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005669 TemplateArgumentLoc Loc;
5670 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005671 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005672 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005673 }
5674
John McCallf7a1a742009-11-24 19:00:30 +00005675 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5676 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005677 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005678 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005679}
5680
5681template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005682ExprResult
John McCall454feb92009-12-08 09:21:05 +00005683TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005684 // CXXConstructExprs are always implicit, so when we have a
5685 // 1-argument construction we just transform that argument.
5686 if (E->getNumArgs() == 1 ||
5687 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5688 return getDerived().TransformExpr(E->getArg(0));
5689
Douglas Gregorb98b1992009-08-11 05:31:07 +00005690 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5691
5692 QualType T = getDerived().TransformType(E->getType());
5693 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005694 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005695
5696 CXXConstructorDecl *Constructor
5697 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005698 getDerived().TransformDecl(E->getLocStart(),
5699 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005700 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005701 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005702
Douglas Gregorb98b1992009-08-11 05:31:07 +00005703 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005704 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005705 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005706 ArgEnd = E->arg_end();
5707 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005708 if (getDerived().DropCallArgument(*Arg)) {
5709 ArgumentChanged = true;
5710 break;
5711 }
5712
John McCall60d7b3a2010-08-24 06:29:42 +00005713 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005714 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005715 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005716
Douglas Gregorb98b1992009-08-11 05:31:07 +00005717 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005718 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005719 }
5720
5721 if (!getDerived().AlwaysRebuild() &&
5722 T == E->getType() &&
5723 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005724 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005725 // Mark the constructor as referenced.
5726 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005727 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005728 return SemaRef.Owned(E->Retain());
Douglas Gregorc845aad2010-02-26 00:01:57 +00005729 }
Mike Stump1eb44332009-09-09 15:08:12 +00005730
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005731 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5732 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00005733 move_arg(Args),
5734 E->requiresZeroInitialization(),
5735 E->getConstructionKind());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005736}
Mike Stump1eb44332009-09-09 15:08:12 +00005737
Douglas Gregorb98b1992009-08-11 05:31:07 +00005738/// \brief Transform a C++ temporary-binding expression.
5739///
Douglas Gregor51326552009-12-24 18:51:59 +00005740/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5741/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005742template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005743ExprResult
John McCall454feb92009-12-08 09:21:05 +00005744TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005745 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005746}
Mike Stump1eb44332009-09-09 15:08:12 +00005747
5748/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005749/// be destroyed after the expression is evaluated.
5750///
Douglas Gregor51326552009-12-24 18:51:59 +00005751/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5752/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005753template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005754ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005755TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005756 CXXExprWithTemporaries *E) {
5757 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005758}
Mike Stump1eb44332009-09-09 15:08:12 +00005759
Douglas Gregorb98b1992009-08-11 05:31:07 +00005760template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005761ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005762TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00005763 CXXTemporaryObjectExpr *E) {
5764 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5765 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005766 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005767
Douglas Gregorb98b1992009-08-11 05:31:07 +00005768 CXXConstructorDecl *Constructor
5769 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005770 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005771 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005772 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005773 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005774
Douglas Gregorb98b1992009-08-11 05:31:07 +00005775 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005776 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005777 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005778 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005779 ArgEnd = E->arg_end();
5780 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005781 if (getDerived().DropCallArgument(*Arg)) {
5782 ArgumentChanged = true;
5783 break;
5784 }
5785
John McCall60d7b3a2010-08-24 06:29:42 +00005786 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005787 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005788 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005789
Douglas Gregorb98b1992009-08-11 05:31:07 +00005790 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5791 Args.push_back((Expr *)TransArg.release());
5792 }
Mike Stump1eb44332009-09-09 15:08:12 +00005793
Douglas Gregorb98b1992009-08-11 05:31:07 +00005794 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005795 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005796 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005797 !ArgumentChanged) {
5798 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00005799 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Chandler Carrutha3ce8ae2010-03-31 18:34:58 +00005800 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor91be6f52010-03-02 17:18:33 +00005801 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00005802
5803 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5804 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005805 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005806 E->getLocEnd());
5807}
Mike Stump1eb44332009-09-09 15:08:12 +00005808
Douglas Gregorb98b1992009-08-11 05:31:07 +00005809template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005810ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005811TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005812 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00005813 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5814 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005815 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005816
Douglas Gregorb98b1992009-08-11 05:31:07 +00005817 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005818 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005819 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5820 ArgEnd = E->arg_end();
5821 Arg != ArgEnd; ++Arg) {
John McCall60d7b3a2010-08-24 06:29:42 +00005822 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005823 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005824 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005825
Douglas Gregorb98b1992009-08-11 05:31:07 +00005826 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005827 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005828 }
Mike Stump1eb44332009-09-09 15:08:12 +00005829
Douglas Gregorb98b1992009-08-11 05:31:07 +00005830 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005831 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005832 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005833 return SemaRef.Owned(E->Retain());
5834
Douglas Gregorb98b1992009-08-11 05:31:07 +00005835 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00005836 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005837 E->getLParenLoc(),
5838 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005839 E->getRParenLoc());
5840}
Mike Stump1eb44332009-09-09 15:08:12 +00005841
Douglas Gregorb98b1992009-08-11 05:31:07 +00005842template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005843ExprResult
John McCall865d4472009-11-19 22:55:06 +00005844TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005845 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005846 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005847 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005848 Expr *OldBase;
5849 QualType BaseType;
5850 QualType ObjectType;
5851 if (!E->isImplicitAccess()) {
5852 OldBase = E->getBase();
5853 Base = getDerived().TransformExpr(OldBase);
5854 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005855 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005856
John McCallaa81e162009-12-01 22:10:20 +00005857 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00005858 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00005859 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005860 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005861 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005862 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005863 ObjectTy,
5864 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005865 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005866 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005867
John McCallb3d87482010-08-24 05:47:05 +00005868 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00005869 BaseType = ((Expr*) Base.get())->getType();
5870 } else {
5871 OldBase = 0;
5872 BaseType = getDerived().TransformType(E->getBaseType());
5873 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5874 }
Mike Stump1eb44332009-09-09 15:08:12 +00005875
Douglas Gregor6cd21982009-10-20 05:58:46 +00005876 // Transform the first part of the nested-name-specifier that qualifies
5877 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005878 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005879 = getDerived().TransformFirstQualifierInScope(
5880 E->getFirstQualifierFoundInScope(),
5881 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005882
Douglas Gregora38c6872009-09-03 16:14:30 +00005883 NestedNameSpecifier *Qualifier = 0;
5884 if (E->getQualifier()) {
5885 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5886 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005887 ObjectType,
5888 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005889 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005890 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00005891 }
Mike Stump1eb44332009-09-09 15:08:12 +00005892
Abramo Bagnara25777432010-08-11 22:01:17 +00005893 DeclarationNameInfo NameInfo
5894 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5895 ObjectType);
5896 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005897 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005898
John McCallaa81e162009-12-01 22:10:20 +00005899 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005900 // This is a reference to a member without an explicitly-specified
5901 // template argument list. Optimize for this common case.
5902 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005903 Base.get() == OldBase &&
5904 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005905 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005906 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005907 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005908 return SemaRef.Owned(E->Retain());
5909
John McCall9ae2f072010-08-23 23:25:46 +00005910 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005911 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005912 E->isArrow(),
5913 E->getOperatorLoc(),
5914 Qualifier,
5915 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005916 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005917 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005918 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005919 }
5920
John McCalld5532b62009-11-23 01:53:49 +00005921 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005922 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005923 TemplateArgumentLoc Loc;
5924 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005925 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005926 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005927 }
Mike Stump1eb44332009-09-09 15:08:12 +00005928
John McCall9ae2f072010-08-23 23:25:46 +00005929 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005930 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005931 E->isArrow(),
5932 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005933 Qualifier,
5934 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005935 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005936 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005937 &TransArgs);
5938}
5939
5940template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005941ExprResult
John McCall454feb92009-12-08 09:21:05 +00005942TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005943 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005944 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005945 QualType BaseType;
5946 if (!Old->isImplicitAccess()) {
5947 Base = getDerived().TransformExpr(Old->getBase());
5948 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005949 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005950 BaseType = ((Expr*) Base.get())->getType();
5951 } else {
5952 BaseType = getDerived().TransformType(Old->getBaseType());
5953 }
John McCall129e2df2009-11-30 22:42:35 +00005954
5955 NestedNameSpecifier *Qualifier = 0;
5956 if (Old->getQualifier()) {
5957 Qualifier
5958 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005959 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005960 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00005961 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00005962 }
5963
Abramo Bagnara25777432010-08-11 22:01:17 +00005964 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00005965 Sema::LookupOrdinaryName);
5966
5967 // Transform all the decls.
5968 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5969 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005970 NamedDecl *InstD = static_cast<NamedDecl*>(
5971 getDerived().TransformDecl(Old->getMemberLoc(),
5972 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005973 if (!InstD) {
5974 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5975 // This can happen because of dependent hiding.
5976 if (isa<UsingShadowDecl>(*I))
5977 continue;
5978 else
John McCallf312b1e2010-08-26 23:41:50 +00005979 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005980 }
John McCall129e2df2009-11-30 22:42:35 +00005981
5982 // Expand using declarations.
5983 if (isa<UsingDecl>(InstD)) {
5984 UsingDecl *UD = cast<UsingDecl>(InstD);
5985 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5986 E = UD->shadow_end(); I != E; ++I)
5987 R.addDecl(*I);
5988 continue;
5989 }
5990
5991 R.addDecl(InstD);
5992 }
5993
5994 R.resolveKind();
5995
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005996 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00005997 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00005998 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005999 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00006000 Old->getMemberLoc(),
6001 Old->getNamingClass()));
6002 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006003 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006004
Douglas Gregor66c45152010-04-27 16:10:10 +00006005 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006006 }
Sean Huntc3021132010-05-05 15:23:54 +00006007
John McCall129e2df2009-11-30 22:42:35 +00006008 TemplateArgumentListInfo TransArgs;
6009 if (Old->hasExplicitTemplateArgs()) {
6010 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6011 TransArgs.setRAngleLoc(Old->getRAngleLoc());
6012 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6013 TemplateArgumentLoc Loc;
6014 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6015 Loc))
John McCallf312b1e2010-08-26 23:41:50 +00006016 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006017 TransArgs.addArgument(Loc);
6018 }
6019 }
John McCallc2233c52010-01-15 08:34:02 +00006020
6021 // FIXME: to do this check properly, we will need to preserve the
6022 // first-qualifier-in-scope here, just in case we had a dependent
6023 // base (and therefore couldn't do the check) and a
6024 // nested-name-qualifier (and therefore could do the lookup).
6025 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006026
John McCall9ae2f072010-08-23 23:25:46 +00006027 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006028 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006029 Old->getOperatorLoc(),
6030 Old->isArrow(),
6031 Qualifier,
6032 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006033 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006034 R,
6035 (Old->hasExplicitTemplateArgs()
6036 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006037}
6038
6039template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006040ExprResult
John McCall454feb92009-12-08 09:21:05 +00006041TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006042 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006043}
6044
Mike Stump1eb44332009-09-09 15:08:12 +00006045template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006046ExprResult
John McCall454feb92009-12-08 09:21:05 +00006047TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006048 TypeSourceInfo *EncodedTypeInfo
6049 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6050 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006051 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006052
Douglas Gregorb98b1992009-08-11 05:31:07 +00006053 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006054 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00006055 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006056
6057 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006058 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006059 E->getRParenLoc());
6060}
Mike Stump1eb44332009-09-09 15:08:12 +00006061
Douglas Gregorb98b1992009-08-11 05:31:07 +00006062template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006063ExprResult
John McCall454feb92009-12-08 09:21:05 +00006064TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006065 // Transform arguments.
6066 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006067 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006068 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006069 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor92e986e2010-04-22 16:44:27 +00006070 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006071 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006072
Douglas Gregor92e986e2010-04-22 16:44:27 +00006073 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00006074 Args.push_back(Arg.get());
Douglas Gregor92e986e2010-04-22 16:44:27 +00006075 }
6076
6077 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6078 // Class message: transform the receiver type.
6079 TypeSourceInfo *ReceiverTypeInfo
6080 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6081 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006082 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006083
Douglas Gregor92e986e2010-04-22 16:44:27 +00006084 // If nothing changed, just retain the existing message send.
6085 if (!getDerived().AlwaysRebuild() &&
6086 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6087 return SemaRef.Owned(E->Retain());
6088
6089 // Build a new class message send.
6090 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6091 E->getSelector(),
6092 E->getMethodDecl(),
6093 E->getLeftLoc(),
6094 move_arg(Args),
6095 E->getRightLoc());
6096 }
6097
6098 // Instance message: transform the receiver
6099 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6100 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006101 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006102 = getDerived().TransformExpr(E->getInstanceReceiver());
6103 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006104 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006105
6106 // If nothing changed, just retain the existing message send.
6107 if (!getDerived().AlwaysRebuild() &&
6108 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6109 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006110
Douglas Gregor92e986e2010-04-22 16:44:27 +00006111 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006112 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006113 E->getSelector(),
6114 E->getMethodDecl(),
6115 E->getLeftLoc(),
6116 move_arg(Args),
6117 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006118}
6119
Mike Stump1eb44332009-09-09 15:08:12 +00006120template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006121ExprResult
John McCall454feb92009-12-08 09:21:05 +00006122TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006123 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006124}
6125
Mike Stump1eb44332009-09-09 15:08:12 +00006126template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006127ExprResult
John McCall454feb92009-12-08 09:21:05 +00006128TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006129 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006130}
6131
Mike Stump1eb44332009-09-09 15:08:12 +00006132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006133ExprResult
John McCall454feb92009-12-08 09:21:05 +00006134TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006135 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006136 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006137 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006138 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006139
6140 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006141
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006142 // If nothing changed, just retain the existing expression.
6143 if (!getDerived().AlwaysRebuild() &&
6144 Base.get() == E->getBase())
6145 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006146
John McCall9ae2f072010-08-23 23:25:46 +00006147 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006148 E->getLocation(),
6149 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006150}
6151
Mike Stump1eb44332009-09-09 15:08:12 +00006152template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006153ExprResult
John McCall454feb92009-12-08 09:21:05 +00006154TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregore3303542010-04-26 20:47:02 +00006155 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006156 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00006157 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006158 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006159
Douglas Gregore3303542010-04-26 20:47:02 +00006160 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006161
Douglas Gregore3303542010-04-26 20:47:02 +00006162 // If nothing changed, just retain the existing expression.
6163 if (!getDerived().AlwaysRebuild() &&
6164 Base.get() == E->getBase())
6165 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006166
John McCall9ae2f072010-08-23 23:25:46 +00006167 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregore3303542010-04-26 20:47:02 +00006168 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006169}
6170
Mike Stump1eb44332009-09-09 15:08:12 +00006171template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006172ExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00006173TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00006174 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006175 // If this implicit setter/getter refers to class methods, it cannot have any
6176 // dependent parts. Just retain the existing declaration.
6177 if (E->getInterfaceDecl())
6178 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006179
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006180 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006181 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006182 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006183 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006184
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006185 // We don't need to transform the getters/setters; they will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006186
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006187 // If nothing changed, just retain the existing expression.
6188 if (!getDerived().AlwaysRebuild() &&
6189 Base.get() == E->getBase())
6190 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006191
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006192 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6193 E->getGetterMethod(),
6194 E->getType(),
6195 E->getSetterMethod(),
6196 E->getLocation(),
John McCall9ae2f072010-08-23 23:25:46 +00006197 Base.get());
Sean Huntc3021132010-05-05 15:23:54 +00006198
Douglas Gregorb98b1992009-08-11 05:31:07 +00006199}
6200
Mike Stump1eb44332009-09-09 15:08:12 +00006201template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006202ExprResult
John McCall454feb92009-12-08 09:21:05 +00006203TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006204 // Can never occur in a dependent context.
Mike Stump1eb44332009-09-09 15:08:12 +00006205 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006206}
6207
Mike Stump1eb44332009-09-09 15:08:12 +00006208template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006209ExprResult
John McCall454feb92009-12-08 09:21:05 +00006210TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006211 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006212 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006213 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006214 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006215
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006216 // If nothing changed, just retain the existing expression.
6217 if (!getDerived().AlwaysRebuild() &&
6218 Base.get() == E->getBase())
6219 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006220
John McCall9ae2f072010-08-23 23:25:46 +00006221 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006222 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006223}
6224
Mike Stump1eb44332009-09-09 15:08:12 +00006225template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006226ExprResult
John McCall454feb92009-12-08 09:21:05 +00006227TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006228 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006229 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006230 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006231 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006232 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006233 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006234
Douglas Gregorb98b1992009-08-11 05:31:07 +00006235 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00006236 SubExprs.push_back(SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006237 }
Mike Stump1eb44332009-09-09 15:08:12 +00006238
Douglas Gregorb98b1992009-08-11 05:31:07 +00006239 if (!getDerived().AlwaysRebuild() &&
6240 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00006241 return SemaRef.Owned(E->Retain());
6242
Douglas Gregorb98b1992009-08-11 05:31:07 +00006243 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6244 move_arg(SubExprs),
6245 E->getRParenLoc());
6246}
6247
Mike Stump1eb44332009-09-09 15:08:12 +00006248template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006249ExprResult
John McCall454feb92009-12-08 09:21:05 +00006250TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006251 SourceLocation CaretLoc(E->getExprLoc());
6252
6253 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6254 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6255 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6256 llvm::SmallVector<ParmVarDecl*, 4> Params;
6257 llvm::SmallVector<QualType, 4> ParamTypes;
6258
6259 // Parameter substitution.
6260 const BlockDecl *BD = E->getBlockDecl();
6261 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6262 EN = BD->param_end(); P != EN; ++P) {
6263 ParmVarDecl *OldParm = (*P);
6264 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6265 QualType NewType = NewParm->getType();
6266 Params.push_back(NewParm);
6267 ParamTypes.push_back(NewParm->getType());
6268 }
6269
6270 const FunctionType *BExprFunctionType = E->getFunctionType();
6271 QualType BExprResultType = BExprFunctionType->getResultType();
6272 if (!BExprResultType.isNull()) {
6273 if (!BExprResultType->isDependentType())
6274 CurBlock->ReturnType = BExprResultType;
6275 else if (BExprResultType != SemaRef.Context.DependentTy)
6276 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6277 }
6278
6279 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00006280 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006281 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006282 return ExprError();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006283 // Set the parameters on the block decl.
6284 if (!Params.empty())
6285 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6286
6287 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6288 CurBlock->ReturnType,
6289 ParamTypes.data(),
6290 ParamTypes.size(),
6291 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006292 0,
6293 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006294
6295 CurBlock->FunctionType = FunctionType;
John McCall9ae2f072010-08-23 23:25:46 +00006296 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006297}
6298
Mike Stump1eb44332009-09-09 15:08:12 +00006299template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006300ExprResult
John McCall454feb92009-12-08 09:21:05 +00006301TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006302 NestedNameSpecifier *Qualifier = 0;
6303
6304 ValueDecl *ND
6305 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6306 E->getDecl()));
6307 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006308 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00006309
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006310 if (!getDerived().AlwaysRebuild() &&
6311 ND == E->getDecl()) {
6312 // Mark it referenced in the new context regardless.
6313 // FIXME: this is a bit instantiation-specific.
6314 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6315
6316 return SemaRef.Owned(E->Retain());
6317 }
6318
Abramo Bagnara25777432010-08-11 22:01:17 +00006319 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006320 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006321 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006322}
Mike Stump1eb44332009-09-09 15:08:12 +00006323
Douglas Gregorb98b1992009-08-11 05:31:07 +00006324//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006325// Type reconstruction
6326//===----------------------------------------------------------------------===//
6327
Mike Stump1eb44332009-09-09 15:08:12 +00006328template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006329QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6330 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006331 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006332 getDerived().getBaseEntity());
6333}
6334
Mike Stump1eb44332009-09-09 15:08:12 +00006335template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006336QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6337 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006338 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006339 getDerived().getBaseEntity());
6340}
6341
Mike Stump1eb44332009-09-09 15:08:12 +00006342template<typename Derived>
6343QualType
John McCall85737a72009-10-30 00:06:24 +00006344TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6345 bool WrittenAsLValue,
6346 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006347 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006348 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006349}
6350
6351template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006352QualType
John McCall85737a72009-10-30 00:06:24 +00006353TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6354 QualType ClassType,
6355 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006356 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006357 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006358}
6359
6360template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006361QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006362TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6363 ArrayType::ArraySizeModifier SizeMod,
6364 const llvm::APInt *Size,
6365 Expr *SizeExpr,
6366 unsigned IndexTypeQuals,
6367 SourceRange BracketsRange) {
6368 if (SizeExpr || !Size)
6369 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6370 IndexTypeQuals, BracketsRange,
6371 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006372
6373 QualType Types[] = {
6374 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6375 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6376 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006377 };
6378 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6379 QualType SizeType;
6380 for (unsigned I = 0; I != NumTypes; ++I)
6381 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6382 SizeType = Types[I];
6383 break;
6384 }
Mike Stump1eb44332009-09-09 15:08:12 +00006385
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006386 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6387 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006388 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006389 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006390 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006391}
Mike Stump1eb44332009-09-09 15:08:12 +00006392
Douglas Gregor577f75a2009-08-04 16:50:30 +00006393template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006394QualType
6395TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006396 ArrayType::ArraySizeModifier SizeMod,
6397 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006398 unsigned IndexTypeQuals,
6399 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006400 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006401 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006402}
6403
6404template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006405QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006406TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006407 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006408 unsigned IndexTypeQuals,
6409 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006410 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006411 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006412}
Mike Stump1eb44332009-09-09 15:08:12 +00006413
Douglas Gregor577f75a2009-08-04 16:50:30 +00006414template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006415QualType
6416TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006417 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006418 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006419 unsigned IndexTypeQuals,
6420 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006421 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006422 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006423 IndexTypeQuals, BracketsRange);
6424}
6425
6426template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006427QualType
6428TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006429 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006430 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006431 unsigned IndexTypeQuals,
6432 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006433 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006434 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006435 IndexTypeQuals, BracketsRange);
6436}
6437
6438template<typename Derived>
6439QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner788b0fd2010-06-23 06:00:24 +00006440 unsigned NumElements,
6441 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006442 // FIXME: semantic checking!
Chris Lattner788b0fd2010-06-23 06:00:24 +00006443 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
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>
6447QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6448 unsigned NumElements,
6449 SourceLocation AttributeLoc) {
6450 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6451 NumElements, true);
6452 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006453 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6454 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00006455 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006456}
Mike Stump1eb44332009-09-09 15:08:12 +00006457
Douglas Gregor577f75a2009-08-04 16:50:30 +00006458template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006459QualType
6460TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00006461 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006462 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00006463 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006464}
Mike Stump1eb44332009-09-09 15:08:12 +00006465
Douglas Gregor577f75a2009-08-04 16:50:30 +00006466template<typename Derived>
6467QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006468 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006469 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006470 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00006471 unsigned Quals,
6472 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00006473 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006474 Quals,
6475 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006476 getDerived().getBaseEntity(),
6477 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006478}
Mike Stump1eb44332009-09-09 15:08:12 +00006479
Douglas Gregor577f75a2009-08-04 16:50:30 +00006480template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006481QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6482 return SemaRef.Context.getFunctionNoProtoType(T);
6483}
6484
6485template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006486QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6487 assert(D && "no decl found");
6488 if (D->isInvalidDecl()) return QualType();
6489
Douglas Gregor92e986e2010-04-22 16:44:27 +00006490 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006491 TypeDecl *Ty;
6492 if (isa<UsingDecl>(D)) {
6493 UsingDecl *Using = cast<UsingDecl>(D);
6494 assert(Using->isTypeName() &&
6495 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6496
6497 // A valid resolved using typename decl points to exactly one type decl.
6498 assert(++Using->shadow_begin() == Using->shadow_end());
6499 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006500
John McCalled976492009-12-04 22:46:56 +00006501 } else {
6502 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6503 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6504 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6505 }
6506
6507 return SemaRef.Context.getTypeDeclType(Ty);
6508}
6509
6510template<typename Derived>
John McCall9ae2f072010-08-23 23:25:46 +00006511QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E) {
6512 return SemaRef.BuildTypeofExprType(E);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006513}
6514
6515template<typename Derived>
6516QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6517 return SemaRef.Context.getTypeOfType(Underlying);
6518}
6519
6520template<typename Derived>
John McCall9ae2f072010-08-23 23:25:46 +00006521QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E) {
6522 return SemaRef.BuildDecltypeType(E);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006523}
6524
6525template<typename Derived>
6526QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006527 TemplateName Template,
6528 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006529 const TemplateArgumentListInfo &TemplateArgs) {
6530 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006531}
Mike Stump1eb44332009-09-09 15:08:12 +00006532
Douglas Gregordcee1a12009-08-06 05:28:30 +00006533template<typename Derived>
6534NestedNameSpecifier *
6535TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6536 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006537 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006538 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006539 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006540 CXXScopeSpec SS;
6541 // FIXME: The source location information is all wrong.
6542 SS.setRange(Range);
6543 SS.setScopeRep(Prefix);
6544 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006545 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006546 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006547 ObjectType,
6548 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006549 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006550}
6551
6552template<typename Derived>
6553NestedNameSpecifier *
6554TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6555 SourceRange Range,
6556 NamespaceDecl *NS) {
6557 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6558}
6559
6560template<typename Derived>
6561NestedNameSpecifier *
6562TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6563 SourceRange Range,
6564 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006565 QualType T) {
6566 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006567 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006568 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006569 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6570 T.getTypePtr());
6571 }
Mike Stump1eb44332009-09-09 15:08:12 +00006572
Douglas Gregordcee1a12009-08-06 05:28:30 +00006573 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6574 return 0;
6575}
Mike Stump1eb44332009-09-09 15:08:12 +00006576
Douglas Gregord1067e52009-08-06 06:41:21 +00006577template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006578TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006579TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6580 bool TemplateKW,
6581 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006582 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006583 Template);
6584}
6585
6586template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006587TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006588TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006589 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006590 const IdentifierInfo &II,
6591 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006592 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006593 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00006594 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006595 UnqualifiedId Name;
6596 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00006597 Sema::TemplateTy Template;
6598 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6599 /*FIXME:*/getDerived().getBaseLocation(),
6600 SS,
6601 Name,
John McCallb3d87482010-08-24 05:47:05 +00006602 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006603 /*EnteringContext=*/false,
6604 Template);
6605 return Template.template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00006606}
Mike Stump1eb44332009-09-09 15:08:12 +00006607
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006609TemplateName
6610TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6611 OverloadedOperatorKind Operator,
6612 QualType ObjectType) {
6613 CXXScopeSpec SS;
6614 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6615 SS.setScopeRep(Qualifier);
6616 UnqualifiedId Name;
6617 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6618 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6619 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00006620 Sema::TemplateTy Template;
6621 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006622 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006623 SS,
6624 Name,
John McCallb3d87482010-08-24 05:47:05 +00006625 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006626 /*EnteringContext=*/false,
6627 Template);
6628 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006629}
Sean Huntc3021132010-05-05 15:23:54 +00006630
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006631template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006632ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6634 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006635 Expr *OrigCallee,
6636 Expr *First,
6637 Expr *Second) {
6638 Expr *Callee = OrigCallee->IgnoreParenCasts();
6639 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006640
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006642 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00006643 if (!First->getType()->isOverloadableType() &&
6644 !Second->getType()->isOverloadableType())
6645 return getSema().CreateBuiltinArraySubscriptExpr(First,
6646 Callee->getLocStart(),
6647 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006648 } else if (Op == OO_Arrow) {
6649 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00006650 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6651 } else if (Second == 0 || isPostIncDec) {
6652 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006653 // The argument is not of overloadable type, so try to create a
6654 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00006655 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006657
John McCall9ae2f072010-08-23 23:25:46 +00006658 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659 }
6660 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006661 if (!First->getType()->isOverloadableType() &&
6662 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663 // Neither of the arguments is an overloadable type, so try to
6664 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00006665 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006666 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00006667 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006668 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006669 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006670
Douglas Gregorb98b1992009-08-11 05:31:07 +00006671 return move(Result);
6672 }
6673 }
Mike Stump1eb44332009-09-09 15:08:12 +00006674
6675 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006677 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006678
John McCall9ae2f072010-08-23 23:25:46 +00006679 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00006680 assert(ULE->requiresADL());
6681
6682 // FIXME: Do we have to check
6683 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006684 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006685 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006686 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006687 }
Mike Stump1eb44332009-09-09 15:08:12 +00006688
Douglas Gregorb98b1992009-08-11 05:31:07 +00006689 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00006690 Expr *Args[2] = { First, Second };
6691 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006692
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693 // Create the overloaded operator invocation for unary operators.
6694 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00006695 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00006697 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698 }
Mike Stump1eb44332009-09-09 15:08:12 +00006699
Sebastian Redlf322ed62009-10-29 20:17:01 +00006700 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00006701 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00006702 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006703 First,
6704 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006705
Douglas Gregorb98b1992009-08-11 05:31:07 +00006706 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00006707 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006708 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006709 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6710 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006711 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006712
Mike Stump1eb44332009-09-09 15:08:12 +00006713 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714}
Mike Stump1eb44332009-09-09 15:08:12 +00006715
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006716template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006717ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00006718TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006719 SourceLocation OperatorLoc,
6720 bool isArrow,
6721 NestedNameSpecifier *Qualifier,
6722 SourceRange QualifierRange,
6723 TypeSourceInfo *ScopeType,
6724 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006725 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006726 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006727 CXXScopeSpec SS;
6728 if (Qualifier) {
6729 SS.setRange(QualifierRange);
6730 SS.setScopeRep(Qualifier);
6731 }
6732
John McCall9ae2f072010-08-23 23:25:46 +00006733 QualType BaseType = Base->getType();
6734 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006735 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006736 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006737 !BaseType->getAs<PointerType>()->getPointeeType()
6738 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006739 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00006740 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006741 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006742 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006743 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006744 /*FIXME?*/true);
6745 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006746
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006747 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00006748 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6749 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6750 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6751 NameInfo.setNamedTypeInfo(DestroyedType);
6752
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006753 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00006754
John McCall9ae2f072010-08-23 23:25:46 +00006755 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006756 OperatorLoc, isArrow,
6757 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00006758 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006759 /*TemplateArgs*/ 0);
6760}
6761
Douglas Gregor577f75a2009-08-04 16:50:30 +00006762} // end namespace clang
6763
6764#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H