blob: 135ca46958d82f53535a88fbd4152866833ecd90 [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,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +0000761 Stmt *SubStmt, bool HasUnusedAttr) {
762 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
763 HasUnusedAttr);
Douglas Gregor43959a92009-08-20 07:17:43 +0000764 }
Mike Stump1eb44332009-09-09 15:08:12 +0000765
Douglas Gregor43959a92009-08-20 07:17:43 +0000766 /// \brief Build a new "if" statement.
767 ///
768 /// By default, performs semantic analysis to build the new statement.
769 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000770 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCall9ae2f072010-08-23 23:25:46 +0000771 VarDecl *CondVar, Stmt *Then,
772 SourceLocation ElseLoc, Stmt *Else) {
773 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000774 }
Mike Stump1eb44332009-09-09 15:08:12 +0000775
Douglas Gregor43959a92009-08-20 07:17:43 +0000776 /// \brief Start building a new switch statement.
777 ///
778 /// By default, performs semantic analysis to build the new statement.
779 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000780 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000781 Expr *Cond, VarDecl *CondVar) {
782 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +0000783 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +0000784 }
Mike Stump1eb44332009-09-09 15:08:12 +0000785
Douglas Gregor43959a92009-08-20 07:17:43 +0000786 /// \brief Attach the body to the switch statement.
787 ///
788 /// By default, performs semantic analysis to build the new statement.
789 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000790 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000791 Stmt *Switch, Stmt *Body) {
792 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000793 }
794
795 /// \brief Build a new while statement.
796 ///
797 /// By default, performs semantic analysis to build the new statement.
798 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000799 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000800 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000801 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000802 Stmt *Body) {
803 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000804 }
Mike Stump1eb44332009-09-09 15:08:12 +0000805
Douglas Gregor43959a92009-08-20 07:17:43 +0000806 /// \brief Build a new do-while statement.
807 ///
808 /// By default, performs semantic analysis to build the new statement.
809 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000810 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregor43959a92009-08-20 07:17:43 +0000811 SourceLocation WhileLoc,
812 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000813 Expr *Cond,
Douglas Gregor43959a92009-08-20 07:17:43 +0000814 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000815 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
816 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +0000817 }
818
819 /// \brief Build a new for statement.
820 ///
821 /// By default, performs semantic analysis to build the new statement.
822 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000823 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000824 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000825 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000826 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCall9ae2f072010-08-23 23:25:46 +0000827 SourceLocation RParenLoc, Stmt *Body) {
828 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCalld226f652010-08-21 09:40:31 +0000829 CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000830 Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000831 }
Mike Stump1eb44332009-09-09 15:08:12 +0000832
Douglas Gregor43959a92009-08-20 07:17:43 +0000833 /// \brief Build a new goto statement.
834 ///
835 /// By default, performs semantic analysis to build the new statement.
836 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000837 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000838 SourceLocation LabelLoc,
839 LabelStmt *Label) {
840 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
841 }
842
843 /// \brief Build a new indirect goto statement.
844 ///
845 /// By default, performs semantic analysis to build the new statement.
846 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000847 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000848 SourceLocation StarLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000849 Expr *Target) {
850 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +0000851 }
Mike Stump1eb44332009-09-09 15:08:12 +0000852
Douglas Gregor43959a92009-08-20 07:17:43 +0000853 /// \brief Build a new return statement.
854 ///
855 /// By default, performs semantic analysis to build the new statement.
856 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000857 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000858 Expr *Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000859
John McCall9ae2f072010-08-23 23:25:46 +0000860 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +0000861 }
Mike Stump1eb44332009-09-09 15:08:12 +0000862
Douglas Gregor43959a92009-08-20 07:17:43 +0000863 /// \brief Build a new declaration statement.
864 ///
865 /// By default, performs semantic analysis to build the new statement.
866 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000867 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000868 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000869 SourceLocation EndLoc) {
870 return getSema().Owned(
871 new (getSema().Context) DeclStmt(
872 DeclGroupRef::Create(getSema().Context,
873 Decls, NumDecls),
874 StartLoc, EndLoc));
875 }
Mike Stump1eb44332009-09-09 15:08:12 +0000876
Anders Carlsson703e3942010-01-24 05:50:09 +0000877 /// \brief Build a new inline asm statement.
878 ///
879 /// By default, performs semantic analysis to build the new statement.
880 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000881 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +0000882 bool IsSimple,
883 bool IsVolatile,
884 unsigned NumOutputs,
885 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000886 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000887 MultiExprArg Constraints,
888 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +0000889 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +0000890 MultiExprArg Clobbers,
891 SourceLocation RParenLoc,
892 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000893 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000894 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +0000895 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +0000896 RParenLoc, MSAsm);
897 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000898
899 /// \brief Build a new Objective-C @try statement.
900 ///
901 /// By default, performs semantic analysis to build the new statement.
902 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000903 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000904 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000905 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +0000906 Stmt *Finally) {
907 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
908 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000909 }
910
Douglas Gregorbe270a02010-04-26 17:57:08 +0000911 /// \brief Rebuild an Objective-C exception declaration.
912 ///
913 /// By default, performs semantic analysis to build the new declaration.
914 /// Subclasses may override this routine to provide different behavior.
915 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
916 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +0000917 return getSema().BuildObjCExceptionDecl(TInfo, T,
918 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +0000919 ExceptionDecl->getLocation());
920 }
Sean Huntc3021132010-05-05 15:23:54 +0000921
Douglas Gregorbe270a02010-04-26 17:57:08 +0000922 /// \brief Build a new Objective-C @catch statement.
923 ///
924 /// By default, performs semantic analysis to build the new statement.
925 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000926 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +0000927 SourceLocation RParenLoc,
928 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +0000929 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +0000930 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000931 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +0000932 }
Sean Huntc3021132010-05-05 15:23:54 +0000933
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000934 /// \brief Build a new Objective-C @finally statement.
935 ///
936 /// By default, performs semantic analysis to build the new statement.
937 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000938 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000939 Stmt *Body) {
940 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000941 }
Sean Huntc3021132010-05-05 15:23:54 +0000942
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000943 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +0000944 ///
945 /// By default, performs semantic analysis to build the new statement.
946 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000947 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000948 Expr *Operand) {
949 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +0000950 }
Sean Huntc3021132010-05-05 15:23:54 +0000951
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000952 /// \brief Build a new Objective-C @synchronized statement.
953 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000954 /// By default, performs semantic analysis to build the new statement.
955 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000956 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000957 Expr *Object,
958 Stmt *Body) {
959 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
960 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000961 }
Douglas Gregorc3203e72010-04-22 23:10:45 +0000962
963 /// \brief Build a new Objective-C fast enumeration statement.
964 ///
965 /// By default, performs semantic analysis to build the new statement.
966 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000967 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +0000968 SourceLocation LParenLoc,
969 Stmt *Element,
970 Expr *Collection,
971 SourceLocation RParenLoc,
972 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +0000973 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000974 Element,
975 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +0000976 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000977 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +0000978 }
Sean Huntc3021132010-05-05 15:23:54 +0000979
Douglas Gregor43959a92009-08-20 07:17:43 +0000980 /// \brief Build a new C++ exception declaration.
981 ///
982 /// By default, performs semantic analysis to build the new decaration.
983 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor83cb9422010-09-09 17:09:21 +0000984 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +0000985 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000986 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +0000987 SourceLocation Loc) {
988 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-08-20 07:17:43 +0000989 }
990
991 /// \brief Build a new C++ catch statement.
992 ///
993 /// By default, performs semantic analysis to build the new statement.
994 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000995 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +0000996 VarDecl *ExceptionDecl,
997 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +0000998 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
999 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001000 }
Mike Stump1eb44332009-09-09 15:08:12 +00001001
Douglas Gregor43959a92009-08-20 07:17:43 +00001002 /// \brief Build a new C++ try statement.
1003 ///
1004 /// By default, performs semantic analysis to build the new statement.
1005 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001006 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001007 Stmt *TryBlock,
1008 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001009 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001010 }
Mike Stump1eb44332009-09-09 15:08:12 +00001011
Douglas Gregorb98b1992009-08-11 05:31:07 +00001012 /// \brief Build a new expression that references a declaration.
1013 ///
1014 /// By default, performs semantic analysis to build the new expression.
1015 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001016 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001017 LookupResult &R,
1018 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001019 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1020 }
1021
1022
1023 /// \brief Build a new expression that references a declaration.
1024 ///
1025 /// By default, performs semantic analysis to build the new expression.
1026 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001027 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001028 SourceRange QualifierRange,
1029 ValueDecl *VD,
1030 const DeclarationNameInfo &NameInfo,
1031 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001032 CXXScopeSpec SS;
1033 SS.setScopeRep(Qualifier);
1034 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001035
1036 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001037
1038 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001039 }
Mike Stump1eb44332009-09-09 15:08:12 +00001040
Douglas Gregorb98b1992009-08-11 05:31:07 +00001041 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001042 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001043 /// By default, performs semantic analysis to build the new expression.
1044 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001045 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001046 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001047 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001048 }
1049
Douglas Gregora71d8192009-09-04 17:36:40 +00001050 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001051 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001052 /// By default, performs semantic analysis to build the new expression.
1053 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001054 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001055 SourceLocation OperatorLoc,
1056 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001057 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001058 SourceRange QualifierRange,
1059 TypeSourceInfo *ScopeType,
1060 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001061 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001062 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001063
Douglas Gregorb98b1992009-08-11 05:31:07 +00001064 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001065 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001066 /// By default, performs semantic analysis to build the new expression.
1067 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001068 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001069 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001070 Expr *SubExpr) {
1071 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001072 }
Mike Stump1eb44332009-09-09 15:08:12 +00001073
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001074 /// \brief Build a new builtin offsetof expression.
1075 ///
1076 /// By default, performs semantic analysis to build the new expression.
1077 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001078 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001079 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001080 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001081 unsigned NumComponents,
1082 SourceLocation RParenLoc) {
1083 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1084 NumComponents, RParenLoc);
1085 }
Sean Huntc3021132010-05-05 15:23:54 +00001086
Douglas Gregorb98b1992009-08-11 05:31:07 +00001087 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001088 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001089 /// By default, performs semantic analysis to build the new expression.
1090 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001091 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001092 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001093 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001094 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001095 }
1096
Mike Stump1eb44332009-09-09 15:08:12 +00001097 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001098 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001099 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001100 /// By default, performs semantic analysis to build the new expression.
1101 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001102 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001103 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001104 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001105 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001106 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001107 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001108
Douglas Gregorb98b1992009-08-11 05:31:07 +00001109 return move(Result);
1110 }
Mike Stump1eb44332009-09-09 15:08:12 +00001111
Douglas Gregorb98b1992009-08-11 05:31:07 +00001112 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001113 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001114 /// By default, performs semantic analysis to build the new expression.
1115 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001116 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001117 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001118 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001119 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001120 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1121 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001122 RBracketLoc);
1123 }
1124
1125 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001126 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001127 /// By default, performs semantic analysis to build the new expression.
1128 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001129 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001130 MultiExprArg Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001131 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001132 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora1a04782010-09-09 16:33:13 +00001133 move(Args), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001134 }
1135
1136 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001137 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001138 /// By default, performs semantic analysis to build the new expression.
1139 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001140 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001141 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001142 NestedNameSpecifier *Qualifier,
1143 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001144 const DeclarationNameInfo &MemberNameInfo,
Eli Friedmanf595cc42009-12-04 06:40:45 +00001145 ValueDecl *Member,
John McCall6bb80172010-03-30 21:47:33 +00001146 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001147 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +00001148 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001149 if (!Member->getDeclName()) {
1150 // We have a reference to an unnamed field.
1151 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +00001152
John McCall9ae2f072010-08-23 23:25:46 +00001153 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001154 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001155 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001156
Mike Stump1eb44332009-09-09 15:08:12 +00001157 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001158 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001159 Member, MemberNameInfo,
Anders Carlssond8b285f2009-09-01 04:26:58 +00001160 cast<FieldDecl>(Member)->getType());
1161 return getSema().Owned(ME);
1162 }
Mike Stump1eb44332009-09-09 15:08:12 +00001163
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001164 CXXScopeSpec SS;
1165 if (Qualifier) {
1166 SS.setRange(QualifierRange);
1167 SS.setScopeRep(Qualifier);
1168 }
1169
John McCall9ae2f072010-08-23 23:25:46 +00001170 getSema().DefaultFunctionArrayConversion(Base);
1171 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001172
John McCall6bb80172010-03-30 21:47:33 +00001173 // FIXME: this involves duplicating earlier analysis in a lot of
1174 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001175 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001176 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001177 R.resolveKind();
1178
John McCall9ae2f072010-08-23 23:25:46 +00001179 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001180 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001181 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001182 }
Mike Stump1eb44332009-09-09 15:08:12 +00001183
Douglas Gregorb98b1992009-08-11 05:31:07 +00001184 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001185 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001186 /// By default, performs semantic analysis to build the new expression.
1187 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001188 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001189 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001190 Expr *LHS, Expr *RHS) {
1191 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001192 }
1193
1194 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001195 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001196 /// By default, performs semantic analysis to build the new expression.
1197 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001198 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001199 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001200 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001201 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001202 Expr *RHS) {
1203 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1204 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001205 }
1206
Douglas Gregorb98b1992009-08-11 05:31:07 +00001207 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001208 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001209 /// By default, performs semantic analysis to build the new expression.
1210 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001211 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001212 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001213 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001214 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001215 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001216 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001217 }
Mike Stump1eb44332009-09-09 15:08:12 +00001218
Douglas Gregorb98b1992009-08-11 05:31:07 +00001219 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001220 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001221 /// By default, performs semantic analysis to build the new expression.
1222 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001223 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001224 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001225 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001226 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001227 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001228 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001229 }
Mike Stump1eb44332009-09-09 15:08:12 +00001230
Douglas Gregorb98b1992009-08-11 05:31:07 +00001231 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001232 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001233 /// By default, performs semantic analysis to build the new expression.
1234 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001235 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001236 SourceLocation OpLoc,
1237 SourceLocation AccessorLoc,
1238 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001239
John McCall129e2df2009-11-30 22:42:35 +00001240 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001241 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001242 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001243 OpLoc, /*IsArrow*/ false,
1244 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001245 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001246 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001247 }
Mike Stump1eb44332009-09-09 15:08:12 +00001248
Douglas Gregorb98b1992009-08-11 05:31:07 +00001249 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001250 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001251 /// By default, performs semantic analysis to build the new expression.
1252 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001253 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001254 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001255 SourceLocation RBraceLoc,
1256 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001257 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001258 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1259 if (Result.isInvalid() || ResultTy->isDependentType())
1260 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001261
Douglas Gregore48319a2009-11-09 17:16:50 +00001262 // Patch in the result type we were given, which may have been computed
1263 // when the initial InitListExpr was built.
1264 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1265 ILE->setType(ResultTy);
1266 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001267 }
Mike Stump1eb44332009-09-09 15:08:12 +00001268
Douglas Gregorb98b1992009-08-11 05:31:07 +00001269 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001270 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001271 /// By default, performs semantic analysis to build the new expression.
1272 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001273 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001274 MultiExprArg ArrayExprs,
1275 SourceLocation EqualOrColonLoc,
1276 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001277 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001278 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001279 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001280 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001281 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001282 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001283
Douglas Gregorb98b1992009-08-11 05:31:07 +00001284 ArrayExprs.release();
1285 return move(Result);
1286 }
Mike Stump1eb44332009-09-09 15:08:12 +00001287
Douglas Gregorb98b1992009-08-11 05:31:07 +00001288 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001289 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001290 /// By default, builds the implicit value initialization without performing
1291 /// any semantic analysis. Subclasses may override this routine to provide
1292 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001293 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001294 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1295 }
Mike Stump1eb44332009-09-09 15:08:12 +00001296
Douglas Gregorb98b1992009-08-11 05:31:07 +00001297 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001298 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001299 /// By default, performs semantic analysis to build the new expression.
1300 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001301 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001302 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001303 SourceLocation RParenLoc) {
1304 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001305 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001306 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001307 }
1308
1309 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001310 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001311 /// By default, performs semantic analysis to build the new expression.
1312 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001313 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001314 MultiExprArg SubExprs,
1315 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001316 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001317 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001318 }
Mike Stump1eb44332009-09-09 15:08:12 +00001319
Douglas Gregorb98b1992009-08-11 05:31:07 +00001320 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001321 ///
1322 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001323 /// rather than attempting to map the label statement itself.
1324 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001325 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001326 SourceLocation LabelLoc,
1327 LabelStmt *Label) {
1328 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1329 }
Mike Stump1eb44332009-09-09 15:08:12 +00001330
Douglas Gregorb98b1992009-08-11 05:31:07 +00001331 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001332 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001333 /// By default, performs semantic analysis to build the new expression.
1334 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001335 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001336 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001337 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001338 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001339 }
Mike Stump1eb44332009-09-09 15:08:12 +00001340
Douglas Gregorb98b1992009-08-11 05:31:07 +00001341 /// \brief Build a new __builtin_types_compatible_p expression.
1342 ///
1343 /// By default, performs semantic analysis to build the new expression.
1344 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001345 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001346 TypeSourceInfo *TInfo1,
1347 TypeSourceInfo *TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001348 SourceLocation RParenLoc) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001349 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1350 TInfo1, TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001351 RParenLoc);
1352 }
Mike Stump1eb44332009-09-09 15:08:12 +00001353
Douglas Gregorb98b1992009-08-11 05:31:07 +00001354 /// \brief Build a new __builtin_choose_expr expression.
1355 ///
1356 /// By default, performs semantic analysis to build the new expression.
1357 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001358 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001359 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001360 SourceLocation RParenLoc) {
1361 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001362 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001363 RParenLoc);
1364 }
Mike Stump1eb44332009-09-09 15:08:12 +00001365
Douglas Gregorb98b1992009-08-11 05:31:07 +00001366 /// \brief Build a new overloaded operator call expression.
1367 ///
1368 /// By default, performs semantic analysis to build the new expression.
1369 /// The semantic analysis provides the behavior of template instantiation,
1370 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001371 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001372 /// argument-dependent lookup, etc. Subclasses may override this routine to
1373 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001374 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001375 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001376 Expr *Callee,
1377 Expr *First,
1378 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001379
1380 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001381 /// reinterpret_cast.
1382 ///
1383 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001384 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001385 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001386 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001387 Stmt::StmtClass Class,
1388 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001389 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001390 SourceLocation RAngleLoc,
1391 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001392 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001393 SourceLocation RParenLoc) {
1394 switch (Class) {
1395 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001396 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001397 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001398 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001399
1400 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001401 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001402 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001403 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001404
Douglas Gregorb98b1992009-08-11 05:31:07 +00001405 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001406 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001407 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001408 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001410
Douglas Gregorb98b1992009-08-11 05:31:07 +00001411 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001412 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001413 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001414 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001415
Douglas Gregorb98b1992009-08-11 05:31:07 +00001416 default:
1417 assert(false && "Invalid C++ named cast");
1418 break;
1419 }
Mike Stump1eb44332009-09-09 15:08:12 +00001420
John McCallf312b1e2010-08-26 23:41:50 +00001421 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001422 }
Mike Stump1eb44332009-09-09 15:08:12 +00001423
Douglas Gregorb98b1992009-08-11 05:31:07 +00001424 /// \brief Build a new C++ static_cast expression.
1425 ///
1426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001428 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001430 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 SourceLocation RAngleLoc,
1432 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001433 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001435 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001436 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001437 SourceRange(LAngleLoc, RAngleLoc),
1438 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 }
1440
1441 /// \brief Build a new C++ dynamic_cast expression.
1442 ///
1443 /// By default, performs semantic analysis to build the new expression.
1444 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001445 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001446 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001447 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001448 SourceLocation RAngleLoc,
1449 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001450 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001451 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001452 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001453 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001454 SourceRange(LAngleLoc, RAngleLoc),
1455 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 }
1457
1458 /// \brief Build a new C++ reinterpret_cast expression.
1459 ///
1460 /// By default, performs semantic analysis to build the new expression.
1461 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001462 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001464 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001465 SourceLocation RAngleLoc,
1466 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001467 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001468 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001469 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001470 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001471 SourceRange(LAngleLoc, RAngleLoc),
1472 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 }
1474
1475 /// \brief Build a new C++ const_cast expression.
1476 ///
1477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001479 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001481 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 SourceLocation RAngleLoc,
1483 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001484 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001486 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001487 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001488 SourceRange(LAngleLoc, RAngleLoc),
1489 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 }
Mike Stump1eb44332009-09-09 15:08:12 +00001491
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 /// \brief Build a new C++ functional-style cast expression.
1493 ///
1494 /// By default, performs semantic analysis to build the new expression.
1495 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001496 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1497 SourceLocation LParenLoc,
1498 Expr *Sub,
1499 SourceLocation RParenLoc) {
1500 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001501 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 RParenLoc);
1503 }
Mike Stump1eb44332009-09-09 15:08:12 +00001504
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 /// \brief Build a new C++ typeid(type) expression.
1506 ///
1507 /// By default, performs semantic analysis to build the new expression.
1508 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001509 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001510 SourceLocation TypeidLoc,
1511 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001513 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001514 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 }
Mike Stump1eb44332009-09-09 15:08:12 +00001516
Francois Pichet01b7c302010-09-08 12:20:18 +00001517
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 /// \brief Build a new C++ typeid(expr) expression.
1519 ///
1520 /// By default, performs semantic analysis to build the new expression.
1521 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001522 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001523 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001524 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001526 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001527 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001528 }
1529
Francois Pichet01b7c302010-09-08 12:20:18 +00001530 /// \brief Build a new C++ __uuidof(type) expression.
1531 ///
1532 /// By default, performs semantic analysis to build the new expression.
1533 /// Subclasses may override this routine to provide different behavior.
1534 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1535 SourceLocation TypeidLoc,
1536 TypeSourceInfo *Operand,
1537 SourceLocation RParenLoc) {
1538 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1539 RParenLoc);
1540 }
1541
1542 /// \brief Build a new C++ __uuidof(expr) expression.
1543 ///
1544 /// By default, performs semantic analysis to build the new expression.
1545 /// Subclasses may override this routine to provide different behavior.
1546 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1547 SourceLocation TypeidLoc,
1548 Expr *Operand,
1549 SourceLocation RParenLoc) {
1550 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1551 RParenLoc);
1552 }
1553
Douglas Gregorb98b1992009-08-11 05:31:07 +00001554 /// \brief Build a new C++ "this" expression.
1555 ///
1556 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001557 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001558 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001559 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001560 QualType ThisType,
1561 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001562 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001563 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1564 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 }
1566
1567 /// \brief Build a new C++ throw expression.
1568 ///
1569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001571 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001572 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 }
1574
1575 /// \brief Build a new C++ default-argument expression.
1576 ///
1577 /// By default, builds a new default-argument expression, which does not
1578 /// require any semantic analysis. Subclasses may override this routine to
1579 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001580 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001581 ParmVarDecl *Param) {
1582 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1583 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 }
1585
1586 /// \brief Build a new C++ zero-initialization expression.
1587 ///
1588 /// By default, performs semantic analysis to build the new expression.
1589 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001590 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1591 SourceLocation LParenLoc,
1592 SourceLocation RParenLoc) {
1593 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001594 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001595 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 }
Mike Stump1eb44332009-09-09 15:08:12 +00001597
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 /// \brief Build a new C++ "new" expression.
1599 ///
1600 /// By default, performs semantic analysis to build the new expression.
1601 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001602 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001603 bool UseGlobal,
1604 SourceLocation PlacementLParen,
1605 MultiExprArg PlacementArgs,
1606 SourceLocation PlacementRParen,
1607 SourceRange TypeIdParens,
1608 QualType AllocatedType,
1609 TypeSourceInfo *AllocatedTypeInfo,
1610 Expr *ArraySize,
1611 SourceLocation ConstructorLParen,
1612 MultiExprArg ConstructorArgs,
1613 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001614 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001615 PlacementLParen,
1616 move(PlacementArgs),
1617 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001618 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001619 AllocatedType,
1620 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001621 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 ConstructorLParen,
1623 move(ConstructorArgs),
1624 ConstructorRParen);
1625 }
Mike Stump1eb44332009-09-09 15:08:12 +00001626
Douglas Gregorb98b1992009-08-11 05:31:07 +00001627 /// \brief Build a new C++ "delete" expression.
1628 ///
1629 /// By default, performs semantic analysis to build the new expression.
1630 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001631 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 bool IsGlobalDelete,
1633 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001634 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001636 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 }
Mike Stump1eb44332009-09-09 15:08:12 +00001638
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 /// \brief Build a new unary type trait expression.
1640 ///
1641 /// By default, performs semantic analysis to build the new expression.
1642 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001643 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001644 SourceLocation StartLoc,
1645 TypeSourceInfo *T,
1646 SourceLocation RParenLoc) {
1647 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 }
1649
Mike Stump1eb44332009-09-09 15:08:12 +00001650 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001651 /// expression.
1652 ///
1653 /// By default, performs semantic analysis to build the new expression.
1654 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001655 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001657 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001658 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 CXXScopeSpec SS;
1660 SS.setRange(QualifierRange);
1661 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001662
1663 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001664 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001665 *TemplateArgs);
1666
Abramo Bagnara25777432010-08-11 22:01:17 +00001667 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 }
1669
1670 /// \brief Build a new template-id expression.
1671 ///
1672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001674 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001675 LookupResult &R,
1676 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001677 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001678 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 }
1680
1681 /// \brief Build a new object-construction expression.
1682 ///
1683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001685 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001686 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 CXXConstructorDecl *Constructor,
1688 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001689 MultiExprArg Args,
1690 bool RequiresZeroInit,
1691 CXXConstructExpr::ConstructionKind ConstructKind) {
John McCallca0408f2010-08-23 06:44:23 +00001692 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001693 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001694 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001695 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001696
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001697 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001698 move_arg(ConvertedArgs),
1699 RequiresZeroInit, ConstructKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 }
1701
1702 /// \brief Build a new object-construction expression.
1703 ///
1704 /// By default, performs semantic analysis to build the new expression.
1705 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001706 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1707 SourceLocation LParenLoc,
1708 MultiExprArg Args,
1709 SourceLocation RParenLoc) {
1710 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 LParenLoc,
1712 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 RParenLoc);
1714 }
1715
1716 /// \brief Build a new object-construction expression.
1717 ///
1718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001720 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1721 SourceLocation LParenLoc,
1722 MultiExprArg Args,
1723 SourceLocation RParenLoc) {
1724 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 LParenLoc,
1726 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001727 RParenLoc);
1728 }
Mike Stump1eb44332009-09-09 15:08:12 +00001729
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 /// \brief Build a new member reference expression.
1731 ///
1732 /// By default, performs semantic analysis to build the new expression.
1733 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001734 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001735 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 bool IsArrow,
1737 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001738 NestedNameSpecifier *Qualifier,
1739 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001740 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001741 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001742 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001743 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001744 SS.setRange(QualifierRange);
1745 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001746
John McCall9ae2f072010-08-23 23:25:46 +00001747 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001748 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001749 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001750 MemberNameInfo,
1751 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001752 }
1753
John McCall129e2df2009-11-30 22:42:35 +00001754 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001755 ///
1756 /// By default, performs semantic analysis to build the new expression.
1757 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001758 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001759 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001760 SourceLocation OperatorLoc,
1761 bool IsArrow,
1762 NestedNameSpecifier *Qualifier,
1763 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001764 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001765 LookupResult &R,
1766 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001767 CXXScopeSpec SS;
1768 SS.setRange(QualifierRange);
1769 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001770
John McCall9ae2f072010-08-23 23:25:46 +00001771 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001772 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001773 SS, FirstQualifierInScope,
1774 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001775 }
Mike Stump1eb44332009-09-09 15:08:12 +00001776
Sebastian Redl2e156222010-09-10 20:55:43 +00001777 /// \brief Build a new noexcept expression.
1778 ///
1779 /// By default, performs semantic analysis to build the new expression.
1780 /// Subclasses may override this routine to provide different behavior.
1781 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1782 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1783 }
1784
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 /// \brief Build a new Objective-C @encode expression.
1786 ///
1787 /// By default, performs semantic analysis to build the new expression.
1788 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001789 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001790 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001792 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001794 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795
Douglas Gregor92e986e2010-04-22 16:44:27 +00001796 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00001797 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001798 Selector Sel,
1799 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001800 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001801 MultiExprArg Args,
1802 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001803 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1804 ReceiverTypeInfo->getType(),
1805 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001806 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001807 move(Args));
1808 }
1809
1810 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00001811 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001812 Selector Sel,
1813 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001814 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001815 MultiExprArg Args,
1816 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001817 return SemaRef.BuildInstanceMessage(Receiver,
1818 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00001819 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001820 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001821 move(Args));
1822 }
1823
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001824 /// \brief Build a new Objective-C ivar reference expression.
1825 ///
1826 /// By default, performs semantic analysis to build the new expression.
1827 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001828 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001829 SourceLocation IvarLoc,
1830 bool IsArrow, bool IsFreeIvar) {
1831 // FIXME: We lose track of the IsFreeIvar bit.
1832 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001833 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001834 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1835 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001836 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001837 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00001838 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00001839 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001840 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001841 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001842
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001843 if (Result.get())
1844 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001845
John McCall9ae2f072010-08-23 23:25:46 +00001846 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001847 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001848 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001849 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001850 /*TemplateArgs=*/0);
1851 }
Douglas Gregore3303542010-04-26 20:47:02 +00001852
1853 /// \brief Build a new Objective-C property reference expression.
1854 ///
1855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001857 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001858 ObjCPropertyDecl *Property,
1859 SourceLocation PropertyLoc) {
1860 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001861 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00001862 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1863 Sema::LookupMemberName);
1864 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00001865 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00001866 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00001867 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00001868 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001869 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001870
Douglas Gregore3303542010-04-26 20:47:02 +00001871 if (Result.get())
1872 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001873
John McCall9ae2f072010-08-23 23:25:46 +00001874 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001875 /*FIXME:*/PropertyLoc, IsArrow,
1876 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001877 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001878 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001879 /*TemplateArgs=*/0);
1880 }
Sean Huntc3021132010-05-05 15:23:54 +00001881
1882 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001883 /// expression.
1884 ///
1885 /// By default, performs semantic analysis to build the new expression.
Sean Huntc3021132010-05-05 15:23:54 +00001886 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001887 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001888 ObjCMethodDecl *Getter,
1889 QualType T,
1890 ObjCMethodDecl *Setter,
1891 SourceLocation NameLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001892 Expr *Base) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001893 // Since these expressions can only be value-dependent, we do not need to
1894 // perform semantic analysis again.
John McCall9ae2f072010-08-23 23:25:46 +00001895 return Owned(
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001896 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1897 Setter,
1898 NameLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001899 Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001900 }
1901
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001902 /// \brief Build a new Objective-C "isa" expression.
1903 ///
1904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001906 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001907 bool IsArrow) {
1908 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001909 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001910 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1911 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001912 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001913 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00001914 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001915 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001916 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001917
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001918 if (Result.get())
1919 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001920
John McCall9ae2f072010-08-23 23:25:46 +00001921 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001922 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001923 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001924 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001925 /*TemplateArgs=*/0);
1926 }
Sean Huntc3021132010-05-05 15:23:54 +00001927
Douglas Gregorb98b1992009-08-11 05:31:07 +00001928 /// \brief Build a new shuffle vector expression.
1929 ///
1930 /// By default, performs semantic analysis to build the new expression.
1931 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001932 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001933 MultiExprArg SubExprs,
1934 SourceLocation RParenLoc) {
1935 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001936 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001937 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1938 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1939 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1940 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001941
Douglas Gregorb98b1992009-08-11 05:31:07 +00001942 // Build a reference to the __builtin_shufflevector builtin
1943 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001944 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001945 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001946 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001948
1949 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001950 unsigned NumSubExprs = SubExprs.size();
1951 Expr **Subs = (Expr **)SubExprs.release();
1952 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1953 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00001954 Builtin->getCallResultType(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001955 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00001956 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001957
Douglas Gregorb98b1992009-08-11 05:31:07 +00001958 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00001959 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001961 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001962
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001964 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001965 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001966};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001967
Douglas Gregor43959a92009-08-20 07:17:43 +00001968template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00001969StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00001970 if (!S)
1971 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001972
Douglas Gregor43959a92009-08-20 07:17:43 +00001973 switch (S->getStmtClass()) {
1974 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001975
Douglas Gregor43959a92009-08-20 07:17:43 +00001976 // Transform individual statement nodes
1977#define STMT(Node, Parent) \
1978 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1979#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00001980#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001981
Douglas Gregor43959a92009-08-20 07:17:43 +00001982 // Transform expressions by calling TransformExpr.
1983#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00001984#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00001985#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00001986#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00001987 {
John McCall60d7b3a2010-08-24 06:29:42 +00001988 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00001989 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001990 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001991
John McCall9ae2f072010-08-23 23:25:46 +00001992 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00001993 }
Mike Stump1eb44332009-09-09 15:08:12 +00001994 }
1995
Douglas Gregor43959a92009-08-20 07:17:43 +00001996 return SemaRef.Owned(S->Retain());
1997}
Mike Stump1eb44332009-09-09 15:08:12 +00001998
1999
Douglas Gregor670444e2009-08-04 22:27:00 +00002000template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002001ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002002 if (!E)
2003 return SemaRef.Owned(E);
2004
2005 switch (E->getStmtClass()) {
2006 case Stmt::NoStmtClass: break;
2007#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002008#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002009#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002010 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002011#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002012 }
2013
Douglas Gregorb98b1992009-08-11 05:31:07 +00002014 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002015}
2016
2017template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002018NestedNameSpecifier *
2019TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002020 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002021 QualType ObjectType,
2022 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00002023 if (!NNS)
2024 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002025
Douglas Gregor43959a92009-08-20 07:17:43 +00002026 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002027 NestedNameSpecifier *Prefix = NNS->getPrefix();
2028 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002029 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002030 ObjectType,
2031 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002032 if (!Prefix)
2033 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002034
2035 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00002036 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00002037 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00002038 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002039 }
Mike Stump1eb44332009-09-09 15:08:12 +00002040
Douglas Gregordcee1a12009-08-06 05:28:30 +00002041 switch (NNS->getKind()) {
2042 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00002043 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002044 "Identifier nested-name-specifier with no prefix or object type");
2045 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2046 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002047 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002048
2049 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002050 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002051 ObjectType,
2052 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002053
Douglas Gregordcee1a12009-08-06 05:28:30 +00002054 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002055 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002056 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002057 getDerived().TransformDecl(Range.getBegin(),
2058 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002059 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002060 Prefix == NNS->getPrefix() &&
2061 NS == NNS->getAsNamespace())
2062 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002063
Douglas Gregordcee1a12009-08-06 05:28:30 +00002064 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2065 }
Mike Stump1eb44332009-09-09 15:08:12 +00002066
Douglas Gregordcee1a12009-08-06 05:28:30 +00002067 case NestedNameSpecifier::Global:
2068 // There is no meaningful transformation that one could perform on the
2069 // global scope.
2070 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002071
Douglas Gregordcee1a12009-08-06 05:28:30 +00002072 case NestedNameSpecifier::TypeSpecWithTemplate:
2073 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002074 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00002075 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2076 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002077 if (T.isNull())
2078 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002079
Douglas Gregordcee1a12009-08-06 05:28:30 +00002080 if (!getDerived().AlwaysRebuild() &&
2081 Prefix == NNS->getPrefix() &&
2082 T == QualType(NNS->getAsType(), 0))
2083 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002084
2085 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2086 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002087 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002088 }
2089 }
Mike Stump1eb44332009-09-09 15:08:12 +00002090
Douglas Gregordcee1a12009-08-06 05:28:30 +00002091 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002092 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002093}
2094
2095template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002096DeclarationNameInfo
2097TreeTransform<Derived>
2098::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2099 QualType ObjectType) {
2100 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002101 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002102 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002103
2104 switch (Name.getNameKind()) {
2105 case DeclarationName::Identifier:
2106 case DeclarationName::ObjCZeroArgSelector:
2107 case DeclarationName::ObjCOneArgSelector:
2108 case DeclarationName::ObjCMultiArgSelector:
2109 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002110 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002111 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002112 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002113
Douglas Gregor81499bb2009-09-03 22:13:48 +00002114 case DeclarationName::CXXConstructorName:
2115 case DeclarationName::CXXDestructorName:
2116 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002117 TypeSourceInfo *NewTInfo;
2118 CanQualType NewCanTy;
2119 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2120 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2121 if (!NewTInfo)
2122 return DeclarationNameInfo();
2123 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2124 }
2125 else {
2126 NewTInfo = 0;
2127 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2128 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2129 ObjectType);
2130 if (NewT.isNull())
2131 return DeclarationNameInfo();
2132 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2133 }
Mike Stump1eb44332009-09-09 15:08:12 +00002134
Abramo Bagnara25777432010-08-11 22:01:17 +00002135 DeclarationName NewName
2136 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2137 NewCanTy);
2138 DeclarationNameInfo NewNameInfo(NameInfo);
2139 NewNameInfo.setName(NewName);
2140 NewNameInfo.setNamedTypeInfo(NewTInfo);
2141 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002142 }
Mike Stump1eb44332009-09-09 15:08:12 +00002143 }
2144
Abramo Bagnara25777432010-08-11 22:01:17 +00002145 assert(0 && "Unknown name kind.");
2146 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002147}
2148
2149template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002150TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002151TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2152 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002153 SourceLocation Loc = getDerived().getBaseLocation();
2154
Douglas Gregord1067e52009-08-06 06:41:21 +00002155 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002156 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002157 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002158 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2159 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002160 if (!NNS)
2161 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002162
Douglas Gregord1067e52009-08-06 06:41:21 +00002163 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002164 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002165 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002166 if (!TransTemplate)
2167 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002168
Douglas Gregord1067e52009-08-06 06:41:21 +00002169 if (!getDerived().AlwaysRebuild() &&
2170 NNS == QTN->getQualifier() &&
2171 TransTemplate == Template)
2172 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002173
Douglas Gregord1067e52009-08-06 06:41:21 +00002174 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2175 TransTemplate);
2176 }
Mike Stump1eb44332009-09-09 15:08:12 +00002177
John McCallf7a1a742009-11-24 19:00:30 +00002178 // These should be getting filtered out before they make it into the AST.
2179 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002180 }
Mike Stump1eb44332009-09-09 15:08:12 +00002181
Douglas Gregord1067e52009-08-06 06:41:21 +00002182 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002183 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002184 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002185 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2186 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002187 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00002188 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002189
Douglas Gregord1067e52009-08-06 06:41:21 +00002190 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002191 NNS == DTN->getQualifier() &&
2192 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002193 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002194
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002195 if (DTN->isIdentifier()) {
2196 // FIXME: Bad range
2197 SourceRange QualifierRange(getDerived().getBaseLocation());
2198 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2199 *DTN->getIdentifier(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002200 ObjectType);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002201 }
Sean Huntc3021132010-05-05 15:23:54 +00002202
2203 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002204 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002205 }
Mike Stump1eb44332009-09-09 15:08:12 +00002206
Douglas Gregord1067e52009-08-06 06:41:21 +00002207 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002208 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002209 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002210 if (!TransTemplate)
2211 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002212
Douglas Gregord1067e52009-08-06 06:41:21 +00002213 if (!getDerived().AlwaysRebuild() &&
2214 TransTemplate == Template)
2215 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002216
Douglas Gregord1067e52009-08-06 06:41:21 +00002217 return TemplateName(TransTemplate);
2218 }
Mike Stump1eb44332009-09-09 15:08:12 +00002219
John McCallf7a1a742009-11-24 19:00:30 +00002220 // These should be getting filtered out before they reach the AST.
2221 assert(false && "overloaded function decl survived to here");
2222 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002223}
2224
2225template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002226void TreeTransform<Derived>::InventTemplateArgumentLoc(
2227 const TemplateArgument &Arg,
2228 TemplateArgumentLoc &Output) {
2229 SourceLocation Loc = getDerived().getBaseLocation();
2230 switch (Arg.getKind()) {
2231 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002232 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002233 break;
2234
2235 case TemplateArgument::Type:
2236 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002237 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002238
John McCall833ca992009-10-29 08:12:44 +00002239 break;
2240
Douglas Gregor788cd062009-11-11 01:00:40 +00002241 case TemplateArgument::Template:
2242 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2243 break;
Sean Huntc3021132010-05-05 15:23:54 +00002244
John McCall833ca992009-10-29 08:12:44 +00002245 case TemplateArgument::Expression:
2246 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2247 break;
2248
2249 case TemplateArgument::Declaration:
2250 case TemplateArgument::Integral:
2251 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002252 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002253 break;
2254 }
2255}
2256
2257template<typename Derived>
2258bool TreeTransform<Derived>::TransformTemplateArgument(
2259 const TemplateArgumentLoc &Input,
2260 TemplateArgumentLoc &Output) {
2261 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002262 switch (Arg.getKind()) {
2263 case TemplateArgument::Null:
2264 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002265 Output = Input;
2266 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002267
Douglas Gregor670444e2009-08-04 22:27:00 +00002268 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002269 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002270 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002271 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002272
2273 DI = getDerived().TransformType(DI);
2274 if (!DI) return true;
2275
2276 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2277 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002278 }
Mike Stump1eb44332009-09-09 15:08:12 +00002279
Douglas Gregor670444e2009-08-04 22:27:00 +00002280 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002281 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002282 DeclarationName Name;
2283 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2284 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002285 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002286 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002287 if (!D) return true;
2288
John McCall828bff22009-10-29 18:45:58 +00002289 Expr *SourceExpr = Input.getSourceDeclExpression();
2290 if (SourceExpr) {
2291 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002292 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002293 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002294 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002295 }
2296
2297 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002298 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002299 }
Mike Stump1eb44332009-09-09 15:08:12 +00002300
Douglas Gregor788cd062009-11-11 01:00:40 +00002301 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002302 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002303 TemplateName Template
2304 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2305 if (Template.isNull())
2306 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002307
Douglas Gregor788cd062009-11-11 01:00:40 +00002308 Output = TemplateArgumentLoc(TemplateArgument(Template),
2309 Input.getTemplateQualifierRange(),
2310 Input.getTemplateNameLoc());
2311 return false;
2312 }
Sean Huntc3021132010-05-05 15:23:54 +00002313
Douglas Gregor670444e2009-08-04 22:27:00 +00002314 case TemplateArgument::Expression: {
2315 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002316 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002317 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002318
John McCall833ca992009-10-29 08:12:44 +00002319 Expr *InputExpr = Input.getSourceExpression();
2320 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2321
John McCall60d7b3a2010-08-24 06:29:42 +00002322 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002323 = getDerived().TransformExpr(InputExpr);
2324 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002325 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002326 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002327 }
Mike Stump1eb44332009-09-09 15:08:12 +00002328
Douglas Gregor670444e2009-08-04 22:27:00 +00002329 case TemplateArgument::Pack: {
2330 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2331 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002332 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002333 AEnd = Arg.pack_end();
2334 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002335
John McCall833ca992009-10-29 08:12:44 +00002336 // FIXME: preserve source information here when we start
2337 // caring about parameter packs.
2338
John McCall828bff22009-10-29 18:45:58 +00002339 TemplateArgumentLoc InputArg;
2340 TemplateArgumentLoc OutputArg;
2341 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2342 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002343 return true;
2344
John McCall828bff22009-10-29 18:45:58 +00002345 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002346 }
2347 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002348 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002349 true);
John McCall828bff22009-10-29 18:45:58 +00002350 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002351 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002352 }
2353 }
Mike Stump1eb44332009-09-09 15:08:12 +00002354
Douglas Gregor670444e2009-08-04 22:27:00 +00002355 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002356 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002357}
2358
Douglas Gregor577f75a2009-08-04 16:50:30 +00002359//===----------------------------------------------------------------------===//
2360// Type transformation
2361//===----------------------------------------------------------------------===//
2362
2363template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00002364QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregor124b8782010-02-16 19:09:40 +00002365 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002366 if (getDerived().AlreadyTransformed(T))
2367 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002368
John McCalla2becad2009-10-21 00:40:46 +00002369 // Temporary workaround. All of these transformations should
2370 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002371 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002372 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002373
Douglas Gregor124b8782010-02-16 19:09:40 +00002374 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002375
John McCalla2becad2009-10-21 00:40:46 +00002376 if (!NewDI)
2377 return QualType();
2378
2379 return NewDI->getType();
2380}
2381
2382template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002383TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2384 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002385 if (getDerived().AlreadyTransformed(DI->getType()))
2386 return DI;
2387
2388 TypeLocBuilder TLB;
2389
2390 TypeLoc TL = DI->getTypeLoc();
2391 TLB.reserve(TL.getFullDataSize());
2392
Douglas Gregor124b8782010-02-16 19:09:40 +00002393 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002394 if (Result.isNull())
2395 return 0;
2396
John McCalla93c9342009-12-07 02:54:59 +00002397 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002398}
2399
2400template<typename Derived>
2401QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002402TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2403 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002404 switch (T.getTypeLocClass()) {
2405#define ABSTRACT_TYPELOC(CLASS, PARENT)
2406#define TYPELOC(CLASS, PARENT) \
2407 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002408 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2409 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002410#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002411 }
Mike Stump1eb44332009-09-09 15:08:12 +00002412
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002413 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002414 return QualType();
2415}
2416
2417/// FIXME: By default, this routine adds type qualifiers only to types
2418/// that can have qualifiers, and silently suppresses those qualifiers
2419/// that are not permitted (e.g., qualifiers on reference or function
2420/// types). This is the right thing for template instantiation, but
2421/// probably not for other clients.
2422template<typename Derived>
2423QualType
2424TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002425 QualifiedTypeLoc T,
2426 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002427 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002428
Douglas Gregor124b8782010-02-16 19:09:40 +00002429 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2430 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002431 if (Result.isNull())
2432 return QualType();
2433
2434 // Silently suppress qualifiers if the result type can't be qualified.
2435 // FIXME: this is the right thing for template instantiation, but
2436 // probably not for other clients.
2437 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002438 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002439
John McCall28654742010-06-05 06:41:15 +00002440 if (!Quals.empty()) {
2441 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2442 TLB.push<QualifiedTypeLoc>(Result);
2443 // No location information to preserve.
2444 }
John McCalla2becad2009-10-21 00:40:46 +00002445
2446 return Result;
2447}
2448
2449template <class TyLoc> static inline
2450QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2451 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2452 NewT.setNameLoc(T.getNameLoc());
2453 return T.getType();
2454}
2455
John McCalla2becad2009-10-21 00:40:46 +00002456template<typename Derived>
2457QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002458 BuiltinTypeLoc T,
2459 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002460 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2461 NewT.setBuiltinLoc(T.getBuiltinLoc());
2462 if (T.needsExtraLocalData())
2463 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2464 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002465}
Mike Stump1eb44332009-09-09 15:08:12 +00002466
Douglas Gregor577f75a2009-08-04 16:50:30 +00002467template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002468QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002469 ComplexTypeLoc T,
2470 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002471 // FIXME: recurse?
2472 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002473}
Mike Stump1eb44332009-09-09 15:08:12 +00002474
Douglas Gregor577f75a2009-08-04 16:50:30 +00002475template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002476QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Sean Huntc3021132010-05-05 15:23:54 +00002477 PointerTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00002478 QualType ObjectType) {
Sean Huntc3021132010-05-05 15:23:54 +00002479 QualType PointeeType
2480 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002481 if (PointeeType.isNull())
2482 return QualType();
2483
2484 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002485 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002486 // A dependent pointer type 'T *' has is being transformed such
2487 // that an Objective-C class type is being replaced for 'T'. The
2488 // resulting pointer type is an ObjCObjectPointerType, not a
2489 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002490 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002491
John McCallc12c5bb2010-05-15 11:32:37 +00002492 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2493 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002494 return Result;
2495 }
Sean Huntc3021132010-05-05 15:23:54 +00002496
Douglas Gregor92e986e2010-04-22 16:44:27 +00002497 if (getDerived().AlwaysRebuild() ||
2498 PointeeType != TL.getPointeeLoc().getType()) {
2499 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2500 if (Result.isNull())
2501 return QualType();
2502 }
Sean Huntc3021132010-05-05 15:23:54 +00002503
Douglas Gregor92e986e2010-04-22 16:44:27 +00002504 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2505 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002506 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002507}
Mike Stump1eb44332009-09-09 15:08:12 +00002508
2509template<typename Derived>
2510QualType
John McCalla2becad2009-10-21 00:40:46 +00002511TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002512 BlockPointerTypeLoc TL,
2513 QualType ObjectType) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002514 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002515 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2516 if (PointeeType.isNull())
2517 return QualType();
2518
2519 QualType Result = TL.getType();
2520 if (getDerived().AlwaysRebuild() ||
2521 PointeeType != TL.getPointeeLoc().getType()) {
2522 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002523 TL.getSigilLoc());
2524 if (Result.isNull())
2525 return QualType();
2526 }
2527
Douglas Gregor39968ad2010-04-22 16:50:51 +00002528 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002529 NewT.setSigilLoc(TL.getSigilLoc());
2530 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002531}
2532
John McCall85737a72009-10-30 00:06:24 +00002533/// Transforms a reference type. Note that somewhat paradoxically we
2534/// don't care whether the type itself is an l-value type or an r-value
2535/// type; we only care if the type was *written* as an l-value type
2536/// or an r-value type.
2537template<typename Derived>
2538QualType
2539TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002540 ReferenceTypeLoc TL,
2541 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002542 const ReferenceType *T = TL.getTypePtr();
2543
2544 // Note that this works with the pointee-as-written.
2545 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2546 if (PointeeType.isNull())
2547 return QualType();
2548
2549 QualType Result = TL.getType();
2550 if (getDerived().AlwaysRebuild() ||
2551 PointeeType != T->getPointeeTypeAsWritten()) {
2552 Result = getDerived().RebuildReferenceType(PointeeType,
2553 T->isSpelledAsLValue(),
2554 TL.getSigilLoc());
2555 if (Result.isNull())
2556 return QualType();
2557 }
2558
2559 // r-value references can be rebuilt as l-value references.
2560 ReferenceTypeLoc NewTL;
2561 if (isa<LValueReferenceType>(Result))
2562 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2563 else
2564 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2565 NewTL.setSigilLoc(TL.getSigilLoc());
2566
2567 return Result;
2568}
2569
Mike Stump1eb44332009-09-09 15:08:12 +00002570template<typename Derived>
2571QualType
John McCalla2becad2009-10-21 00:40:46 +00002572TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002573 LValueReferenceTypeLoc TL,
2574 QualType ObjectType) {
2575 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002576}
2577
Mike Stump1eb44332009-09-09 15:08:12 +00002578template<typename Derived>
2579QualType
John McCalla2becad2009-10-21 00:40:46 +00002580TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002581 RValueReferenceTypeLoc TL,
2582 QualType ObjectType) {
2583 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002584}
Mike Stump1eb44332009-09-09 15:08:12 +00002585
Douglas Gregor577f75a2009-08-04 16:50:30 +00002586template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002587QualType
John McCalla2becad2009-10-21 00:40:46 +00002588TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002589 MemberPointerTypeLoc TL,
2590 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002591 MemberPointerType *T = TL.getTypePtr();
2592
2593 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002594 if (PointeeType.isNull())
2595 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002596
John McCalla2becad2009-10-21 00:40:46 +00002597 // TODO: preserve source information for this.
2598 QualType ClassType
2599 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002600 if (ClassType.isNull())
2601 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002602
John McCalla2becad2009-10-21 00:40:46 +00002603 QualType Result = TL.getType();
2604 if (getDerived().AlwaysRebuild() ||
2605 PointeeType != T->getPointeeType() ||
2606 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002607 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2608 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002609 if (Result.isNull())
2610 return QualType();
2611 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002612
John McCalla2becad2009-10-21 00:40:46 +00002613 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2614 NewTL.setSigilLoc(TL.getSigilLoc());
2615
2616 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002617}
2618
Mike Stump1eb44332009-09-09 15:08:12 +00002619template<typename Derived>
2620QualType
John McCalla2becad2009-10-21 00:40:46 +00002621TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002622 ConstantArrayTypeLoc TL,
2623 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002624 ConstantArrayType *T = TL.getTypePtr();
2625 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002626 if (ElementType.isNull())
2627 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002628
John McCalla2becad2009-10-21 00:40:46 +00002629 QualType Result = TL.getType();
2630 if (getDerived().AlwaysRebuild() ||
2631 ElementType != T->getElementType()) {
2632 Result = getDerived().RebuildConstantArrayType(ElementType,
2633 T->getSizeModifier(),
2634 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002635 T->getIndexTypeCVRQualifiers(),
2636 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002637 if (Result.isNull())
2638 return QualType();
2639 }
Sean Huntc3021132010-05-05 15:23:54 +00002640
John McCalla2becad2009-10-21 00:40:46 +00002641 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2642 NewTL.setLBracketLoc(TL.getLBracketLoc());
2643 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002644
John McCalla2becad2009-10-21 00:40:46 +00002645 Expr *Size = TL.getSizeExpr();
2646 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00002647 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002648 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2649 }
2650 NewTL.setSizeExpr(Size);
2651
2652 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002653}
Mike Stump1eb44332009-09-09 15:08:12 +00002654
Douglas Gregor577f75a2009-08-04 16:50:30 +00002655template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002656QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002657 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002658 IncompleteArrayTypeLoc TL,
2659 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002660 IncompleteArrayType *T = TL.getTypePtr();
2661 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002662 if (ElementType.isNull())
2663 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002664
John McCalla2becad2009-10-21 00:40:46 +00002665 QualType Result = TL.getType();
2666 if (getDerived().AlwaysRebuild() ||
2667 ElementType != T->getElementType()) {
2668 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002669 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002670 T->getIndexTypeCVRQualifiers(),
2671 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002672 if (Result.isNull())
2673 return QualType();
2674 }
Sean Huntc3021132010-05-05 15:23:54 +00002675
John McCalla2becad2009-10-21 00:40:46 +00002676 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2677 NewTL.setLBracketLoc(TL.getLBracketLoc());
2678 NewTL.setRBracketLoc(TL.getRBracketLoc());
2679 NewTL.setSizeExpr(0);
2680
2681 return Result;
2682}
2683
2684template<typename Derived>
2685QualType
2686TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002687 VariableArrayTypeLoc TL,
2688 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002689 VariableArrayType *T = TL.getTypePtr();
2690 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2691 if (ElementType.isNull())
2692 return QualType();
2693
2694 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002695 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002696
John McCall60d7b3a2010-08-24 06:29:42 +00002697 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002698 = getDerived().TransformExpr(T->getSizeExpr());
2699 if (SizeResult.isInvalid())
2700 return QualType();
2701
John McCall9ae2f072010-08-23 23:25:46 +00002702 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00002703
2704 QualType Result = TL.getType();
2705 if (getDerived().AlwaysRebuild() ||
2706 ElementType != T->getElementType() ||
2707 Size != T->getSizeExpr()) {
2708 Result = getDerived().RebuildVariableArrayType(ElementType,
2709 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002710 Size,
John McCalla2becad2009-10-21 00:40:46 +00002711 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002712 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002713 if (Result.isNull())
2714 return QualType();
2715 }
Sean Huntc3021132010-05-05 15:23:54 +00002716
John McCalla2becad2009-10-21 00:40:46 +00002717 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2718 NewTL.setLBracketLoc(TL.getLBracketLoc());
2719 NewTL.setRBracketLoc(TL.getRBracketLoc());
2720 NewTL.setSizeExpr(Size);
2721
2722 return Result;
2723}
2724
2725template<typename Derived>
2726QualType
2727TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002728 DependentSizedArrayTypeLoc TL,
2729 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002730 DependentSizedArrayType *T = TL.getTypePtr();
2731 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2732 if (ElementType.isNull())
2733 return QualType();
2734
2735 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002736 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002737
John McCall60d7b3a2010-08-24 06:29:42 +00002738 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002739 = getDerived().TransformExpr(T->getSizeExpr());
2740 if (SizeResult.isInvalid())
2741 return QualType();
2742
2743 Expr *Size = static_cast<Expr*>(SizeResult.get());
2744
2745 QualType Result = TL.getType();
2746 if (getDerived().AlwaysRebuild() ||
2747 ElementType != T->getElementType() ||
2748 Size != T->getSizeExpr()) {
2749 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2750 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002751 Size,
John McCalla2becad2009-10-21 00:40:46 +00002752 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002753 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002754 if (Result.isNull())
2755 return QualType();
2756 }
2757 else SizeResult.take();
2758
2759 // We might have any sort of array type now, but fortunately they
2760 // all have the same location layout.
2761 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2762 NewTL.setLBracketLoc(TL.getLBracketLoc());
2763 NewTL.setRBracketLoc(TL.getRBracketLoc());
2764 NewTL.setSizeExpr(Size);
2765
2766 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002767}
Mike Stump1eb44332009-09-09 15:08:12 +00002768
2769template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002770QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002771 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002772 DependentSizedExtVectorTypeLoc TL,
2773 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002774 DependentSizedExtVectorType *T = TL.getTypePtr();
2775
2776 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002777 QualType ElementType = getDerived().TransformType(T->getElementType());
2778 if (ElementType.isNull())
2779 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002780
Douglas Gregor670444e2009-08-04 22:27:00 +00002781 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002782 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00002783
John McCall60d7b3a2010-08-24 06:29:42 +00002784 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002785 if (Size.isInvalid())
2786 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002787
John McCalla2becad2009-10-21 00:40:46 +00002788 QualType Result = TL.getType();
2789 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002790 ElementType != T->getElementType() ||
2791 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002792 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00002793 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00002794 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002795 if (Result.isNull())
2796 return QualType();
2797 }
John McCalla2becad2009-10-21 00:40:46 +00002798
2799 // Result might be dependent or not.
2800 if (isa<DependentSizedExtVectorType>(Result)) {
2801 DependentSizedExtVectorTypeLoc NewTL
2802 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2803 NewTL.setNameLoc(TL.getNameLoc());
2804 } else {
2805 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2806 NewTL.setNameLoc(TL.getNameLoc());
2807 }
2808
2809 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002810}
Mike Stump1eb44332009-09-09 15:08:12 +00002811
2812template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002813QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002814 VectorTypeLoc TL,
2815 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002816 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002817 QualType ElementType = getDerived().TransformType(T->getElementType());
2818 if (ElementType.isNull())
2819 return QualType();
2820
John McCalla2becad2009-10-21 00:40:46 +00002821 QualType Result = TL.getType();
2822 if (getDerived().AlwaysRebuild() ||
2823 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002824 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner788b0fd2010-06-23 06:00:24 +00002825 T->getAltiVecSpecific());
John McCalla2becad2009-10-21 00:40:46 +00002826 if (Result.isNull())
2827 return QualType();
2828 }
Sean Huntc3021132010-05-05 15:23:54 +00002829
John McCalla2becad2009-10-21 00:40:46 +00002830 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2831 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002832
John McCalla2becad2009-10-21 00:40:46 +00002833 return Result;
2834}
2835
2836template<typename Derived>
2837QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002838 ExtVectorTypeLoc TL,
2839 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002840 VectorType *T = TL.getTypePtr();
2841 QualType ElementType = getDerived().TransformType(T->getElementType());
2842 if (ElementType.isNull())
2843 return QualType();
2844
2845 QualType Result = TL.getType();
2846 if (getDerived().AlwaysRebuild() ||
2847 ElementType != T->getElementType()) {
2848 Result = getDerived().RebuildExtVectorType(ElementType,
2849 T->getNumElements(),
2850 /*FIXME*/ SourceLocation());
2851 if (Result.isNull())
2852 return QualType();
2853 }
Sean Huntc3021132010-05-05 15:23:54 +00002854
John McCalla2becad2009-10-21 00:40:46 +00002855 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2856 NewTL.setNameLoc(TL.getNameLoc());
2857
2858 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002859}
Mike Stump1eb44332009-09-09 15:08:12 +00002860
2861template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002862ParmVarDecl *
2863TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2864 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2865 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2866 if (!NewDI)
2867 return 0;
2868
2869 if (NewDI == OldDI)
2870 return OldParm;
2871 else
2872 return ParmVarDecl::Create(SemaRef.Context,
2873 OldParm->getDeclContext(),
2874 OldParm->getLocation(),
2875 OldParm->getIdentifier(),
2876 NewDI->getType(),
2877 NewDI,
2878 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002879 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002880 /* DefArg */ NULL);
2881}
2882
2883template<typename Derived>
2884bool TreeTransform<Derived>::
2885 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2886 llvm::SmallVectorImpl<QualType> &PTypes,
2887 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2888 FunctionProtoType *T = TL.getTypePtr();
2889
2890 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2891 ParmVarDecl *OldParm = TL.getArg(i);
2892
2893 QualType NewType;
2894 ParmVarDecl *NewParm;
2895
2896 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002897 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2898 if (!NewParm)
2899 return true;
2900 NewType = NewParm->getType();
2901
2902 // Deal with the possibility that we don't have a parameter
2903 // declaration for this parameter.
2904 } else {
2905 NewParm = 0;
2906
2907 QualType OldType = T->getArgType(i);
2908 NewType = getDerived().TransformType(OldType);
2909 if (NewType.isNull())
2910 return true;
2911 }
2912
2913 PTypes.push_back(NewType);
2914 PVars.push_back(NewParm);
2915 }
2916
2917 return false;
2918}
2919
2920template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002921QualType
John McCalla2becad2009-10-21 00:40:46 +00002922TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002923 FunctionProtoTypeLoc TL,
2924 QualType ObjectType) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00002925 // Transform the parameters and return type.
2926 //
2927 // We instantiate in source order, with the return type first followed by
2928 // the parameters, because users tend to expect this (even if they shouldn't
2929 // rely on it!).
2930 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00002931 // When the function has a trailing return type, we instantiate the
2932 // parameters before the return type, since the return type can then refer
2933 // to the parameters themselves (via decltype, sizeof, etc.).
2934 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00002935 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002936 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor895162d2010-04-30 18:55:50 +00002937 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00002938
Douglas Gregordab60ad2010-10-01 18:44:50 +00002939 QualType ResultType;
2940
2941 if (TL.getTrailingReturn()) {
2942 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2943 return QualType();
2944
2945 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2946 if (ResultType.isNull())
2947 return QualType();
2948 }
2949 else {
2950 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2951 if (ResultType.isNull())
2952 return QualType();
2953
2954 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2955 return QualType();
2956 }
2957
John McCalla2becad2009-10-21 00:40:46 +00002958 QualType Result = TL.getType();
2959 if (getDerived().AlwaysRebuild() ||
2960 ResultType != T->getResultType() ||
2961 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2962 Result = getDerived().RebuildFunctionProtoType(ResultType,
2963 ParamTypes.data(),
2964 ParamTypes.size(),
2965 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00002966 T->getTypeQuals(),
2967 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00002968 if (Result.isNull())
2969 return QualType();
2970 }
Mike Stump1eb44332009-09-09 15:08:12 +00002971
John McCalla2becad2009-10-21 00:40:46 +00002972 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2973 NewTL.setLParenLoc(TL.getLParenLoc());
2974 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00002975 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00002976 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2977 NewTL.setArg(i, ParamDecls[i]);
2978
2979 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002980}
Mike Stump1eb44332009-09-09 15:08:12 +00002981
Douglas Gregor577f75a2009-08-04 16:50:30 +00002982template<typename Derived>
2983QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002984 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002985 FunctionNoProtoTypeLoc TL,
2986 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002987 FunctionNoProtoType *T = TL.getTypePtr();
2988 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2989 if (ResultType.isNull())
2990 return QualType();
2991
2992 QualType Result = TL.getType();
2993 if (getDerived().AlwaysRebuild() ||
2994 ResultType != T->getResultType())
2995 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2996
2997 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2998 NewTL.setLParenLoc(TL.getLParenLoc());
2999 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003000 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003001
3002 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003003}
Mike Stump1eb44332009-09-09 15:08:12 +00003004
John McCalled976492009-12-04 22:46:56 +00003005template<typename Derived> QualType
3006TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003007 UnresolvedUsingTypeLoc TL,
3008 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00003009 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003010 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00003011 if (!D)
3012 return QualType();
3013
3014 QualType Result = TL.getType();
3015 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3016 Result = getDerived().RebuildUnresolvedUsingType(D);
3017 if (Result.isNull())
3018 return QualType();
3019 }
3020
3021 // We might get an arbitrary type spec type back. We should at
3022 // least always get a type spec type, though.
3023 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3024 NewTL.setNameLoc(TL.getNameLoc());
3025
3026 return Result;
3027}
3028
Douglas Gregor577f75a2009-08-04 16:50:30 +00003029template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003030QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003031 TypedefTypeLoc TL,
3032 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003033 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003034 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003035 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3036 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003037 if (!Typedef)
3038 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003039
John McCalla2becad2009-10-21 00:40:46 +00003040 QualType Result = TL.getType();
3041 if (getDerived().AlwaysRebuild() ||
3042 Typedef != T->getDecl()) {
3043 Result = getDerived().RebuildTypedefType(Typedef);
3044 if (Result.isNull())
3045 return QualType();
3046 }
Mike Stump1eb44332009-09-09 15:08:12 +00003047
John McCalla2becad2009-10-21 00:40:46 +00003048 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3049 NewTL.setNameLoc(TL.getNameLoc());
3050
3051 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003052}
Mike Stump1eb44332009-09-09 15:08:12 +00003053
Douglas Gregor577f75a2009-08-04 16:50:30 +00003054template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003055QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003056 TypeOfExprTypeLoc TL,
3057 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003058 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003059 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003060
John McCall60d7b3a2010-08-24 06:29:42 +00003061 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003062 if (E.isInvalid())
3063 return QualType();
3064
John McCalla2becad2009-10-21 00:40:46 +00003065 QualType Result = TL.getType();
3066 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003067 E.get() != TL.getUnderlyingExpr()) {
John McCall9ae2f072010-08-23 23:25:46 +00003068 Result = getDerived().RebuildTypeOfExprType(E.get());
John McCalla2becad2009-10-21 00:40:46 +00003069 if (Result.isNull())
3070 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003071 }
John McCalla2becad2009-10-21 00:40:46 +00003072 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003073
John McCalla2becad2009-10-21 00:40:46 +00003074 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003075 NewTL.setTypeofLoc(TL.getTypeofLoc());
3076 NewTL.setLParenLoc(TL.getLParenLoc());
3077 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003078
3079 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003080}
Mike Stump1eb44332009-09-09 15:08:12 +00003081
3082template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003083QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003084 TypeOfTypeLoc TL,
3085 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00003086 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3087 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3088 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003089 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003090
John McCalla2becad2009-10-21 00:40:46 +00003091 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003092 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3093 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003094 if (Result.isNull())
3095 return QualType();
3096 }
Mike Stump1eb44332009-09-09 15:08:12 +00003097
John McCalla2becad2009-10-21 00:40:46 +00003098 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003099 NewTL.setTypeofLoc(TL.getTypeofLoc());
3100 NewTL.setLParenLoc(TL.getLParenLoc());
3101 NewTL.setRParenLoc(TL.getRParenLoc());
3102 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003103
3104 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003105}
Mike Stump1eb44332009-09-09 15:08:12 +00003106
3107template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003108QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003109 DecltypeTypeLoc TL,
3110 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003111 DecltypeType *T = TL.getTypePtr();
3112
Douglas Gregor670444e2009-08-04 22:27:00 +00003113 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003114 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003115
John McCall60d7b3a2010-08-24 06:29:42 +00003116 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003117 if (E.isInvalid())
3118 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003119
John McCalla2becad2009-10-21 00:40:46 +00003120 QualType Result = TL.getType();
3121 if (getDerived().AlwaysRebuild() ||
3122 E.get() != T->getUnderlyingExpr()) {
John McCall9ae2f072010-08-23 23:25:46 +00003123 Result = getDerived().RebuildDecltypeType(E.get());
John McCalla2becad2009-10-21 00:40:46 +00003124 if (Result.isNull())
3125 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003126 }
John McCalla2becad2009-10-21 00:40:46 +00003127 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003128
John McCalla2becad2009-10-21 00:40:46 +00003129 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3130 NewTL.setNameLoc(TL.getNameLoc());
3131
3132 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003133}
3134
3135template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003136QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003137 RecordTypeLoc TL,
3138 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003139 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003140 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003141 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3142 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003143 if (!Record)
3144 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003145
John McCalla2becad2009-10-21 00:40:46 +00003146 QualType Result = TL.getType();
3147 if (getDerived().AlwaysRebuild() ||
3148 Record != T->getDecl()) {
3149 Result = getDerived().RebuildRecordType(Record);
3150 if (Result.isNull())
3151 return QualType();
3152 }
Mike Stump1eb44332009-09-09 15:08:12 +00003153
John McCalla2becad2009-10-21 00:40:46 +00003154 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3155 NewTL.setNameLoc(TL.getNameLoc());
3156
3157 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003158}
Mike Stump1eb44332009-09-09 15:08:12 +00003159
3160template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003161QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003162 EnumTypeLoc TL,
3163 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003164 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003165 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003166 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3167 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003168 if (!Enum)
3169 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003170
John McCalla2becad2009-10-21 00:40:46 +00003171 QualType Result = TL.getType();
3172 if (getDerived().AlwaysRebuild() ||
3173 Enum != T->getDecl()) {
3174 Result = getDerived().RebuildEnumType(Enum);
3175 if (Result.isNull())
3176 return QualType();
3177 }
Mike Stump1eb44332009-09-09 15:08:12 +00003178
John McCalla2becad2009-10-21 00:40:46 +00003179 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3180 NewTL.setNameLoc(TL.getNameLoc());
3181
3182 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003183}
John McCall7da24312009-09-05 00:15:47 +00003184
John McCall3cb0ebd2010-03-10 03:28:59 +00003185template<typename Derived>
3186QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3187 TypeLocBuilder &TLB,
3188 InjectedClassNameTypeLoc TL,
3189 QualType ObjectType) {
3190 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3191 TL.getTypePtr()->getDecl());
3192 if (!D) return QualType();
3193
3194 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3195 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3196 return T;
3197}
3198
Mike Stump1eb44332009-09-09 15:08:12 +00003199
Douglas Gregor577f75a2009-08-04 16:50:30 +00003200template<typename Derived>
3201QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003202 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003203 TemplateTypeParmTypeLoc TL,
3204 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003205 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003206}
3207
Mike Stump1eb44332009-09-09 15:08:12 +00003208template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003209QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003210 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003211 SubstTemplateTypeParmTypeLoc TL,
3212 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003213 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003214}
3215
3216template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003217QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3218 const TemplateSpecializationType *TST,
3219 QualType ObjectType) {
3220 // FIXME: this entire method is a temporary workaround; callers
3221 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00003222
John McCall833ca992009-10-29 08:12:44 +00003223 // Fake up a TemplateSpecializationTypeLoc.
3224 TypeLocBuilder TLB;
3225 TemplateSpecializationTypeLoc TL
3226 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3227
John McCall828bff22009-10-29 18:45:58 +00003228 SourceLocation BaseLoc = getDerived().getBaseLocation();
3229
3230 TL.setTemplateNameLoc(BaseLoc);
3231 TL.setLAngleLoc(BaseLoc);
3232 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00003233 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3234 const TemplateArgument &TA = TST->getArg(i);
3235 TemplateArgumentLoc TAL;
3236 getDerived().InventTemplateArgumentLoc(TA, TAL);
3237 TL.setArgLocInfo(i, TAL.getLocInfo());
3238 }
3239
3240 TypeLocBuilder IgnoredTLB;
3241 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00003242}
Sean Huntc3021132010-05-05 15:23:54 +00003243
Douglas Gregordd62b152009-10-19 22:04:39 +00003244template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003245QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003246 TypeLocBuilder &TLB,
3247 TemplateSpecializationTypeLoc TL,
3248 QualType ObjectType) {
3249 const TemplateSpecializationType *T = TL.getTypePtr();
3250
Mike Stump1eb44332009-09-09 15:08:12 +00003251 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00003252 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003253 if (Template.isNull())
3254 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003255
John McCalld5532b62009-11-23 01:53:49 +00003256 TemplateArgumentListInfo NewTemplateArgs;
3257 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3258 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3259
3260 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3261 TemplateArgumentLoc Loc;
3262 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003263 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003264 NewTemplateArgs.addArgument(Loc);
3265 }
Mike Stump1eb44332009-09-09 15:08:12 +00003266
John McCall833ca992009-10-29 08:12:44 +00003267 // FIXME: maybe don't rebuild if all the template arguments are the same.
3268
3269 QualType Result =
3270 getDerived().RebuildTemplateSpecializationType(Template,
3271 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003272 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003273
3274 if (!Result.isNull()) {
3275 TemplateSpecializationTypeLoc NewTL
3276 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3277 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3278 NewTL.setLAngleLoc(TL.getLAngleLoc());
3279 NewTL.setRAngleLoc(TL.getRAngleLoc());
3280 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3281 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003282 }
Mike Stump1eb44332009-09-09 15:08:12 +00003283
John McCall833ca992009-10-29 08:12:44 +00003284 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003285}
Mike Stump1eb44332009-09-09 15:08:12 +00003286
3287template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003288QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003289TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3290 ElaboratedTypeLoc TL,
3291 QualType ObjectType) {
3292 ElaboratedType *T = TL.getTypePtr();
3293
3294 NestedNameSpecifier *NNS = 0;
3295 // NOTE: the qualifier in an ElaboratedType is optional.
3296 if (T->getQualifier() != 0) {
3297 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003298 TL.getQualifierRange(),
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003299 ObjectType);
3300 if (!NNS)
3301 return QualType();
3302 }
Mike Stump1eb44332009-09-09 15:08:12 +00003303
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003304 QualType NamedT;
3305 // FIXME: this test is meant to workaround a problem (failing assertion)
3306 // occurring if directly executing the code in the else branch.
3307 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3308 TemplateSpecializationTypeLoc OldNamedTL
3309 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3310 const TemplateSpecializationType* OldTST
Jim Grosbach9cbb4d82010-05-19 23:53:08 +00003311 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003312 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3313 if (NamedT.isNull())
3314 return QualType();
3315 TemplateSpecializationTypeLoc NewNamedTL
3316 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3317 NewNamedTL.copy(OldNamedTL);
3318 }
3319 else {
3320 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3321 if (NamedT.isNull())
3322 return QualType();
3323 }
Daniel Dunbara63db842010-05-14 16:34:09 +00003324
John McCalla2becad2009-10-21 00:40:46 +00003325 QualType Result = TL.getType();
3326 if (getDerived().AlwaysRebuild() ||
3327 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003328 NamedT != T->getNamedType()) {
3329 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003330 if (Result.isNull())
3331 return QualType();
3332 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003333
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003334 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003335 NewTL.setKeywordLoc(TL.getKeywordLoc());
3336 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003337
3338 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003339}
Mike Stump1eb44332009-09-09 15:08:12 +00003340
3341template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003342QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3343 DependentNameTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00003344 QualType ObjectType) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003345 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003346
Douglas Gregor577f75a2009-08-04 16:50:30 +00003347 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003348 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3349 TL.getQualifierRange(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003350 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003351 if (!NNS)
3352 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003353
John McCall33500952010-06-11 00:33:02 +00003354 QualType Result
3355 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3356 T->getIdentifier(),
3357 TL.getKeywordLoc(),
3358 TL.getQualifierRange(),
3359 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003360 if (Result.isNull())
3361 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003362
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003363 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3364 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003365 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3366
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003367 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3368 NewTL.setKeywordLoc(TL.getKeywordLoc());
3369 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003370 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003371 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3372 NewTL.setKeywordLoc(TL.getKeywordLoc());
3373 NewTL.setQualifierRange(TL.getQualifierRange());
3374 NewTL.setNameLoc(TL.getNameLoc());
3375 }
John McCalla2becad2009-10-21 00:40:46 +00003376 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003377}
Mike Stump1eb44332009-09-09 15:08:12 +00003378
Douglas Gregor577f75a2009-08-04 16:50:30 +00003379template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003380QualType TreeTransform<Derived>::
3381 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3382 DependentTemplateSpecializationTypeLoc TL,
3383 QualType ObjectType) {
3384 DependentTemplateSpecializationType *T = TL.getTypePtr();
3385
3386 NestedNameSpecifier *NNS
3387 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3388 TL.getQualifierRange(),
3389 ObjectType);
3390 if (!NNS)
3391 return QualType();
3392
3393 TemplateArgumentListInfo NewTemplateArgs;
3394 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3395 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3396
3397 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3398 TemplateArgumentLoc Loc;
3399 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3400 return QualType();
3401 NewTemplateArgs.addArgument(Loc);
3402 }
3403
Douglas Gregor1efb6c72010-09-08 23:56:00 +00003404 QualType Result
3405 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3406 NNS,
3407 TL.getQualifierRange(),
3408 T->getIdentifier(),
3409 TL.getNameLoc(),
3410 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00003411 if (Result.isNull())
3412 return QualType();
3413
3414 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3415 QualType NamedT = ElabT->getNamedType();
3416
3417 // Copy information relevant to the template specialization.
3418 TemplateSpecializationTypeLoc NamedTL
3419 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3420 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3421 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3422 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3423 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3424
3425 // Copy information relevant to the elaborated type.
3426 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3427 NewTL.setKeywordLoc(TL.getKeywordLoc());
3428 NewTL.setQualifierRange(TL.getQualifierRange());
3429 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003430 TypeLoc NewTL(Result, TL.getOpaqueData());
3431 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003432 }
3433 return Result;
3434}
3435
3436template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003437QualType
3438TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003439 ObjCInterfaceTypeLoc TL,
3440 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003441 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003442 TLB.pushFullCopy(TL);
3443 return TL.getType();
3444}
3445
3446template<typename Derived>
3447QualType
3448TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3449 ObjCObjectTypeLoc TL,
3450 QualType ObjectType) {
3451 // ObjCObjectType is never dependent.
3452 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003453 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003454}
Mike Stump1eb44332009-09-09 15:08:12 +00003455
3456template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003457QualType
3458TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003459 ObjCObjectPointerTypeLoc TL,
3460 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003461 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003462 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003463 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003464}
3465
Douglas Gregor577f75a2009-08-04 16:50:30 +00003466//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003467// Statement transformation
3468//===----------------------------------------------------------------------===//
3469template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003470StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003471TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3472 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003473}
3474
3475template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003476StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003477TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3478 return getDerived().TransformCompoundStmt(S, false);
3479}
3480
3481template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003482StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003483TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003484 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00003485 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00003486 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003487 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00003488 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3489 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00003490 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00003491 if (Result.isInvalid()) {
3492 // Immediately fail if this was a DeclStmt, since it's very
3493 // likely that this will cause problems for future statements.
3494 if (isa<DeclStmt>(*B))
3495 return StmtError();
3496
3497 // Otherwise, just keep processing substatements and fail later.
3498 SubStmtInvalid = true;
3499 continue;
3500 }
Mike Stump1eb44332009-09-09 15:08:12 +00003501
Douglas Gregor43959a92009-08-20 07:17:43 +00003502 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3503 Statements.push_back(Result.takeAs<Stmt>());
3504 }
Mike Stump1eb44332009-09-09 15:08:12 +00003505
John McCall7114cba2010-08-27 19:56:05 +00003506 if (SubStmtInvalid)
3507 return StmtError();
3508
Douglas Gregor43959a92009-08-20 07:17:43 +00003509 if (!getDerived().AlwaysRebuild() &&
3510 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003511 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003512
3513 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3514 move_arg(Statements),
3515 S->getRBracLoc(),
3516 IsStmtExpr);
3517}
Mike Stump1eb44332009-09-09 15:08:12 +00003518
Douglas Gregor43959a92009-08-20 07:17:43 +00003519template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003520StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003521TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003522 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00003523 {
3524 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00003525 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003526
Eli Friedman264c1f82009-11-19 03:14:00 +00003527 // Transform the left-hand case value.
3528 LHS = getDerived().TransformExpr(S->getLHS());
3529 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003530 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003531
Eli Friedman264c1f82009-11-19 03:14:00 +00003532 // Transform the right-hand case value (for the GNU case-range extension).
3533 RHS = getDerived().TransformExpr(S->getRHS());
3534 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003535 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00003536 }
Mike Stump1eb44332009-09-09 15:08:12 +00003537
Douglas Gregor43959a92009-08-20 07:17:43 +00003538 // Build the case statement.
3539 // Case statements are always rebuilt so that they will attached to their
3540 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003541 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003542 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003543 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003544 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003545 S->getColonLoc());
3546 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003547 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003548
Douglas Gregor43959a92009-08-20 07:17:43 +00003549 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00003550 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003551 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003552 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003553
Douglas Gregor43959a92009-08-20 07:17:43 +00003554 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00003555 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003556}
3557
3558template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003559StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003560TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003561 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00003562 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003563 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003564 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003565
Douglas Gregor43959a92009-08-20 07:17:43 +00003566 // Default statements are always rebuilt
3567 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003568 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003569}
Mike Stump1eb44332009-09-09 15:08:12 +00003570
Douglas Gregor43959a92009-08-20 07:17:43 +00003571template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003572StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003573TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003574 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003575 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003576 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003577
Douglas Gregor43959a92009-08-20 07:17:43 +00003578 // FIXME: Pass the real colon location in.
3579 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3580 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +00003581 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00003582}
Mike Stump1eb44332009-09-09 15:08:12 +00003583
Douglas Gregor43959a92009-08-20 07:17:43 +00003584template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003585StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003586TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003587 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003588 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003589 VarDecl *ConditionVar = 0;
3590 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003591 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003592 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003593 getDerived().TransformDefinition(
3594 S->getConditionVariable()->getLocation(),
3595 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003596 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003597 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003598 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003599 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003600
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003601 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003602 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003603
3604 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003605 if (S->getCond()) {
John McCall60d7b3a2010-08-24 06:29:42 +00003606 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003607 S->getIfLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003608 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003609 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003610 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003611
John McCall9ae2f072010-08-23 23:25:46 +00003612 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003613 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003614 }
Sean Huntc3021132010-05-05 15:23:54 +00003615
John McCall9ae2f072010-08-23 23:25:46 +00003616 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3617 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003618 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003619
Douglas Gregor43959a92009-08-20 07:17:43 +00003620 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003621 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00003622 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003623 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003624
Douglas Gregor43959a92009-08-20 07:17:43 +00003625 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003626 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00003627 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003628 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003629
Douglas Gregor43959a92009-08-20 07:17:43 +00003630 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003631 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003632 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003633 Then.get() == S->getThen() &&
3634 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003635 return SemaRef.Owned(S->Retain());
3636
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003637 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCall9ae2f072010-08-23 23:25:46 +00003638 Then.get(),
3639 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003640}
3641
3642template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003643StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003644TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003645 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00003646 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00003647 VarDecl *ConditionVar = 0;
3648 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003649 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003650 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003651 getDerived().TransformDefinition(
3652 S->getConditionVariable()->getLocation(),
3653 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003654 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003655 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003656 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003657 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003658
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003659 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003660 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003661 }
Mike Stump1eb44332009-09-09 15:08:12 +00003662
Douglas Gregor43959a92009-08-20 07:17:43 +00003663 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003664 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00003665 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00003666 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003667 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003668 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003669
Douglas Gregor43959a92009-08-20 07:17:43 +00003670 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003671 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003672 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003673 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003674
Douglas Gregor43959a92009-08-20 07:17:43 +00003675 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00003676 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3677 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003678}
Mike Stump1eb44332009-09-09 15:08:12 +00003679
Douglas Gregor43959a92009-08-20 07:17:43 +00003680template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003681StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003682TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003683 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003684 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00003685 VarDecl *ConditionVar = 0;
3686 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003687 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003688 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003689 getDerived().TransformDefinition(
3690 S->getConditionVariable()->getLocation(),
3691 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003692 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003693 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003694 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003695 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003696
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003697 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003698 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003699
3700 if (S->getCond()) {
3701 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003702 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003703 S->getWhileLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003704 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003705 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003706 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00003707 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003708 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003709 }
Mike Stump1eb44332009-09-09 15:08:12 +00003710
John McCall9ae2f072010-08-23 23:25:46 +00003711 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3712 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003713 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003714
Douglas Gregor43959a92009-08-20 07:17:43 +00003715 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003716 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003717 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003718 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003719
Douglas Gregor43959a92009-08-20 07:17:43 +00003720 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003721 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003722 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003723 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00003724 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003725
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003726 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00003727 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003728}
Mike Stump1eb44332009-09-09 15:08:12 +00003729
Douglas Gregor43959a92009-08-20 07:17:43 +00003730template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003731StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003732TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003733 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003734 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003735 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003736 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003737
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003738 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003739 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003740 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003741 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003742
Douglas Gregor43959a92009-08-20 07:17:43 +00003743 if (!getDerived().AlwaysRebuild() &&
3744 Cond.get() == S->getCond() &&
3745 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003746 return SemaRef.Owned(S->Retain());
3747
John McCall9ae2f072010-08-23 23:25:46 +00003748 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3749 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003750 S->getRParenLoc());
3751}
Mike Stump1eb44332009-09-09 15:08:12 +00003752
Douglas Gregor43959a92009-08-20 07:17:43 +00003753template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003754StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003755TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003756 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00003757 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00003758 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003759 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003760
Douglas Gregor43959a92009-08-20 07:17:43 +00003761 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003762 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003763 VarDecl *ConditionVar = 0;
3764 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003765 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003766 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003767 getDerived().TransformDefinition(
3768 S->getConditionVariable()->getLocation(),
3769 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003770 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003771 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003772 } else {
3773 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003774
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003775 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003776 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003777
3778 if (S->getCond()) {
3779 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003780 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003781 S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003782 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003783 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003784 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003785
John McCall9ae2f072010-08-23 23:25:46 +00003786 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003787 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003788 }
Mike Stump1eb44332009-09-09 15:08:12 +00003789
John McCall9ae2f072010-08-23 23:25:46 +00003790 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3791 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003792 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003793
Douglas Gregor43959a92009-08-20 07:17:43 +00003794 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00003795 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00003796 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003797 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003798
John McCall9ae2f072010-08-23 23:25:46 +00003799 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3800 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00003801 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003802
Douglas Gregor43959a92009-08-20 07:17:43 +00003803 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003804 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003805 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003806 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003807
Douglas Gregor43959a92009-08-20 07:17:43 +00003808 if (!getDerived().AlwaysRebuild() &&
3809 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00003810 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003811 Inc.get() == S->getInc() &&
3812 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003813 return SemaRef.Owned(S->Retain());
3814
Douglas Gregor43959a92009-08-20 07:17:43 +00003815 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003816 Init.get(), FullCond, ConditionVar,
3817 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003818}
3819
3820template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003821StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003822TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003823 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003824 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003825 S->getLabel());
3826}
3827
3828template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003829StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003830TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003831 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00003832 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003833 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003834
Douglas Gregor43959a92009-08-20 07:17:43 +00003835 if (!getDerived().AlwaysRebuild() &&
3836 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003837 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003838
3839 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003840 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003841}
3842
3843template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003844StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003845TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3846 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003847}
Mike Stump1eb44332009-09-09 15:08:12 +00003848
Douglas Gregor43959a92009-08-20 07:17:43 +00003849template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003850StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003851TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3852 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003853}
Mike Stump1eb44332009-09-09 15:08:12 +00003854
Douglas Gregor43959a92009-08-20 07:17:43 +00003855template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003856StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003857TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003858 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00003859 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003860 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00003861
Mike Stump1eb44332009-09-09 15:08:12 +00003862 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003863 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00003864 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003865}
Mike Stump1eb44332009-09-09 15:08:12 +00003866
Douglas Gregor43959a92009-08-20 07:17:43 +00003867template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003868StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003869TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003870 bool DeclChanged = false;
3871 llvm::SmallVector<Decl *, 4> Decls;
3872 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3873 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003874 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3875 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003876 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00003877 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003878
Douglas Gregor43959a92009-08-20 07:17:43 +00003879 if (Transformed != *D)
3880 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003881
Douglas Gregor43959a92009-08-20 07:17:43 +00003882 Decls.push_back(Transformed);
3883 }
Mike Stump1eb44332009-09-09 15:08:12 +00003884
Douglas Gregor43959a92009-08-20 07:17:43 +00003885 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003886 return SemaRef.Owned(S->Retain());
3887
3888 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003889 S->getStartLoc(), S->getEndLoc());
3890}
Mike Stump1eb44332009-09-09 15:08:12 +00003891
Douglas Gregor43959a92009-08-20 07:17:43 +00003892template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003893StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003894TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003895 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003896 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003897}
3898
3899template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003900StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003901TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003902
John McCallca0408f2010-08-23 06:44:23 +00003903 ASTOwningVector<Expr*> Constraints(getSema());
3904 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003905 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003906
John McCall60d7b3a2010-08-24 06:29:42 +00003907 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00003908 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00003909
3910 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003911
Anders Carlsson703e3942010-01-24 05:50:09 +00003912 // Go through the outputs.
3913 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003914 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003915
Anders Carlsson703e3942010-01-24 05:50:09 +00003916 // No need to transform the constraint literal.
3917 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003918
Anders Carlsson703e3942010-01-24 05:50:09 +00003919 // Transform the output expr.
3920 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003921 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003922 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003923 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003924
Anders Carlsson703e3942010-01-24 05:50:09 +00003925 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003926
John McCall9ae2f072010-08-23 23:25:46 +00003927 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003928 }
Sean Huntc3021132010-05-05 15:23:54 +00003929
Anders Carlsson703e3942010-01-24 05:50:09 +00003930 // Go through the inputs.
3931 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003932 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003933
Anders Carlsson703e3942010-01-24 05:50:09 +00003934 // No need to transform the constraint literal.
3935 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003936
Anders Carlsson703e3942010-01-24 05:50:09 +00003937 // Transform the input expr.
3938 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003939 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003940 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003941 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003942
Anders Carlsson703e3942010-01-24 05:50:09 +00003943 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003944
John McCall9ae2f072010-08-23 23:25:46 +00003945 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003946 }
Sean Huntc3021132010-05-05 15:23:54 +00003947
Anders Carlsson703e3942010-01-24 05:50:09 +00003948 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3949 return SemaRef.Owned(S->Retain());
3950
3951 // Go through the clobbers.
3952 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3953 Clobbers.push_back(S->getClobber(I)->Retain());
3954
3955 // No need to transform the asm string literal.
3956 AsmString = SemaRef.Owned(S->getAsmString());
3957
3958 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3959 S->isSimple(),
3960 S->isVolatile(),
3961 S->getNumOutputs(),
3962 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003963 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003964 move_arg(Constraints),
3965 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00003966 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003967 move_arg(Clobbers),
3968 S->getRParenLoc(),
3969 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003970}
3971
3972
3973template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003974StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003975TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003976 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00003977 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003978 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003979 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003980
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003981 // Transform the @catch statements (if present).
3982 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003983 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003984 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00003985 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003986 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003987 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003988 if (Catch.get() != S->getCatchStmt(I))
3989 AnyCatchChanged = true;
3990 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003991 }
Sean Huntc3021132010-05-05 15:23:54 +00003992
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003993 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00003994 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003995 if (S->getFinallyStmt()) {
3996 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3997 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003998 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003999 }
4000
4001 // If nothing changed, just retain this statement.
4002 if (!getDerived().AlwaysRebuild() &&
4003 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004004 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004005 Finally.get() == S->getFinallyStmt())
4006 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004007
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004008 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00004009 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4010 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004011}
Mike Stump1eb44332009-09-09 15:08:12 +00004012
Douglas Gregor43959a92009-08-20 07:17:43 +00004013template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004014StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004015TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004016 // Transform the @catch parameter, if there is one.
4017 VarDecl *Var = 0;
4018 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4019 TypeSourceInfo *TSInfo = 0;
4020 if (FromVar->getTypeSourceInfo()) {
4021 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4022 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004023 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004024 }
Sean Huntc3021132010-05-05 15:23:54 +00004025
Douglas Gregorbe270a02010-04-26 17:57:08 +00004026 QualType T;
4027 if (TSInfo)
4028 T = TSInfo->getType();
4029 else {
4030 T = getDerived().TransformType(FromVar->getType());
4031 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004032 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004033 }
Sean Huntc3021132010-05-05 15:23:54 +00004034
Douglas Gregorbe270a02010-04-26 17:57:08 +00004035 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4036 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004037 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004038 }
Sean Huntc3021132010-05-05 15:23:54 +00004039
John McCall60d7b3a2010-08-24 06:29:42 +00004040 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004041 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004042 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004043
4044 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004045 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004046 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004047}
Mike Stump1eb44332009-09-09 15:08:12 +00004048
Douglas Gregor43959a92009-08-20 07:17:43 +00004049template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004050StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004051TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004052 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004053 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004054 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004055 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004056
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004057 // If nothing changed, just retain this statement.
4058 if (!getDerived().AlwaysRebuild() &&
4059 Body.get() == S->getFinallyBody())
4060 return SemaRef.Owned(S->Retain());
4061
4062 // Build a new statement.
4063 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004064 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004065}
Mike Stump1eb44332009-09-09 15:08:12 +00004066
Douglas Gregor43959a92009-08-20 07:17:43 +00004067template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004068StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004069TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004070 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004071 if (S->getThrowExpr()) {
4072 Operand = getDerived().TransformExpr(S->getThrowExpr());
4073 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004074 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004075 }
Sean Huntc3021132010-05-05 15:23:54 +00004076
Douglas Gregord1377b22010-04-22 21:44:01 +00004077 if (!getDerived().AlwaysRebuild() &&
4078 Operand.get() == S->getThrowExpr())
4079 return getSema().Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004080
John McCall9ae2f072010-08-23 23:25:46 +00004081 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004082}
Mike Stump1eb44332009-09-09 15:08:12 +00004083
Douglas Gregor43959a92009-08-20 07:17:43 +00004084template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004085StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004086TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004087 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004088 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004089 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004090 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004091 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004092
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004093 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004094 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004095 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004096 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004097
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004098 // If nothing change, just retain the current statement.
4099 if (!getDerived().AlwaysRebuild() &&
4100 Object.get() == S->getSynchExpr() &&
4101 Body.get() == S->getSynchBody())
4102 return SemaRef.Owned(S->Retain());
4103
4104 // Build a new statement.
4105 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004106 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004107}
4108
4109template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004110StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004111TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004112 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004113 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004114 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004115 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004116 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004117
Douglas Gregorc3203e72010-04-22 23:10:45 +00004118 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00004119 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004120 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004121 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004122
Douglas Gregorc3203e72010-04-22 23:10:45 +00004123 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004124 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004125 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004126 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004127
Douglas Gregorc3203e72010-04-22 23:10:45 +00004128 // If nothing changed, just retain this statement.
4129 if (!getDerived().AlwaysRebuild() &&
4130 Element.get() == S->getElement() &&
4131 Collection.get() == S->getCollection() &&
4132 Body.get() == S->getBody())
4133 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004134
Douglas Gregorc3203e72010-04-22 23:10:45 +00004135 // Build a new statement.
4136 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4137 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004138 Element.get(),
4139 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00004140 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004141 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004142}
4143
4144
4145template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004146StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004147TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4148 // Transform the exception declaration, if any.
4149 VarDecl *Var = 0;
4150 if (S->getExceptionDecl()) {
4151 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00004152 TypeSourceInfo *T = getDerived().TransformType(
4153 ExceptionDecl->getTypeSourceInfo());
4154 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00004155 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004156
Douglas Gregor83cb9422010-09-09 17:09:21 +00004157 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00004158 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00004159 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00004160 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00004161 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004162 }
Mike Stump1eb44332009-09-09 15:08:12 +00004163
Douglas Gregor43959a92009-08-20 07:17:43 +00004164 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00004165 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004166 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004167 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004168
Douglas Gregor43959a92009-08-20 07:17:43 +00004169 if (!getDerived().AlwaysRebuild() &&
4170 !Var &&
4171 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00004172 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004173
4174 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4175 Var,
John McCall9ae2f072010-08-23 23:25:46 +00004176 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004177}
Mike Stump1eb44332009-09-09 15:08:12 +00004178
Douglas Gregor43959a92009-08-20 07:17:43 +00004179template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004180StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004181TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4182 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004183 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004184 = getDerived().TransformCompoundStmt(S->getTryBlock());
4185 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004186 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004187
Douglas Gregor43959a92009-08-20 07:17:43 +00004188 // Transform the handlers.
4189 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004190 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00004191 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004192 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004193 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4194 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004195 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004196
Douglas Gregor43959a92009-08-20 07:17:43 +00004197 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4198 Handlers.push_back(Handler.takeAs<Stmt>());
4199 }
Mike Stump1eb44332009-09-09 15:08:12 +00004200
Douglas Gregor43959a92009-08-20 07:17:43 +00004201 if (!getDerived().AlwaysRebuild() &&
4202 TryBlock.get() == S->getTryBlock() &&
4203 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004204 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004205
John McCall9ae2f072010-08-23 23:25:46 +00004206 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00004207 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004208}
Mike Stump1eb44332009-09-09 15:08:12 +00004209
Douglas Gregor43959a92009-08-20 07:17:43 +00004210//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004211// Expression transformation
4212//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004213template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004214ExprResult
John McCall454feb92009-12-08 09:21:05 +00004215TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004216 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004217}
Mike Stump1eb44332009-09-09 15:08:12 +00004218
4219template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004220ExprResult
John McCall454feb92009-12-08 09:21:05 +00004221TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004222 NestedNameSpecifier *Qualifier = 0;
4223 if (E->getQualifier()) {
4224 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004225 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004226 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00004227 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00004228 }
John McCalldbd872f2009-12-08 09:08:17 +00004229
4230 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004231 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4232 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004233 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00004234 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004235
John McCallec8045d2010-08-17 21:27:17 +00004236 DeclarationNameInfo NameInfo = E->getNameInfo();
4237 if (NameInfo.getName()) {
4238 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4239 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00004240 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00004241 }
Abramo Bagnara25777432010-08-11 22:01:17 +00004242
4243 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004244 Qualifier == E->getQualifier() &&
4245 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00004246 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00004247 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004248
4249 // Mark it referenced in the new context regardless.
4250 // FIXME: this is a bit instantiation-specific.
4251 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4252
Mike Stump1eb44332009-09-09 15:08:12 +00004253 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004254 }
John McCalldbd872f2009-12-08 09:08:17 +00004255
4256 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00004257 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004258 TemplateArgs = &TransArgs;
4259 TransArgs.setLAngleLoc(E->getLAngleLoc());
4260 TransArgs.setRAngleLoc(E->getRAngleLoc());
4261 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4262 TemplateArgumentLoc Loc;
4263 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004264 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00004265 TransArgs.addArgument(Loc);
4266 }
4267 }
4268
Douglas Gregora2813ce2009-10-23 18:54:35 +00004269 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004270 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004271}
Mike Stump1eb44332009-09-09 15:08:12 +00004272
Douglas Gregorb98b1992009-08-11 05:31:07 +00004273template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004274ExprResult
John McCall454feb92009-12-08 09:21:05 +00004275TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004276 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004277}
Mike Stump1eb44332009-09-09 15:08:12 +00004278
Douglas Gregorb98b1992009-08-11 05:31:07 +00004279template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004280ExprResult
John McCall454feb92009-12-08 09:21:05 +00004281TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004282 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004283}
Mike Stump1eb44332009-09-09 15:08:12 +00004284
Douglas Gregorb98b1992009-08-11 05:31:07 +00004285template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004286ExprResult
John McCall454feb92009-12-08 09:21:05 +00004287TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004288 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004289}
Mike Stump1eb44332009-09-09 15:08:12 +00004290
Douglas Gregorb98b1992009-08-11 05:31:07 +00004291template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004292ExprResult
John McCall454feb92009-12-08 09:21:05 +00004293TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004294 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004295}
Mike Stump1eb44332009-09-09 15:08:12 +00004296
Douglas Gregorb98b1992009-08-11 05:31:07 +00004297template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004298ExprResult
John McCall454feb92009-12-08 09:21:05 +00004299TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004300 return SemaRef.Owned(E->Retain());
4301}
4302
4303template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004304ExprResult
John McCall454feb92009-12-08 09:21:05 +00004305TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004306 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004307 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004308 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004309
Douglas Gregorb98b1992009-08-11 05:31:07 +00004310 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004311 return SemaRef.Owned(E->Retain());
4312
John McCall9ae2f072010-08-23 23:25:46 +00004313 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004314 E->getRParen());
4315}
4316
Mike Stump1eb44332009-09-09 15:08:12 +00004317template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004318ExprResult
John McCall454feb92009-12-08 09:21:05 +00004319TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004320 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004321 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004322 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004323
Douglas Gregorb98b1992009-08-11 05:31:07 +00004324 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004325 return SemaRef.Owned(E->Retain());
4326
Douglas Gregorb98b1992009-08-11 05:31:07 +00004327 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4328 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004329 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004330}
Mike Stump1eb44332009-09-09 15:08:12 +00004331
Douglas Gregorb98b1992009-08-11 05:31:07 +00004332template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004333ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004334TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4335 // Transform the type.
4336 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4337 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00004338 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004339
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004340 // Transform all of the components into components similar to what the
4341 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004342 // FIXME: It would be slightly more efficient in the non-dependent case to
4343 // just map FieldDecls, rather than requiring the rebuilder to look for
4344 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004345 // template code that we don't care.
4346 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00004347 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004348 typedef OffsetOfExpr::OffsetOfNode Node;
4349 llvm::SmallVector<Component, 4> Components;
4350 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4351 const Node &ON = E->getComponent(I);
4352 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004353 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004354 Comp.LocStart = ON.getRange().getBegin();
4355 Comp.LocEnd = ON.getRange().getEnd();
4356 switch (ON.getKind()) {
4357 case Node::Array: {
4358 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00004359 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004360 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004361 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004362
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004363 ExprChanged = ExprChanged || Index.get() != FromIndex;
4364 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00004365 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004366 break;
4367 }
Sean Huntc3021132010-05-05 15:23:54 +00004368
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004369 case Node::Field:
4370 case Node::Identifier:
4371 Comp.isBrackets = false;
4372 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004373 if (!Comp.U.IdentInfo)
4374 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004375
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004376 break;
Sean Huntc3021132010-05-05 15:23:54 +00004377
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004378 case Node::Base:
4379 // Will be recomputed during the rebuild.
4380 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004381 }
Sean Huntc3021132010-05-05 15:23:54 +00004382
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004383 Components.push_back(Comp);
4384 }
Sean Huntc3021132010-05-05 15:23:54 +00004385
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004386 // If nothing changed, retain the existing expression.
4387 if (!getDerived().AlwaysRebuild() &&
4388 Type == E->getTypeSourceInfo() &&
4389 !ExprChanged)
4390 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004391
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004392 // Build a new offsetof expression.
4393 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4394 Components.data(), Components.size(),
4395 E->getRParenLoc());
4396}
4397
4398template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004399ExprResult
John McCall454feb92009-12-08 09:21:05 +00004400TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004401 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004402 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004403
John McCalla93c9342009-12-07 02:54:59 +00004404 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004405 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004406 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004407
John McCall5ab75172009-11-04 07:28:41 +00004408 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004409 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004410
John McCall5ab75172009-11-04 07:28:41 +00004411 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004412 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004413 E->getSourceRange());
4414 }
Mike Stump1eb44332009-09-09 15:08:12 +00004415
John McCall60d7b3a2010-08-24 06:29:42 +00004416 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00004417 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004418 // C++0x [expr.sizeof]p1:
4419 // The operand is either an expression, which is an unevaluated operand
4420 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00004421 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004422
Douglas Gregorb98b1992009-08-11 05:31:07 +00004423 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4424 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004425 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004426
Douglas Gregorb98b1992009-08-11 05:31:07 +00004427 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4428 return SemaRef.Owned(E->Retain());
4429 }
Mike Stump1eb44332009-09-09 15:08:12 +00004430
John McCall9ae2f072010-08-23 23:25:46 +00004431 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004432 E->isSizeOf(),
4433 E->getSourceRange());
4434}
Mike Stump1eb44332009-09-09 15:08:12 +00004435
Douglas Gregorb98b1992009-08-11 05:31:07 +00004436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004437ExprResult
John McCall454feb92009-12-08 09:21:05 +00004438TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004439 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004440 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004441 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004442
John McCall60d7b3a2010-08-24 06:29:42 +00004443 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004444 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004445 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004446
4447
Douglas Gregorb98b1992009-08-11 05:31:07 +00004448 if (!getDerived().AlwaysRebuild() &&
4449 LHS.get() == E->getLHS() &&
4450 RHS.get() == E->getRHS())
4451 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004452
John McCall9ae2f072010-08-23 23:25:46 +00004453 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004454 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00004455 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004456 E->getRBracketLoc());
4457}
Mike Stump1eb44332009-09-09 15:08:12 +00004458
4459template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004460ExprResult
John McCall454feb92009-12-08 09:21:05 +00004461TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004462 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00004463 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004464 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004465 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004466
4467 // Transform arguments.
4468 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004469 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004470 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004471 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004472 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004473 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004474
Mike Stump1eb44332009-09-09 15:08:12 +00004475 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00004476 Args.push_back(Arg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004477 }
Mike Stump1eb44332009-09-09 15:08:12 +00004478
Douglas Gregorb98b1992009-08-11 05:31:07 +00004479 if (!getDerived().AlwaysRebuild() &&
4480 Callee.get() == E->getCallee() &&
4481 !ArgChanged)
4482 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004483
Douglas Gregorb98b1992009-08-11 05:31:07 +00004484 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004485 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004486 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00004487 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004488 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004489 E->getRParenLoc());
4490}
Mike Stump1eb44332009-09-09 15:08:12 +00004491
4492template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004493ExprResult
John McCall454feb92009-12-08 09:21:05 +00004494TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004495 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004496 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004497 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004498
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004499 NestedNameSpecifier *Qualifier = 0;
4500 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004501 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004502 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004503 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004504 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00004505 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004506 }
Mike Stump1eb44332009-09-09 15:08:12 +00004507
Eli Friedmanf595cc42009-12-04 06:40:45 +00004508 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004509 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4510 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004511 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00004512 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004513
John McCall6bb80172010-03-30 21:47:33 +00004514 NamedDecl *FoundDecl = E->getFoundDecl();
4515 if (FoundDecl == E->getMemberDecl()) {
4516 FoundDecl = Member;
4517 } else {
4518 FoundDecl = cast_or_null<NamedDecl>(
4519 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4520 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00004521 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00004522 }
4523
Douglas Gregorb98b1992009-08-11 05:31:07 +00004524 if (!getDerived().AlwaysRebuild() &&
4525 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004526 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004527 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004528 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00004529 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00004530
Anders Carlsson1f240322009-12-22 05:24:09 +00004531 // Mark it referenced in the new context regardless.
4532 // FIXME: this is a bit instantiation-specific.
4533 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00004534 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00004535 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004536
John McCalld5532b62009-11-23 01:53:49 +00004537 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00004538 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00004539 TransArgs.setLAngleLoc(E->getLAngleLoc());
4540 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004541 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004542 TemplateArgumentLoc Loc;
4543 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004544 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004545 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004546 }
4547 }
Sean Huntc3021132010-05-05 15:23:54 +00004548
Douglas Gregorb98b1992009-08-11 05:31:07 +00004549 // FIXME: Bogus source location for the operator
4550 SourceLocation FakeOperatorLoc
4551 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4552
John McCallc2233c52010-01-15 08:34:02 +00004553 // FIXME: to do this check properly, we will need to preserve the
4554 // first-qualifier-in-scope here, just in case we had a dependent
4555 // base (and therefore couldn't do the check) and a
4556 // nested-name-qualifier (and therefore could do the lookup).
4557 NamedDecl *FirstQualifierInScope = 0;
4558
John McCall9ae2f072010-08-23 23:25:46 +00004559 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004560 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004561 Qualifier,
4562 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004563 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004564 Member,
John McCall6bb80172010-03-30 21:47:33 +00004565 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00004566 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00004567 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004568 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004569}
Mike Stump1eb44332009-09-09 15:08:12 +00004570
Douglas Gregorb98b1992009-08-11 05:31:07 +00004571template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004572ExprResult
John McCall454feb92009-12-08 09:21:05 +00004573TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004574 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004575 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004576 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004577
John McCall60d7b3a2010-08-24 06:29:42 +00004578 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004579 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004580 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004581
Douglas Gregorb98b1992009-08-11 05:31:07 +00004582 if (!getDerived().AlwaysRebuild() &&
4583 LHS.get() == E->getLHS() &&
4584 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004585 return SemaRef.Owned(E->Retain());
4586
Douglas Gregorb98b1992009-08-11 05:31:07 +00004587 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004588 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004589}
4590
Mike Stump1eb44332009-09-09 15:08:12 +00004591template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004592ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004593TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004594 CompoundAssignOperator *E) {
4595 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004596}
Mike Stump1eb44332009-09-09 15:08:12 +00004597
Douglas Gregorb98b1992009-08-11 05:31:07 +00004598template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004599ExprResult
John McCall454feb92009-12-08 09:21:05 +00004600TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004601 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004602 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004603 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004604
John McCall60d7b3a2010-08-24 06:29:42 +00004605 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004606 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004607 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004608
John McCall60d7b3a2010-08-24 06:29:42 +00004609 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004610 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004611 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004612
Douglas Gregorb98b1992009-08-11 05:31:07 +00004613 if (!getDerived().AlwaysRebuild() &&
4614 Cond.get() == E->getCond() &&
4615 LHS.get() == E->getLHS() &&
4616 RHS.get() == E->getRHS())
4617 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004618
John McCall9ae2f072010-08-23 23:25:46 +00004619 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004620 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004621 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004622 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004623 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004624}
Mike Stump1eb44332009-09-09 15:08:12 +00004625
4626template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004627ExprResult
John McCall454feb92009-12-08 09:21:05 +00004628TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004629 // Implicit casts are eliminated during transformation, since they
4630 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004631 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004632}
Mike Stump1eb44332009-09-09 15:08:12 +00004633
Douglas Gregorb98b1992009-08-11 05:31:07 +00004634template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004635ExprResult
John McCall454feb92009-12-08 09:21:05 +00004636TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004637 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4638 if (!Type)
4639 return ExprError();
4640
John McCall60d7b3a2010-08-24 06:29:42 +00004641 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004642 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004643 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004644 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004645
Douglas Gregorb98b1992009-08-11 05:31:07 +00004646 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004647 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004648 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004649 return SemaRef.Owned(E->Retain());
4650
John McCall9d125032010-01-15 18:39:57 +00004651 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004652 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004653 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004654 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004655}
Mike Stump1eb44332009-09-09 15:08:12 +00004656
Douglas Gregorb98b1992009-08-11 05:31:07 +00004657template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004658ExprResult
John McCall454feb92009-12-08 09:21:05 +00004659TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004660 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4661 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4662 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004663 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004664
John McCall60d7b3a2010-08-24 06:29:42 +00004665 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004666 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004667 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004668
Douglas Gregorb98b1992009-08-11 05:31:07 +00004669 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004670 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004671 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00004672 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004673
John McCall1d7d8d62010-01-19 22:33:45 +00004674 // Note: the expression type doesn't necessarily match the
4675 // type-as-written, but that's okay, because it should always be
4676 // derivable from the initializer.
4677
John McCall42f56b52010-01-18 19:35:47 +00004678 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004679 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00004680 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004681}
Mike Stump1eb44332009-09-09 15:08:12 +00004682
Douglas Gregorb98b1992009-08-11 05:31:07 +00004683template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004684ExprResult
John McCall454feb92009-12-08 09:21:05 +00004685TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004686 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004687 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004688 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004689
Douglas Gregorb98b1992009-08-11 05:31:07 +00004690 if (!getDerived().AlwaysRebuild() &&
4691 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00004692 return SemaRef.Owned(E->Retain());
4693
Douglas Gregorb98b1992009-08-11 05:31:07 +00004694 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004695 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004696 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00004697 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004698 E->getAccessorLoc(),
4699 E->getAccessor());
4700}
Mike Stump1eb44332009-09-09 15:08:12 +00004701
Douglas Gregorb98b1992009-08-11 05:31:07 +00004702template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004703ExprResult
John McCall454feb92009-12-08 09:21:05 +00004704TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004705 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004706
John McCallca0408f2010-08-23 06:44:23 +00004707 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004708 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004709 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004710 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004711 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004712
Douglas Gregorb98b1992009-08-11 05:31:07 +00004713 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCall9ae2f072010-08-23 23:25:46 +00004714 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004715 }
Mike Stump1eb44332009-09-09 15:08:12 +00004716
Douglas Gregorb98b1992009-08-11 05:31:07 +00004717 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004718 return SemaRef.Owned(E->Retain());
4719
Douglas Gregorb98b1992009-08-11 05:31:07 +00004720 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004721 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004722}
Mike Stump1eb44332009-09-09 15:08:12 +00004723
Douglas Gregorb98b1992009-08-11 05:31:07 +00004724template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004725ExprResult
John McCall454feb92009-12-08 09:21:05 +00004726TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004727 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004728
Douglas Gregor43959a92009-08-20 07:17:43 +00004729 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00004730 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004731 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004732 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004733
Douglas Gregor43959a92009-08-20 07:17:43 +00004734 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00004735 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004736 bool ExprChanged = false;
4737 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4738 DEnd = E->designators_end();
4739 D != DEnd; ++D) {
4740 if (D->isFieldDesignator()) {
4741 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4742 D->getDotLoc(),
4743 D->getFieldLoc()));
4744 continue;
4745 }
Mike Stump1eb44332009-09-09 15:08:12 +00004746
Douglas Gregorb98b1992009-08-11 05:31:07 +00004747 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00004748 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004749 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004750 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004751
4752 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004753 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004754
Douglas Gregorb98b1992009-08-11 05:31:07 +00004755 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4756 ArrayExprs.push_back(Index.release());
4757 continue;
4758 }
Mike Stump1eb44332009-09-09 15:08:12 +00004759
Douglas Gregorb98b1992009-08-11 05:31:07 +00004760 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00004761 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004762 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4763 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004764 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004765
John McCall60d7b3a2010-08-24 06:29:42 +00004766 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004767 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004768 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004769
4770 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004771 End.get(),
4772 D->getLBracketLoc(),
4773 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004774
Douglas Gregorb98b1992009-08-11 05:31:07 +00004775 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4776 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004777
Douglas Gregorb98b1992009-08-11 05:31:07 +00004778 ArrayExprs.push_back(Start.release());
4779 ArrayExprs.push_back(End.release());
4780 }
Mike Stump1eb44332009-09-09 15:08:12 +00004781
Douglas Gregorb98b1992009-08-11 05:31:07 +00004782 if (!getDerived().AlwaysRebuild() &&
4783 Init.get() == E->getInit() &&
4784 !ExprChanged)
4785 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004786
Douglas Gregorb98b1992009-08-11 05:31:07 +00004787 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4788 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004789 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004790}
Mike Stump1eb44332009-09-09 15:08:12 +00004791
Douglas Gregorb98b1992009-08-11 05:31:07 +00004792template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004793ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004794TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004795 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004796 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004797
Douglas Gregor5557b252009-10-28 00:29:27 +00004798 // FIXME: Will we ever have proper type location here? Will we actually
4799 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004800 QualType T = getDerived().TransformType(E->getType());
4801 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004802 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004803
Douglas Gregorb98b1992009-08-11 05:31:07 +00004804 if (!getDerived().AlwaysRebuild() &&
4805 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004806 return SemaRef.Owned(E->Retain());
4807
Douglas Gregorb98b1992009-08-11 05:31:07 +00004808 return getDerived().RebuildImplicitValueInitExpr(T);
4809}
Mike Stump1eb44332009-09-09 15:08:12 +00004810
Douglas Gregorb98b1992009-08-11 05:31:07 +00004811template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004812ExprResult
John McCall454feb92009-12-08 09:21:05 +00004813TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004814 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4815 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004816 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004817
John McCall60d7b3a2010-08-24 06:29:42 +00004818 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004819 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004820 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004821
Douglas Gregorb98b1992009-08-11 05:31:07 +00004822 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004823 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004824 SubExpr.get() == E->getSubExpr())
4825 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004826
John McCall9ae2f072010-08-23 23:25:46 +00004827 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004828 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004829}
4830
4831template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004832ExprResult
John McCall454feb92009-12-08 09:21:05 +00004833TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004834 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004835 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004836 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004837 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004838 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004839 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004840
Douglas Gregorb98b1992009-08-11 05:31:07 +00004841 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00004842 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004843 }
Mike Stump1eb44332009-09-09 15:08:12 +00004844
Douglas Gregorb98b1992009-08-11 05:31:07 +00004845 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4846 move_arg(Inits),
4847 E->getRParenLoc());
4848}
Mike Stump1eb44332009-09-09 15:08:12 +00004849
Douglas Gregorb98b1992009-08-11 05:31:07 +00004850/// \brief Transform an address-of-label expression.
4851///
4852/// By default, the transformation of an address-of-label expression always
4853/// rebuilds the expression, so that the label identifier can be resolved to
4854/// the corresponding label statement by semantic analysis.
4855template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004856ExprResult
John McCall454feb92009-12-08 09:21:05 +00004857TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004858 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4859 E->getLabel());
4860}
Mike Stump1eb44332009-09-09 15:08:12 +00004861
4862template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004863ExprResult
John McCall454feb92009-12-08 09:21:05 +00004864TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004865 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004866 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4867 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004868 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004869
Douglas Gregorb98b1992009-08-11 05:31:07 +00004870 if (!getDerived().AlwaysRebuild() &&
4871 SubStmt.get() == E->getSubStmt())
4872 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004873
4874 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004875 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004876 E->getRParenLoc());
4877}
Mike Stump1eb44332009-09-09 15:08:12 +00004878
Douglas Gregorb98b1992009-08-11 05:31:07 +00004879template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004880ExprResult
John McCall454feb92009-12-08 09:21:05 +00004881TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004882 TypeSourceInfo *TInfo1;
4883 TypeSourceInfo *TInfo2;
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004884
4885 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4886 if (!TInfo1)
John McCallf312b1e2010-08-26 23:41:50 +00004887 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004888
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004889 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4890 if (!TInfo2)
John McCallf312b1e2010-08-26 23:41:50 +00004891 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004892
4893 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004894 TInfo1 == E->getArgTInfo1() &&
4895 TInfo2 == E->getArgTInfo2())
Mike Stump1eb44332009-09-09 15:08:12 +00004896 return SemaRef.Owned(E->Retain());
4897
Douglas Gregorb98b1992009-08-11 05:31:07 +00004898 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004899 TInfo1, TInfo2,
4900 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004901}
Mike Stump1eb44332009-09-09 15:08:12 +00004902
Douglas Gregorb98b1992009-08-11 05:31:07 +00004903template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004904ExprResult
John McCall454feb92009-12-08 09:21:05 +00004905TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004906 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004907 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004908 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004909
John McCall60d7b3a2010-08-24 06:29:42 +00004910 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004911 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004912 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004913
John McCall60d7b3a2010-08-24 06:29:42 +00004914 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004915 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004916 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004917
Douglas Gregorb98b1992009-08-11 05:31:07 +00004918 if (!getDerived().AlwaysRebuild() &&
4919 Cond.get() == E->getCond() &&
4920 LHS.get() == E->getLHS() &&
4921 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004922 return SemaRef.Owned(E->Retain());
4923
Douglas Gregorb98b1992009-08-11 05:31:07 +00004924 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004925 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004926 E->getRParenLoc());
4927}
Mike Stump1eb44332009-09-09 15:08:12 +00004928
Douglas Gregorb98b1992009-08-11 05:31:07 +00004929template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004930ExprResult
John McCall454feb92009-12-08 09:21:05 +00004931TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004932 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004933}
4934
4935template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004936ExprResult
John McCall454feb92009-12-08 09:21:05 +00004937TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004938 switch (E->getOperator()) {
4939 case OO_New:
4940 case OO_Delete:
4941 case OO_Array_New:
4942 case OO_Array_Delete:
4943 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00004944 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004945
Douglas Gregor668d6d92009-12-13 20:44:55 +00004946 case OO_Call: {
4947 // This is a call to an object's operator().
4948 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4949
4950 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004951 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00004952 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004953 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004954
4955 // FIXME: Poor location information
4956 SourceLocation FakeLParenLoc
4957 = SemaRef.PP.getLocForEndOfToken(
4958 static_cast<Expr *>(Object.get())->getLocEnd());
4959
4960 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00004961 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor668d6d92009-12-13 20:44:55 +00004962 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004963 if (getDerived().DropCallArgument(E->getArg(I)))
4964 break;
Sean Huntc3021132010-05-05 15:23:54 +00004965
John McCall60d7b3a2010-08-24 06:29:42 +00004966 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor668d6d92009-12-13 20:44:55 +00004967 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004968 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004969
Douglas Gregor668d6d92009-12-13 20:44:55 +00004970 Args.push_back(Arg.release());
4971 }
4972
John McCall9ae2f072010-08-23 23:25:46 +00004973 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00004974 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00004975 E->getLocEnd());
4976 }
4977
4978#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4979 case OO_##Name:
4980#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4981#include "clang/Basic/OperatorKinds.def"
4982 case OO_Subscript:
4983 // Handled below.
4984 break;
4985
4986 case OO_Conditional:
4987 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00004988 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004989
4990 case OO_None:
4991 case NUM_OVERLOADED_OPERATORS:
4992 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00004993 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004994 }
4995
John McCall60d7b3a2010-08-24 06:29:42 +00004996 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004997 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004998 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004999
John McCall60d7b3a2010-08-24 06:29:42 +00005000 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005001 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005002 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005003
John McCall60d7b3a2010-08-24 06:29:42 +00005004 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005005 if (E->getNumArgs() == 2) {
5006 Second = getDerived().TransformExpr(E->getArg(1));
5007 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005008 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005009 }
Mike Stump1eb44332009-09-09 15:08:12 +00005010
Douglas Gregorb98b1992009-08-11 05:31:07 +00005011 if (!getDerived().AlwaysRebuild() &&
5012 Callee.get() == E->getCallee() &&
5013 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005014 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5015 return SemaRef.Owned(E->Retain());
5016
Douglas Gregorb98b1992009-08-11 05:31:07 +00005017 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5018 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005019 Callee.get(),
5020 First.get(),
5021 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005022}
Mike Stump1eb44332009-09-09 15:08:12 +00005023
Douglas Gregorb98b1992009-08-11 05:31:07 +00005024template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005025ExprResult
John McCall454feb92009-12-08 09:21:05 +00005026TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5027 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005028}
Mike Stump1eb44332009-09-09 15:08:12 +00005029
Douglas Gregorb98b1992009-08-11 05:31:07 +00005030template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005031ExprResult
John McCall454feb92009-12-08 09:21:05 +00005032TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005033 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5034 if (!Type)
5035 return ExprError();
5036
John McCall60d7b3a2010-08-24 06:29:42 +00005037 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005038 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005039 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005040 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005041
Douglas Gregorb98b1992009-08-11 05:31:07 +00005042 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005043 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005044 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005045 return SemaRef.Owned(E->Retain());
5046
Douglas Gregorb98b1992009-08-11 05:31:07 +00005047 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005048 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005049 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5050 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5051 SourceLocation FakeRParenLoc
5052 = SemaRef.PP.getLocForEndOfToken(
5053 E->getSubExpr()->getSourceRange().getEnd());
5054 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005055 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005056 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005057 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005058 FakeRAngleLoc,
5059 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005060 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005061 FakeRParenLoc);
5062}
Mike Stump1eb44332009-09-09 15:08:12 +00005063
Douglas Gregorb98b1992009-08-11 05:31:07 +00005064template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005065ExprResult
John McCall454feb92009-12-08 09:21:05 +00005066TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5067 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005068}
Mike Stump1eb44332009-09-09 15:08:12 +00005069
5070template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005071ExprResult
John McCall454feb92009-12-08 09:21:05 +00005072TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5073 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005074}
5075
Douglas Gregorb98b1992009-08-11 05:31:07 +00005076template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005077ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005078TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005079 CXXReinterpretCastExpr *E) {
5080 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005081}
Mike Stump1eb44332009-09-09 15:08:12 +00005082
Douglas Gregorb98b1992009-08-11 05:31:07 +00005083template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005084ExprResult
John McCall454feb92009-12-08 09:21:05 +00005085TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5086 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005087}
Mike Stump1eb44332009-09-09 15:08:12 +00005088
Douglas Gregorb98b1992009-08-11 05:31:07 +00005089template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005090ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005091TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005092 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005093 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5094 if (!Type)
5095 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005096
John McCall60d7b3a2010-08-24 06:29:42 +00005097 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005098 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005099 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005100 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005101
Douglas Gregorb98b1992009-08-11 05:31:07 +00005102 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005103 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005104 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005105 return SemaRef.Owned(E->Retain());
5106
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005107 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005108 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005109 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005110 E->getRParenLoc());
5111}
Mike Stump1eb44332009-09-09 15:08:12 +00005112
Douglas Gregorb98b1992009-08-11 05:31:07 +00005113template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005114ExprResult
John McCall454feb92009-12-08 09:21:05 +00005115TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005116 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005117 TypeSourceInfo *TInfo
5118 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5119 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005120 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005121
Douglas Gregorb98b1992009-08-11 05:31:07 +00005122 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005123 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005124 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005125
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005126 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5127 E->getLocStart(),
5128 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005129 E->getLocEnd());
5130 }
Mike Stump1eb44332009-09-09 15:08:12 +00005131
Douglas Gregorb98b1992009-08-11 05:31:07 +00005132 // We don't know whether the expression is potentially evaluated until
5133 // after we perform semantic analysis, so the expression is potentially
5134 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005135 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00005136 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005137
John McCall60d7b3a2010-08-24 06:29:42 +00005138 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005139 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005140 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005141
Douglas Gregorb98b1992009-08-11 05:31:07 +00005142 if (!getDerived().AlwaysRebuild() &&
5143 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00005144 return SemaRef.Owned(E->Retain());
5145
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005146 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5147 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005148 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005149 E->getLocEnd());
5150}
5151
5152template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005153ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00005154TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5155 if (E->isTypeOperand()) {
5156 TypeSourceInfo *TInfo
5157 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5158 if (!TInfo)
5159 return ExprError();
5160
5161 if (!getDerived().AlwaysRebuild() &&
5162 TInfo == E->getTypeOperandSourceInfo())
5163 return SemaRef.Owned(E->Retain());
5164
5165 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5166 E->getLocStart(),
5167 TInfo,
5168 E->getLocEnd());
5169 }
5170
5171 // We don't know whether the expression is potentially evaluated until
5172 // after we perform semantic analysis, so the expression is potentially
5173 // potentially evaluated.
5174 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5175
5176 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5177 if (SubExpr.isInvalid())
5178 return ExprError();
5179
5180 if (!getDerived().AlwaysRebuild() &&
5181 SubExpr.get() == E->getExprOperand())
5182 return SemaRef.Owned(E->Retain());
5183
5184 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5185 E->getLocStart(),
5186 SubExpr.get(),
5187 E->getLocEnd());
5188}
5189
5190template<typename Derived>
5191ExprResult
John McCall454feb92009-12-08 09:21:05 +00005192TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005193 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005194}
Mike Stump1eb44332009-09-09 15:08:12 +00005195
Douglas Gregorb98b1992009-08-11 05:31:07 +00005196template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005197ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005198TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005199 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005200 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005201}
Mike Stump1eb44332009-09-09 15:08:12 +00005202
Douglas Gregorb98b1992009-08-11 05:31:07 +00005203template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005204ExprResult
John McCall454feb92009-12-08 09:21:05 +00005205TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005206 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5207 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5208 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005210 if (!getDerived().AlwaysRebuild() && T == E->getType())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005211 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005212
Douglas Gregor828a1972010-01-07 23:12:05 +00005213 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005214}
Mike Stump1eb44332009-09-09 15:08:12 +00005215
Douglas Gregorb98b1992009-08-11 05:31:07 +00005216template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005217ExprResult
John McCall454feb92009-12-08 09:21:05 +00005218TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005219 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005220 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005221 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005222
Douglas Gregorb98b1992009-08-11 05:31:07 +00005223 if (!getDerived().AlwaysRebuild() &&
5224 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005225 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005226
John McCall9ae2f072010-08-23 23:25:46 +00005227 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
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>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005233 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005234 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5235 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005236 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00005237 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005238
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005239 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005240 Param == E->getParam())
5241 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005242
Douglas Gregor036aed12009-12-23 23:03:06 +00005243 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
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
Douglas Gregorab6677e2010-09-08 00:15:04 +00005248TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5249 CXXScalarValueInitExpr *E) {
5250 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5251 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005252 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00005253
Douglas Gregorb98b1992009-08-11 05:31:07 +00005254 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005255 T == E->getTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00005256 return SemaRef.Owned(E->Retain());
5257
Douglas Gregorab6677e2010-09-08 00:15:04 +00005258 return getDerived().RebuildCXXScalarValueInitExpr(T,
5259 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00005260 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005261}
Mike Stump1eb44332009-09-09 15:08:12 +00005262
Douglas Gregorb98b1992009-08-11 05:31:07 +00005263template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005264ExprResult
John McCall454feb92009-12-08 09:21:05 +00005265TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005266 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005267 TypeSourceInfo *AllocTypeInfo
5268 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5269 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005270 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005271
Douglas Gregorb98b1992009-08-11 05:31:07 +00005272 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00005273 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005274 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005275 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005276
Douglas Gregorb98b1992009-08-11 05:31:07 +00005277 // Transform the placement arguments (if any).
5278 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005279 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005280 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005281 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005282 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005283 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005284
Douglas Gregorb98b1992009-08-11 05:31:07 +00005285 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5286 PlacementArgs.push_back(Arg.take());
5287 }
Mike Stump1eb44332009-09-09 15:08:12 +00005288
Douglas Gregor43959a92009-08-20 07:17:43 +00005289 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00005290 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005291 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005292 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5293 break;
5294
John McCall60d7b3a2010-08-24 06:29:42 +00005295 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005296 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005297 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005298
Douglas Gregorb98b1992009-08-11 05:31:07 +00005299 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5300 ConstructorArgs.push_back(Arg.take());
5301 }
Mike Stump1eb44332009-09-09 15:08:12 +00005302
Douglas Gregor1af74512010-02-26 00:38:10 +00005303 // Transform constructor, new operator, and delete operator.
5304 CXXConstructorDecl *Constructor = 0;
5305 if (E->getConstructor()) {
5306 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005307 getDerived().TransformDecl(E->getLocStart(),
5308 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005309 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005310 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005311 }
5312
5313 FunctionDecl *OperatorNew = 0;
5314 if (E->getOperatorNew()) {
5315 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005316 getDerived().TransformDecl(E->getLocStart(),
5317 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005318 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00005319 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005320 }
5321
5322 FunctionDecl *OperatorDelete = 0;
5323 if (E->getOperatorDelete()) {
5324 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005325 getDerived().TransformDecl(E->getLocStart(),
5326 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005327 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005328 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005329 }
Sean Huntc3021132010-05-05 15:23:54 +00005330
Douglas Gregorb98b1992009-08-11 05:31:07 +00005331 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005332 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005333 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005334 Constructor == E->getConstructor() &&
5335 OperatorNew == E->getOperatorNew() &&
5336 OperatorDelete == E->getOperatorDelete() &&
5337 !ArgumentChanged) {
5338 // Mark any declarations we need as referenced.
5339 // FIXME: instantiation-specific.
5340 if (Constructor)
5341 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5342 if (OperatorNew)
5343 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5344 if (OperatorDelete)
5345 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005346 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005347 }
Mike Stump1eb44332009-09-09 15:08:12 +00005348
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005349 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005350 if (!ArraySize.get()) {
5351 // If no array size was specified, but the new expression was
5352 // instantiated with an array type (e.g., "new T" where T is
5353 // instantiated with "int[4]"), extract the outer bound from the
5354 // array type as our array size. We do this with constant and
5355 // dependently-sized array types.
5356 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5357 if (!ArrayT) {
5358 // Do nothing
5359 } else if (const ConstantArrayType *ConsArrayT
5360 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005361 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00005362 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5363 ConsArrayT->getSize(),
5364 SemaRef.Context.getSizeType(),
5365 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005366 AllocType = ConsArrayT->getElementType();
5367 } else if (const DependentSizedArrayType *DepArrayT
5368 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5369 if (DepArrayT->getSizeExpr()) {
5370 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5371 AllocType = DepArrayT->getElementType();
5372 }
5373 }
5374 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005375
Douglas Gregorb98b1992009-08-11 05:31:07 +00005376 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5377 E->isGlobalNew(),
5378 /*FIXME:*/E->getLocStart(),
5379 move_arg(PlacementArgs),
5380 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00005381 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005382 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005383 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00005384 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005385 /*FIXME:*/E->getLocStart(),
5386 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005387 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005388}
Mike Stump1eb44332009-09-09 15:08:12 +00005389
Douglas Gregorb98b1992009-08-11 05:31:07 +00005390template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005391ExprResult
John McCall454feb92009-12-08 09:21:05 +00005392TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005393 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005394 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005395 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005396
Douglas Gregor1af74512010-02-26 00:38:10 +00005397 // Transform the delete operator, if known.
5398 FunctionDecl *OperatorDelete = 0;
5399 if (E->getOperatorDelete()) {
5400 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005401 getDerived().TransformDecl(E->getLocStart(),
5402 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005403 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005404 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005405 }
Sean Huntc3021132010-05-05 15:23:54 +00005406
Douglas Gregorb98b1992009-08-11 05:31:07 +00005407 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005408 Operand.get() == E->getArgument() &&
5409 OperatorDelete == E->getOperatorDelete()) {
5410 // Mark any declarations we need as referenced.
5411 // FIXME: instantiation-specific.
5412 if (OperatorDelete)
5413 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00005414
5415 if (!E->getArgument()->isTypeDependent()) {
5416 QualType Destroyed = SemaRef.Context.getBaseElementType(
5417 E->getDestroyedType());
5418 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5419 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5420 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5421 SemaRef.LookupDestructor(Record));
5422 }
5423 }
5424
Mike Stump1eb44332009-09-09 15:08:12 +00005425 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005426 }
Mike Stump1eb44332009-09-09 15:08:12 +00005427
Douglas Gregorb98b1992009-08-11 05:31:07 +00005428 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5429 E->isGlobalDelete(),
5430 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00005431 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005432}
Mike Stump1eb44332009-09-09 15:08:12 +00005433
Douglas Gregorb98b1992009-08-11 05:31:07 +00005434template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005435ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005436TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005437 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005438 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00005439 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005440 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005441
John McCallb3d87482010-08-24 05:47:05 +00005442 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005443 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005444 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005445 E->getOperatorLoc(),
5446 E->isArrow()? tok::arrow : tok::period,
5447 ObjectTypePtr,
5448 MayBePseudoDestructor);
5449 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005450 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005451
John McCallb3d87482010-08-24 05:47:05 +00005452 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora71d8192009-09-04 17:36:40 +00005453 NestedNameSpecifier *Qualifier
5454 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00005455 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005456 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00005457 if (E->getQualifier() && !Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005458 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005459
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005460 PseudoDestructorTypeStorage Destroyed;
5461 if (E->getDestroyedTypeInfo()) {
5462 TypeSourceInfo *DestroyedTypeInfo
5463 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5464 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005465 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005466 Destroyed = DestroyedTypeInfo;
5467 } else if (ObjectType->isDependentType()) {
5468 // We aren't likely to be able to resolve the identifier down to a type
5469 // now anyway, so just retain the identifier.
5470 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5471 E->getDestroyedTypeLoc());
5472 } else {
5473 // Look for a destructor known with the given name.
5474 CXXScopeSpec SS;
5475 if (Qualifier) {
5476 SS.setScopeRep(Qualifier);
5477 SS.setRange(E->getQualifierRange());
5478 }
Sean Huntc3021132010-05-05 15:23:54 +00005479
John McCallb3d87482010-08-24 05:47:05 +00005480 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005481 *E->getDestroyedTypeIdentifier(),
5482 E->getDestroyedTypeLoc(),
5483 /*Scope=*/0,
5484 SS, ObjectTypePtr,
5485 false);
5486 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005487 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005488
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005489 Destroyed
5490 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5491 E->getDestroyedTypeLoc());
5492 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005493
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005494 TypeSourceInfo *ScopeTypeInfo = 0;
5495 if (E->getScopeTypeInfo()) {
Sean Huntc3021132010-05-05 15:23:54 +00005496 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005497 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005498 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005499 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00005500 }
Sean Huntc3021132010-05-05 15:23:54 +00005501
John McCall9ae2f072010-08-23 23:25:46 +00005502 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005503 E->getOperatorLoc(),
5504 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005505 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005506 E->getQualifierRange(),
5507 ScopeTypeInfo,
5508 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005509 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005510 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005511}
Mike Stump1eb44332009-09-09 15:08:12 +00005512
Douglas Gregora71d8192009-09-04 17:36:40 +00005513template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005514ExprResult
John McCallba135432009-11-21 08:51:07 +00005515TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005516 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005517 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5518
5519 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5520 Sema::LookupOrdinaryName);
5521
5522 // Transform all the decls.
5523 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5524 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005525 NamedDecl *InstD = static_cast<NamedDecl*>(
5526 getDerived().TransformDecl(Old->getNameLoc(),
5527 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005528 if (!InstD) {
5529 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5530 // This can happen because of dependent hiding.
5531 if (isa<UsingShadowDecl>(*I))
5532 continue;
5533 else
John McCallf312b1e2010-08-26 23:41:50 +00005534 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005535 }
John McCallf7a1a742009-11-24 19:00:30 +00005536
5537 // Expand using declarations.
5538 if (isa<UsingDecl>(InstD)) {
5539 UsingDecl *UD = cast<UsingDecl>(InstD);
5540 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5541 E = UD->shadow_end(); I != E; ++I)
5542 R.addDecl(*I);
5543 continue;
5544 }
5545
5546 R.addDecl(InstD);
5547 }
5548
5549 // Resolve a kind, but don't do any further analysis. If it's
5550 // ambiguous, the callee needs to deal with it.
5551 R.resolveKind();
5552
5553 // Rebuild the nested-name qualifier, if present.
5554 CXXScopeSpec SS;
5555 NestedNameSpecifier *Qualifier = 0;
5556 if (Old->getQualifier()) {
5557 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005558 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005559 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005560 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005561
John McCallf7a1a742009-11-24 19:00:30 +00005562 SS.setScopeRep(Qualifier);
5563 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005564 }
5565
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005566 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005567 CXXRecordDecl *NamingClass
5568 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5569 Old->getNameLoc(),
5570 Old->getNamingClass()));
5571 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00005572 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005573
Douglas Gregor66c45152010-04-27 16:10:10 +00005574 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005575 }
5576
5577 // If we have no template arguments, it's a normal declaration name.
5578 if (!Old->hasExplicitTemplateArgs())
5579 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5580
5581 // If we have template arguments, rebuild them, then rebuild the
5582 // templateid expression.
5583 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5584 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5585 TemplateArgumentLoc Loc;
5586 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005587 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00005588 TransArgs.addArgument(Loc);
5589 }
5590
5591 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5592 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005593}
Mike Stump1eb44332009-09-09 15:08:12 +00005594
Douglas Gregorb98b1992009-08-11 05:31:07 +00005595template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005596ExprResult
John McCall454feb92009-12-08 09:21:05 +00005597TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005598 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5599 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005600 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005601
Douglas Gregorb98b1992009-08-11 05:31:07 +00005602 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005603 T == E->getQueriedTypeSourceInfo())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005604 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005605
Mike Stump1eb44332009-09-09 15:08:12 +00005606 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005607 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005608 T,
5609 E->getLocEnd());
5610}
Mike Stump1eb44332009-09-09 15:08:12 +00005611
Douglas Gregorb98b1992009-08-11 05:31:07 +00005612template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005613ExprResult
John McCall865d4472009-11-19 22:55:06 +00005614TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005615 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005616 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005617 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005618 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005619 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00005620 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005621
Abramo Bagnara25777432010-08-11 22:01:17 +00005622 DeclarationNameInfo NameInfo
5623 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5624 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005625 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005626
John McCallf7a1a742009-11-24 19:00:30 +00005627 if (!E->hasExplicitTemplateArgs()) {
5628 if (!getDerived().AlwaysRebuild() &&
5629 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005630 // Note: it is sufficient to compare the Name component of NameInfo:
5631 // if name has not changed, DNLoc has not changed either.
5632 NameInfo.getName() == E->getDeclName())
John McCallf7a1a742009-11-24 19:00:30 +00005633 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005634
John McCallf7a1a742009-11-24 19:00:30 +00005635 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5636 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005637 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005638 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005639 }
John McCalld5532b62009-11-23 01:53:49 +00005640
5641 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005642 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005643 TemplateArgumentLoc Loc;
5644 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005645 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005646 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005647 }
5648
John McCallf7a1a742009-11-24 19:00:30 +00005649 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5650 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005651 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005652 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005653}
5654
5655template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005656ExprResult
John McCall454feb92009-12-08 09:21:05 +00005657TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005658 // CXXConstructExprs are always implicit, so when we have a
5659 // 1-argument construction we just transform that argument.
5660 if (E->getNumArgs() == 1 ||
5661 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5662 return getDerived().TransformExpr(E->getArg(0));
5663
Douglas Gregorb98b1992009-08-11 05:31:07 +00005664 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5665
5666 QualType T = getDerived().TransformType(E->getType());
5667 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005668 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005669
5670 CXXConstructorDecl *Constructor
5671 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005672 getDerived().TransformDecl(E->getLocStart(),
5673 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005674 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005675 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005676
Douglas Gregorb98b1992009-08-11 05:31:07 +00005677 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005678 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005679 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005680 ArgEnd = E->arg_end();
5681 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005682 if (getDerived().DropCallArgument(*Arg)) {
5683 ArgumentChanged = true;
5684 break;
5685 }
5686
John McCall60d7b3a2010-08-24 06:29:42 +00005687 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005688 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005689 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005690
Douglas Gregorb98b1992009-08-11 05:31:07 +00005691 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005692 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005693 }
5694
5695 if (!getDerived().AlwaysRebuild() &&
5696 T == E->getType() &&
5697 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005698 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005699 // Mark the constructor as referenced.
5700 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005701 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005702 return SemaRef.Owned(E->Retain());
Douglas Gregorc845aad2010-02-26 00:01:57 +00005703 }
Mike Stump1eb44332009-09-09 15:08:12 +00005704
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005705 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5706 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00005707 move_arg(Args),
5708 E->requiresZeroInitialization(),
5709 E->getConstructionKind());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005710}
Mike Stump1eb44332009-09-09 15:08:12 +00005711
Douglas Gregorb98b1992009-08-11 05:31:07 +00005712/// \brief Transform a C++ temporary-binding expression.
5713///
Douglas Gregor51326552009-12-24 18:51:59 +00005714/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5715/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005716template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005717ExprResult
John McCall454feb92009-12-08 09:21:05 +00005718TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005719 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005720}
Mike Stump1eb44332009-09-09 15:08:12 +00005721
5722/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005723/// be destroyed after the expression is evaluated.
5724///
Douglas Gregor51326552009-12-24 18:51:59 +00005725/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5726/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005727template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005728ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005729TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005730 CXXExprWithTemporaries *E) {
5731 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005732}
Mike Stump1eb44332009-09-09 15:08:12 +00005733
Douglas Gregorb98b1992009-08-11 05:31:07 +00005734template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005735ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005736TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00005737 CXXTemporaryObjectExpr *E) {
5738 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5739 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005740 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005741
Douglas Gregorb98b1992009-08-11 05:31:07 +00005742 CXXConstructorDecl *Constructor
5743 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005744 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005745 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005746 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005747 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005748
Douglas Gregorb98b1992009-08-11 05:31:07 +00005749 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005750 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005751 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005752 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005753 ArgEnd = E->arg_end();
5754 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005755 if (getDerived().DropCallArgument(*Arg)) {
5756 ArgumentChanged = true;
5757 break;
5758 }
5759
John McCall60d7b3a2010-08-24 06:29:42 +00005760 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005761 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005762 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005763
Douglas Gregorb98b1992009-08-11 05:31:07 +00005764 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5765 Args.push_back((Expr *)TransArg.release());
5766 }
Mike Stump1eb44332009-09-09 15:08:12 +00005767
Douglas Gregorb98b1992009-08-11 05:31:07 +00005768 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005769 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005770 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005771 !ArgumentChanged) {
5772 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00005773 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Chandler Carrutha3ce8ae2010-03-31 18:34:58 +00005774 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor91be6f52010-03-02 17:18:33 +00005775 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00005776
5777 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5778 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005779 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005780 E->getLocEnd());
5781}
Mike Stump1eb44332009-09-09 15:08:12 +00005782
Douglas Gregorb98b1992009-08-11 05:31:07 +00005783template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005784ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005785TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005786 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00005787 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5788 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005789 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005790
Douglas Gregorb98b1992009-08-11 05:31:07 +00005791 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005792 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005793 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5794 ArgEnd = E->arg_end();
5795 Arg != ArgEnd; ++Arg) {
John McCall60d7b3a2010-08-24 06:29:42 +00005796 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005797 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005798 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005799
Douglas Gregorb98b1992009-08-11 05:31:07 +00005800 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005801 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005802 }
Mike Stump1eb44332009-09-09 15:08:12 +00005803
Douglas Gregorb98b1992009-08-11 05:31:07 +00005804 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005805 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005806 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005807 return SemaRef.Owned(E->Retain());
5808
Douglas Gregorb98b1992009-08-11 05:31:07 +00005809 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00005810 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005811 E->getLParenLoc(),
5812 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005813 E->getRParenLoc());
5814}
Mike Stump1eb44332009-09-09 15:08:12 +00005815
Douglas Gregorb98b1992009-08-11 05:31:07 +00005816template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005817ExprResult
John McCall865d4472009-11-19 22:55:06 +00005818TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005819 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005820 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005821 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005822 Expr *OldBase;
5823 QualType BaseType;
5824 QualType ObjectType;
5825 if (!E->isImplicitAccess()) {
5826 OldBase = E->getBase();
5827 Base = getDerived().TransformExpr(OldBase);
5828 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005829 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005830
John McCallaa81e162009-12-01 22:10:20 +00005831 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00005832 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00005833 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005834 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005835 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005836 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005837 ObjectTy,
5838 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005839 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005840 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005841
John McCallb3d87482010-08-24 05:47:05 +00005842 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00005843 BaseType = ((Expr*) Base.get())->getType();
5844 } else {
5845 OldBase = 0;
5846 BaseType = getDerived().TransformType(E->getBaseType());
5847 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5848 }
Mike Stump1eb44332009-09-09 15:08:12 +00005849
Douglas Gregor6cd21982009-10-20 05:58:46 +00005850 // Transform the first part of the nested-name-specifier that qualifies
5851 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005852 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005853 = getDerived().TransformFirstQualifierInScope(
5854 E->getFirstQualifierFoundInScope(),
5855 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005856
Douglas Gregora38c6872009-09-03 16:14:30 +00005857 NestedNameSpecifier *Qualifier = 0;
5858 if (E->getQualifier()) {
5859 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5860 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005861 ObjectType,
5862 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005863 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005864 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00005865 }
Mike Stump1eb44332009-09-09 15:08:12 +00005866
Abramo Bagnara25777432010-08-11 22:01:17 +00005867 DeclarationNameInfo NameInfo
5868 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5869 ObjectType);
5870 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005871 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005872
John McCallaa81e162009-12-01 22:10:20 +00005873 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005874 // This is a reference to a member without an explicitly-specified
5875 // template argument list. Optimize for this common case.
5876 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005877 Base.get() == OldBase &&
5878 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005879 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005880 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005881 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005882 return SemaRef.Owned(E->Retain());
5883
John McCall9ae2f072010-08-23 23:25:46 +00005884 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005885 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005886 E->isArrow(),
5887 E->getOperatorLoc(),
5888 Qualifier,
5889 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005890 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005891 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005892 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005893 }
5894
John McCalld5532b62009-11-23 01:53:49 +00005895 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005896 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005897 TemplateArgumentLoc Loc;
5898 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005899 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005900 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005901 }
Mike Stump1eb44332009-09-09 15:08:12 +00005902
John McCall9ae2f072010-08-23 23:25:46 +00005903 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005904 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005905 E->isArrow(),
5906 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005907 Qualifier,
5908 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005909 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005910 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005911 &TransArgs);
5912}
5913
5914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005915ExprResult
John McCall454feb92009-12-08 09:21:05 +00005916TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005917 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005918 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005919 QualType BaseType;
5920 if (!Old->isImplicitAccess()) {
5921 Base = getDerived().TransformExpr(Old->getBase());
5922 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005923 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005924 BaseType = ((Expr*) Base.get())->getType();
5925 } else {
5926 BaseType = getDerived().TransformType(Old->getBaseType());
5927 }
John McCall129e2df2009-11-30 22:42:35 +00005928
5929 NestedNameSpecifier *Qualifier = 0;
5930 if (Old->getQualifier()) {
5931 Qualifier
5932 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005933 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005934 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00005935 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00005936 }
5937
Abramo Bagnara25777432010-08-11 22:01:17 +00005938 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00005939 Sema::LookupOrdinaryName);
5940
5941 // Transform all the decls.
5942 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5943 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005944 NamedDecl *InstD = static_cast<NamedDecl*>(
5945 getDerived().TransformDecl(Old->getMemberLoc(),
5946 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005947 if (!InstD) {
5948 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5949 // This can happen because of dependent hiding.
5950 if (isa<UsingShadowDecl>(*I))
5951 continue;
5952 else
John McCallf312b1e2010-08-26 23:41:50 +00005953 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005954 }
John McCall129e2df2009-11-30 22:42:35 +00005955
5956 // Expand using declarations.
5957 if (isa<UsingDecl>(InstD)) {
5958 UsingDecl *UD = cast<UsingDecl>(InstD);
5959 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5960 E = UD->shadow_end(); I != E; ++I)
5961 R.addDecl(*I);
5962 continue;
5963 }
5964
5965 R.addDecl(InstD);
5966 }
5967
5968 R.resolveKind();
5969
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005970 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00005971 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00005972 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005973 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00005974 Old->getMemberLoc(),
5975 Old->getNamingClass()));
5976 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00005977 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005978
Douglas Gregor66c45152010-04-27 16:10:10 +00005979 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005980 }
Sean Huntc3021132010-05-05 15:23:54 +00005981
John McCall129e2df2009-11-30 22:42:35 +00005982 TemplateArgumentListInfo TransArgs;
5983 if (Old->hasExplicitTemplateArgs()) {
5984 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5985 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5986 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5987 TemplateArgumentLoc Loc;
5988 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5989 Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005990 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00005991 TransArgs.addArgument(Loc);
5992 }
5993 }
John McCallc2233c52010-01-15 08:34:02 +00005994
5995 // FIXME: to do this check properly, we will need to preserve the
5996 // first-qualifier-in-scope here, just in case we had a dependent
5997 // base (and therefore couldn't do the check) and a
5998 // nested-name-qualifier (and therefore could do the lookup).
5999 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006000
John McCall9ae2f072010-08-23 23:25:46 +00006001 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006002 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006003 Old->getOperatorLoc(),
6004 Old->isArrow(),
6005 Qualifier,
6006 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006007 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006008 R,
6009 (Old->hasExplicitTemplateArgs()
6010 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006011}
6012
6013template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006014ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006015TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6016 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6017 if (SubExpr.isInvalid())
6018 return ExprError();
6019
6020 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
6021 return SemaRef.Owned(E->Retain());
6022
6023 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6024}
6025
6026template<typename Derived>
6027ExprResult
John McCall454feb92009-12-08 09:21:05 +00006028TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006029 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006030}
6031
Mike Stump1eb44332009-09-09 15:08:12 +00006032template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006033ExprResult
John McCall454feb92009-12-08 09:21:05 +00006034TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006035 TypeSourceInfo *EncodedTypeInfo
6036 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6037 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006038 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006039
Douglas Gregorb98b1992009-08-11 05:31:07 +00006040 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006041 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00006042 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006043
6044 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006045 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006046 E->getRParenLoc());
6047}
Mike Stump1eb44332009-09-09 15:08:12 +00006048
Douglas Gregorb98b1992009-08-11 05:31:07 +00006049template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006050ExprResult
John McCall454feb92009-12-08 09:21:05 +00006051TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006052 // Transform arguments.
6053 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006054 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006055 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006056 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor92e986e2010-04-22 16:44:27 +00006057 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006058 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006059
Douglas Gregor92e986e2010-04-22 16:44:27 +00006060 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00006061 Args.push_back(Arg.get());
Douglas Gregor92e986e2010-04-22 16:44:27 +00006062 }
6063
6064 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6065 // Class message: transform the receiver type.
6066 TypeSourceInfo *ReceiverTypeInfo
6067 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6068 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006069 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006070
Douglas Gregor92e986e2010-04-22 16:44:27 +00006071 // If nothing changed, just retain the existing message send.
6072 if (!getDerived().AlwaysRebuild() &&
6073 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6074 return SemaRef.Owned(E->Retain());
6075
6076 // Build a new class message send.
6077 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6078 E->getSelector(),
6079 E->getMethodDecl(),
6080 E->getLeftLoc(),
6081 move_arg(Args),
6082 E->getRightLoc());
6083 }
6084
6085 // Instance message: transform the receiver
6086 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6087 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006088 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006089 = getDerived().TransformExpr(E->getInstanceReceiver());
6090 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006091 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006092
6093 // If nothing changed, just retain the existing message send.
6094 if (!getDerived().AlwaysRebuild() &&
6095 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6096 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006097
Douglas Gregor92e986e2010-04-22 16:44:27 +00006098 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006099 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006100 E->getSelector(),
6101 E->getMethodDecl(),
6102 E->getLeftLoc(),
6103 move_arg(Args),
6104 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006105}
6106
Mike Stump1eb44332009-09-09 15:08:12 +00006107template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006108ExprResult
John McCall454feb92009-12-08 09:21:05 +00006109TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006110 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006111}
6112
Mike Stump1eb44332009-09-09 15:08:12 +00006113template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006114ExprResult
John McCall454feb92009-12-08 09:21:05 +00006115TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006116 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006117}
6118
Mike Stump1eb44332009-09-09 15:08:12 +00006119template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006120ExprResult
John McCall454feb92009-12-08 09:21:05 +00006121TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006122 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006123 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006124 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006125 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006126
6127 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006128
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006129 // If nothing changed, just retain the existing expression.
6130 if (!getDerived().AlwaysRebuild() &&
6131 Base.get() == E->getBase())
6132 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006133
John McCall9ae2f072010-08-23 23:25:46 +00006134 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006135 E->getLocation(),
6136 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006137}
6138
Mike Stump1eb44332009-09-09 15:08:12 +00006139template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006140ExprResult
John McCall454feb92009-12-08 09:21:05 +00006141TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregore3303542010-04-26 20:47:02 +00006142 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006143 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00006144 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006145 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006146
Douglas Gregore3303542010-04-26 20:47:02 +00006147 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006148
Douglas Gregore3303542010-04-26 20:47:02 +00006149 // If nothing changed, just retain the existing expression.
6150 if (!getDerived().AlwaysRebuild() &&
6151 Base.get() == E->getBase())
6152 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006153
John McCall9ae2f072010-08-23 23:25:46 +00006154 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregore3303542010-04-26 20:47:02 +00006155 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006156}
6157
Mike Stump1eb44332009-09-09 15:08:12 +00006158template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006159ExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00006160TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00006161 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006162 // If this implicit setter/getter refers to class methods, it cannot have any
6163 // dependent parts. Just retain the existing declaration.
6164 if (E->getInterfaceDecl())
6165 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006166
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006167 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006168 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006169 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006170 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006171
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006172 // We don't need to transform the getters/setters; they will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006173
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006174 // If nothing changed, just retain the existing expression.
6175 if (!getDerived().AlwaysRebuild() &&
6176 Base.get() == E->getBase())
6177 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006178
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006179 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6180 E->getGetterMethod(),
6181 E->getType(),
6182 E->getSetterMethod(),
6183 E->getLocation(),
John McCall9ae2f072010-08-23 23:25:46 +00006184 Base.get());
Sean Huntc3021132010-05-05 15:23:54 +00006185
Douglas Gregorb98b1992009-08-11 05:31:07 +00006186}
6187
Mike Stump1eb44332009-09-09 15:08:12 +00006188template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006189ExprResult
John McCall454feb92009-12-08 09:21:05 +00006190TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006191 // Can never occur in a dependent context.
Mike Stump1eb44332009-09-09 15:08:12 +00006192 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006193}
6194
Mike Stump1eb44332009-09-09 15:08:12 +00006195template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006196ExprResult
John McCall454feb92009-12-08 09:21:05 +00006197TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006198 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006199 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006200 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006201 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006202
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006203 // If nothing changed, just retain the existing expression.
6204 if (!getDerived().AlwaysRebuild() &&
6205 Base.get() == E->getBase())
6206 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006207
John McCall9ae2f072010-08-23 23:25:46 +00006208 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006209 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006210}
6211
Mike Stump1eb44332009-09-09 15:08:12 +00006212template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006213ExprResult
John McCall454feb92009-12-08 09:21:05 +00006214TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006216 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006218 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006219 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006220 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006221
Douglas Gregorb98b1992009-08-11 05:31:07 +00006222 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00006223 SubExprs.push_back(SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006224 }
Mike Stump1eb44332009-09-09 15:08:12 +00006225
Douglas Gregorb98b1992009-08-11 05:31:07 +00006226 if (!getDerived().AlwaysRebuild() &&
6227 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00006228 return SemaRef.Owned(E->Retain());
6229
Douglas Gregorb98b1992009-08-11 05:31:07 +00006230 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6231 move_arg(SubExprs),
6232 E->getRParenLoc());
6233}
6234
Mike Stump1eb44332009-09-09 15:08:12 +00006235template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006236ExprResult
John McCall454feb92009-12-08 09:21:05 +00006237TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006238 SourceLocation CaretLoc(E->getExprLoc());
6239
6240 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6241 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6242 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6243 llvm::SmallVector<ParmVarDecl*, 4> Params;
6244 llvm::SmallVector<QualType, 4> ParamTypes;
6245
6246 // Parameter substitution.
6247 const BlockDecl *BD = E->getBlockDecl();
6248 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6249 EN = BD->param_end(); P != EN; ++P) {
6250 ParmVarDecl *OldParm = (*P);
6251 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6252 QualType NewType = NewParm->getType();
6253 Params.push_back(NewParm);
6254 ParamTypes.push_back(NewParm->getType());
6255 }
6256
6257 const FunctionType *BExprFunctionType = E->getFunctionType();
6258 QualType BExprResultType = BExprFunctionType->getResultType();
6259 if (!BExprResultType.isNull()) {
6260 if (!BExprResultType->isDependentType())
6261 CurBlock->ReturnType = BExprResultType;
6262 else if (BExprResultType != SemaRef.Context.DependentTy)
6263 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6264 }
6265
6266 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00006267 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006268 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006269 return ExprError();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006270 // Set the parameters on the block decl.
6271 if (!Params.empty())
6272 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6273
6274 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6275 CurBlock->ReturnType,
6276 ParamTypes.data(),
6277 ParamTypes.size(),
6278 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006279 0,
6280 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006281
6282 CurBlock->FunctionType = FunctionType;
John McCall9ae2f072010-08-23 23:25:46 +00006283 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006284}
6285
Mike Stump1eb44332009-09-09 15:08:12 +00006286template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006287ExprResult
John McCall454feb92009-12-08 09:21:05 +00006288TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006289 NestedNameSpecifier *Qualifier = 0;
6290
6291 ValueDecl *ND
6292 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6293 E->getDecl()));
6294 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006295 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00006296
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006297 if (!getDerived().AlwaysRebuild() &&
6298 ND == E->getDecl()) {
6299 // Mark it referenced in the new context regardless.
6300 // FIXME: this is a bit instantiation-specific.
6301 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6302
6303 return SemaRef.Owned(E->Retain());
6304 }
6305
Abramo Bagnara25777432010-08-11 22:01:17 +00006306 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006307 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006308 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006309}
Mike Stump1eb44332009-09-09 15:08:12 +00006310
Douglas Gregorb98b1992009-08-11 05:31:07 +00006311//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006312// Type reconstruction
6313//===----------------------------------------------------------------------===//
6314
Mike Stump1eb44332009-09-09 15:08:12 +00006315template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006316QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6317 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006318 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006319 getDerived().getBaseEntity());
6320}
6321
Mike Stump1eb44332009-09-09 15:08:12 +00006322template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006323QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6324 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006325 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006326 getDerived().getBaseEntity());
6327}
6328
Mike Stump1eb44332009-09-09 15:08:12 +00006329template<typename Derived>
6330QualType
John McCall85737a72009-10-30 00:06:24 +00006331TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6332 bool WrittenAsLValue,
6333 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006334 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006335 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006336}
6337
6338template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006339QualType
John McCall85737a72009-10-30 00:06:24 +00006340TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6341 QualType ClassType,
6342 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006343 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006344 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006345}
6346
6347template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006348QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006349TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6350 ArrayType::ArraySizeModifier SizeMod,
6351 const llvm::APInt *Size,
6352 Expr *SizeExpr,
6353 unsigned IndexTypeQuals,
6354 SourceRange BracketsRange) {
6355 if (SizeExpr || !Size)
6356 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6357 IndexTypeQuals, BracketsRange,
6358 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006359
6360 QualType Types[] = {
6361 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6362 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6363 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006364 };
6365 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6366 QualType SizeType;
6367 for (unsigned I = 0; I != NumTypes; ++I)
6368 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6369 SizeType = Types[I];
6370 break;
6371 }
Mike Stump1eb44332009-09-09 15:08:12 +00006372
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006373 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6374 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006375 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006376 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006377 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006378}
Mike Stump1eb44332009-09-09 15:08:12 +00006379
Douglas Gregor577f75a2009-08-04 16:50:30 +00006380template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006381QualType
6382TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006383 ArrayType::ArraySizeModifier SizeMod,
6384 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006385 unsigned IndexTypeQuals,
6386 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006387 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006388 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006389}
6390
6391template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006392QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006393TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006394 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006395 unsigned IndexTypeQuals,
6396 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006397 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006398 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006399}
Mike Stump1eb44332009-09-09 15:08:12 +00006400
Douglas Gregor577f75a2009-08-04 16:50:30 +00006401template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006402QualType
6403TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006404 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006405 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006406 unsigned IndexTypeQuals,
6407 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006408 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006409 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006410 IndexTypeQuals, BracketsRange);
6411}
6412
6413template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006414QualType
6415TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006416 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006417 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006418 unsigned IndexTypeQuals,
6419 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006420 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006421 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006422 IndexTypeQuals, BracketsRange);
6423}
6424
6425template<typename Derived>
6426QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner788b0fd2010-06-23 06:00:24 +00006427 unsigned NumElements,
6428 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006429 // FIXME: semantic checking!
Chris Lattner788b0fd2010-06-23 06:00:24 +00006430 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006431}
Mike Stump1eb44332009-09-09 15:08:12 +00006432
Douglas Gregor577f75a2009-08-04 16:50:30 +00006433template<typename Derived>
6434QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6435 unsigned NumElements,
6436 SourceLocation AttributeLoc) {
6437 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6438 NumElements, true);
6439 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006440 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6441 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00006442 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006443}
Mike Stump1eb44332009-09-09 15:08:12 +00006444
Douglas Gregor577f75a2009-08-04 16:50:30 +00006445template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006446QualType
6447TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00006448 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006449 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00006450 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006451}
Mike Stump1eb44332009-09-09 15:08:12 +00006452
Douglas Gregor577f75a2009-08-04 16:50:30 +00006453template<typename Derived>
6454QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006455 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006456 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006457 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00006458 unsigned Quals,
6459 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00006460 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006461 Quals,
6462 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006463 getDerived().getBaseEntity(),
6464 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006465}
Mike Stump1eb44332009-09-09 15:08:12 +00006466
Douglas Gregor577f75a2009-08-04 16:50:30 +00006467template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006468QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6469 return SemaRef.Context.getFunctionNoProtoType(T);
6470}
6471
6472template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006473QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6474 assert(D && "no decl found");
6475 if (D->isInvalidDecl()) return QualType();
6476
Douglas Gregor92e986e2010-04-22 16:44:27 +00006477 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006478 TypeDecl *Ty;
6479 if (isa<UsingDecl>(D)) {
6480 UsingDecl *Using = cast<UsingDecl>(D);
6481 assert(Using->isTypeName() &&
6482 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6483
6484 // A valid resolved using typename decl points to exactly one type decl.
6485 assert(++Using->shadow_begin() == Using->shadow_end());
6486 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006487
John McCalled976492009-12-04 22:46:56 +00006488 } else {
6489 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6490 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6491 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6492 }
6493
6494 return SemaRef.Context.getTypeDeclType(Ty);
6495}
6496
6497template<typename Derived>
John McCall9ae2f072010-08-23 23:25:46 +00006498QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E) {
6499 return SemaRef.BuildTypeofExprType(E);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006500}
6501
6502template<typename Derived>
6503QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6504 return SemaRef.Context.getTypeOfType(Underlying);
6505}
6506
6507template<typename Derived>
John McCall9ae2f072010-08-23 23:25:46 +00006508QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E) {
6509 return SemaRef.BuildDecltypeType(E);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006510}
6511
6512template<typename Derived>
6513QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006514 TemplateName Template,
6515 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006516 const TemplateArgumentListInfo &TemplateArgs) {
6517 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006518}
Mike Stump1eb44332009-09-09 15:08:12 +00006519
Douglas Gregordcee1a12009-08-06 05:28:30 +00006520template<typename Derived>
6521NestedNameSpecifier *
6522TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6523 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006524 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006525 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006526 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006527 CXXScopeSpec SS;
6528 // FIXME: The source location information is all wrong.
6529 SS.setRange(Range);
6530 SS.setScopeRep(Prefix);
6531 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006532 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006533 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006534 ObjectType,
6535 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006536 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006537}
6538
6539template<typename Derived>
6540NestedNameSpecifier *
6541TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6542 SourceRange Range,
6543 NamespaceDecl *NS) {
6544 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6545}
6546
6547template<typename Derived>
6548NestedNameSpecifier *
6549TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6550 SourceRange Range,
6551 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006552 QualType T) {
6553 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006554 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006555 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006556 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6557 T.getTypePtr());
6558 }
Mike Stump1eb44332009-09-09 15:08:12 +00006559
Douglas Gregordcee1a12009-08-06 05:28:30 +00006560 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6561 return 0;
6562}
Mike Stump1eb44332009-09-09 15:08:12 +00006563
Douglas Gregord1067e52009-08-06 06:41:21 +00006564template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006565TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006566TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6567 bool TemplateKW,
6568 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006569 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006570 Template);
6571}
6572
6573template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006574TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006575TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006576 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006577 const IdentifierInfo &II,
6578 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006579 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006580 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00006581 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006582 UnqualifiedId Name;
6583 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00006584 Sema::TemplateTy Template;
6585 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6586 /*FIXME:*/getDerived().getBaseLocation(),
6587 SS,
6588 Name,
John McCallb3d87482010-08-24 05:47:05 +00006589 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006590 /*EnteringContext=*/false,
6591 Template);
6592 return Template.template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00006593}
Mike Stump1eb44332009-09-09 15:08:12 +00006594
Douglas Gregorb98b1992009-08-11 05:31:07 +00006595template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006596TemplateName
6597TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6598 OverloadedOperatorKind Operator,
6599 QualType ObjectType) {
6600 CXXScopeSpec SS;
6601 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6602 SS.setScopeRep(Qualifier);
6603 UnqualifiedId Name;
6604 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6605 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6606 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00006607 Sema::TemplateTy Template;
6608 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006609 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006610 SS,
6611 Name,
John McCallb3d87482010-08-24 05:47:05 +00006612 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006613 /*EnteringContext=*/false,
6614 Template);
6615 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006616}
Sean Huntc3021132010-05-05 15:23:54 +00006617
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006618template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006619ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6621 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006622 Expr *OrigCallee,
6623 Expr *First,
6624 Expr *Second) {
6625 Expr *Callee = OrigCallee->IgnoreParenCasts();
6626 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006627
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006629 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00006630 if (!First->getType()->isOverloadableType() &&
6631 !Second->getType()->isOverloadableType())
6632 return getSema().CreateBuiltinArraySubscriptExpr(First,
6633 Callee->getLocStart(),
6634 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006635 } else if (Op == OO_Arrow) {
6636 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00006637 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6638 } else if (Second == 0 || isPostIncDec) {
6639 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 // The argument is not of overloadable type, so try to create a
6641 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00006642 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006644
John McCall9ae2f072010-08-23 23:25:46 +00006645 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 }
6647 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006648 if (!First->getType()->isOverloadableType() &&
6649 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006650 // Neither of the arguments is an overloadable type, so try to
6651 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00006652 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006653 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00006654 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006656 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006657
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658 return move(Result);
6659 }
6660 }
Mike Stump1eb44332009-09-09 15:08:12 +00006661
6662 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006664 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006665
John McCall9ae2f072010-08-23 23:25:46 +00006666 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00006667 assert(ULE->requiresADL());
6668
6669 // FIXME: Do we have to check
6670 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006671 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006672 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006673 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006674 }
Mike Stump1eb44332009-09-09 15:08:12 +00006675
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00006677 Expr *Args[2] = { First, Second };
6678 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006679
Douglas Gregorb98b1992009-08-11 05:31:07 +00006680 // Create the overloaded operator invocation for unary operators.
6681 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00006682 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00006684 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006685 }
Mike Stump1eb44332009-09-09 15:08:12 +00006686
Sebastian Redlf322ed62009-10-29 20:17:01 +00006687 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00006688 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00006689 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006690 First,
6691 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006692
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00006694 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006695 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6697 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006698 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006699
Mike Stump1eb44332009-09-09 15:08:12 +00006700 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701}
Mike Stump1eb44332009-09-09 15:08:12 +00006702
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006703template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006704ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00006705TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006706 SourceLocation OperatorLoc,
6707 bool isArrow,
6708 NestedNameSpecifier *Qualifier,
6709 SourceRange QualifierRange,
6710 TypeSourceInfo *ScopeType,
6711 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006712 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006713 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006714 CXXScopeSpec SS;
6715 if (Qualifier) {
6716 SS.setRange(QualifierRange);
6717 SS.setScopeRep(Qualifier);
6718 }
6719
John McCall9ae2f072010-08-23 23:25:46 +00006720 QualType BaseType = Base->getType();
6721 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006722 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006723 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006724 !BaseType->getAs<PointerType>()->getPointeeType()
6725 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006726 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00006727 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006728 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006729 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006730 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006731 /*FIXME?*/true);
6732 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006733
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006734 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00006735 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6736 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6737 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6738 NameInfo.setNamedTypeInfo(DestroyedType);
6739
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006740 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00006741
John McCall9ae2f072010-08-23 23:25:46 +00006742 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006743 OperatorLoc, isArrow,
6744 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00006745 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006746 /*TemplateArgs*/ 0);
6747}
6748
Douglas Gregor577f75a2009-08-04 16:50:30 +00006749} // end namespace clang
6750
6751#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H