blob: 41d8f2a71133ee1d5281c583adc7e536ebea970f [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 McCall2a984ca2010-10-12 00:20:44 +0000498 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
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 McCall2a984ca2010-10-12 00:20:44 +0000509 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
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.
John McCall21e413f2010-11-04 19:04:38 +0000525 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
526 ElaboratedTypeKeyword Keyword,
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000527 NestedNameSpecifier *NNS, QualType Named) {
528 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000529 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000530
531 /// \brief Build a new typename type that refers to a template-id.
532 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000533 /// By default, builds a new DependentNameType type from the
534 /// nested-name-specifier and the given type. Subclasses may override
535 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000536 QualType RebuildDependentTemplateSpecializationType(
537 ElaboratedTypeKeyword Keyword,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000538 NestedNameSpecifier *Qualifier,
539 SourceRange QualifierRange,
John McCall33500952010-06-11 00:33:02 +0000540 const IdentifierInfo *Name,
541 SourceLocation NameLoc,
542 const TemplateArgumentListInfo &Args) {
543 // Rebuild the template name.
544 // TODO: avoid TemplateName abstraction
545 TemplateName InstName =
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000546 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
547 QualType());
John McCall33500952010-06-11 00:33:02 +0000548
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000549 if (InstName.isNull())
550 return QualType();
551
John McCall33500952010-06-11 00:33:02 +0000552 // If it's still dependent, make a dependent specialization.
553 if (InstName.getAsDependentTemplateName())
554 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000555 Keyword, Qualifier, Name, Args);
John McCall33500952010-06-11 00:33:02 +0000556
557 // Otherwise, make an elaborated type wrapping a non-dependent
558 // specialization.
559 QualType T =
560 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
561 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000562
Abramo Bagnara22f638a2010-08-10 13:46:45 +0000563 // NOTE: NNS is already recorded in template specialization type T.
564 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000565 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000566
567 /// \brief Build a new typename type that refers to an identifier.
568 ///
569 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000570 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000571 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000572 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000573 NestedNameSpecifier *NNS,
574 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000575 SourceLocation KeywordLoc,
576 SourceRange NNSRange,
577 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000578 CXXScopeSpec SS;
579 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000580 SS.setRange(NNSRange);
581
Douglas Gregor40336422010-03-31 22:19:08 +0000582 if (NNS->isDependent()) {
583 // If the name is still dependent, just build a new dependent name type.
584 if (!SemaRef.computeDeclContext(SS))
585 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
586 }
587
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000588 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000589 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
590 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000591
592 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
593
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000594 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000595 // into a non-dependent elaborated-type-specifier. Find the tag we're
596 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000597 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000598 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
599 if (!DC)
600 return QualType();
601
John McCall56138762010-05-27 06:40:31 +0000602 if (SemaRef.RequireCompleteDeclContext(SS, DC))
603 return QualType();
604
Douglas Gregor40336422010-03-31 22:19:08 +0000605 TagDecl *Tag = 0;
606 SemaRef.LookupQualifiedName(Result, DC);
607 switch (Result.getResultKind()) {
608 case LookupResult::NotFound:
609 case LookupResult::NotFoundInCurrentInstantiation:
610 break;
Sean Huntc3021132010-05-05 15:23:54 +0000611
Douglas Gregor40336422010-03-31 22:19:08 +0000612 case LookupResult::Found:
613 Tag = Result.getAsSingle<TagDecl>();
614 break;
Sean Huntc3021132010-05-05 15:23:54 +0000615
Douglas Gregor40336422010-03-31 22:19:08 +0000616 case LookupResult::FoundOverloaded:
617 case LookupResult::FoundUnresolvedValue:
618 llvm_unreachable("Tag lookup cannot find non-tags");
619 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000620
Douglas Gregor40336422010-03-31 22:19:08 +0000621 case LookupResult::Ambiguous:
622 // Let the LookupResult structure handle ambiguities.
623 return QualType();
624 }
625
626 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000627 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000628 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000629 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000630 return QualType();
631 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000632
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000633 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
634 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000635 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
636 return QualType();
637 }
638
639 // Build the elaborated-type-specifier type.
640 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000641 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000642 }
Mike Stump1eb44332009-09-09 15:08:12 +0000643
Douglas Gregordcee1a12009-08-06 05:28:30 +0000644 /// \brief Build a new nested-name-specifier given the prefix and an
645 /// identifier that names the next step in the nested-name-specifier.
646 ///
647 /// By default, performs semantic analysis when building the new
648 /// nested-name-specifier. Subclasses may override this routine to provide
649 /// different behavior.
650 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
651 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000652 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000653 QualType ObjectType,
654 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000655
656 /// \brief Build a new nested-name-specifier given the prefix and the
657 /// namespace named in the next step in the nested-name-specifier.
658 ///
659 /// By default, performs semantic analysis when building the new
660 /// nested-name-specifier. Subclasses may override this routine to provide
661 /// different behavior.
662 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
663 SourceRange Range,
664 NamespaceDecl *NS);
665
666 /// \brief Build a new nested-name-specifier given the prefix and the
667 /// type named in the next step in the nested-name-specifier.
668 ///
669 /// By default, performs semantic analysis when building the new
670 /// nested-name-specifier. Subclasses may override this routine to provide
671 /// different behavior.
672 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
673 SourceRange Range,
674 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000675 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000676
677 /// \brief Build a new template name given a nested name specifier, a flag
678 /// indicating whether the "template" keyword was provided, and the template
679 /// that the template name refers to.
680 ///
681 /// By default, builds the new template name directly. Subclasses may override
682 /// this routine to provide different behavior.
683 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
684 bool TemplateKW,
685 TemplateDecl *Template);
686
Douglas Gregord1067e52009-08-06 06:41:21 +0000687 /// \brief Build a new template name given a nested name specifier and the
688 /// name that is referred to as a template.
689 ///
690 /// By default, performs semantic analysis to determine whether the name can
691 /// be resolved to a specific template, then builds the appropriate kind of
692 /// template name. Subclasses may override this routine to provide different
693 /// behavior.
694 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000695 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000696 const IdentifierInfo &II,
697 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000698
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000699 /// \brief Build a new template name given a nested name specifier and the
700 /// overloaded operator name that is referred to as a template.
701 ///
702 /// By default, performs semantic analysis to determine whether the name can
703 /// be resolved to a specific template, then builds the appropriate kind of
704 /// template name. Subclasses may override this routine to provide different
705 /// behavior.
706 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
707 OverloadedOperatorKind Operator,
708 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000709
Douglas Gregor43959a92009-08-20 07:17:43 +0000710 /// \brief Build a new compound statement.
711 ///
712 /// By default, performs semantic analysis to build the new statement.
713 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000714 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000715 MultiStmtArg Statements,
716 SourceLocation RBraceLoc,
717 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000718 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000719 IsStmtExpr);
720 }
721
722 /// \brief Build a new case statement.
723 ///
724 /// By default, performs semantic analysis to build the new statement.
725 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000726 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000727 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000728 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000729 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000730 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000731 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000732 ColonLoc);
733 }
Mike Stump1eb44332009-09-09 15:08:12 +0000734
Douglas Gregor43959a92009-08-20 07:17:43 +0000735 /// \brief Attach the body to a new case statement.
736 ///
737 /// By default, performs semantic analysis to build the new statement.
738 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000739 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000740 getSema().ActOnCaseStmtBody(S, Body);
741 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000742 }
Mike Stump1eb44332009-09-09 15:08:12 +0000743
Douglas Gregor43959a92009-08-20 07:17:43 +0000744 /// \brief Build a new default statement.
745 ///
746 /// By default, performs semantic analysis to build the new statement.
747 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000748 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000749 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000750 Stmt *SubStmt) {
751 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000752 /*CurScope=*/0);
753 }
Mike Stump1eb44332009-09-09 15:08:12 +0000754
Douglas Gregor43959a92009-08-20 07:17:43 +0000755 /// \brief Build a new label statement.
756 ///
757 /// By default, performs semantic analysis to build the new statement.
758 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000759 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000760 IdentifierInfo *Id,
761 SourceLocation ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +0000762 Stmt *SubStmt, bool HasUnusedAttr) {
763 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
764 HasUnusedAttr);
Douglas Gregor43959a92009-08-20 07:17:43 +0000765 }
Mike Stump1eb44332009-09-09 15:08:12 +0000766
Douglas Gregor43959a92009-08-20 07:17:43 +0000767 /// \brief Build a new "if" statement.
768 ///
769 /// By default, performs semantic analysis to build the new statement.
770 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000771 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCall9ae2f072010-08-23 23:25:46 +0000772 VarDecl *CondVar, Stmt *Then,
773 SourceLocation ElseLoc, Stmt *Else) {
774 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000775 }
Mike Stump1eb44332009-09-09 15:08:12 +0000776
Douglas Gregor43959a92009-08-20 07:17:43 +0000777 /// \brief Start building a new switch statement.
778 ///
779 /// By default, performs semantic analysis to build the new statement.
780 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000781 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000782 Expr *Cond, VarDecl *CondVar) {
783 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +0000784 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +0000785 }
Mike Stump1eb44332009-09-09 15:08:12 +0000786
Douglas Gregor43959a92009-08-20 07:17:43 +0000787 /// \brief Attach the body to the switch statement.
788 ///
789 /// By default, performs semantic analysis to build the new statement.
790 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000791 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000792 Stmt *Switch, Stmt *Body) {
793 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000794 }
795
796 /// \brief Build a new while statement.
797 ///
798 /// By default, performs semantic analysis to build the new statement.
799 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000800 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000801 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000802 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000803 Stmt *Body) {
804 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000805 }
Mike Stump1eb44332009-09-09 15:08:12 +0000806
Douglas Gregor43959a92009-08-20 07:17:43 +0000807 /// \brief Build a new do-while statement.
808 ///
809 /// By default, performs semantic analysis to build the new statement.
810 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000811 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregor43959a92009-08-20 07:17:43 +0000812 SourceLocation WhileLoc,
813 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000814 Expr *Cond,
Douglas Gregor43959a92009-08-20 07:17:43 +0000815 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000816 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
817 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +0000818 }
819
820 /// \brief Build a new for statement.
821 ///
822 /// By default, performs semantic analysis to build the new statement.
823 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000824 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000825 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000826 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000827 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCall9ae2f072010-08-23 23:25:46 +0000828 SourceLocation RParenLoc, Stmt *Body) {
829 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCalld226f652010-08-21 09:40:31 +0000830 CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000831 Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000832 }
Mike Stump1eb44332009-09-09 15:08:12 +0000833
Douglas Gregor43959a92009-08-20 07:17:43 +0000834 /// \brief Build a new goto statement.
835 ///
836 /// By default, performs semantic analysis to build the new statement.
837 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000838 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000839 SourceLocation LabelLoc,
840 LabelStmt *Label) {
841 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
842 }
843
844 /// \brief Build a new indirect goto statement.
845 ///
846 /// By default, performs semantic analysis to build the new statement.
847 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000848 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000849 SourceLocation StarLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000850 Expr *Target) {
851 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +0000852 }
Mike Stump1eb44332009-09-09 15:08:12 +0000853
Douglas Gregor43959a92009-08-20 07:17:43 +0000854 /// \brief Build a new return statement.
855 ///
856 /// By default, performs semantic analysis to build the new statement.
857 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000858 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000859 Expr *Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000860
John McCall9ae2f072010-08-23 23:25:46 +0000861 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +0000862 }
Mike Stump1eb44332009-09-09 15:08:12 +0000863
Douglas Gregor43959a92009-08-20 07:17:43 +0000864 /// \brief Build a new declaration statement.
865 ///
866 /// By default, performs semantic analysis to build the new statement.
867 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000868 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000869 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000870 SourceLocation EndLoc) {
871 return getSema().Owned(
872 new (getSema().Context) DeclStmt(
873 DeclGroupRef::Create(getSema().Context,
874 Decls, NumDecls),
875 StartLoc, EndLoc));
876 }
Mike Stump1eb44332009-09-09 15:08:12 +0000877
Anders Carlsson703e3942010-01-24 05:50:09 +0000878 /// \brief Build a new inline asm statement.
879 ///
880 /// By default, performs semantic analysis to build the new statement.
881 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000882 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +0000883 bool IsSimple,
884 bool IsVolatile,
885 unsigned NumOutputs,
886 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000887 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000888 MultiExprArg Constraints,
889 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +0000890 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +0000891 MultiExprArg Clobbers,
892 SourceLocation RParenLoc,
893 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000894 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000895 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +0000896 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +0000897 RParenLoc, MSAsm);
898 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000899
900 /// \brief Build a new Objective-C @try statement.
901 ///
902 /// By default, performs semantic analysis to build the new statement.
903 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000904 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000905 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000906 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +0000907 Stmt *Finally) {
908 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
909 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000910 }
911
Douglas Gregorbe270a02010-04-26 17:57:08 +0000912 /// \brief Rebuild an Objective-C exception declaration.
913 ///
914 /// By default, performs semantic analysis to build the new declaration.
915 /// Subclasses may override this routine to provide different behavior.
916 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
917 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +0000918 return getSema().BuildObjCExceptionDecl(TInfo, T,
919 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +0000920 ExceptionDecl->getLocation());
921 }
Sean Huntc3021132010-05-05 15:23:54 +0000922
Douglas Gregorbe270a02010-04-26 17:57:08 +0000923 /// \brief Build a new Objective-C @catch statement.
924 ///
925 /// By default, performs semantic analysis to build the new statement.
926 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000927 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +0000928 SourceLocation RParenLoc,
929 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +0000930 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +0000931 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000932 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +0000933 }
Sean Huntc3021132010-05-05 15:23:54 +0000934
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000935 /// \brief Build a new Objective-C @finally statement.
936 ///
937 /// By default, performs semantic analysis to build the new statement.
938 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000939 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000940 Stmt *Body) {
941 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000942 }
Sean Huntc3021132010-05-05 15:23:54 +0000943
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000944 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +0000945 ///
946 /// By default, performs semantic analysis to build the new statement.
947 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000948 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000949 Expr *Operand) {
950 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +0000951 }
Sean Huntc3021132010-05-05 15:23:54 +0000952
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000953 /// \brief Build a new Objective-C @synchronized statement.
954 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000955 /// By default, performs semantic analysis to build the new statement.
956 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000957 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000958 Expr *Object,
959 Stmt *Body) {
960 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
961 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000962 }
Douglas Gregorc3203e72010-04-22 23:10:45 +0000963
964 /// \brief Build a new Objective-C fast enumeration statement.
965 ///
966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000968 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +0000969 SourceLocation LParenLoc,
970 Stmt *Element,
971 Expr *Collection,
972 SourceLocation RParenLoc,
973 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +0000974 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000975 Element,
976 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +0000977 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000978 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +0000979 }
Sean Huntc3021132010-05-05 15:23:54 +0000980
Douglas Gregor43959a92009-08-20 07:17:43 +0000981 /// \brief Build a new C++ exception declaration.
982 ///
983 /// By default, performs semantic analysis to build the new decaration.
984 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor83cb9422010-09-09 17:09:21 +0000985 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +0000986 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000987 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +0000988 SourceLocation Loc) {
989 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-08-20 07:17:43 +0000990 }
991
992 /// \brief Build a new C++ catch statement.
993 ///
994 /// By default, performs semantic analysis to build the new statement.
995 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000996 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +0000997 VarDecl *ExceptionDecl,
998 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +0000999 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1000 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001001 }
Mike Stump1eb44332009-09-09 15:08:12 +00001002
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 /// \brief Build a new C++ try statement.
1004 ///
1005 /// By default, performs semantic analysis to build the new statement.
1006 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001007 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001008 Stmt *TryBlock,
1009 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001010 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001011 }
Mike Stump1eb44332009-09-09 15:08:12 +00001012
Douglas Gregorb98b1992009-08-11 05:31:07 +00001013 /// \brief Build a new expression that references a declaration.
1014 ///
1015 /// By default, performs semantic analysis to build the new expression.
1016 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001017 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001018 LookupResult &R,
1019 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001020 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1021 }
1022
1023
1024 /// \brief Build a new expression that references a declaration.
1025 ///
1026 /// By default, performs semantic analysis to build the new expression.
1027 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001028 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001029 SourceRange QualifierRange,
1030 ValueDecl *VD,
1031 const DeclarationNameInfo &NameInfo,
1032 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001033 CXXScopeSpec SS;
1034 SS.setScopeRep(Qualifier);
1035 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001036
1037 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001038
1039 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001040 }
Mike Stump1eb44332009-09-09 15:08:12 +00001041
Douglas Gregorb98b1992009-08-11 05:31:07 +00001042 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001043 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001044 /// By default, performs semantic analysis to build the new expression.
1045 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001046 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001047 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001048 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001049 }
1050
Douglas Gregora71d8192009-09-04 17:36:40 +00001051 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001052 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001053 /// By default, performs semantic analysis to build the new expression.
1054 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001055 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001056 SourceLocation OperatorLoc,
1057 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001058 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001059 SourceRange QualifierRange,
1060 TypeSourceInfo *ScopeType,
1061 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001062 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001063 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001064
Douglas Gregorb98b1992009-08-11 05:31:07 +00001065 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001066 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001067 /// By default, performs semantic analysis to build the new expression.
1068 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001069 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001070 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001071 Expr *SubExpr) {
1072 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001073 }
Mike Stump1eb44332009-09-09 15:08:12 +00001074
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001075 /// \brief Build a new builtin offsetof expression.
1076 ///
1077 /// By default, performs semantic analysis to build the new expression.
1078 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001079 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001080 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001081 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001082 unsigned NumComponents,
1083 SourceLocation RParenLoc) {
1084 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1085 NumComponents, RParenLoc);
1086 }
Sean Huntc3021132010-05-05 15:23:54 +00001087
Douglas Gregorb98b1992009-08-11 05:31:07 +00001088 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001089 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001090 /// By default, performs semantic analysis to build the new expression.
1091 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001092 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001093 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001094 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001095 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001096 }
1097
Mike Stump1eb44332009-09-09 15:08:12 +00001098 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001099 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001100 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001101 /// By default, performs semantic analysis to build the new expression.
1102 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001103 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001104 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001105 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001106 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001107 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001108 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001109
Douglas Gregorb98b1992009-08-11 05:31:07 +00001110 return move(Result);
1111 }
Mike Stump1eb44332009-09-09 15:08:12 +00001112
Douglas Gregorb98b1992009-08-11 05:31:07 +00001113 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001114 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001115 /// By default, performs semantic analysis to build the new expression.
1116 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001117 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001118 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001119 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001120 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001121 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1122 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001123 RBracketLoc);
1124 }
1125
1126 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001127 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001128 /// By default, performs semantic analysis to build the new expression.
1129 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001130 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001131 MultiExprArg Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001132 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001133 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora1a04782010-09-09 16:33:13 +00001134 move(Args), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001135 }
1136
1137 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001138 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001139 /// By default, performs semantic analysis to build the new expression.
1140 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001141 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001142 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001143 NestedNameSpecifier *Qualifier,
1144 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001145 const DeclarationNameInfo &MemberNameInfo,
Eli Friedmanf595cc42009-12-04 06:40:45 +00001146 ValueDecl *Member,
John McCall6bb80172010-03-30 21:47:33 +00001147 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001148 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +00001149 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001150 if (!Member->getDeclName()) {
1151 // We have a reference to an unnamed field.
1152 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +00001153
John McCall9ae2f072010-08-23 23:25:46 +00001154 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001155 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001156 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001157
Mike Stump1eb44332009-09-09 15:08:12 +00001158 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001159 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001160 Member, MemberNameInfo,
Anders Carlssond8b285f2009-09-01 04:26:58 +00001161 cast<FieldDecl>(Member)->getType());
1162 return getSema().Owned(ME);
1163 }
Mike Stump1eb44332009-09-09 15:08:12 +00001164
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001165 CXXScopeSpec SS;
1166 if (Qualifier) {
1167 SS.setRange(QualifierRange);
1168 SS.setScopeRep(Qualifier);
1169 }
1170
John McCall9ae2f072010-08-23 23:25:46 +00001171 getSema().DefaultFunctionArrayConversion(Base);
1172 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001173
John McCall6bb80172010-03-30 21:47:33 +00001174 // FIXME: this involves duplicating earlier analysis in a lot of
1175 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001176 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001177 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001178 R.resolveKind();
1179
John McCall9ae2f072010-08-23 23:25:46 +00001180 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001181 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001182 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001183 }
Mike Stump1eb44332009-09-09 15:08:12 +00001184
Douglas Gregorb98b1992009-08-11 05:31:07 +00001185 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001186 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001187 /// By default, performs semantic analysis to build the new expression.
1188 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001189 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001190 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001191 Expr *LHS, Expr *RHS) {
1192 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001193 }
1194
1195 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001196 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001197 /// By default, performs semantic analysis to build the new expression.
1198 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001199 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001200 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001201 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001202 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001203 Expr *RHS) {
1204 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1205 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001206 }
1207
Douglas Gregorb98b1992009-08-11 05:31:07 +00001208 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001209 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001210 /// By default, performs semantic analysis to build the new expression.
1211 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001212 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001213 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001214 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001215 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001216 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001217 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001218 }
Mike Stump1eb44332009-09-09 15:08:12 +00001219
Douglas Gregorb98b1992009-08-11 05:31:07 +00001220 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001221 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001222 /// By default, performs semantic analysis to build the new expression.
1223 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001224 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001225 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001226 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001227 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001228 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001229 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001230 }
Mike Stump1eb44332009-09-09 15:08:12 +00001231
Douglas Gregorb98b1992009-08-11 05:31:07 +00001232 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001233 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001234 /// By default, performs semantic analysis to build the new expression.
1235 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001236 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001237 SourceLocation OpLoc,
1238 SourceLocation AccessorLoc,
1239 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001240
John McCall129e2df2009-11-30 22:42:35 +00001241 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001242 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001243 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001244 OpLoc, /*IsArrow*/ false,
1245 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001246 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001247 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001248 }
Mike Stump1eb44332009-09-09 15:08:12 +00001249
Douglas Gregorb98b1992009-08-11 05:31:07 +00001250 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001251 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001252 /// By default, performs semantic analysis to build the new expression.
1253 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001254 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001255 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001256 SourceLocation RBraceLoc,
1257 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001258 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001259 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1260 if (Result.isInvalid() || ResultTy->isDependentType())
1261 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001262
Douglas Gregore48319a2009-11-09 17:16:50 +00001263 // Patch in the result type we were given, which may have been computed
1264 // when the initial InitListExpr was built.
1265 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1266 ILE->setType(ResultTy);
1267 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001268 }
Mike Stump1eb44332009-09-09 15:08:12 +00001269
Douglas Gregorb98b1992009-08-11 05:31:07 +00001270 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001271 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001272 /// By default, performs semantic analysis to build the new expression.
1273 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001274 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001275 MultiExprArg ArrayExprs,
1276 SourceLocation EqualOrColonLoc,
1277 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001278 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001279 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001280 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001281 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001282 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001283 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001284
Douglas Gregorb98b1992009-08-11 05:31:07 +00001285 ArrayExprs.release();
1286 return move(Result);
1287 }
Mike Stump1eb44332009-09-09 15:08:12 +00001288
Douglas Gregorb98b1992009-08-11 05:31:07 +00001289 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001290 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001291 /// By default, builds the implicit value initialization without performing
1292 /// any semantic analysis. Subclasses may override this routine to provide
1293 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001294 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001295 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1296 }
Mike Stump1eb44332009-09-09 15:08:12 +00001297
Douglas Gregorb98b1992009-08-11 05:31:07 +00001298 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001299 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001300 /// By default, performs semantic analysis to build the new expression.
1301 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001302 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001303 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001304 SourceLocation RParenLoc) {
1305 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001306 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001307 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001308 }
1309
1310 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001311 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001314 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001315 MultiExprArg SubExprs,
1316 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001317 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001318 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001319 }
Mike Stump1eb44332009-09-09 15:08:12 +00001320
Douglas Gregorb98b1992009-08-11 05:31:07 +00001321 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001322 ///
1323 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001324 /// rather than attempting to map the label statement itself.
1325 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001326 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001327 SourceLocation LabelLoc,
1328 LabelStmt *Label) {
1329 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1330 }
Mike Stump1eb44332009-09-09 15:08:12 +00001331
Douglas Gregorb98b1992009-08-11 05:31:07 +00001332 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001333 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001336 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001337 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001338 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001339 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001340 }
Mike Stump1eb44332009-09-09 15:08:12 +00001341
Douglas Gregorb98b1992009-08-11 05:31:07 +00001342 /// \brief Build a new __builtin_types_compatible_p expression.
1343 ///
1344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001346 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001347 TypeSourceInfo *TInfo1,
1348 TypeSourceInfo *TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001349 SourceLocation RParenLoc) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001350 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1351 TInfo1, TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001352 RParenLoc);
1353 }
Mike Stump1eb44332009-09-09 15:08:12 +00001354
Douglas Gregorb98b1992009-08-11 05:31:07 +00001355 /// \brief Build a new __builtin_choose_expr expression.
1356 ///
1357 /// By default, performs semantic analysis to build the new expression.
1358 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001359 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001360 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001361 SourceLocation RParenLoc) {
1362 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001363 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001364 RParenLoc);
1365 }
Mike Stump1eb44332009-09-09 15:08:12 +00001366
Douglas Gregorb98b1992009-08-11 05:31:07 +00001367 /// \brief Build a new overloaded operator call expression.
1368 ///
1369 /// By default, performs semantic analysis to build the new expression.
1370 /// The semantic analysis provides the behavior of template instantiation,
1371 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001372 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001373 /// argument-dependent lookup, etc. Subclasses may override this routine to
1374 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001375 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001376 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001377 Expr *Callee,
1378 Expr *First,
1379 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001380
1381 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001382 /// reinterpret_cast.
1383 ///
1384 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001385 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001386 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001387 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001388 Stmt::StmtClass Class,
1389 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001390 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001391 SourceLocation RAngleLoc,
1392 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001393 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001394 SourceLocation RParenLoc) {
1395 switch (Class) {
1396 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001397 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001398 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001399 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400
1401 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001402 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001403 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001404 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001405
Douglas Gregorb98b1992009-08-11 05:31:07 +00001406 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001407 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001408 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001409 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001411
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001413 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001414 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001415 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001416
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 default:
1418 assert(false && "Invalid C++ named cast");
1419 break;
1420 }
Mike Stump1eb44332009-09-09 15:08:12 +00001421
John McCallf312b1e2010-08-26 23:41:50 +00001422 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001423 }
Mike Stump1eb44332009-09-09 15:08:12 +00001424
Douglas Gregorb98b1992009-08-11 05:31:07 +00001425 /// \brief Build a new C++ static_cast expression.
1426 ///
1427 /// By default, performs semantic analysis to build the new expression.
1428 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001429 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001430 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001431 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001432 SourceLocation RAngleLoc,
1433 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001434 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001435 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001436 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001437 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001438 SourceRange(LAngleLoc, RAngleLoc),
1439 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001440 }
1441
1442 /// \brief Build a new C++ dynamic_cast expression.
1443 ///
1444 /// By default, performs semantic analysis to build the new expression.
1445 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001446 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001447 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001448 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001449 SourceLocation RAngleLoc,
1450 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001451 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001452 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001453 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001454 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001455 SourceRange(LAngleLoc, RAngleLoc),
1456 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001457 }
1458
1459 /// \brief Build a new C++ reinterpret_cast expression.
1460 ///
1461 /// By default, performs semantic analysis to build the new expression.
1462 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001463 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001464 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001465 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001466 SourceLocation RAngleLoc,
1467 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001468 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001469 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001470 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001471 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001472 SourceRange(LAngleLoc, RAngleLoc),
1473 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001474 }
1475
1476 /// \brief Build a new C++ const_cast expression.
1477 ///
1478 /// By default, performs semantic analysis to build the new expression.
1479 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001480 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001482 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 SourceLocation RAngleLoc,
1484 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001485 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001486 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001487 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001488 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001489 SourceRange(LAngleLoc, RAngleLoc),
1490 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001491 }
Mike Stump1eb44332009-09-09 15:08:12 +00001492
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 /// \brief Build a new C++ functional-style cast expression.
1494 ///
1495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001497 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1498 SourceLocation LParenLoc,
1499 Expr *Sub,
1500 SourceLocation RParenLoc) {
1501 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001502 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 RParenLoc);
1504 }
Mike Stump1eb44332009-09-09 15:08:12 +00001505
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 /// \brief Build a new C++ typeid(type) expression.
1507 ///
1508 /// By default, performs semantic analysis to build the new expression.
1509 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001510 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001511 SourceLocation TypeidLoc,
1512 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001513 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001514 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001515 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 }
Mike Stump1eb44332009-09-09 15:08:12 +00001517
Francois Pichet01b7c302010-09-08 12:20:18 +00001518
Douglas Gregorb98b1992009-08-11 05:31:07 +00001519 /// \brief Build a new C++ typeid(expr) expression.
1520 ///
1521 /// By default, performs semantic analysis to build the new expression.
1522 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001523 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001524 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001525 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001526 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001527 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001528 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001529 }
1530
Francois Pichet01b7c302010-09-08 12:20:18 +00001531 /// \brief Build a new C++ __uuidof(type) expression.
1532 ///
1533 /// By default, performs semantic analysis to build the new expression.
1534 /// Subclasses may override this routine to provide different behavior.
1535 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1536 SourceLocation TypeidLoc,
1537 TypeSourceInfo *Operand,
1538 SourceLocation RParenLoc) {
1539 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1540 RParenLoc);
1541 }
1542
1543 /// \brief Build a new C++ __uuidof(expr) expression.
1544 ///
1545 /// By default, performs semantic analysis to build the new expression.
1546 /// Subclasses may override this routine to provide different behavior.
1547 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1548 SourceLocation TypeidLoc,
1549 Expr *Operand,
1550 SourceLocation RParenLoc) {
1551 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1552 RParenLoc);
1553 }
1554
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 /// \brief Build a new C++ "this" expression.
1556 ///
1557 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001558 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001560 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001561 QualType ThisType,
1562 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001564 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1565 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001566 }
1567
1568 /// \brief Build a new C++ throw expression.
1569 ///
1570 /// By default, performs semantic analysis to build the new expression.
1571 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001572 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001573 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001574 }
1575
1576 /// \brief Build a new C++ default-argument expression.
1577 ///
1578 /// By default, builds a new default-argument expression, which does not
1579 /// require any semantic analysis. Subclasses may override this routine to
1580 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001581 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001582 ParmVarDecl *Param) {
1583 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1584 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 }
1586
1587 /// \brief Build a new C++ zero-initialization expression.
1588 ///
1589 /// By default, performs semantic analysis to build the new expression.
1590 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001591 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1592 SourceLocation LParenLoc,
1593 SourceLocation RParenLoc) {
1594 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001595 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001596 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 }
Mike Stump1eb44332009-09-09 15:08:12 +00001598
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 /// \brief Build a new C++ "new" expression.
1600 ///
1601 /// By default, performs semantic analysis to build the new expression.
1602 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001603 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001604 bool UseGlobal,
1605 SourceLocation PlacementLParen,
1606 MultiExprArg PlacementArgs,
1607 SourceLocation PlacementRParen,
1608 SourceRange TypeIdParens,
1609 QualType AllocatedType,
1610 TypeSourceInfo *AllocatedTypeInfo,
1611 Expr *ArraySize,
1612 SourceLocation ConstructorLParen,
1613 MultiExprArg ConstructorArgs,
1614 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001615 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 PlacementLParen,
1617 move(PlacementArgs),
1618 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001619 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001620 AllocatedType,
1621 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001622 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001623 ConstructorLParen,
1624 move(ConstructorArgs),
1625 ConstructorRParen);
1626 }
Mike Stump1eb44332009-09-09 15:08:12 +00001627
Douglas Gregorb98b1992009-08-11 05:31:07 +00001628 /// \brief Build a new C++ "delete" expression.
1629 ///
1630 /// By default, performs semantic analysis to build the new expression.
1631 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001632 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001633 bool IsGlobalDelete,
1634 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001635 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001637 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001638 }
Mike Stump1eb44332009-09-09 15:08:12 +00001639
Douglas Gregorb98b1992009-08-11 05:31:07 +00001640 /// \brief Build a new unary type trait expression.
1641 ///
1642 /// By default, performs semantic analysis to build the new expression.
1643 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001644 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001645 SourceLocation StartLoc,
1646 TypeSourceInfo *T,
1647 SourceLocation RParenLoc) {
1648 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 }
1650
Mike Stump1eb44332009-09-09 15:08:12 +00001651 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 /// expression.
1653 ///
1654 /// By default, performs semantic analysis to build the new expression.
1655 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001656 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001657 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001658 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001659 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 CXXScopeSpec SS;
1661 SS.setRange(QualifierRange);
1662 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001663
1664 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001665 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001666 *TemplateArgs);
1667
Abramo Bagnara25777432010-08-11 22:01:17 +00001668 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 }
1670
1671 /// \brief Build a new template-id expression.
1672 ///
1673 /// By default, performs semantic analysis to build the new expression.
1674 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001675 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001676 LookupResult &R,
1677 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001678 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001679 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 }
1681
1682 /// \brief Build a new object-construction expression.
1683 ///
1684 /// By default, performs semantic analysis to build the new expression.
1685 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001686 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001687 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001688 CXXConstructorDecl *Constructor,
1689 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001690 MultiExprArg Args,
1691 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00001692 CXXConstructExpr::ConstructionKind ConstructKind,
1693 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00001694 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001695 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001696 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001697 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001698
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001699 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001700 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00001701 RequiresZeroInit, ConstructKind,
1702 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 }
1704
1705 /// \brief Build a new object-construction expression.
1706 ///
1707 /// By default, performs semantic analysis to build the new expression.
1708 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001709 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1710 SourceLocation LParenLoc,
1711 MultiExprArg Args,
1712 SourceLocation RParenLoc) {
1713 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 LParenLoc,
1715 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 RParenLoc);
1717 }
1718
1719 /// \brief Build a new object-construction expression.
1720 ///
1721 /// By default, performs semantic analysis to build the new expression.
1722 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001723 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1724 SourceLocation LParenLoc,
1725 MultiExprArg Args,
1726 SourceLocation RParenLoc) {
1727 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001728 LParenLoc,
1729 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 RParenLoc);
1731 }
Mike Stump1eb44332009-09-09 15:08:12 +00001732
Douglas Gregorb98b1992009-08-11 05:31:07 +00001733 /// \brief Build a new member reference expression.
1734 ///
1735 /// By default, performs semantic analysis to build the new expression.
1736 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001737 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001738 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001739 bool IsArrow,
1740 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001741 NestedNameSpecifier *Qualifier,
1742 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001743 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001744 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001745 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001747 SS.setRange(QualifierRange);
1748 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001749
John McCall9ae2f072010-08-23 23:25:46 +00001750 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001751 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001752 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001753 MemberNameInfo,
1754 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 }
1756
John McCall129e2df2009-11-30 22:42:35 +00001757 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001758 ///
1759 /// By default, performs semantic analysis to build the new expression.
1760 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001761 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001762 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001763 SourceLocation OperatorLoc,
1764 bool IsArrow,
1765 NestedNameSpecifier *Qualifier,
1766 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001767 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001768 LookupResult &R,
1769 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001770 CXXScopeSpec SS;
1771 SS.setRange(QualifierRange);
1772 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001773
John McCall9ae2f072010-08-23 23:25:46 +00001774 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001775 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001776 SS, FirstQualifierInScope,
1777 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001778 }
Mike Stump1eb44332009-09-09 15:08:12 +00001779
Sebastian Redl2e156222010-09-10 20:55:43 +00001780 /// \brief Build a new noexcept expression.
1781 ///
1782 /// By default, performs semantic analysis to build the new expression.
1783 /// Subclasses may override this routine to provide different behavior.
1784 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1785 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1786 }
1787
Douglas Gregorb98b1992009-08-11 05:31:07 +00001788 /// \brief Build a new Objective-C @encode expression.
1789 ///
1790 /// By default, performs semantic analysis to build the new expression.
1791 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001792 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001793 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001795 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001797 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001798
Douglas Gregor92e986e2010-04-22 16:44:27 +00001799 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00001800 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001801 Selector Sel,
1802 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001803 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001804 MultiExprArg Args,
1805 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001806 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1807 ReceiverTypeInfo->getType(),
1808 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001809 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001810 move(Args));
1811 }
1812
1813 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00001814 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001815 Selector Sel,
1816 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001817 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001818 MultiExprArg Args,
1819 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001820 return SemaRef.BuildInstanceMessage(Receiver,
1821 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00001822 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001823 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001824 move(Args));
1825 }
1826
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001827 /// \brief Build a new Objective-C ivar reference expression.
1828 ///
1829 /// By default, performs semantic analysis to build the new expression.
1830 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001831 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001832 SourceLocation IvarLoc,
1833 bool IsArrow, bool IsFreeIvar) {
1834 // FIXME: We lose track of the IsFreeIvar bit.
1835 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001836 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001837 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1838 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001839 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001840 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00001841 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00001842 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001843 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001844 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001845
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001846 if (Result.get())
1847 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001848
John McCall9ae2f072010-08-23 23:25:46 +00001849 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001850 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001851 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001852 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001853 /*TemplateArgs=*/0);
1854 }
Douglas Gregore3303542010-04-26 20:47:02 +00001855
1856 /// \brief Build a new Objective-C property reference expression.
1857 ///
1858 /// By default, performs semantic analysis to build the new expression.
1859 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001860 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001861 ObjCPropertyDecl *Property,
1862 SourceLocation PropertyLoc) {
1863 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001864 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00001865 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1866 Sema::LookupMemberName);
1867 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00001868 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00001869 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00001870 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00001871 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001872 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001873
Douglas Gregore3303542010-04-26 20:47:02 +00001874 if (Result.get())
1875 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001876
John McCall9ae2f072010-08-23 23:25:46 +00001877 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001878 /*FIXME:*/PropertyLoc, IsArrow,
1879 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001880 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001881 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001882 /*TemplateArgs=*/0);
1883 }
Sean Huntc3021132010-05-05 15:23:54 +00001884
1885 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001886 /// expression.
1887 ///
1888 /// By default, performs semantic analysis to build the new expression.
Sean Huntc3021132010-05-05 15:23:54 +00001889 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001890 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001891 ObjCMethodDecl *Getter,
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001892 QualType T,
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001893 ObjCMethodDecl *Setter,
1894 SourceLocation NameLoc,
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001895 Expr *Base,
1896 SourceLocation SuperLoc,
1897 QualType SuperTy,
1898 bool Super) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001899 // Since these expressions can only be value-dependent, we do not need to
1900 // perform semantic analysis again.
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001901 if (Super)
1902 return Owned(
1903 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1904 Setter,
1905 NameLoc,
1906 SuperLoc,
1907 SuperTy));
1908 else
1909 return Owned(
1910 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(
1911 Getter, T,
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001912 Setter,
1913 NameLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001914 Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001915 }
1916
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001917 /// \brief Build a new Objective-C "isa" expression.
1918 ///
1919 /// By default, performs semantic analysis to build the new expression.
1920 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001921 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001922 bool IsArrow) {
1923 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001924 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001925 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1926 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001927 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001928 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00001929 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001930 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001931 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001932
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001933 if (Result.get())
1934 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001935
John McCall9ae2f072010-08-23 23:25:46 +00001936 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001937 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001938 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001939 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001940 /*TemplateArgs=*/0);
1941 }
Sean Huntc3021132010-05-05 15:23:54 +00001942
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 /// \brief Build a new shuffle vector expression.
1944 ///
1945 /// By default, performs semantic analysis to build the new expression.
1946 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001947 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001948 MultiExprArg SubExprs,
1949 SourceLocation RParenLoc) {
1950 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001951 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1953 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1954 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1955 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001956
Douglas Gregorb98b1992009-08-11 05:31:07 +00001957 // Build a reference to the __builtin_shufflevector builtin
1958 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001959 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001961 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001962 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001963
1964 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001965 unsigned NumSubExprs = SubExprs.size();
1966 Expr **Subs = (Expr **)SubExprs.release();
1967 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1968 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00001969 Builtin->getCallResultType(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00001971 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001972
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00001974 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001975 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001976 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001977
Douglas Gregorb98b1992009-08-11 05:31:07 +00001978 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001979 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001980 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001981};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001982
Douglas Gregor43959a92009-08-20 07:17:43 +00001983template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00001984StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00001985 if (!S)
1986 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001987
Douglas Gregor43959a92009-08-20 07:17:43 +00001988 switch (S->getStmtClass()) {
1989 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001990
Douglas Gregor43959a92009-08-20 07:17:43 +00001991 // Transform individual statement nodes
1992#define STMT(Node, Parent) \
1993 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1994#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00001995#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001996
Douglas Gregor43959a92009-08-20 07:17:43 +00001997 // Transform expressions by calling TransformExpr.
1998#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00001999#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002000#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002001#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002002 {
John McCall60d7b3a2010-08-24 06:29:42 +00002003 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002004 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002005 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002006
John McCall9ae2f072010-08-23 23:25:46 +00002007 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002008 }
Mike Stump1eb44332009-09-09 15:08:12 +00002009 }
2010
John McCall3fa5cae2010-10-26 07:05:15 +00002011 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002012}
Mike Stump1eb44332009-09-09 15:08:12 +00002013
2014
Douglas Gregor670444e2009-08-04 22:27:00 +00002015template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002016ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002017 if (!E)
2018 return SemaRef.Owned(E);
2019
2020 switch (E->getStmtClass()) {
2021 case Stmt::NoStmtClass: break;
2022#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002023#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002024#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002025 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002026#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002027 }
2028
John McCall3fa5cae2010-10-26 07:05:15 +00002029 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002030}
2031
2032template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002033NestedNameSpecifier *
2034TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002035 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002036 QualType ObjectType,
2037 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00002038 if (!NNS)
2039 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002040
Douglas Gregor43959a92009-08-20 07:17:43 +00002041 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002042 NestedNameSpecifier *Prefix = NNS->getPrefix();
2043 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002044 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002045 ObjectType,
2046 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002047 if (!Prefix)
2048 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002049
2050 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00002051 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00002052 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00002053 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002054 }
Mike Stump1eb44332009-09-09 15:08:12 +00002055
Douglas Gregordcee1a12009-08-06 05:28:30 +00002056 switch (NNS->getKind()) {
2057 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00002058 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002059 "Identifier nested-name-specifier with no prefix or object type");
2060 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2061 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002062 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002063
2064 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002065 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002066 ObjectType,
2067 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002068
Douglas Gregordcee1a12009-08-06 05:28:30 +00002069 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002070 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002071 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002072 getDerived().TransformDecl(Range.getBegin(),
2073 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002074 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002075 Prefix == NNS->getPrefix() &&
2076 NS == NNS->getAsNamespace())
2077 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002078
Douglas Gregordcee1a12009-08-06 05:28:30 +00002079 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2080 }
Mike Stump1eb44332009-09-09 15:08:12 +00002081
Douglas Gregordcee1a12009-08-06 05:28:30 +00002082 case NestedNameSpecifier::Global:
2083 // There is no meaningful transformation that one could perform on the
2084 // global scope.
2085 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002086
Douglas Gregordcee1a12009-08-06 05:28:30 +00002087 case NestedNameSpecifier::TypeSpecWithTemplate:
2088 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002089 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00002090 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2091 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002092 if (T.isNull())
2093 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002094
Douglas Gregordcee1a12009-08-06 05:28:30 +00002095 if (!getDerived().AlwaysRebuild() &&
2096 Prefix == NNS->getPrefix() &&
2097 T == QualType(NNS->getAsType(), 0))
2098 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002099
2100 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2101 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002102 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002103 }
2104 }
Mike Stump1eb44332009-09-09 15:08:12 +00002105
Douglas Gregordcee1a12009-08-06 05:28:30 +00002106 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002107 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002108}
2109
2110template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002111DeclarationNameInfo
2112TreeTransform<Derived>
2113::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2114 QualType ObjectType) {
2115 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002116 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002117 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002118
2119 switch (Name.getNameKind()) {
2120 case DeclarationName::Identifier:
2121 case DeclarationName::ObjCZeroArgSelector:
2122 case DeclarationName::ObjCOneArgSelector:
2123 case DeclarationName::ObjCMultiArgSelector:
2124 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002125 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002126 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002127 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002128
Douglas Gregor81499bb2009-09-03 22:13:48 +00002129 case DeclarationName::CXXConstructorName:
2130 case DeclarationName::CXXDestructorName:
2131 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002132 TypeSourceInfo *NewTInfo;
2133 CanQualType NewCanTy;
2134 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2135 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2136 if (!NewTInfo)
2137 return DeclarationNameInfo();
2138 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2139 }
2140 else {
2141 NewTInfo = 0;
2142 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2143 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2144 ObjectType);
2145 if (NewT.isNull())
2146 return DeclarationNameInfo();
2147 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2148 }
Mike Stump1eb44332009-09-09 15:08:12 +00002149
Abramo Bagnara25777432010-08-11 22:01:17 +00002150 DeclarationName NewName
2151 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2152 NewCanTy);
2153 DeclarationNameInfo NewNameInfo(NameInfo);
2154 NewNameInfo.setName(NewName);
2155 NewNameInfo.setNamedTypeInfo(NewTInfo);
2156 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002157 }
Mike Stump1eb44332009-09-09 15:08:12 +00002158 }
2159
Abramo Bagnara25777432010-08-11 22:01:17 +00002160 assert(0 && "Unknown name kind.");
2161 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002162}
2163
2164template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002165TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002166TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2167 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002168 SourceLocation Loc = getDerived().getBaseLocation();
2169
Douglas Gregord1067e52009-08-06 06:41:21 +00002170 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002171 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002172 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002173 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2174 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002175 if (!NNS)
2176 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002177
Douglas Gregord1067e52009-08-06 06:41:21 +00002178 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002179 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002180 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002181 if (!TransTemplate)
2182 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002183
Douglas Gregord1067e52009-08-06 06:41:21 +00002184 if (!getDerived().AlwaysRebuild() &&
2185 NNS == QTN->getQualifier() &&
2186 TransTemplate == Template)
2187 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002188
Douglas Gregord1067e52009-08-06 06:41:21 +00002189 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2190 TransTemplate);
2191 }
Mike Stump1eb44332009-09-09 15:08:12 +00002192
John McCallf7a1a742009-11-24 19:00:30 +00002193 // These should be getting filtered out before they make it into the AST.
2194 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002195 }
Mike Stump1eb44332009-09-09 15:08:12 +00002196
Douglas Gregord1067e52009-08-06 06:41:21 +00002197 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002198 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002199 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002200 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2201 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002202 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00002203 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002204
Douglas Gregord1067e52009-08-06 06:41:21 +00002205 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002206 NNS == DTN->getQualifier() &&
2207 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002208 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002209
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002210 if (DTN->isIdentifier()) {
2211 // FIXME: Bad range
2212 SourceRange QualifierRange(getDerived().getBaseLocation());
2213 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2214 *DTN->getIdentifier(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002215 ObjectType);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002216 }
Sean Huntc3021132010-05-05 15:23:54 +00002217
2218 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002219 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002220 }
Mike Stump1eb44332009-09-09 15:08:12 +00002221
Douglas Gregord1067e52009-08-06 06:41:21 +00002222 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002223 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002224 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002225 if (!TransTemplate)
2226 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002227
Douglas Gregord1067e52009-08-06 06:41:21 +00002228 if (!getDerived().AlwaysRebuild() &&
2229 TransTemplate == Template)
2230 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002231
Douglas Gregord1067e52009-08-06 06:41:21 +00002232 return TemplateName(TransTemplate);
2233 }
Mike Stump1eb44332009-09-09 15:08:12 +00002234
John McCallf7a1a742009-11-24 19:00:30 +00002235 // These should be getting filtered out before they reach the AST.
2236 assert(false && "overloaded function decl survived to here");
2237 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002238}
2239
2240template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002241void TreeTransform<Derived>::InventTemplateArgumentLoc(
2242 const TemplateArgument &Arg,
2243 TemplateArgumentLoc &Output) {
2244 SourceLocation Loc = getDerived().getBaseLocation();
2245 switch (Arg.getKind()) {
2246 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002247 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002248 break;
2249
2250 case TemplateArgument::Type:
2251 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002252 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002253
John McCall833ca992009-10-29 08:12:44 +00002254 break;
2255
Douglas Gregor788cd062009-11-11 01:00:40 +00002256 case TemplateArgument::Template:
2257 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2258 break;
Sean Huntc3021132010-05-05 15:23:54 +00002259
John McCall833ca992009-10-29 08:12:44 +00002260 case TemplateArgument::Expression:
2261 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2262 break;
2263
2264 case TemplateArgument::Declaration:
2265 case TemplateArgument::Integral:
2266 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002267 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002268 break;
2269 }
2270}
2271
2272template<typename Derived>
2273bool TreeTransform<Derived>::TransformTemplateArgument(
2274 const TemplateArgumentLoc &Input,
2275 TemplateArgumentLoc &Output) {
2276 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002277 switch (Arg.getKind()) {
2278 case TemplateArgument::Null:
2279 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002280 Output = Input;
2281 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002282
Douglas Gregor670444e2009-08-04 22:27:00 +00002283 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002284 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002285 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002286 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002287
2288 DI = getDerived().TransformType(DI);
2289 if (!DI) return true;
2290
2291 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2292 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002293 }
Mike Stump1eb44332009-09-09 15:08:12 +00002294
Douglas Gregor670444e2009-08-04 22:27:00 +00002295 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002296 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002297 DeclarationName Name;
2298 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2299 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002300 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002301 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002302 if (!D) return true;
2303
John McCall828bff22009-10-29 18:45:58 +00002304 Expr *SourceExpr = Input.getSourceDeclExpression();
2305 if (SourceExpr) {
2306 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002307 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002308 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002309 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002310 }
2311
2312 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002313 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002314 }
Mike Stump1eb44332009-09-09 15:08:12 +00002315
Douglas Gregor788cd062009-11-11 01:00:40 +00002316 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002317 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002318 TemplateName Template
2319 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2320 if (Template.isNull())
2321 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002322
Douglas Gregor788cd062009-11-11 01:00:40 +00002323 Output = TemplateArgumentLoc(TemplateArgument(Template),
2324 Input.getTemplateQualifierRange(),
2325 Input.getTemplateNameLoc());
2326 return false;
2327 }
Sean Huntc3021132010-05-05 15:23:54 +00002328
Douglas Gregor670444e2009-08-04 22:27:00 +00002329 case TemplateArgument::Expression: {
2330 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002331 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002332 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002333
John McCall833ca992009-10-29 08:12:44 +00002334 Expr *InputExpr = Input.getSourceExpression();
2335 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2336
John McCall60d7b3a2010-08-24 06:29:42 +00002337 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002338 = getDerived().TransformExpr(InputExpr);
2339 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002340 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002341 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002342 }
Mike Stump1eb44332009-09-09 15:08:12 +00002343
Douglas Gregor670444e2009-08-04 22:27:00 +00002344 case TemplateArgument::Pack: {
2345 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2346 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002347 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002348 AEnd = Arg.pack_end();
2349 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002350
John McCall833ca992009-10-29 08:12:44 +00002351 // FIXME: preserve source information here when we start
2352 // caring about parameter packs.
2353
John McCall828bff22009-10-29 18:45:58 +00002354 TemplateArgumentLoc InputArg;
2355 TemplateArgumentLoc OutputArg;
2356 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2357 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002358 return true;
2359
John McCall828bff22009-10-29 18:45:58 +00002360 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002361 }
2362 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002363 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002364 true);
John McCall828bff22009-10-29 18:45:58 +00002365 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002366 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002367 }
2368 }
Mike Stump1eb44332009-09-09 15:08:12 +00002369
Douglas Gregor670444e2009-08-04 22:27:00 +00002370 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002371 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002372}
2373
Douglas Gregor577f75a2009-08-04 16:50:30 +00002374//===----------------------------------------------------------------------===//
2375// Type transformation
2376//===----------------------------------------------------------------------===//
2377
2378template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00002379QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregor124b8782010-02-16 19:09:40 +00002380 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002381 if (getDerived().AlreadyTransformed(T))
2382 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002383
John McCalla2becad2009-10-21 00:40:46 +00002384 // Temporary workaround. All of these transformations should
2385 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002386 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002387 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002388
Douglas Gregor124b8782010-02-16 19:09:40 +00002389 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002390
John McCalla2becad2009-10-21 00:40:46 +00002391 if (!NewDI)
2392 return QualType();
2393
2394 return NewDI->getType();
2395}
2396
2397template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002398TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2399 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002400 if (getDerived().AlreadyTransformed(DI->getType()))
2401 return DI;
2402
2403 TypeLocBuilder TLB;
2404
2405 TypeLoc TL = DI->getTypeLoc();
2406 TLB.reserve(TL.getFullDataSize());
2407
Douglas Gregor124b8782010-02-16 19:09:40 +00002408 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002409 if (Result.isNull())
2410 return 0;
2411
John McCalla93c9342009-12-07 02:54:59 +00002412 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002413}
2414
2415template<typename Derived>
2416QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002417TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2418 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002419 switch (T.getTypeLocClass()) {
2420#define ABSTRACT_TYPELOC(CLASS, PARENT)
2421#define TYPELOC(CLASS, PARENT) \
2422 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002423 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2424 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002425#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002426 }
Mike Stump1eb44332009-09-09 15:08:12 +00002427
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002428 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002429 return QualType();
2430}
2431
2432/// FIXME: By default, this routine adds type qualifiers only to types
2433/// that can have qualifiers, and silently suppresses those qualifiers
2434/// that are not permitted (e.g., qualifiers on reference or function
2435/// types). This is the right thing for template instantiation, but
2436/// probably not for other clients.
2437template<typename Derived>
2438QualType
2439TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002440 QualifiedTypeLoc T,
2441 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002442 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002443
Douglas Gregor124b8782010-02-16 19:09:40 +00002444 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2445 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002446 if (Result.isNull())
2447 return QualType();
2448
2449 // Silently suppress qualifiers if the result type can't be qualified.
2450 // FIXME: this is the right thing for template instantiation, but
2451 // probably not for other clients.
2452 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002453 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002454
John McCall28654742010-06-05 06:41:15 +00002455 if (!Quals.empty()) {
2456 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2457 TLB.push<QualifiedTypeLoc>(Result);
2458 // No location information to preserve.
2459 }
John McCalla2becad2009-10-21 00:40:46 +00002460
2461 return Result;
2462}
2463
2464template <class TyLoc> static inline
2465QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2466 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2467 NewT.setNameLoc(T.getNameLoc());
2468 return T.getType();
2469}
2470
John McCalla2becad2009-10-21 00:40:46 +00002471template<typename Derived>
2472QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002473 BuiltinTypeLoc T,
2474 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002475 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2476 NewT.setBuiltinLoc(T.getBuiltinLoc());
2477 if (T.needsExtraLocalData())
2478 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2479 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002480}
Mike Stump1eb44332009-09-09 15:08:12 +00002481
Douglas Gregor577f75a2009-08-04 16:50:30 +00002482template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002483QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002484 ComplexTypeLoc T,
2485 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002486 // FIXME: recurse?
2487 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002488}
Mike Stump1eb44332009-09-09 15:08:12 +00002489
Douglas Gregor577f75a2009-08-04 16:50:30 +00002490template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002491QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Sean Huntc3021132010-05-05 15:23:54 +00002492 PointerTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00002493 QualType ObjectType) {
Sean Huntc3021132010-05-05 15:23:54 +00002494 QualType PointeeType
2495 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002496 if (PointeeType.isNull())
2497 return QualType();
2498
2499 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002500 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002501 // A dependent pointer type 'T *' has is being transformed such
2502 // that an Objective-C class type is being replaced for 'T'. The
2503 // resulting pointer type is an ObjCObjectPointerType, not a
2504 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002505 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002506
John McCallc12c5bb2010-05-15 11:32:37 +00002507 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2508 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002509 return Result;
2510 }
Sean Huntc3021132010-05-05 15:23:54 +00002511
Douglas Gregor92e986e2010-04-22 16:44:27 +00002512 if (getDerived().AlwaysRebuild() ||
2513 PointeeType != TL.getPointeeLoc().getType()) {
2514 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2515 if (Result.isNull())
2516 return QualType();
2517 }
Sean Huntc3021132010-05-05 15:23:54 +00002518
Douglas Gregor92e986e2010-04-22 16:44:27 +00002519 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2520 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002521 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002522}
Mike Stump1eb44332009-09-09 15:08:12 +00002523
2524template<typename Derived>
2525QualType
John McCalla2becad2009-10-21 00:40:46 +00002526TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002527 BlockPointerTypeLoc TL,
2528 QualType ObjectType) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002529 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002530 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2531 if (PointeeType.isNull())
2532 return QualType();
2533
2534 QualType Result = TL.getType();
2535 if (getDerived().AlwaysRebuild() ||
2536 PointeeType != TL.getPointeeLoc().getType()) {
2537 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002538 TL.getSigilLoc());
2539 if (Result.isNull())
2540 return QualType();
2541 }
2542
Douglas Gregor39968ad2010-04-22 16:50:51 +00002543 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002544 NewT.setSigilLoc(TL.getSigilLoc());
2545 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002546}
2547
John McCall85737a72009-10-30 00:06:24 +00002548/// Transforms a reference type. Note that somewhat paradoxically we
2549/// don't care whether the type itself is an l-value type or an r-value
2550/// type; we only care if the type was *written* as an l-value type
2551/// or an r-value type.
2552template<typename Derived>
2553QualType
2554TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002555 ReferenceTypeLoc TL,
2556 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002557 const ReferenceType *T = TL.getTypePtr();
2558
2559 // Note that this works with the pointee-as-written.
2560 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2561 if (PointeeType.isNull())
2562 return QualType();
2563
2564 QualType Result = TL.getType();
2565 if (getDerived().AlwaysRebuild() ||
2566 PointeeType != T->getPointeeTypeAsWritten()) {
2567 Result = getDerived().RebuildReferenceType(PointeeType,
2568 T->isSpelledAsLValue(),
2569 TL.getSigilLoc());
2570 if (Result.isNull())
2571 return QualType();
2572 }
2573
2574 // r-value references can be rebuilt as l-value references.
2575 ReferenceTypeLoc NewTL;
2576 if (isa<LValueReferenceType>(Result))
2577 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2578 else
2579 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2580 NewTL.setSigilLoc(TL.getSigilLoc());
2581
2582 return Result;
2583}
2584
Mike Stump1eb44332009-09-09 15:08:12 +00002585template<typename Derived>
2586QualType
John McCalla2becad2009-10-21 00:40:46 +00002587TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002588 LValueReferenceTypeLoc TL,
2589 QualType ObjectType) {
2590 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002591}
2592
Mike Stump1eb44332009-09-09 15:08:12 +00002593template<typename Derived>
2594QualType
John McCalla2becad2009-10-21 00:40:46 +00002595TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002596 RValueReferenceTypeLoc TL,
2597 QualType ObjectType) {
2598 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002599}
Mike Stump1eb44332009-09-09 15:08:12 +00002600
Douglas Gregor577f75a2009-08-04 16:50:30 +00002601template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002602QualType
John McCalla2becad2009-10-21 00:40:46 +00002603TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002604 MemberPointerTypeLoc TL,
2605 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002606 MemberPointerType *T = TL.getTypePtr();
2607
2608 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002609 if (PointeeType.isNull())
2610 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002611
John McCalla2becad2009-10-21 00:40:46 +00002612 // TODO: preserve source information for this.
2613 QualType ClassType
2614 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002615 if (ClassType.isNull())
2616 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002617
John McCalla2becad2009-10-21 00:40:46 +00002618 QualType Result = TL.getType();
2619 if (getDerived().AlwaysRebuild() ||
2620 PointeeType != T->getPointeeType() ||
2621 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002622 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2623 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002624 if (Result.isNull())
2625 return QualType();
2626 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002627
John McCalla2becad2009-10-21 00:40:46 +00002628 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2629 NewTL.setSigilLoc(TL.getSigilLoc());
2630
2631 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002632}
2633
Mike Stump1eb44332009-09-09 15:08:12 +00002634template<typename Derived>
2635QualType
John McCalla2becad2009-10-21 00:40:46 +00002636TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002637 ConstantArrayTypeLoc TL,
2638 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002639 ConstantArrayType *T = TL.getTypePtr();
2640 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002641 if (ElementType.isNull())
2642 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002643
John McCalla2becad2009-10-21 00:40:46 +00002644 QualType Result = TL.getType();
2645 if (getDerived().AlwaysRebuild() ||
2646 ElementType != T->getElementType()) {
2647 Result = getDerived().RebuildConstantArrayType(ElementType,
2648 T->getSizeModifier(),
2649 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002650 T->getIndexTypeCVRQualifiers(),
2651 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002652 if (Result.isNull())
2653 return QualType();
2654 }
Sean Huntc3021132010-05-05 15:23:54 +00002655
John McCalla2becad2009-10-21 00:40:46 +00002656 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2657 NewTL.setLBracketLoc(TL.getLBracketLoc());
2658 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002659
John McCalla2becad2009-10-21 00:40:46 +00002660 Expr *Size = TL.getSizeExpr();
2661 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00002662 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002663 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2664 }
2665 NewTL.setSizeExpr(Size);
2666
2667 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002668}
Mike Stump1eb44332009-09-09 15:08:12 +00002669
Douglas Gregor577f75a2009-08-04 16:50:30 +00002670template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002671QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002672 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002673 IncompleteArrayTypeLoc TL,
2674 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002675 IncompleteArrayType *T = TL.getTypePtr();
2676 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002677 if (ElementType.isNull())
2678 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002679
John McCalla2becad2009-10-21 00:40:46 +00002680 QualType Result = TL.getType();
2681 if (getDerived().AlwaysRebuild() ||
2682 ElementType != T->getElementType()) {
2683 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002684 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002685 T->getIndexTypeCVRQualifiers(),
2686 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002687 if (Result.isNull())
2688 return QualType();
2689 }
Sean Huntc3021132010-05-05 15:23:54 +00002690
John McCalla2becad2009-10-21 00:40:46 +00002691 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2692 NewTL.setLBracketLoc(TL.getLBracketLoc());
2693 NewTL.setRBracketLoc(TL.getRBracketLoc());
2694 NewTL.setSizeExpr(0);
2695
2696 return Result;
2697}
2698
2699template<typename Derived>
2700QualType
2701TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002702 VariableArrayTypeLoc TL,
2703 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002704 VariableArrayType *T = TL.getTypePtr();
2705 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2706 if (ElementType.isNull())
2707 return QualType();
2708
2709 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002710 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002711
John McCall60d7b3a2010-08-24 06:29:42 +00002712 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002713 = getDerived().TransformExpr(T->getSizeExpr());
2714 if (SizeResult.isInvalid())
2715 return QualType();
2716
John McCall9ae2f072010-08-23 23:25:46 +00002717 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00002718
2719 QualType Result = TL.getType();
2720 if (getDerived().AlwaysRebuild() ||
2721 ElementType != T->getElementType() ||
2722 Size != T->getSizeExpr()) {
2723 Result = getDerived().RebuildVariableArrayType(ElementType,
2724 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002725 Size,
John McCalla2becad2009-10-21 00:40:46 +00002726 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002727 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002728 if (Result.isNull())
2729 return QualType();
2730 }
Sean Huntc3021132010-05-05 15:23:54 +00002731
John McCalla2becad2009-10-21 00:40:46 +00002732 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2733 NewTL.setLBracketLoc(TL.getLBracketLoc());
2734 NewTL.setRBracketLoc(TL.getRBracketLoc());
2735 NewTL.setSizeExpr(Size);
2736
2737 return Result;
2738}
2739
2740template<typename Derived>
2741QualType
2742TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002743 DependentSizedArrayTypeLoc TL,
2744 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002745 DependentSizedArrayType *T = TL.getTypePtr();
2746 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2747 if (ElementType.isNull())
2748 return QualType();
2749
2750 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002751 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002752
John McCall60d7b3a2010-08-24 06:29:42 +00002753 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002754 = getDerived().TransformExpr(T->getSizeExpr());
2755 if (SizeResult.isInvalid())
2756 return QualType();
2757
2758 Expr *Size = static_cast<Expr*>(SizeResult.get());
2759
2760 QualType Result = TL.getType();
2761 if (getDerived().AlwaysRebuild() ||
2762 ElementType != T->getElementType() ||
2763 Size != T->getSizeExpr()) {
2764 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2765 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002766 Size,
John McCalla2becad2009-10-21 00:40:46 +00002767 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002768 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002769 if (Result.isNull())
2770 return QualType();
2771 }
2772 else SizeResult.take();
2773
2774 // We might have any sort of array type now, but fortunately they
2775 // all have the same location layout.
2776 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2777 NewTL.setLBracketLoc(TL.getLBracketLoc());
2778 NewTL.setRBracketLoc(TL.getRBracketLoc());
2779 NewTL.setSizeExpr(Size);
2780
2781 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002782}
Mike Stump1eb44332009-09-09 15:08:12 +00002783
2784template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002785QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002786 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002787 DependentSizedExtVectorTypeLoc TL,
2788 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002789 DependentSizedExtVectorType *T = TL.getTypePtr();
2790
2791 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002792 QualType ElementType = getDerived().TransformType(T->getElementType());
2793 if (ElementType.isNull())
2794 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002795
Douglas Gregor670444e2009-08-04 22:27:00 +00002796 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002797 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00002798
John McCall60d7b3a2010-08-24 06:29:42 +00002799 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002800 if (Size.isInvalid())
2801 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002802
John McCalla2becad2009-10-21 00:40:46 +00002803 QualType Result = TL.getType();
2804 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002805 ElementType != T->getElementType() ||
2806 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002807 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00002808 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00002809 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002810 if (Result.isNull())
2811 return QualType();
2812 }
John McCalla2becad2009-10-21 00:40:46 +00002813
2814 // Result might be dependent or not.
2815 if (isa<DependentSizedExtVectorType>(Result)) {
2816 DependentSizedExtVectorTypeLoc NewTL
2817 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2818 NewTL.setNameLoc(TL.getNameLoc());
2819 } else {
2820 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2821 NewTL.setNameLoc(TL.getNameLoc());
2822 }
2823
2824 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002825}
Mike Stump1eb44332009-09-09 15:08:12 +00002826
2827template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002828QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002829 VectorTypeLoc TL,
2830 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002831 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002832 QualType ElementType = getDerived().TransformType(T->getElementType());
2833 if (ElementType.isNull())
2834 return QualType();
2835
John McCalla2becad2009-10-21 00:40:46 +00002836 QualType Result = TL.getType();
2837 if (getDerived().AlwaysRebuild() ||
2838 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002839 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner788b0fd2010-06-23 06:00:24 +00002840 T->getAltiVecSpecific());
John McCalla2becad2009-10-21 00:40:46 +00002841 if (Result.isNull())
2842 return QualType();
2843 }
Sean Huntc3021132010-05-05 15:23:54 +00002844
John McCalla2becad2009-10-21 00:40:46 +00002845 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2846 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002847
John McCalla2becad2009-10-21 00:40:46 +00002848 return Result;
2849}
2850
2851template<typename Derived>
2852QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002853 ExtVectorTypeLoc TL,
2854 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002855 VectorType *T = TL.getTypePtr();
2856 QualType ElementType = getDerived().TransformType(T->getElementType());
2857 if (ElementType.isNull())
2858 return QualType();
2859
2860 QualType Result = TL.getType();
2861 if (getDerived().AlwaysRebuild() ||
2862 ElementType != T->getElementType()) {
2863 Result = getDerived().RebuildExtVectorType(ElementType,
2864 T->getNumElements(),
2865 /*FIXME*/ SourceLocation());
2866 if (Result.isNull())
2867 return QualType();
2868 }
Sean Huntc3021132010-05-05 15:23:54 +00002869
John McCalla2becad2009-10-21 00:40:46 +00002870 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2871 NewTL.setNameLoc(TL.getNameLoc());
2872
2873 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002874}
Mike Stump1eb44332009-09-09 15:08:12 +00002875
2876template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002877ParmVarDecl *
2878TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2879 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2880 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2881 if (!NewDI)
2882 return 0;
2883
2884 if (NewDI == OldDI)
2885 return OldParm;
2886 else
2887 return ParmVarDecl::Create(SemaRef.Context,
2888 OldParm->getDeclContext(),
2889 OldParm->getLocation(),
2890 OldParm->getIdentifier(),
2891 NewDI->getType(),
2892 NewDI,
2893 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002894 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002895 /* DefArg */ NULL);
2896}
2897
2898template<typename Derived>
2899bool TreeTransform<Derived>::
2900 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2901 llvm::SmallVectorImpl<QualType> &PTypes,
2902 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2903 FunctionProtoType *T = TL.getTypePtr();
2904
2905 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2906 ParmVarDecl *OldParm = TL.getArg(i);
2907
2908 QualType NewType;
2909 ParmVarDecl *NewParm;
2910
2911 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002912 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2913 if (!NewParm)
2914 return true;
2915 NewType = NewParm->getType();
2916
2917 // Deal with the possibility that we don't have a parameter
2918 // declaration for this parameter.
2919 } else {
2920 NewParm = 0;
2921
2922 QualType OldType = T->getArgType(i);
2923 NewType = getDerived().TransformType(OldType);
2924 if (NewType.isNull())
2925 return true;
2926 }
2927
2928 PTypes.push_back(NewType);
2929 PVars.push_back(NewParm);
2930 }
2931
2932 return false;
2933}
2934
2935template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002936QualType
John McCalla2becad2009-10-21 00:40:46 +00002937TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002938 FunctionProtoTypeLoc TL,
2939 QualType ObjectType) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00002940 // Transform the parameters and return type.
2941 //
2942 // We instantiate in source order, with the return type first followed by
2943 // the parameters, because users tend to expect this (even if they shouldn't
2944 // rely on it!).
2945 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00002946 // When the function has a trailing return type, we instantiate the
2947 // parameters before the return type, since the return type can then refer
2948 // to the parameters themselves (via decltype, sizeof, etc.).
2949 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00002950 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002951 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor895162d2010-04-30 18:55:50 +00002952 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00002953
Douglas Gregordab60ad2010-10-01 18:44:50 +00002954 QualType ResultType;
2955
2956 if (TL.getTrailingReturn()) {
2957 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2958 return QualType();
2959
2960 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2961 if (ResultType.isNull())
2962 return QualType();
2963 }
2964 else {
2965 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2966 if (ResultType.isNull())
2967 return QualType();
2968
2969 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2970 return QualType();
2971 }
2972
John McCalla2becad2009-10-21 00:40:46 +00002973 QualType Result = TL.getType();
2974 if (getDerived().AlwaysRebuild() ||
2975 ResultType != T->getResultType() ||
2976 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2977 Result = getDerived().RebuildFunctionProtoType(ResultType,
2978 ParamTypes.data(),
2979 ParamTypes.size(),
2980 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00002981 T->getTypeQuals(),
2982 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00002983 if (Result.isNull())
2984 return QualType();
2985 }
Mike Stump1eb44332009-09-09 15:08:12 +00002986
John McCalla2becad2009-10-21 00:40:46 +00002987 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2988 NewTL.setLParenLoc(TL.getLParenLoc());
2989 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00002990 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00002991 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2992 NewTL.setArg(i, ParamDecls[i]);
2993
2994 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002995}
Mike Stump1eb44332009-09-09 15:08:12 +00002996
Douglas Gregor577f75a2009-08-04 16:50:30 +00002997template<typename Derived>
2998QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002999 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003000 FunctionNoProtoTypeLoc TL,
3001 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003002 FunctionNoProtoType *T = TL.getTypePtr();
3003 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3004 if (ResultType.isNull())
3005 return QualType();
3006
3007 QualType Result = TL.getType();
3008 if (getDerived().AlwaysRebuild() ||
3009 ResultType != T->getResultType())
3010 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3011
3012 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3013 NewTL.setLParenLoc(TL.getLParenLoc());
3014 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003015 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003016
3017 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003018}
Mike Stump1eb44332009-09-09 15:08:12 +00003019
John McCalled976492009-12-04 22:46:56 +00003020template<typename Derived> QualType
3021TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003022 UnresolvedUsingTypeLoc TL,
3023 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00003024 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003025 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00003026 if (!D)
3027 return QualType();
3028
3029 QualType Result = TL.getType();
3030 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3031 Result = getDerived().RebuildUnresolvedUsingType(D);
3032 if (Result.isNull())
3033 return QualType();
3034 }
3035
3036 // We might get an arbitrary type spec type back. We should at
3037 // least always get a type spec type, though.
3038 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3039 NewTL.setNameLoc(TL.getNameLoc());
3040
3041 return Result;
3042}
3043
Douglas Gregor577f75a2009-08-04 16:50:30 +00003044template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003045QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003046 TypedefTypeLoc TL,
3047 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003048 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003049 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003050 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3051 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003052 if (!Typedef)
3053 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003054
John McCalla2becad2009-10-21 00:40:46 +00003055 QualType Result = TL.getType();
3056 if (getDerived().AlwaysRebuild() ||
3057 Typedef != T->getDecl()) {
3058 Result = getDerived().RebuildTypedefType(Typedef);
3059 if (Result.isNull())
3060 return QualType();
3061 }
Mike Stump1eb44332009-09-09 15:08:12 +00003062
John McCalla2becad2009-10-21 00:40:46 +00003063 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3064 NewTL.setNameLoc(TL.getNameLoc());
3065
3066 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003067}
Mike Stump1eb44332009-09-09 15:08:12 +00003068
Douglas Gregor577f75a2009-08-04 16:50:30 +00003069template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003070QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003071 TypeOfExprTypeLoc TL,
3072 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003073 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003074 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003075
John McCall60d7b3a2010-08-24 06:29:42 +00003076 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003077 if (E.isInvalid())
3078 return QualType();
3079
John McCalla2becad2009-10-21 00:40:46 +00003080 QualType Result = TL.getType();
3081 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003082 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003083 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00003084 if (Result.isNull())
3085 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003086 }
John McCalla2becad2009-10-21 00:40:46 +00003087 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003088
John McCalla2becad2009-10-21 00:40:46 +00003089 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003090 NewTL.setTypeofLoc(TL.getTypeofLoc());
3091 NewTL.setLParenLoc(TL.getLParenLoc());
3092 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003093
3094 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003095}
Mike Stump1eb44332009-09-09 15:08:12 +00003096
3097template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003098QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003099 TypeOfTypeLoc TL,
3100 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00003101 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3102 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3103 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003104 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003105
John McCalla2becad2009-10-21 00:40:46 +00003106 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003107 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3108 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003109 if (Result.isNull())
3110 return QualType();
3111 }
Mike Stump1eb44332009-09-09 15:08:12 +00003112
John McCalla2becad2009-10-21 00:40:46 +00003113 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003114 NewTL.setTypeofLoc(TL.getTypeofLoc());
3115 NewTL.setLParenLoc(TL.getLParenLoc());
3116 NewTL.setRParenLoc(TL.getRParenLoc());
3117 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003118
3119 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003120}
Mike Stump1eb44332009-09-09 15:08:12 +00003121
3122template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003123QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003124 DecltypeTypeLoc TL,
3125 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003126 DecltypeType *T = TL.getTypePtr();
3127
Douglas Gregor670444e2009-08-04 22:27:00 +00003128 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003129 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003130
John McCall60d7b3a2010-08-24 06:29:42 +00003131 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003132 if (E.isInvalid())
3133 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003134
John McCalla2becad2009-10-21 00:40:46 +00003135 QualType Result = TL.getType();
3136 if (getDerived().AlwaysRebuild() ||
3137 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003138 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003139 if (Result.isNull())
3140 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003141 }
John McCalla2becad2009-10-21 00:40:46 +00003142 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003143
John McCalla2becad2009-10-21 00:40:46 +00003144 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3145 NewTL.setNameLoc(TL.getNameLoc());
3146
3147 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003148}
3149
3150template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003151QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003152 RecordTypeLoc TL,
3153 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003154 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003155 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003156 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3157 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003158 if (!Record)
3159 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003160
John McCalla2becad2009-10-21 00:40:46 +00003161 QualType Result = TL.getType();
3162 if (getDerived().AlwaysRebuild() ||
3163 Record != T->getDecl()) {
3164 Result = getDerived().RebuildRecordType(Record);
3165 if (Result.isNull())
3166 return QualType();
3167 }
Mike Stump1eb44332009-09-09 15:08:12 +00003168
John McCalla2becad2009-10-21 00:40:46 +00003169 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3170 NewTL.setNameLoc(TL.getNameLoc());
3171
3172 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003173}
Mike Stump1eb44332009-09-09 15:08:12 +00003174
3175template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003176QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003177 EnumTypeLoc TL,
3178 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003179 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003180 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003181 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3182 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003183 if (!Enum)
3184 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003185
John McCalla2becad2009-10-21 00:40:46 +00003186 QualType Result = TL.getType();
3187 if (getDerived().AlwaysRebuild() ||
3188 Enum != T->getDecl()) {
3189 Result = getDerived().RebuildEnumType(Enum);
3190 if (Result.isNull())
3191 return QualType();
3192 }
Mike Stump1eb44332009-09-09 15:08:12 +00003193
John McCalla2becad2009-10-21 00:40:46 +00003194 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3195 NewTL.setNameLoc(TL.getNameLoc());
3196
3197 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003198}
John McCall7da24312009-09-05 00:15:47 +00003199
John McCall3cb0ebd2010-03-10 03:28:59 +00003200template<typename Derived>
3201QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3202 TypeLocBuilder &TLB,
3203 InjectedClassNameTypeLoc TL,
3204 QualType ObjectType) {
3205 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3206 TL.getTypePtr()->getDecl());
3207 if (!D) return QualType();
3208
3209 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3210 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3211 return T;
3212}
3213
Mike Stump1eb44332009-09-09 15:08:12 +00003214
Douglas Gregor577f75a2009-08-04 16:50:30 +00003215template<typename Derived>
3216QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003217 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003218 TemplateTypeParmTypeLoc TL,
3219 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003220 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003221}
3222
Mike Stump1eb44332009-09-09 15:08:12 +00003223template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003224QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003225 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003226 SubstTemplateTypeParmTypeLoc TL,
3227 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003228 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003229}
3230
3231template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003232QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3233 const TemplateSpecializationType *TST,
3234 QualType ObjectType) {
3235 // FIXME: this entire method is a temporary workaround; callers
3236 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00003237
John McCall833ca992009-10-29 08:12:44 +00003238 // Fake up a TemplateSpecializationTypeLoc.
3239 TypeLocBuilder TLB;
3240 TemplateSpecializationTypeLoc TL
3241 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3242
John McCall828bff22009-10-29 18:45:58 +00003243 SourceLocation BaseLoc = getDerived().getBaseLocation();
3244
3245 TL.setTemplateNameLoc(BaseLoc);
3246 TL.setLAngleLoc(BaseLoc);
3247 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00003248 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3249 const TemplateArgument &TA = TST->getArg(i);
3250 TemplateArgumentLoc TAL;
3251 getDerived().InventTemplateArgumentLoc(TA, TAL);
3252 TL.setArgLocInfo(i, TAL.getLocInfo());
3253 }
3254
3255 TypeLocBuilder IgnoredTLB;
3256 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00003257}
Sean Huntc3021132010-05-05 15:23:54 +00003258
Douglas Gregordd62b152009-10-19 22:04:39 +00003259template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003260QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003261 TypeLocBuilder &TLB,
3262 TemplateSpecializationTypeLoc TL,
3263 QualType ObjectType) {
3264 const TemplateSpecializationType *T = TL.getTypePtr();
3265
Mike Stump1eb44332009-09-09 15:08:12 +00003266 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00003267 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003268 if (Template.isNull())
3269 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003270
John McCalld5532b62009-11-23 01:53:49 +00003271 TemplateArgumentListInfo NewTemplateArgs;
3272 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3273 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3274
3275 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3276 TemplateArgumentLoc Loc;
3277 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003278 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003279 NewTemplateArgs.addArgument(Loc);
3280 }
Mike Stump1eb44332009-09-09 15:08:12 +00003281
John McCall833ca992009-10-29 08:12:44 +00003282 // FIXME: maybe don't rebuild if all the template arguments are the same.
3283
3284 QualType Result =
3285 getDerived().RebuildTemplateSpecializationType(Template,
3286 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003287 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003288
3289 if (!Result.isNull()) {
3290 TemplateSpecializationTypeLoc NewTL
3291 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3292 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3293 NewTL.setLAngleLoc(TL.getLAngleLoc());
3294 NewTL.setRAngleLoc(TL.getRAngleLoc());
3295 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3296 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003297 }
Mike Stump1eb44332009-09-09 15:08:12 +00003298
John McCall833ca992009-10-29 08:12:44 +00003299 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003300}
Mike Stump1eb44332009-09-09 15:08:12 +00003301
3302template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003303QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003304TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3305 ElaboratedTypeLoc TL,
3306 QualType ObjectType) {
3307 ElaboratedType *T = TL.getTypePtr();
3308
3309 NestedNameSpecifier *NNS = 0;
3310 // NOTE: the qualifier in an ElaboratedType is optional.
3311 if (T->getQualifier() != 0) {
3312 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003313 TL.getQualifierRange(),
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003314 ObjectType);
3315 if (!NNS)
3316 return QualType();
3317 }
Mike Stump1eb44332009-09-09 15:08:12 +00003318
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003319 QualType NamedT;
3320 // FIXME: this test is meant to workaround a problem (failing assertion)
3321 // occurring if directly executing the code in the else branch.
3322 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3323 TemplateSpecializationTypeLoc OldNamedTL
3324 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3325 const TemplateSpecializationType* OldTST
Jim Grosbach9cbb4d82010-05-19 23:53:08 +00003326 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003327 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3328 if (NamedT.isNull())
3329 return QualType();
3330 TemplateSpecializationTypeLoc NewNamedTL
3331 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3332 NewNamedTL.copy(OldNamedTL);
3333 }
3334 else {
3335 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3336 if (NamedT.isNull())
3337 return QualType();
3338 }
Daniel Dunbara63db842010-05-14 16:34:09 +00003339
John McCalla2becad2009-10-21 00:40:46 +00003340 QualType Result = TL.getType();
3341 if (getDerived().AlwaysRebuild() ||
3342 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003343 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00003344 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3345 T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003346 if (Result.isNull())
3347 return QualType();
3348 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003349
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003350 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003351 NewTL.setKeywordLoc(TL.getKeywordLoc());
3352 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003353
3354 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003355}
Mike Stump1eb44332009-09-09 15:08:12 +00003356
3357template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003358QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3359 DependentNameTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00003360 QualType ObjectType) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003361 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003362
Douglas Gregor577f75a2009-08-04 16:50:30 +00003363 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003364 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3365 TL.getQualifierRange(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003366 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003367 if (!NNS)
3368 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003369
John McCall33500952010-06-11 00:33:02 +00003370 QualType Result
3371 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3372 T->getIdentifier(),
3373 TL.getKeywordLoc(),
3374 TL.getQualifierRange(),
3375 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003376 if (Result.isNull())
3377 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003378
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003379 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3380 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003381 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3382
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003383 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3384 NewTL.setKeywordLoc(TL.getKeywordLoc());
3385 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003386 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003387 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3388 NewTL.setKeywordLoc(TL.getKeywordLoc());
3389 NewTL.setQualifierRange(TL.getQualifierRange());
3390 NewTL.setNameLoc(TL.getNameLoc());
3391 }
John McCalla2becad2009-10-21 00:40:46 +00003392 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003393}
Mike Stump1eb44332009-09-09 15:08:12 +00003394
Douglas Gregor577f75a2009-08-04 16:50:30 +00003395template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003396QualType TreeTransform<Derived>::
3397 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3398 DependentTemplateSpecializationTypeLoc TL,
3399 QualType ObjectType) {
3400 DependentTemplateSpecializationType *T = TL.getTypePtr();
3401
3402 NestedNameSpecifier *NNS
3403 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3404 TL.getQualifierRange(),
3405 ObjectType);
3406 if (!NNS)
3407 return QualType();
3408
3409 TemplateArgumentListInfo NewTemplateArgs;
3410 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3411 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3412
3413 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3414 TemplateArgumentLoc Loc;
3415 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3416 return QualType();
3417 NewTemplateArgs.addArgument(Loc);
3418 }
3419
Douglas Gregor1efb6c72010-09-08 23:56:00 +00003420 QualType Result
3421 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3422 NNS,
3423 TL.getQualifierRange(),
3424 T->getIdentifier(),
3425 TL.getNameLoc(),
3426 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00003427 if (Result.isNull())
3428 return QualType();
3429
3430 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3431 QualType NamedT = ElabT->getNamedType();
3432
3433 // Copy information relevant to the template specialization.
3434 TemplateSpecializationTypeLoc NamedTL
3435 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3436 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3437 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3438 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3439 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3440
3441 // Copy information relevant to the elaborated type.
3442 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3443 NewTL.setKeywordLoc(TL.getKeywordLoc());
3444 NewTL.setQualifierRange(TL.getQualifierRange());
3445 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003446 TypeLoc NewTL(Result, TL.getOpaqueData());
3447 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003448 }
3449 return Result;
3450}
3451
3452template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003453QualType
3454TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003455 ObjCInterfaceTypeLoc TL,
3456 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003457 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003458 TLB.pushFullCopy(TL);
3459 return TL.getType();
3460}
3461
3462template<typename Derived>
3463QualType
3464TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3465 ObjCObjectTypeLoc TL,
3466 QualType ObjectType) {
3467 // ObjCObjectType is never dependent.
3468 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003469 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003470}
Mike Stump1eb44332009-09-09 15:08:12 +00003471
3472template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003473QualType
3474TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003475 ObjCObjectPointerTypeLoc TL,
3476 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003477 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003478 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003479 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003480}
3481
Douglas Gregor577f75a2009-08-04 16:50:30 +00003482//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003483// Statement transformation
3484//===----------------------------------------------------------------------===//
3485template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003486StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003487TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00003488 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003489}
3490
3491template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003492StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003493TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3494 return getDerived().TransformCompoundStmt(S, false);
3495}
3496
3497template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003498StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003499TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003500 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00003501 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00003502 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003503 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00003504 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3505 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00003506 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00003507 if (Result.isInvalid()) {
3508 // Immediately fail if this was a DeclStmt, since it's very
3509 // likely that this will cause problems for future statements.
3510 if (isa<DeclStmt>(*B))
3511 return StmtError();
3512
3513 // Otherwise, just keep processing substatements and fail later.
3514 SubStmtInvalid = true;
3515 continue;
3516 }
Mike Stump1eb44332009-09-09 15:08:12 +00003517
Douglas Gregor43959a92009-08-20 07:17:43 +00003518 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3519 Statements.push_back(Result.takeAs<Stmt>());
3520 }
Mike Stump1eb44332009-09-09 15:08:12 +00003521
John McCall7114cba2010-08-27 19:56:05 +00003522 if (SubStmtInvalid)
3523 return StmtError();
3524
Douglas Gregor43959a92009-08-20 07:17:43 +00003525 if (!getDerived().AlwaysRebuild() &&
3526 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00003527 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003528
3529 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3530 move_arg(Statements),
3531 S->getRBracLoc(),
3532 IsStmtExpr);
3533}
Mike Stump1eb44332009-09-09 15:08:12 +00003534
Douglas Gregor43959a92009-08-20 07:17:43 +00003535template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003536StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003537TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003538 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00003539 {
3540 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00003541 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003542
Eli Friedman264c1f82009-11-19 03:14:00 +00003543 // Transform the left-hand case value.
3544 LHS = getDerived().TransformExpr(S->getLHS());
3545 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003546 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003547
Eli Friedman264c1f82009-11-19 03:14:00 +00003548 // Transform the right-hand case value (for the GNU case-range extension).
3549 RHS = getDerived().TransformExpr(S->getRHS());
3550 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003551 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00003552 }
Mike Stump1eb44332009-09-09 15:08:12 +00003553
Douglas Gregor43959a92009-08-20 07:17:43 +00003554 // Build the case statement.
3555 // Case statements are always rebuilt so that they will attached to their
3556 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003557 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003558 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003559 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003560 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003561 S->getColonLoc());
3562 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003563 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003564
Douglas Gregor43959a92009-08-20 07:17:43 +00003565 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00003566 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003567 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003568 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003569
Douglas Gregor43959a92009-08-20 07:17:43 +00003570 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00003571 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003572}
3573
3574template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003575StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003576TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003577 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00003578 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003579 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003580 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003581
Douglas Gregor43959a92009-08-20 07:17:43 +00003582 // Default statements are always rebuilt
3583 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003584 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003585}
Mike Stump1eb44332009-09-09 15:08:12 +00003586
Douglas Gregor43959a92009-08-20 07:17:43 +00003587template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003588StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003589TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003590 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003591 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003592 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003593
Douglas Gregor43959a92009-08-20 07:17:43 +00003594 // FIXME: Pass the real colon location in.
3595 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3596 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +00003597 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00003598}
Mike Stump1eb44332009-09-09 15:08:12 +00003599
Douglas Gregor43959a92009-08-20 07:17:43 +00003600template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003601StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003602TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003603 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003604 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003605 VarDecl *ConditionVar = 0;
3606 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003607 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003608 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003609 getDerived().TransformDefinition(
3610 S->getConditionVariable()->getLocation(),
3611 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003612 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003613 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003614 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003615 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003616
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003617 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003618 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003619
3620 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003621 if (S->getCond()) {
John McCall60d7b3a2010-08-24 06:29:42 +00003622 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003623 S->getIfLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003624 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003625 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003626 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003627
John McCall9ae2f072010-08-23 23:25:46 +00003628 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003629 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003630 }
Sean Huntc3021132010-05-05 15:23:54 +00003631
John McCall9ae2f072010-08-23 23:25:46 +00003632 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3633 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003634 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003635
Douglas Gregor43959a92009-08-20 07:17:43 +00003636 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003637 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00003638 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003639 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003640
Douglas Gregor43959a92009-08-20 07:17:43 +00003641 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003642 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00003643 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003644 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003645
Douglas Gregor43959a92009-08-20 07:17:43 +00003646 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003647 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003648 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003649 Then.get() == S->getThen() &&
3650 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00003651 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003652
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003653 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCall9ae2f072010-08-23 23:25:46 +00003654 Then.get(),
3655 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003656}
3657
3658template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003659StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003660TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003661 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00003662 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00003663 VarDecl *ConditionVar = 0;
3664 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003665 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003666 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003667 getDerived().TransformDefinition(
3668 S->getConditionVariable()->getLocation(),
3669 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003670 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003671 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003672 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003673 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003674
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003675 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003676 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003677 }
Mike Stump1eb44332009-09-09 15:08:12 +00003678
Douglas Gregor43959a92009-08-20 07:17:43 +00003679 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003680 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00003681 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00003682 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003683 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003684 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003685
Douglas Gregor43959a92009-08-20 07:17:43 +00003686 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003687 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003688 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003689 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003690
Douglas Gregor43959a92009-08-20 07:17:43 +00003691 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00003692 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3693 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003694}
Mike Stump1eb44332009-09-09 15:08:12 +00003695
Douglas Gregor43959a92009-08-20 07:17:43 +00003696template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003697StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003698TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003699 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003700 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00003701 VarDecl *ConditionVar = 0;
3702 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003703 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003704 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003705 getDerived().TransformDefinition(
3706 S->getConditionVariable()->getLocation(),
3707 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003708 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003709 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003710 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003711 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003712
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003713 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003714 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003715
3716 if (S->getCond()) {
3717 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003718 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003719 S->getWhileLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003720 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003721 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003722 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00003723 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003724 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003725 }
Mike Stump1eb44332009-09-09 15:08:12 +00003726
John McCall9ae2f072010-08-23 23:25:46 +00003727 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3728 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003729 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003730
Douglas Gregor43959a92009-08-20 07:17:43 +00003731 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003732 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003733 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003734 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003735
Douglas Gregor43959a92009-08-20 07:17:43 +00003736 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003737 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003738 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003739 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00003740 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003741
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003742 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00003743 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003744}
Mike Stump1eb44332009-09-09 15:08:12 +00003745
Douglas Gregor43959a92009-08-20 07:17:43 +00003746template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003747StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003748TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003749 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003750 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003751 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003752 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003753
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003754 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003755 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003756 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003757 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003758
Douglas Gregor43959a92009-08-20 07:17:43 +00003759 if (!getDerived().AlwaysRebuild() &&
3760 Cond.get() == S->getCond() &&
3761 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00003762 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003763
John McCall9ae2f072010-08-23 23:25:46 +00003764 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3765 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003766 S->getRParenLoc());
3767}
Mike Stump1eb44332009-09-09 15:08:12 +00003768
Douglas Gregor43959a92009-08-20 07:17:43 +00003769template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003770StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003771TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003772 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00003773 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00003774 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003775 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003776
Douglas Gregor43959a92009-08-20 07:17:43 +00003777 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003778 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003779 VarDecl *ConditionVar = 0;
3780 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003781 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003782 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003783 getDerived().TransformDefinition(
3784 S->getConditionVariable()->getLocation(),
3785 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003786 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003787 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003788 } else {
3789 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003790
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003791 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003792 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003793
3794 if (S->getCond()) {
3795 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003796 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003797 S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003798 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003799 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003800 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003801
John McCall9ae2f072010-08-23 23:25:46 +00003802 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003803 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003804 }
Mike Stump1eb44332009-09-09 15:08:12 +00003805
John McCall9ae2f072010-08-23 23:25:46 +00003806 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3807 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003808 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003809
Douglas Gregor43959a92009-08-20 07:17:43 +00003810 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00003811 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00003812 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003813 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003814
John McCall9ae2f072010-08-23 23:25:46 +00003815 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3816 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00003817 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003818
Douglas Gregor43959a92009-08-20 07:17:43 +00003819 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003820 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003821 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003822 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003823
Douglas Gregor43959a92009-08-20 07:17:43 +00003824 if (!getDerived().AlwaysRebuild() &&
3825 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00003826 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003827 Inc.get() == S->getInc() &&
3828 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00003829 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003830
Douglas Gregor43959a92009-08-20 07:17:43 +00003831 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003832 Init.get(), FullCond, ConditionVar,
3833 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003834}
3835
3836template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003837StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003838TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003839 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003840 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003841 S->getLabel());
3842}
3843
3844template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003845StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003846TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003847 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00003848 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003849 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003850
Douglas Gregor43959a92009-08-20 07:17:43 +00003851 if (!getDerived().AlwaysRebuild() &&
3852 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00003853 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003854
3855 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003856 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003857}
3858
3859template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003860StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003861TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00003862 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003863}
Mike Stump1eb44332009-09-09 15:08:12 +00003864
Douglas Gregor43959a92009-08-20 07:17:43 +00003865template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003866StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003867TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00003868 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003869}
Mike Stump1eb44332009-09-09 15:08:12 +00003870
Douglas Gregor43959a92009-08-20 07:17:43 +00003871template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003872StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003873TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003874 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00003875 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003876 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00003877
Mike Stump1eb44332009-09-09 15:08:12 +00003878 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003879 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00003880 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003881}
Mike Stump1eb44332009-09-09 15:08:12 +00003882
Douglas Gregor43959a92009-08-20 07:17:43 +00003883template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003884StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003885TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003886 bool DeclChanged = false;
3887 llvm::SmallVector<Decl *, 4> Decls;
3888 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3889 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003890 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3891 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003892 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00003893 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003894
Douglas Gregor43959a92009-08-20 07:17:43 +00003895 if (Transformed != *D)
3896 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003897
Douglas Gregor43959a92009-08-20 07:17:43 +00003898 Decls.push_back(Transformed);
3899 }
Mike Stump1eb44332009-09-09 15:08:12 +00003900
Douglas Gregor43959a92009-08-20 07:17:43 +00003901 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00003902 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003903
3904 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003905 S->getStartLoc(), S->getEndLoc());
3906}
Mike Stump1eb44332009-09-09 15:08:12 +00003907
Douglas Gregor43959a92009-08-20 07:17:43 +00003908template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003909StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003910TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003911 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCall3fa5cae2010-10-26 07:05:15 +00003912 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003913}
3914
3915template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003916StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003917TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003918
John McCallca0408f2010-08-23 06:44:23 +00003919 ASTOwningVector<Expr*> Constraints(getSema());
3920 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003921 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003922
John McCall60d7b3a2010-08-24 06:29:42 +00003923 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00003924 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00003925
3926 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003927
Anders Carlsson703e3942010-01-24 05:50:09 +00003928 // Go through the outputs.
3929 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003930 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003931
Anders Carlsson703e3942010-01-24 05:50:09 +00003932 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00003933 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00003934
Anders Carlsson703e3942010-01-24 05:50:09 +00003935 // Transform the output expr.
3936 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003937 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003938 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003939 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003940
Anders Carlsson703e3942010-01-24 05:50:09 +00003941 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003942
John McCall9ae2f072010-08-23 23:25:46 +00003943 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003944 }
Sean Huntc3021132010-05-05 15:23:54 +00003945
Anders Carlsson703e3942010-01-24 05:50:09 +00003946 // Go through the inputs.
3947 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003948 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003949
Anders Carlsson703e3942010-01-24 05:50:09 +00003950 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00003951 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00003952
Anders Carlsson703e3942010-01-24 05:50:09 +00003953 // Transform the input expr.
3954 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003955 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003956 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003957 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003958
Anders Carlsson703e3942010-01-24 05:50:09 +00003959 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003960
John McCall9ae2f072010-08-23 23:25:46 +00003961 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003962 }
Sean Huntc3021132010-05-05 15:23:54 +00003963
Anders Carlsson703e3942010-01-24 05:50:09 +00003964 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00003965 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00003966
3967 // Go through the clobbers.
3968 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00003969 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00003970
3971 // No need to transform the asm string literal.
3972 AsmString = SemaRef.Owned(S->getAsmString());
3973
3974 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3975 S->isSimple(),
3976 S->isVolatile(),
3977 S->getNumOutputs(),
3978 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003979 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003980 move_arg(Constraints),
3981 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00003982 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003983 move_arg(Clobbers),
3984 S->getRParenLoc(),
3985 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003986}
3987
3988
3989template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003990StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003991TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003992 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00003993 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003994 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003995 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003996
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003997 // Transform the @catch statements (if present).
3998 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003999 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004000 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004001 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004002 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004003 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004004 if (Catch.get() != S->getCatchStmt(I))
4005 AnyCatchChanged = true;
4006 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004007 }
Sean Huntc3021132010-05-05 15:23:54 +00004008
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004009 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00004010 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004011 if (S->getFinallyStmt()) {
4012 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4013 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004014 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004015 }
4016
4017 // If nothing changed, just retain this statement.
4018 if (!getDerived().AlwaysRebuild() &&
4019 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004020 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004021 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004022 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004023
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004024 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00004025 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4026 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004027}
Mike Stump1eb44332009-09-09 15:08:12 +00004028
Douglas Gregor43959a92009-08-20 07:17:43 +00004029template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004030StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004031TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004032 // Transform the @catch parameter, if there is one.
4033 VarDecl *Var = 0;
4034 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4035 TypeSourceInfo *TSInfo = 0;
4036 if (FromVar->getTypeSourceInfo()) {
4037 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4038 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004039 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004040 }
Sean Huntc3021132010-05-05 15:23:54 +00004041
Douglas Gregorbe270a02010-04-26 17:57:08 +00004042 QualType T;
4043 if (TSInfo)
4044 T = TSInfo->getType();
4045 else {
4046 T = getDerived().TransformType(FromVar->getType());
4047 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004048 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004049 }
Sean Huntc3021132010-05-05 15:23:54 +00004050
Douglas Gregorbe270a02010-04-26 17:57:08 +00004051 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4052 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004053 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004054 }
Sean Huntc3021132010-05-05 15:23:54 +00004055
John McCall60d7b3a2010-08-24 06:29:42 +00004056 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004057 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004058 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004059
4060 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004061 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004062 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004063}
Mike Stump1eb44332009-09-09 15:08:12 +00004064
Douglas Gregor43959a92009-08-20 07:17:43 +00004065template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004066StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004067TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004068 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004069 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004070 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004071 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004072
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004073 // If nothing changed, just retain this statement.
4074 if (!getDerived().AlwaysRebuild() &&
4075 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004076 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004077
4078 // Build a new statement.
4079 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004080 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004081}
Mike Stump1eb44332009-09-09 15:08:12 +00004082
Douglas Gregor43959a92009-08-20 07:17:43 +00004083template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004084StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004085TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004086 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004087 if (S->getThrowExpr()) {
4088 Operand = getDerived().TransformExpr(S->getThrowExpr());
4089 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004090 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004091 }
Sean Huntc3021132010-05-05 15:23:54 +00004092
Douglas Gregord1377b22010-04-22 21:44:01 +00004093 if (!getDerived().AlwaysRebuild() &&
4094 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004095 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004096
John McCall9ae2f072010-08-23 23:25:46 +00004097 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004098}
Mike Stump1eb44332009-09-09 15:08:12 +00004099
Douglas Gregor43959a92009-08-20 07:17:43 +00004100template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004101StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004102TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004103 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004104 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004105 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004106 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004107 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004108
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004109 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004110 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004111 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004112 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004113
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004114 // If nothing change, just retain the current statement.
4115 if (!getDerived().AlwaysRebuild() &&
4116 Object.get() == S->getSynchExpr() &&
4117 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004118 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004119
4120 // Build a new statement.
4121 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004122 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004123}
4124
4125template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004126StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004127TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004128 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004129 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004130 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004131 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004132 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004133
Douglas Gregorc3203e72010-04-22 23:10:45 +00004134 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00004135 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004136 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004137 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004138
Douglas Gregorc3203e72010-04-22 23:10:45 +00004139 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004140 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004141 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004142 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004143
Douglas Gregorc3203e72010-04-22 23:10:45 +00004144 // If nothing changed, just retain this statement.
4145 if (!getDerived().AlwaysRebuild() &&
4146 Element.get() == S->getElement() &&
4147 Collection.get() == S->getCollection() &&
4148 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004149 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004150
Douglas Gregorc3203e72010-04-22 23:10:45 +00004151 // Build a new statement.
4152 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4153 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004154 Element.get(),
4155 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00004156 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004157 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004158}
4159
4160
4161template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004162StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004163TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4164 // Transform the exception declaration, if any.
4165 VarDecl *Var = 0;
4166 if (S->getExceptionDecl()) {
4167 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00004168 TypeSourceInfo *T = getDerived().TransformType(
4169 ExceptionDecl->getTypeSourceInfo());
4170 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00004171 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004172
Douglas Gregor83cb9422010-09-09 17:09:21 +00004173 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00004174 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00004175 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00004176 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00004177 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004178 }
Mike Stump1eb44332009-09-09 15:08:12 +00004179
Douglas Gregor43959a92009-08-20 07:17:43 +00004180 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00004181 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004182 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004183 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004184
Douglas Gregor43959a92009-08-20 07:17:43 +00004185 if (!getDerived().AlwaysRebuild() &&
4186 !Var &&
4187 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00004188 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004189
4190 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4191 Var,
John McCall9ae2f072010-08-23 23:25:46 +00004192 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004193}
Mike Stump1eb44332009-09-09 15:08:12 +00004194
Douglas Gregor43959a92009-08-20 07:17:43 +00004195template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004196StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004197TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4198 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004199 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004200 = getDerived().TransformCompoundStmt(S->getTryBlock());
4201 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004202 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004203
Douglas Gregor43959a92009-08-20 07:17:43 +00004204 // Transform the handlers.
4205 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004206 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00004207 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004208 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004209 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4210 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004211 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004212
Douglas Gregor43959a92009-08-20 07:17:43 +00004213 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4214 Handlers.push_back(Handler.takeAs<Stmt>());
4215 }
Mike Stump1eb44332009-09-09 15:08:12 +00004216
Douglas Gregor43959a92009-08-20 07:17:43 +00004217 if (!getDerived().AlwaysRebuild() &&
4218 TryBlock.get() == S->getTryBlock() &&
4219 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004220 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004221
John McCall9ae2f072010-08-23 23:25:46 +00004222 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00004223 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004224}
Mike Stump1eb44332009-09-09 15:08:12 +00004225
Douglas Gregor43959a92009-08-20 07:17:43 +00004226//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004227// Expression transformation
4228//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004229template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004230ExprResult
John McCall454feb92009-12-08 09:21:05 +00004231TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004232 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004233}
Mike Stump1eb44332009-09-09 15:08:12 +00004234
4235template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004236ExprResult
John McCall454feb92009-12-08 09:21:05 +00004237TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004238 NestedNameSpecifier *Qualifier = 0;
4239 if (E->getQualifier()) {
4240 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004241 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004242 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00004243 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00004244 }
John McCalldbd872f2009-12-08 09:08:17 +00004245
4246 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004247 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4248 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004249 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00004250 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004251
John McCallec8045d2010-08-17 21:27:17 +00004252 DeclarationNameInfo NameInfo = E->getNameInfo();
4253 if (NameInfo.getName()) {
4254 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4255 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00004256 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00004257 }
Abramo Bagnara25777432010-08-11 22:01:17 +00004258
4259 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004260 Qualifier == E->getQualifier() &&
4261 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00004262 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00004263 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004264
4265 // Mark it referenced in the new context regardless.
4266 // FIXME: this is a bit instantiation-specific.
4267 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4268
John McCall3fa5cae2010-10-26 07:05:15 +00004269 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00004270 }
John McCalldbd872f2009-12-08 09:08:17 +00004271
4272 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00004273 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004274 TemplateArgs = &TransArgs;
4275 TransArgs.setLAngleLoc(E->getLAngleLoc());
4276 TransArgs.setRAngleLoc(E->getRAngleLoc());
4277 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4278 TemplateArgumentLoc Loc;
4279 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004280 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00004281 TransArgs.addArgument(Loc);
4282 }
4283 }
4284
Douglas Gregora2813ce2009-10-23 18:54:35 +00004285 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004286 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004287}
Mike Stump1eb44332009-09-09 15:08:12 +00004288
Douglas Gregorb98b1992009-08-11 05:31:07 +00004289template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004290ExprResult
John McCall454feb92009-12-08 09:21:05 +00004291TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004292 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004293}
Mike Stump1eb44332009-09-09 15:08:12 +00004294
Douglas Gregorb98b1992009-08-11 05:31:07 +00004295template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004296ExprResult
John McCall454feb92009-12-08 09:21:05 +00004297TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004298 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004299}
Mike Stump1eb44332009-09-09 15:08:12 +00004300
Douglas Gregorb98b1992009-08-11 05:31:07 +00004301template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004302ExprResult
John McCall454feb92009-12-08 09:21:05 +00004303TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004304 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004305}
Mike Stump1eb44332009-09-09 15:08:12 +00004306
Douglas Gregorb98b1992009-08-11 05:31:07 +00004307template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004308ExprResult
John McCall454feb92009-12-08 09:21:05 +00004309TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004310 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004311}
Mike Stump1eb44332009-09-09 15:08:12 +00004312
Douglas Gregorb98b1992009-08-11 05:31:07 +00004313template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004314ExprResult
John McCall454feb92009-12-08 09:21:05 +00004315TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004316 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004317}
4318
4319template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004320ExprResult
John McCall454feb92009-12-08 09:21:05 +00004321TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004322 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004323 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004324 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004325
Douglas Gregorb98b1992009-08-11 05:31:07 +00004326 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004327 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004328
John McCall9ae2f072010-08-23 23:25:46 +00004329 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004330 E->getRParen());
4331}
4332
Mike Stump1eb44332009-09-09 15:08:12 +00004333template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004334ExprResult
John McCall454feb92009-12-08 09:21:05 +00004335TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004336 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004337 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004338 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004339
Douglas Gregorb98b1992009-08-11 05:31:07 +00004340 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004341 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004342
Douglas Gregorb98b1992009-08-11 05:31:07 +00004343 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4344 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004345 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004346}
Mike Stump1eb44332009-09-09 15:08:12 +00004347
Douglas Gregorb98b1992009-08-11 05:31:07 +00004348template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004349ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004350TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4351 // Transform the type.
4352 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4353 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00004354 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004355
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004356 // Transform all of the components into components similar to what the
4357 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004358 // FIXME: It would be slightly more efficient in the non-dependent case to
4359 // just map FieldDecls, rather than requiring the rebuilder to look for
4360 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004361 // template code that we don't care.
4362 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00004363 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004364 typedef OffsetOfExpr::OffsetOfNode Node;
4365 llvm::SmallVector<Component, 4> Components;
4366 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4367 const Node &ON = E->getComponent(I);
4368 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004369 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004370 Comp.LocStart = ON.getRange().getBegin();
4371 Comp.LocEnd = ON.getRange().getEnd();
4372 switch (ON.getKind()) {
4373 case Node::Array: {
4374 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00004375 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004376 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004377 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004378
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004379 ExprChanged = ExprChanged || Index.get() != FromIndex;
4380 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00004381 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004382 break;
4383 }
Sean Huntc3021132010-05-05 15:23:54 +00004384
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004385 case Node::Field:
4386 case Node::Identifier:
4387 Comp.isBrackets = false;
4388 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004389 if (!Comp.U.IdentInfo)
4390 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004391
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004392 break;
Sean Huntc3021132010-05-05 15:23:54 +00004393
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004394 case Node::Base:
4395 // Will be recomputed during the rebuild.
4396 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004397 }
Sean Huntc3021132010-05-05 15:23:54 +00004398
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004399 Components.push_back(Comp);
4400 }
Sean Huntc3021132010-05-05 15:23:54 +00004401
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004402 // If nothing changed, retain the existing expression.
4403 if (!getDerived().AlwaysRebuild() &&
4404 Type == E->getTypeSourceInfo() &&
4405 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004406 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00004407
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004408 // Build a new offsetof expression.
4409 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4410 Components.data(), Components.size(),
4411 E->getRParenLoc());
4412}
4413
4414template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004415ExprResult
John McCall454feb92009-12-08 09:21:05 +00004416TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004417 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004418 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004419
John McCalla93c9342009-12-07 02:54:59 +00004420 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004421 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004422 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004423
John McCall5ab75172009-11-04 07:28:41 +00004424 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00004425 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004426
John McCall5ab75172009-11-04 07:28:41 +00004427 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004428 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004429 E->getSourceRange());
4430 }
Mike Stump1eb44332009-09-09 15:08:12 +00004431
John McCall60d7b3a2010-08-24 06:29:42 +00004432 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00004433 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004434 // C++0x [expr.sizeof]p1:
4435 // The operand is either an expression, which is an unevaluated operand
4436 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00004437 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004438
Douglas Gregorb98b1992009-08-11 05:31:07 +00004439 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4440 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004441 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004442
Douglas Gregorb98b1992009-08-11 05:31:07 +00004443 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004444 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004445 }
Mike Stump1eb44332009-09-09 15:08:12 +00004446
John McCall9ae2f072010-08-23 23:25:46 +00004447 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004448 E->isSizeOf(),
4449 E->getSourceRange());
4450}
Mike Stump1eb44332009-09-09 15:08:12 +00004451
Douglas Gregorb98b1992009-08-11 05:31:07 +00004452template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004453ExprResult
John McCall454feb92009-12-08 09:21:05 +00004454TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004455 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004456 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004457 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004458
John McCall60d7b3a2010-08-24 06:29:42 +00004459 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004460 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004461 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004462
4463
Douglas Gregorb98b1992009-08-11 05:31:07 +00004464 if (!getDerived().AlwaysRebuild() &&
4465 LHS.get() == E->getLHS() &&
4466 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004467 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004468
John McCall9ae2f072010-08-23 23:25:46 +00004469 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004470 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00004471 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004472 E->getRBracketLoc());
4473}
Mike Stump1eb44332009-09-09 15:08:12 +00004474
4475template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004476ExprResult
John McCall454feb92009-12-08 09:21:05 +00004477TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004478 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00004479 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004480 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004481 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004482
4483 // Transform arguments.
4484 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004485 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004486 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004487 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004488 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004489 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004490
Mike Stump1eb44332009-09-09 15:08:12 +00004491 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00004492 Args.push_back(Arg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004493 }
Mike Stump1eb44332009-09-09 15:08:12 +00004494
Douglas Gregorb98b1992009-08-11 05:31:07 +00004495 if (!getDerived().AlwaysRebuild() &&
4496 Callee.get() == E->getCallee() &&
4497 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004498 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004499
Douglas Gregorb98b1992009-08-11 05:31:07 +00004500 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004501 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004502 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00004503 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004504 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004505 E->getRParenLoc());
4506}
Mike Stump1eb44332009-09-09 15:08:12 +00004507
4508template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004509ExprResult
John McCall454feb92009-12-08 09:21:05 +00004510TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004511 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004512 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004513 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004514
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004515 NestedNameSpecifier *Qualifier = 0;
4516 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004517 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004518 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004519 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004520 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00004521 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004522 }
Mike Stump1eb44332009-09-09 15:08:12 +00004523
Eli Friedmanf595cc42009-12-04 06:40:45 +00004524 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004525 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4526 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004527 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00004528 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004529
John McCall6bb80172010-03-30 21:47:33 +00004530 NamedDecl *FoundDecl = E->getFoundDecl();
4531 if (FoundDecl == E->getMemberDecl()) {
4532 FoundDecl = Member;
4533 } else {
4534 FoundDecl = cast_or_null<NamedDecl>(
4535 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4536 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00004537 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00004538 }
4539
Douglas Gregorb98b1992009-08-11 05:31:07 +00004540 if (!getDerived().AlwaysRebuild() &&
4541 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004542 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004543 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004544 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00004545 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00004546
Anders Carlsson1f240322009-12-22 05:24:09 +00004547 // Mark it referenced in the new context regardless.
4548 // FIXME: this is a bit instantiation-specific.
4549 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00004550 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00004551 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004552
John McCalld5532b62009-11-23 01:53:49 +00004553 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00004554 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00004555 TransArgs.setLAngleLoc(E->getLAngleLoc());
4556 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004557 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004558 TemplateArgumentLoc Loc;
4559 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004560 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004561 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004562 }
4563 }
Sean Huntc3021132010-05-05 15:23:54 +00004564
Douglas Gregorb98b1992009-08-11 05:31:07 +00004565 // FIXME: Bogus source location for the operator
4566 SourceLocation FakeOperatorLoc
4567 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4568
John McCallc2233c52010-01-15 08:34:02 +00004569 // FIXME: to do this check properly, we will need to preserve the
4570 // first-qualifier-in-scope here, just in case we had a dependent
4571 // base (and therefore couldn't do the check) and a
4572 // nested-name-qualifier (and therefore could do the lookup).
4573 NamedDecl *FirstQualifierInScope = 0;
4574
John McCall9ae2f072010-08-23 23:25:46 +00004575 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004576 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004577 Qualifier,
4578 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004579 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004580 Member,
John McCall6bb80172010-03-30 21:47:33 +00004581 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00004582 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00004583 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004584 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004585}
Mike Stump1eb44332009-09-09 15:08:12 +00004586
Douglas Gregorb98b1992009-08-11 05:31:07 +00004587template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004588ExprResult
John McCall454feb92009-12-08 09:21:05 +00004589TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004590 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004591 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004592 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004593
John McCall60d7b3a2010-08-24 06:29:42 +00004594 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004595 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004596 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004597
Douglas Gregorb98b1992009-08-11 05:31:07 +00004598 if (!getDerived().AlwaysRebuild() &&
4599 LHS.get() == E->getLHS() &&
4600 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004601 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004602
Douglas Gregorb98b1992009-08-11 05:31:07 +00004603 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004604 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004605}
4606
Mike Stump1eb44332009-09-09 15:08:12 +00004607template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004608ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004609TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004610 CompoundAssignOperator *E) {
4611 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004612}
Mike Stump1eb44332009-09-09 15:08:12 +00004613
Douglas Gregorb98b1992009-08-11 05:31:07 +00004614template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004615ExprResult
John McCall454feb92009-12-08 09:21:05 +00004616TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004617 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004618 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004619 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004620
John McCall60d7b3a2010-08-24 06:29:42 +00004621 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004622 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004623 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004624
John McCall60d7b3a2010-08-24 06:29:42 +00004625 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004626 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004627 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004628
Douglas Gregorb98b1992009-08-11 05:31:07 +00004629 if (!getDerived().AlwaysRebuild() &&
4630 Cond.get() == E->getCond() &&
4631 LHS.get() == E->getLHS() &&
4632 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004633 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004634
John McCall9ae2f072010-08-23 23:25:46 +00004635 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004636 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004637 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004638 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004639 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004640}
Mike Stump1eb44332009-09-09 15:08:12 +00004641
4642template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004643ExprResult
John McCall454feb92009-12-08 09:21:05 +00004644TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004645 // Implicit casts are eliminated during transformation, since they
4646 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004647 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004648}
Mike Stump1eb44332009-09-09 15:08:12 +00004649
Douglas Gregorb98b1992009-08-11 05:31:07 +00004650template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004651ExprResult
John McCall454feb92009-12-08 09:21:05 +00004652TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004653 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4654 if (!Type)
4655 return ExprError();
4656
John McCall60d7b3a2010-08-24 06:29:42 +00004657 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004658 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004659 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004660 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004661
Douglas Gregorb98b1992009-08-11 05:31:07 +00004662 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004663 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004664 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004665 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004666
John McCall9d125032010-01-15 18:39:57 +00004667 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004668 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004669 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004670 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004671}
Mike Stump1eb44332009-09-09 15:08:12 +00004672
Douglas Gregorb98b1992009-08-11 05:31:07 +00004673template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004674ExprResult
John McCall454feb92009-12-08 09:21:05 +00004675TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004676 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4677 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4678 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004679 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004680
John McCall60d7b3a2010-08-24 06:29:42 +00004681 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004682 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004683 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004684
Douglas Gregorb98b1992009-08-11 05:31:07 +00004685 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004686 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004687 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00004688 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004689
John McCall1d7d8d62010-01-19 22:33:45 +00004690 // Note: the expression type doesn't necessarily match the
4691 // type-as-written, but that's okay, because it should always be
4692 // derivable from the initializer.
4693
John McCall42f56b52010-01-18 19:35:47 +00004694 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004695 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00004696 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004697}
Mike Stump1eb44332009-09-09 15:08:12 +00004698
Douglas Gregorb98b1992009-08-11 05:31:07 +00004699template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004700ExprResult
John McCall454feb92009-12-08 09:21:05 +00004701TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004702 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004703 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004704 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004705
Douglas Gregorb98b1992009-08-11 05:31:07 +00004706 if (!getDerived().AlwaysRebuild() &&
4707 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00004708 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004709
Douglas Gregorb98b1992009-08-11 05:31:07 +00004710 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004711 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004712 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00004713 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004714 E->getAccessorLoc(),
4715 E->getAccessor());
4716}
Mike Stump1eb44332009-09-09 15:08:12 +00004717
Douglas Gregorb98b1992009-08-11 05:31:07 +00004718template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004719ExprResult
John McCall454feb92009-12-08 09:21:05 +00004720TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004721 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004722
John McCallca0408f2010-08-23 06:44:23 +00004723 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004724 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004725 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004726 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004727 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004728
Douglas Gregorb98b1992009-08-11 05:31:07 +00004729 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCall9ae2f072010-08-23 23:25:46 +00004730 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004731 }
Mike Stump1eb44332009-09-09 15:08:12 +00004732
Douglas Gregorb98b1992009-08-11 05:31:07 +00004733 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004734 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004735
Douglas Gregorb98b1992009-08-11 05:31:07 +00004736 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004737 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004738}
Mike Stump1eb44332009-09-09 15:08:12 +00004739
Douglas Gregorb98b1992009-08-11 05:31:07 +00004740template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004741ExprResult
John McCall454feb92009-12-08 09:21:05 +00004742TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004743 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004744
Douglas Gregor43959a92009-08-20 07:17:43 +00004745 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00004746 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004747 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004748 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004749
Douglas Gregor43959a92009-08-20 07:17:43 +00004750 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00004751 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004752 bool ExprChanged = false;
4753 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4754 DEnd = E->designators_end();
4755 D != DEnd; ++D) {
4756 if (D->isFieldDesignator()) {
4757 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4758 D->getDotLoc(),
4759 D->getFieldLoc()));
4760 continue;
4761 }
Mike Stump1eb44332009-09-09 15:08:12 +00004762
Douglas Gregorb98b1992009-08-11 05:31:07 +00004763 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00004764 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004765 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004766 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004767
4768 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004769 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004770
Douglas Gregorb98b1992009-08-11 05:31:07 +00004771 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4772 ArrayExprs.push_back(Index.release());
4773 continue;
4774 }
Mike Stump1eb44332009-09-09 15:08:12 +00004775
Douglas Gregorb98b1992009-08-11 05:31:07 +00004776 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00004777 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004778 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4779 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004780 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004781
John McCall60d7b3a2010-08-24 06:29:42 +00004782 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004783 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004784 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004785
4786 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004787 End.get(),
4788 D->getLBracketLoc(),
4789 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004790
Douglas Gregorb98b1992009-08-11 05:31:07 +00004791 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4792 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004793
Douglas Gregorb98b1992009-08-11 05:31:07 +00004794 ArrayExprs.push_back(Start.release());
4795 ArrayExprs.push_back(End.release());
4796 }
Mike Stump1eb44332009-09-09 15:08:12 +00004797
Douglas Gregorb98b1992009-08-11 05:31:07 +00004798 if (!getDerived().AlwaysRebuild() &&
4799 Init.get() == E->getInit() &&
4800 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004801 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004802
Douglas Gregorb98b1992009-08-11 05:31:07 +00004803 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4804 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004805 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004806}
Mike Stump1eb44332009-09-09 15:08:12 +00004807
Douglas Gregorb98b1992009-08-11 05:31:07 +00004808template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004809ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004810TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004811 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004812 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004813
Douglas Gregor5557b252009-10-28 00:29:27 +00004814 // FIXME: Will we ever have proper type location here? Will we actually
4815 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004816 QualType T = getDerived().TransformType(E->getType());
4817 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004818 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004819
Douglas Gregorb98b1992009-08-11 05:31:07 +00004820 if (!getDerived().AlwaysRebuild() &&
4821 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00004822 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004823
Douglas Gregorb98b1992009-08-11 05:31:07 +00004824 return getDerived().RebuildImplicitValueInitExpr(T);
4825}
Mike Stump1eb44332009-09-09 15:08:12 +00004826
Douglas Gregorb98b1992009-08-11 05:31:07 +00004827template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004828ExprResult
John McCall454feb92009-12-08 09:21:05 +00004829TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004830 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4831 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004832 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004833
John McCall60d7b3a2010-08-24 06:29:42 +00004834 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004835 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004836 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004837
Douglas Gregorb98b1992009-08-11 05:31:07 +00004838 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004839 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004840 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004841 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004842
John McCall9ae2f072010-08-23 23:25:46 +00004843 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004844 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004845}
4846
4847template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004848ExprResult
John McCall454feb92009-12-08 09:21:05 +00004849TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004850 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004851 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004852 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004853 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004854 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004855 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004856
Douglas Gregorb98b1992009-08-11 05:31:07 +00004857 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00004858 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004859 }
Mike Stump1eb44332009-09-09 15:08:12 +00004860
Douglas Gregorb98b1992009-08-11 05:31:07 +00004861 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4862 move_arg(Inits),
4863 E->getRParenLoc());
4864}
Mike Stump1eb44332009-09-09 15:08:12 +00004865
Douglas Gregorb98b1992009-08-11 05:31:07 +00004866/// \brief Transform an address-of-label expression.
4867///
4868/// By default, the transformation of an address-of-label expression always
4869/// rebuilds the expression, so that the label identifier can be resolved to
4870/// the corresponding label statement by semantic analysis.
4871template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004872ExprResult
John McCall454feb92009-12-08 09:21:05 +00004873TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004874 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4875 E->getLabel());
4876}
Mike Stump1eb44332009-09-09 15:08:12 +00004877
4878template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004879ExprResult
John McCall454feb92009-12-08 09:21:05 +00004880TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004881 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004882 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4883 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004884 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004885
Douglas Gregorb98b1992009-08-11 05:31:07 +00004886 if (!getDerived().AlwaysRebuild() &&
4887 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004888 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004889
4890 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004891 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004892 E->getRParenLoc());
4893}
Mike Stump1eb44332009-09-09 15:08:12 +00004894
Douglas Gregorb98b1992009-08-11 05:31:07 +00004895template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004896ExprResult
John McCall454feb92009-12-08 09:21:05 +00004897TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004898 TypeSourceInfo *TInfo1;
4899 TypeSourceInfo *TInfo2;
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004900
4901 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4902 if (!TInfo1)
John McCallf312b1e2010-08-26 23:41:50 +00004903 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004904
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004905 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4906 if (!TInfo2)
John McCallf312b1e2010-08-26 23:41:50 +00004907 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004908
4909 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004910 TInfo1 == E->getArgTInfo1() &&
4911 TInfo2 == E->getArgTInfo2())
John McCall3fa5cae2010-10-26 07:05:15 +00004912 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004913
Douglas Gregorb98b1992009-08-11 05:31:07 +00004914 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004915 TInfo1, TInfo2,
4916 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004917}
Mike Stump1eb44332009-09-09 15:08:12 +00004918
Douglas Gregorb98b1992009-08-11 05:31:07 +00004919template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004920ExprResult
John McCall454feb92009-12-08 09:21:05 +00004921TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004922 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004923 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004924 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004925
John McCall60d7b3a2010-08-24 06:29:42 +00004926 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004927 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004928 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004929
John McCall60d7b3a2010-08-24 06:29:42 +00004930 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004931 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004932 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004933
Douglas Gregorb98b1992009-08-11 05:31:07 +00004934 if (!getDerived().AlwaysRebuild() &&
4935 Cond.get() == E->getCond() &&
4936 LHS.get() == E->getLHS() &&
4937 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004938 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004939
Douglas Gregorb98b1992009-08-11 05:31:07 +00004940 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004941 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004942 E->getRParenLoc());
4943}
Mike Stump1eb44332009-09-09 15:08:12 +00004944
Douglas Gregorb98b1992009-08-11 05:31:07 +00004945template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004946ExprResult
John McCall454feb92009-12-08 09:21:05 +00004947TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004948 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004949}
4950
4951template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004952ExprResult
John McCall454feb92009-12-08 09:21:05 +00004953TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004954 switch (E->getOperator()) {
4955 case OO_New:
4956 case OO_Delete:
4957 case OO_Array_New:
4958 case OO_Array_Delete:
4959 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00004960 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004961
Douglas Gregor668d6d92009-12-13 20:44:55 +00004962 case OO_Call: {
4963 // This is a call to an object's operator().
4964 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4965
4966 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004967 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00004968 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004969 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004970
4971 // FIXME: Poor location information
4972 SourceLocation FakeLParenLoc
4973 = SemaRef.PP.getLocForEndOfToken(
4974 static_cast<Expr *>(Object.get())->getLocEnd());
4975
4976 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00004977 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor668d6d92009-12-13 20:44:55 +00004978 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004979 if (getDerived().DropCallArgument(E->getArg(I)))
4980 break;
Sean Huntc3021132010-05-05 15:23:54 +00004981
John McCall60d7b3a2010-08-24 06:29:42 +00004982 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor668d6d92009-12-13 20:44:55 +00004983 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004984 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004985
Douglas Gregor668d6d92009-12-13 20:44:55 +00004986 Args.push_back(Arg.release());
4987 }
4988
John McCall9ae2f072010-08-23 23:25:46 +00004989 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00004990 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00004991 E->getLocEnd());
4992 }
4993
4994#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4995 case OO_##Name:
4996#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4997#include "clang/Basic/OperatorKinds.def"
4998 case OO_Subscript:
4999 // Handled below.
5000 break;
5001
5002 case OO_Conditional:
5003 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00005004 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005005
5006 case OO_None:
5007 case NUM_OVERLOADED_OPERATORS:
5008 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00005009 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005010 }
5011
John McCall60d7b3a2010-08-24 06:29:42 +00005012 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005013 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005014 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005015
John McCall60d7b3a2010-08-24 06:29:42 +00005016 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005017 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005018 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005019
John McCall60d7b3a2010-08-24 06:29:42 +00005020 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005021 if (E->getNumArgs() == 2) {
5022 Second = getDerived().TransformExpr(E->getArg(1));
5023 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005024 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005025 }
Mike Stump1eb44332009-09-09 15:08:12 +00005026
Douglas Gregorb98b1992009-08-11 05:31:07 +00005027 if (!getDerived().AlwaysRebuild() &&
5028 Callee.get() == E->getCallee() &&
5029 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005030 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00005031 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005032
Douglas Gregorb98b1992009-08-11 05:31:07 +00005033 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5034 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005035 Callee.get(),
5036 First.get(),
5037 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005038}
Mike Stump1eb44332009-09-09 15:08:12 +00005039
Douglas Gregorb98b1992009-08-11 05:31:07 +00005040template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005041ExprResult
John McCall454feb92009-12-08 09:21:05 +00005042TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5043 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005044}
Mike Stump1eb44332009-09-09 15:08:12 +00005045
Douglas Gregorb98b1992009-08-11 05:31:07 +00005046template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005047ExprResult
John McCall454feb92009-12-08 09:21:05 +00005048TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005049 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5050 if (!Type)
5051 return ExprError();
5052
John McCall60d7b3a2010-08-24 06:29:42 +00005053 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005054 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005055 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005056 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005057
Douglas Gregorb98b1992009-08-11 05:31:07 +00005058 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005059 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005060 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005061 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005062
Douglas Gregorb98b1992009-08-11 05:31:07 +00005063 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005064 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005065 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5066 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5067 SourceLocation FakeRParenLoc
5068 = SemaRef.PP.getLocForEndOfToken(
5069 E->getSubExpr()->getSourceRange().getEnd());
5070 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005071 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005072 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005073 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005074 FakeRAngleLoc,
5075 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005076 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005077 FakeRParenLoc);
5078}
Mike Stump1eb44332009-09-09 15:08:12 +00005079
Douglas Gregorb98b1992009-08-11 05:31:07 +00005080template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005081ExprResult
John McCall454feb92009-12-08 09:21:05 +00005082TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5083 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005084}
Mike Stump1eb44332009-09-09 15:08:12 +00005085
5086template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005087ExprResult
John McCall454feb92009-12-08 09:21:05 +00005088TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5089 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005090}
5091
Douglas Gregorb98b1992009-08-11 05:31:07 +00005092template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005093ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005094TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005095 CXXReinterpretCastExpr *E) {
5096 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005097}
Mike Stump1eb44332009-09-09 15:08:12 +00005098
Douglas Gregorb98b1992009-08-11 05:31:07 +00005099template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005100ExprResult
John McCall454feb92009-12-08 09:21:05 +00005101TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5102 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005103}
Mike Stump1eb44332009-09-09 15:08:12 +00005104
Douglas Gregorb98b1992009-08-11 05:31:07 +00005105template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005106ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005107TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005108 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005109 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5110 if (!Type)
5111 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005112
John McCall60d7b3a2010-08-24 06:29:42 +00005113 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005114 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005115 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005116 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005117
Douglas Gregorb98b1992009-08-11 05:31:07 +00005118 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005119 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005120 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005121 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005122
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005123 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005124 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005125 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005126 E->getRParenLoc());
5127}
Mike Stump1eb44332009-09-09 15:08:12 +00005128
Douglas Gregorb98b1992009-08-11 05:31:07 +00005129template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005130ExprResult
John McCall454feb92009-12-08 09:21:05 +00005131TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005132 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005133 TypeSourceInfo *TInfo
5134 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5135 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005136 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005137
Douglas Gregorb98b1992009-08-11 05:31:07 +00005138 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005139 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005140 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005141
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005142 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5143 E->getLocStart(),
5144 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005145 E->getLocEnd());
5146 }
Mike Stump1eb44332009-09-09 15:08:12 +00005147
Douglas Gregorb98b1992009-08-11 05:31:07 +00005148 // We don't know whether the expression is potentially evaluated until
5149 // after we perform semantic analysis, so the expression is potentially
5150 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005151 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00005152 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005153
John McCall60d7b3a2010-08-24 06:29:42 +00005154 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005155 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005156 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005157
Douglas Gregorb98b1992009-08-11 05:31:07 +00005158 if (!getDerived().AlwaysRebuild() &&
5159 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005160 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005161
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005162 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5163 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005164 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005165 E->getLocEnd());
5166}
5167
5168template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005169ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00005170TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5171 if (E->isTypeOperand()) {
5172 TypeSourceInfo *TInfo
5173 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5174 if (!TInfo)
5175 return ExprError();
5176
5177 if (!getDerived().AlwaysRebuild() &&
5178 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005179 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005180
5181 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5182 E->getLocStart(),
5183 TInfo,
5184 E->getLocEnd());
5185 }
5186
5187 // We don't know whether the expression is potentially evaluated until
5188 // after we perform semantic analysis, so the expression is potentially
5189 // potentially evaluated.
5190 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5191
5192 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5193 if (SubExpr.isInvalid())
5194 return ExprError();
5195
5196 if (!getDerived().AlwaysRebuild() &&
5197 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005198 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005199
5200 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5201 E->getLocStart(),
5202 SubExpr.get(),
5203 E->getLocEnd());
5204}
5205
5206template<typename Derived>
5207ExprResult
John McCall454feb92009-12-08 09:21:05 +00005208TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005209 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005210}
Mike Stump1eb44332009-09-09 15:08:12 +00005211
Douglas Gregorb98b1992009-08-11 05:31:07 +00005212template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005213ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005214TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005215 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005216 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005217}
Mike Stump1eb44332009-09-09 15:08:12 +00005218
Douglas Gregorb98b1992009-08-11 05:31:07 +00005219template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005220ExprResult
John McCall454feb92009-12-08 09:21:05 +00005221TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005222 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5223 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5224 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00005225
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005226 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005227 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005228
Douglas Gregor828a1972010-01-07 23:12:05 +00005229 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005230}
Mike Stump1eb44332009-09-09 15:08:12 +00005231
Douglas Gregorb98b1992009-08-11 05:31:07 +00005232template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005233ExprResult
John McCall454feb92009-12-08 09:21:05 +00005234TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005235 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005236 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005237 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005238
Douglas Gregorb98b1992009-08-11 05:31:07 +00005239 if (!getDerived().AlwaysRebuild() &&
5240 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005241 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005242
John McCall9ae2f072010-08-23 23:25:46 +00005243 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005244}
Mike Stump1eb44332009-09-09 15:08:12 +00005245
Douglas Gregorb98b1992009-08-11 05:31:07 +00005246template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005247ExprResult
John McCall454feb92009-12-08 09:21:05 +00005248TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005249 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005250 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5251 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005252 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00005253 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005254
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005255 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005256 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00005257 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005258
Douglas Gregor036aed12009-12-23 23:03:06 +00005259 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005260}
Mike Stump1eb44332009-09-09 15:08:12 +00005261
Douglas Gregorb98b1992009-08-11 05:31:07 +00005262template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005263ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00005264TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5265 CXXScalarValueInitExpr *E) {
5266 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5267 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005268 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00005269
Douglas Gregorb98b1992009-08-11 05:31:07 +00005270 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005271 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005272 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005273
Douglas Gregorab6677e2010-09-08 00:15:04 +00005274 return getDerived().RebuildCXXScalarValueInitExpr(T,
5275 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00005276 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005277}
Mike Stump1eb44332009-09-09 15:08:12 +00005278
Douglas Gregorb98b1992009-08-11 05:31:07 +00005279template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005280ExprResult
John McCall454feb92009-12-08 09:21:05 +00005281TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005282 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005283 TypeSourceInfo *AllocTypeInfo
5284 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5285 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005286 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005287
Douglas Gregorb98b1992009-08-11 05:31:07 +00005288 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00005289 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005290 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005291 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005292
Douglas Gregorb98b1992009-08-11 05:31:07 +00005293 // Transform the placement arguments (if any).
5294 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005295 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005296 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall63d5fb32010-10-05 22:36:42 +00005297 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5298 ArgumentChanged = true;
5299 break;
5300 }
5301
John McCall60d7b3a2010-08-24 06:29:42 +00005302 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005303 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005304 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005305
Douglas Gregorb98b1992009-08-11 05:31:07 +00005306 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5307 PlacementArgs.push_back(Arg.take());
5308 }
Mike Stump1eb44332009-09-09 15:08:12 +00005309
Douglas Gregor43959a92009-08-20 07:17:43 +00005310 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00005311 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005312 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall63d5fb32010-10-05 22:36:42 +00005313 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5314 ArgumentChanged = true;
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005315 break;
John McCall63d5fb32010-10-05 22:36:42 +00005316 }
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005317
John McCall60d7b3a2010-08-24 06:29:42 +00005318 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005319 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005320 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005321
Douglas Gregorb98b1992009-08-11 05:31:07 +00005322 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5323 ConstructorArgs.push_back(Arg.take());
5324 }
Mike Stump1eb44332009-09-09 15:08:12 +00005325
Douglas Gregor1af74512010-02-26 00:38:10 +00005326 // Transform constructor, new operator, and delete operator.
5327 CXXConstructorDecl *Constructor = 0;
5328 if (E->getConstructor()) {
5329 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005330 getDerived().TransformDecl(E->getLocStart(),
5331 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005332 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005333 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005334 }
5335
5336 FunctionDecl *OperatorNew = 0;
5337 if (E->getOperatorNew()) {
5338 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005339 getDerived().TransformDecl(E->getLocStart(),
5340 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005341 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00005342 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005343 }
5344
5345 FunctionDecl *OperatorDelete = 0;
5346 if (E->getOperatorDelete()) {
5347 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005348 getDerived().TransformDecl(E->getLocStart(),
5349 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005350 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005351 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005352 }
Sean Huntc3021132010-05-05 15:23:54 +00005353
Douglas Gregorb98b1992009-08-11 05:31:07 +00005354 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005355 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005356 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005357 Constructor == E->getConstructor() &&
5358 OperatorNew == E->getOperatorNew() &&
5359 OperatorDelete == E->getOperatorDelete() &&
5360 !ArgumentChanged) {
5361 // Mark any declarations we need as referenced.
5362 // FIXME: instantiation-specific.
5363 if (Constructor)
5364 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5365 if (OperatorNew)
5366 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5367 if (OperatorDelete)
5368 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00005369 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00005370 }
Mike Stump1eb44332009-09-09 15:08:12 +00005371
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005372 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005373 if (!ArraySize.get()) {
5374 // If no array size was specified, but the new expression was
5375 // instantiated with an array type (e.g., "new T" where T is
5376 // instantiated with "int[4]"), extract the outer bound from the
5377 // array type as our array size. We do this with constant and
5378 // dependently-sized array types.
5379 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5380 if (!ArrayT) {
5381 // Do nothing
5382 } else if (const ConstantArrayType *ConsArrayT
5383 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005384 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00005385 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5386 ConsArrayT->getSize(),
5387 SemaRef.Context.getSizeType(),
5388 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005389 AllocType = ConsArrayT->getElementType();
5390 } else if (const DependentSizedArrayType *DepArrayT
5391 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5392 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00005393 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005394 AllocType = DepArrayT->getElementType();
5395 }
5396 }
5397 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005398
Douglas Gregorb98b1992009-08-11 05:31:07 +00005399 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5400 E->isGlobalNew(),
5401 /*FIXME:*/E->getLocStart(),
5402 move_arg(PlacementArgs),
5403 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00005404 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005405 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005406 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00005407 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005408 /*FIXME:*/E->getLocStart(),
5409 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005410 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005411}
Mike Stump1eb44332009-09-09 15:08:12 +00005412
Douglas Gregorb98b1992009-08-11 05:31:07 +00005413template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005414ExprResult
John McCall454feb92009-12-08 09:21:05 +00005415TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005416 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005417 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005418 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005419
Douglas Gregor1af74512010-02-26 00:38:10 +00005420 // Transform the delete operator, if known.
5421 FunctionDecl *OperatorDelete = 0;
5422 if (E->getOperatorDelete()) {
5423 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005424 getDerived().TransformDecl(E->getLocStart(),
5425 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005426 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005427 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005428 }
Sean Huntc3021132010-05-05 15:23:54 +00005429
Douglas Gregorb98b1992009-08-11 05:31:07 +00005430 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005431 Operand.get() == E->getArgument() &&
5432 OperatorDelete == E->getOperatorDelete()) {
5433 // Mark any declarations we need as referenced.
5434 // FIXME: instantiation-specific.
5435 if (OperatorDelete)
5436 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00005437
5438 if (!E->getArgument()->isTypeDependent()) {
5439 QualType Destroyed = SemaRef.Context.getBaseElementType(
5440 E->getDestroyedType());
5441 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5442 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5443 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5444 SemaRef.LookupDestructor(Record));
5445 }
5446 }
5447
John McCall3fa5cae2010-10-26 07:05:15 +00005448 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00005449 }
Mike Stump1eb44332009-09-09 15:08:12 +00005450
Douglas Gregorb98b1992009-08-11 05:31:07 +00005451 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5452 E->isGlobalDelete(),
5453 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00005454 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005455}
Mike Stump1eb44332009-09-09 15:08:12 +00005456
Douglas Gregorb98b1992009-08-11 05:31:07 +00005457template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005458ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005459TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005460 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005461 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00005462 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005463 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005464
John McCallb3d87482010-08-24 05:47:05 +00005465 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005466 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005467 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005468 E->getOperatorLoc(),
5469 E->isArrow()? tok::arrow : tok::period,
5470 ObjectTypePtr,
5471 MayBePseudoDestructor);
5472 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005473 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005474
John McCallb3d87482010-08-24 05:47:05 +00005475 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora71d8192009-09-04 17:36:40 +00005476 NestedNameSpecifier *Qualifier
5477 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00005478 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005479 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00005480 if (E->getQualifier() && !Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005481 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005482
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005483 PseudoDestructorTypeStorage Destroyed;
5484 if (E->getDestroyedTypeInfo()) {
5485 TypeSourceInfo *DestroyedTypeInfo
5486 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5487 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005488 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005489 Destroyed = DestroyedTypeInfo;
5490 } else if (ObjectType->isDependentType()) {
5491 // We aren't likely to be able to resolve the identifier down to a type
5492 // now anyway, so just retain the identifier.
5493 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5494 E->getDestroyedTypeLoc());
5495 } else {
5496 // Look for a destructor known with the given name.
5497 CXXScopeSpec SS;
5498 if (Qualifier) {
5499 SS.setScopeRep(Qualifier);
5500 SS.setRange(E->getQualifierRange());
5501 }
Sean Huntc3021132010-05-05 15:23:54 +00005502
John McCallb3d87482010-08-24 05:47:05 +00005503 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005504 *E->getDestroyedTypeIdentifier(),
5505 E->getDestroyedTypeLoc(),
5506 /*Scope=*/0,
5507 SS, ObjectTypePtr,
5508 false);
5509 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005510 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005511
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005512 Destroyed
5513 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5514 E->getDestroyedTypeLoc());
5515 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005516
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005517 TypeSourceInfo *ScopeTypeInfo = 0;
5518 if (E->getScopeTypeInfo()) {
Sean Huntc3021132010-05-05 15:23:54 +00005519 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005520 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005521 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005522 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00005523 }
Sean Huntc3021132010-05-05 15:23:54 +00005524
John McCall9ae2f072010-08-23 23:25:46 +00005525 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005526 E->getOperatorLoc(),
5527 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005528 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005529 E->getQualifierRange(),
5530 ScopeTypeInfo,
5531 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005532 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005533 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005534}
Mike Stump1eb44332009-09-09 15:08:12 +00005535
Douglas Gregora71d8192009-09-04 17:36:40 +00005536template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005537ExprResult
John McCallba135432009-11-21 08:51:07 +00005538TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005539 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005540 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5541
5542 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5543 Sema::LookupOrdinaryName);
5544
5545 // Transform all the decls.
5546 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5547 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005548 NamedDecl *InstD = static_cast<NamedDecl*>(
5549 getDerived().TransformDecl(Old->getNameLoc(),
5550 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005551 if (!InstD) {
5552 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5553 // This can happen because of dependent hiding.
5554 if (isa<UsingShadowDecl>(*I))
5555 continue;
5556 else
John McCallf312b1e2010-08-26 23:41:50 +00005557 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005558 }
John McCallf7a1a742009-11-24 19:00:30 +00005559
5560 // Expand using declarations.
5561 if (isa<UsingDecl>(InstD)) {
5562 UsingDecl *UD = cast<UsingDecl>(InstD);
5563 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5564 E = UD->shadow_end(); I != E; ++I)
5565 R.addDecl(*I);
5566 continue;
5567 }
5568
5569 R.addDecl(InstD);
5570 }
5571
5572 // Resolve a kind, but don't do any further analysis. If it's
5573 // ambiguous, the callee needs to deal with it.
5574 R.resolveKind();
5575
5576 // Rebuild the nested-name qualifier, if present.
5577 CXXScopeSpec SS;
5578 NestedNameSpecifier *Qualifier = 0;
5579 if (Old->getQualifier()) {
5580 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005581 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005582 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005583 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005584
John McCallf7a1a742009-11-24 19:00:30 +00005585 SS.setScopeRep(Qualifier);
5586 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005587 }
5588
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005589 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005590 CXXRecordDecl *NamingClass
5591 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5592 Old->getNameLoc(),
5593 Old->getNamingClass()));
5594 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00005595 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005596
Douglas Gregor66c45152010-04-27 16:10:10 +00005597 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005598 }
5599
5600 // If we have no template arguments, it's a normal declaration name.
5601 if (!Old->hasExplicitTemplateArgs())
5602 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5603
5604 // If we have template arguments, rebuild them, then rebuild the
5605 // templateid expression.
5606 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5607 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5608 TemplateArgumentLoc Loc;
5609 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005610 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00005611 TransArgs.addArgument(Loc);
5612 }
5613
5614 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5615 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005616}
Mike Stump1eb44332009-09-09 15:08:12 +00005617
Douglas Gregorb98b1992009-08-11 05:31:07 +00005618template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005619ExprResult
John McCall454feb92009-12-08 09:21:05 +00005620TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005621 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5622 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005623 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005624
Douglas Gregorb98b1992009-08-11 05:31:07 +00005625 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005626 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005627 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005628
Mike Stump1eb44332009-09-09 15:08:12 +00005629 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005630 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005631 T,
5632 E->getLocEnd());
5633}
Mike Stump1eb44332009-09-09 15:08:12 +00005634
Douglas Gregorb98b1992009-08-11 05:31:07 +00005635template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005636ExprResult
John McCall865d4472009-11-19 22:55:06 +00005637TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005638 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005639 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005640 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005641 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005642 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00005643 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005644
Abramo Bagnara25777432010-08-11 22:01:17 +00005645 DeclarationNameInfo NameInfo
5646 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5647 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005648 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005649
John McCallf7a1a742009-11-24 19:00:30 +00005650 if (!E->hasExplicitTemplateArgs()) {
5651 if (!getDerived().AlwaysRebuild() &&
5652 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005653 // Note: it is sufficient to compare the Name component of NameInfo:
5654 // if name has not changed, DNLoc has not changed either.
5655 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00005656 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005657
John McCallf7a1a742009-11-24 19:00:30 +00005658 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5659 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005660 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005661 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005662 }
John McCalld5532b62009-11-23 01:53:49 +00005663
5664 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005665 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005666 TemplateArgumentLoc Loc;
5667 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005668 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005669 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005670 }
5671
John McCallf7a1a742009-11-24 19:00:30 +00005672 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5673 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005674 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005675 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005676}
5677
5678template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005679ExprResult
John McCall454feb92009-12-08 09:21:05 +00005680TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005681 // CXXConstructExprs are always implicit, so when we have a
5682 // 1-argument construction we just transform that argument.
5683 if (E->getNumArgs() == 1 ||
5684 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5685 return getDerived().TransformExpr(E->getArg(0));
5686
Douglas Gregorb98b1992009-08-11 05:31:07 +00005687 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5688
5689 QualType T = getDerived().TransformType(E->getType());
5690 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005691 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005692
5693 CXXConstructorDecl *Constructor
5694 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005695 getDerived().TransformDecl(E->getLocStart(),
5696 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005697 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005698 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005699
Douglas Gregorb98b1992009-08-11 05:31:07 +00005700 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005701 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005702 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005703 ArgEnd = E->arg_end();
5704 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005705 if (getDerived().DropCallArgument(*Arg)) {
5706 ArgumentChanged = true;
5707 break;
5708 }
5709
John McCall60d7b3a2010-08-24 06:29:42 +00005710 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005711 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005712 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005713
Douglas Gregorb98b1992009-08-11 05:31:07 +00005714 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005715 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005716 }
5717
5718 if (!getDerived().AlwaysRebuild() &&
5719 T == E->getType() &&
5720 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005721 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005722 // Mark the constructor as referenced.
5723 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005724 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00005725 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00005726 }
Mike Stump1eb44332009-09-09 15:08:12 +00005727
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005728 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5729 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00005730 move_arg(Args),
5731 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00005732 E->getConstructionKind(),
5733 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005734}
Mike Stump1eb44332009-09-09 15:08:12 +00005735
Douglas Gregorb98b1992009-08-11 05:31:07 +00005736/// \brief Transform a C++ temporary-binding expression.
5737///
Douglas Gregor51326552009-12-24 18:51:59 +00005738/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5739/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005740template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005741ExprResult
John McCall454feb92009-12-08 09:21:05 +00005742TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005743 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005744}
Mike Stump1eb44332009-09-09 15:08:12 +00005745
5746/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005747/// be destroyed after the expression is evaluated.
5748///
Douglas Gregor51326552009-12-24 18:51:59 +00005749/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5750/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005751template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005752ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005753TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005754 CXXExprWithTemporaries *E) {
5755 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005756}
Mike Stump1eb44332009-09-09 15:08:12 +00005757
Douglas Gregorb98b1992009-08-11 05:31:07 +00005758template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005759ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005760TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00005761 CXXTemporaryObjectExpr *E) {
5762 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5763 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005764 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005765
Douglas Gregorb98b1992009-08-11 05:31:07 +00005766 CXXConstructorDecl *Constructor
5767 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005768 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005769 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005770 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005771 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005772
Douglas Gregorb98b1992009-08-11 05:31:07 +00005773 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005774 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005775 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005776 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005777 ArgEnd = E->arg_end();
5778 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005779 if (getDerived().DropCallArgument(*Arg)) {
5780 ArgumentChanged = true;
5781 break;
5782 }
5783
John McCall60d7b3a2010-08-24 06:29:42 +00005784 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005785 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005786 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005787
Douglas Gregorb98b1992009-08-11 05:31:07 +00005788 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5789 Args.push_back((Expr *)TransArg.release());
5790 }
Mike Stump1eb44332009-09-09 15:08:12 +00005791
Douglas Gregorb98b1992009-08-11 05:31:07 +00005792 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005793 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005794 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005795 !ArgumentChanged) {
5796 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00005797 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00005798 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00005799 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00005800
5801 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5802 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005803 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005804 E->getLocEnd());
5805}
Mike Stump1eb44332009-09-09 15:08:12 +00005806
Douglas Gregorb98b1992009-08-11 05:31:07 +00005807template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005808ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005809TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005810 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00005811 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5812 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005813 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005814
Douglas Gregorb98b1992009-08-11 05:31:07 +00005815 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005816 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005817 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5818 ArgEnd = E->arg_end();
5819 Arg != ArgEnd; ++Arg) {
John McCall60d7b3a2010-08-24 06:29:42 +00005820 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005821 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005822 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005823
Douglas Gregorb98b1992009-08-11 05:31:07 +00005824 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005825 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005826 }
Mike Stump1eb44332009-09-09 15:08:12 +00005827
Douglas Gregorb98b1992009-08-11 05:31:07 +00005828 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005829 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005830 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005831 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005832
Douglas Gregorb98b1992009-08-11 05:31:07 +00005833 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00005834 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005835 E->getLParenLoc(),
5836 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005837 E->getRParenLoc());
5838}
Mike Stump1eb44332009-09-09 15:08:12 +00005839
Douglas Gregorb98b1992009-08-11 05:31:07 +00005840template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005841ExprResult
John McCall865d4472009-11-19 22:55:06 +00005842TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005843 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005844 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005845 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005846 Expr *OldBase;
5847 QualType BaseType;
5848 QualType ObjectType;
5849 if (!E->isImplicitAccess()) {
5850 OldBase = E->getBase();
5851 Base = getDerived().TransformExpr(OldBase);
5852 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005853 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005854
John McCallaa81e162009-12-01 22:10:20 +00005855 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00005856 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00005857 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005858 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005859 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005860 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005861 ObjectTy,
5862 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005863 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005864 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005865
John McCallb3d87482010-08-24 05:47:05 +00005866 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00005867 BaseType = ((Expr*) Base.get())->getType();
5868 } else {
5869 OldBase = 0;
5870 BaseType = getDerived().TransformType(E->getBaseType());
5871 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5872 }
Mike Stump1eb44332009-09-09 15:08:12 +00005873
Douglas Gregor6cd21982009-10-20 05:58:46 +00005874 // Transform the first part of the nested-name-specifier that qualifies
5875 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005876 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005877 = getDerived().TransformFirstQualifierInScope(
5878 E->getFirstQualifierFoundInScope(),
5879 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005880
Douglas Gregora38c6872009-09-03 16:14:30 +00005881 NestedNameSpecifier *Qualifier = 0;
5882 if (E->getQualifier()) {
5883 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5884 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005885 ObjectType,
5886 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005887 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005888 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00005889 }
Mike Stump1eb44332009-09-09 15:08:12 +00005890
Abramo Bagnara25777432010-08-11 22:01:17 +00005891 DeclarationNameInfo NameInfo
5892 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5893 ObjectType);
5894 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005895 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005896
John McCallaa81e162009-12-01 22:10:20 +00005897 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005898 // This is a reference to a member without an explicitly-specified
5899 // template argument list. Optimize for this common case.
5900 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005901 Base.get() == OldBase &&
5902 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005903 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005904 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005905 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00005906 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005907
John McCall9ae2f072010-08-23 23:25:46 +00005908 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005909 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005910 E->isArrow(),
5911 E->getOperatorLoc(),
5912 Qualifier,
5913 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005914 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005915 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005916 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005917 }
5918
John McCalld5532b62009-11-23 01:53:49 +00005919 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005920 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005921 TemplateArgumentLoc Loc;
5922 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005923 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005924 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005925 }
Mike Stump1eb44332009-09-09 15:08:12 +00005926
John McCall9ae2f072010-08-23 23:25:46 +00005927 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005928 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005929 E->isArrow(),
5930 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005931 Qualifier,
5932 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005933 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005934 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005935 &TransArgs);
5936}
5937
5938template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005939ExprResult
John McCall454feb92009-12-08 09:21:05 +00005940TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005941 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005942 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005943 QualType BaseType;
5944 if (!Old->isImplicitAccess()) {
5945 Base = getDerived().TransformExpr(Old->getBase());
5946 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005947 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005948 BaseType = ((Expr*) Base.get())->getType();
5949 } else {
5950 BaseType = getDerived().TransformType(Old->getBaseType());
5951 }
John McCall129e2df2009-11-30 22:42:35 +00005952
5953 NestedNameSpecifier *Qualifier = 0;
5954 if (Old->getQualifier()) {
5955 Qualifier
5956 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005957 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005958 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00005959 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00005960 }
5961
Abramo Bagnara25777432010-08-11 22:01:17 +00005962 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00005963 Sema::LookupOrdinaryName);
5964
5965 // Transform all the decls.
5966 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5967 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005968 NamedDecl *InstD = static_cast<NamedDecl*>(
5969 getDerived().TransformDecl(Old->getMemberLoc(),
5970 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005971 if (!InstD) {
5972 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5973 // This can happen because of dependent hiding.
5974 if (isa<UsingShadowDecl>(*I))
5975 continue;
5976 else
John McCallf312b1e2010-08-26 23:41:50 +00005977 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005978 }
John McCall129e2df2009-11-30 22:42:35 +00005979
5980 // Expand using declarations.
5981 if (isa<UsingDecl>(InstD)) {
5982 UsingDecl *UD = cast<UsingDecl>(InstD);
5983 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5984 E = UD->shadow_end(); I != E; ++I)
5985 R.addDecl(*I);
5986 continue;
5987 }
5988
5989 R.addDecl(InstD);
5990 }
5991
5992 R.resolveKind();
5993
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005994 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00005995 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00005996 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005997 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00005998 Old->getMemberLoc(),
5999 Old->getNamingClass()));
6000 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006001 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006002
Douglas Gregor66c45152010-04-27 16:10:10 +00006003 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006004 }
Sean Huntc3021132010-05-05 15:23:54 +00006005
John McCall129e2df2009-11-30 22:42:35 +00006006 TemplateArgumentListInfo TransArgs;
6007 if (Old->hasExplicitTemplateArgs()) {
6008 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6009 TransArgs.setRAngleLoc(Old->getRAngleLoc());
6010 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6011 TemplateArgumentLoc Loc;
6012 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6013 Loc))
John McCallf312b1e2010-08-26 23:41:50 +00006014 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006015 TransArgs.addArgument(Loc);
6016 }
6017 }
John McCallc2233c52010-01-15 08:34:02 +00006018
6019 // FIXME: to do this check properly, we will need to preserve the
6020 // first-qualifier-in-scope here, just in case we had a dependent
6021 // base (and therefore couldn't do the check) and a
6022 // nested-name-qualifier (and therefore could do the lookup).
6023 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006024
John McCall9ae2f072010-08-23 23:25:46 +00006025 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006026 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006027 Old->getOperatorLoc(),
6028 Old->isArrow(),
6029 Qualifier,
6030 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006031 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006032 R,
6033 (Old->hasExplicitTemplateArgs()
6034 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006035}
6036
6037template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006038ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006039TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6040 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6041 if (SubExpr.isInvalid())
6042 return ExprError();
6043
6044 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006045 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00006046
6047 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6048}
6049
6050template<typename Derived>
6051ExprResult
John McCall454feb92009-12-08 09:21:05 +00006052TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006053 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006054}
6055
Mike Stump1eb44332009-09-09 15:08:12 +00006056template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006057ExprResult
John McCall454feb92009-12-08 09:21:05 +00006058TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006059 TypeSourceInfo *EncodedTypeInfo
6060 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6061 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006062 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006063
Douglas Gregorb98b1992009-08-11 05:31:07 +00006064 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006065 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006066 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006067
6068 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006069 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006070 E->getRParenLoc());
6071}
Mike Stump1eb44332009-09-09 15:08:12 +00006072
Douglas Gregorb98b1992009-08-11 05:31:07 +00006073template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006074ExprResult
John McCall454feb92009-12-08 09:21:05 +00006075TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006076 // Transform arguments.
6077 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006078 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006079 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006080 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor92e986e2010-04-22 16:44:27 +00006081 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006082 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006083
Douglas Gregor92e986e2010-04-22 16:44:27 +00006084 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00006085 Args.push_back(Arg.get());
Douglas Gregor92e986e2010-04-22 16:44:27 +00006086 }
6087
6088 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6089 // Class message: transform the receiver type.
6090 TypeSourceInfo *ReceiverTypeInfo
6091 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6092 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006093 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006094
Douglas Gregor92e986e2010-04-22 16:44:27 +00006095 // If nothing changed, just retain the existing message send.
6096 if (!getDerived().AlwaysRebuild() &&
6097 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006098 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006099
6100 // Build a new class message send.
6101 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6102 E->getSelector(),
6103 E->getMethodDecl(),
6104 E->getLeftLoc(),
6105 move_arg(Args),
6106 E->getRightLoc());
6107 }
6108
6109 // Instance message: transform the receiver
6110 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6111 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006112 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006113 = getDerived().TransformExpr(E->getInstanceReceiver());
6114 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006115 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006116
6117 // If nothing changed, just retain the existing message send.
6118 if (!getDerived().AlwaysRebuild() &&
6119 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006120 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006121
Douglas Gregor92e986e2010-04-22 16:44:27 +00006122 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006123 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006124 E->getSelector(),
6125 E->getMethodDecl(),
6126 E->getLeftLoc(),
6127 move_arg(Args),
6128 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006129}
6130
Mike Stump1eb44332009-09-09 15:08:12 +00006131template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006132ExprResult
John McCall454feb92009-12-08 09:21:05 +00006133TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006134 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006135}
6136
Mike Stump1eb44332009-09-09 15:08:12 +00006137template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006138ExprResult
John McCall454feb92009-12-08 09:21:05 +00006139TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006140 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006141}
6142
Mike Stump1eb44332009-09-09 15:08:12 +00006143template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006144ExprResult
John McCall454feb92009-12-08 09:21:05 +00006145TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006146 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006147 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006148 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006149 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006150
6151 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006152
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006153 // If nothing changed, just retain the existing expression.
6154 if (!getDerived().AlwaysRebuild() &&
6155 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006156 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006157
John McCall9ae2f072010-08-23 23:25:46 +00006158 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006159 E->getLocation(),
6160 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006161}
6162
Mike Stump1eb44332009-09-09 15:08:12 +00006163template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006164ExprResult
John McCall454feb92009-12-08 09:21:05 +00006165TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006166 // 'super' never changes. Property never changes. Just retain the existing
6167 // expression.
6168 if (E->isSuperReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00006169 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006170
Douglas Gregore3303542010-04-26 20:47:02 +00006171 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006172 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00006173 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006174 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006175
Douglas Gregore3303542010-04-26 20:47:02 +00006176 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006177
Douglas Gregore3303542010-04-26 20:47:02 +00006178 // If nothing changed, just retain the existing expression.
6179 if (!getDerived().AlwaysRebuild() &&
6180 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006181 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006182
John McCall9ae2f072010-08-23 23:25:46 +00006183 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregore3303542010-04-26 20:47:02 +00006184 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006185}
6186
Mike Stump1eb44332009-09-09 15:08:12 +00006187template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006188ExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00006189TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00006190 ObjCImplicitSetterGetterRefExpr *E) {
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006191 // If this implicit setter/getter refers to super, it cannot have any
6192 // dependent parts. Just retain the existing declaration.
6193 if (E->isSuperReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00006194 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006195
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006196 // If this implicit setter/getter refers to class methods, it cannot have any
6197 // dependent parts. Just retain the existing declaration.
6198 if (E->getInterfaceDecl())
John McCall3fa5cae2010-10-26 07:05:15 +00006199 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006200
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006201 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006202 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006203 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006204 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006205
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006206 // We don't need to transform the getters/setters; they will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006207
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006208 // If nothing changed, just retain the existing expression.
6209 if (!getDerived().AlwaysRebuild() &&
6210 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006211 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006212
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006213 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6214 E->getGetterMethod(),
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006215 E->getType(),
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006216 E->getSetterMethod(),
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006217 E->getLocation(),
6218 Base.get(),
6219 E->getSuperLocation(),
6220 E->getSuperType(),
6221 E->isSuperReceiver());
Sean Huntc3021132010-05-05 15:23:54 +00006222
Douglas Gregorb98b1992009-08-11 05:31:07 +00006223}
6224
Mike Stump1eb44332009-09-09 15:08:12 +00006225template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006226ExprResult
John McCall454feb92009-12-08 09:21:05 +00006227TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006228 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006229 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006230 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006231 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006232
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006233 // If nothing changed, just retain the existing expression.
6234 if (!getDerived().AlwaysRebuild() &&
6235 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006236 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006237
John McCall9ae2f072010-08-23 23:25:46 +00006238 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006239 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006240}
6241
Mike Stump1eb44332009-09-09 15:08:12 +00006242template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006243ExprResult
John McCall454feb92009-12-08 09:21:05 +00006244TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006245 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006246 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006247 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006248 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006249 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006250 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006251
Douglas Gregorb98b1992009-08-11 05:31:07 +00006252 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00006253 SubExprs.push_back(SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006254 }
Mike Stump1eb44332009-09-09 15:08:12 +00006255
Douglas Gregorb98b1992009-08-11 05:31:07 +00006256 if (!getDerived().AlwaysRebuild() &&
6257 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006258 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006259
Douglas Gregorb98b1992009-08-11 05:31:07 +00006260 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6261 move_arg(SubExprs),
6262 E->getRParenLoc());
6263}
6264
Mike Stump1eb44332009-09-09 15:08:12 +00006265template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006266ExprResult
John McCall454feb92009-12-08 09:21:05 +00006267TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006268 SourceLocation CaretLoc(E->getExprLoc());
6269
6270 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6271 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6272 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6273 llvm::SmallVector<ParmVarDecl*, 4> Params;
6274 llvm::SmallVector<QualType, 4> ParamTypes;
6275
6276 // Parameter substitution.
6277 const BlockDecl *BD = E->getBlockDecl();
6278 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6279 EN = BD->param_end(); P != EN; ++P) {
6280 ParmVarDecl *OldParm = (*P);
6281 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6282 QualType NewType = NewParm->getType();
6283 Params.push_back(NewParm);
6284 ParamTypes.push_back(NewParm->getType());
6285 }
6286
6287 const FunctionType *BExprFunctionType = E->getFunctionType();
6288 QualType BExprResultType = BExprFunctionType->getResultType();
6289 if (!BExprResultType.isNull()) {
6290 if (!BExprResultType->isDependentType())
6291 CurBlock->ReturnType = BExprResultType;
6292 else if (BExprResultType != SemaRef.Context.DependentTy)
6293 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6294 }
6295
6296 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00006297 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006298 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006299 return ExprError();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006300 // Set the parameters on the block decl.
6301 if (!Params.empty())
6302 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6303
6304 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6305 CurBlock->ReturnType,
6306 ParamTypes.data(),
6307 ParamTypes.size(),
6308 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006309 0,
6310 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006311
6312 CurBlock->FunctionType = FunctionType;
John McCall9ae2f072010-08-23 23:25:46 +00006313 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006314}
6315
Mike Stump1eb44332009-09-09 15:08:12 +00006316template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006317ExprResult
John McCall454feb92009-12-08 09:21:05 +00006318TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006319 NestedNameSpecifier *Qualifier = 0;
6320
6321 ValueDecl *ND
6322 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6323 E->getDecl()));
6324 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006325 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00006326
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006327 if (!getDerived().AlwaysRebuild() &&
6328 ND == E->getDecl()) {
6329 // Mark it referenced in the new context regardless.
6330 // FIXME: this is a bit instantiation-specific.
6331 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6332
John McCall3fa5cae2010-10-26 07:05:15 +00006333 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006334 }
6335
Abramo Bagnara25777432010-08-11 22:01:17 +00006336 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006337 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006338 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006339}
Mike Stump1eb44332009-09-09 15:08:12 +00006340
Douglas Gregorb98b1992009-08-11 05:31:07 +00006341//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006342// Type reconstruction
6343//===----------------------------------------------------------------------===//
6344
Mike Stump1eb44332009-09-09 15:08:12 +00006345template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006346QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6347 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006348 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006349 getDerived().getBaseEntity());
6350}
6351
Mike Stump1eb44332009-09-09 15:08:12 +00006352template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006353QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6354 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006355 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006356 getDerived().getBaseEntity());
6357}
6358
Mike Stump1eb44332009-09-09 15:08:12 +00006359template<typename Derived>
6360QualType
John McCall85737a72009-10-30 00:06:24 +00006361TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6362 bool WrittenAsLValue,
6363 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006364 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006365 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006366}
6367
6368template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006369QualType
John McCall85737a72009-10-30 00:06:24 +00006370TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6371 QualType ClassType,
6372 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006373 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006374 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006375}
6376
6377template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006378QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006379TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6380 ArrayType::ArraySizeModifier SizeMod,
6381 const llvm::APInt *Size,
6382 Expr *SizeExpr,
6383 unsigned IndexTypeQuals,
6384 SourceRange BracketsRange) {
6385 if (SizeExpr || !Size)
6386 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6387 IndexTypeQuals, BracketsRange,
6388 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006389
6390 QualType Types[] = {
6391 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6392 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6393 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006394 };
6395 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6396 QualType SizeType;
6397 for (unsigned I = 0; I != NumTypes; ++I)
6398 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6399 SizeType = Types[I];
6400 break;
6401 }
Mike Stump1eb44332009-09-09 15:08:12 +00006402
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006403 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6404 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006405 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006406 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006407 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006408}
Mike Stump1eb44332009-09-09 15:08:12 +00006409
Douglas Gregor577f75a2009-08-04 16:50:30 +00006410template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006411QualType
6412TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006413 ArrayType::ArraySizeModifier SizeMod,
6414 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006415 unsigned IndexTypeQuals,
6416 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006417 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006418 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006419}
6420
6421template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006422QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006423TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006424 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006425 unsigned IndexTypeQuals,
6426 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006427 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006428 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006429}
Mike Stump1eb44332009-09-09 15:08:12 +00006430
Douglas Gregor577f75a2009-08-04 16:50:30 +00006431template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006432QualType
6433TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006434 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006435 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006436 unsigned IndexTypeQuals,
6437 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006438 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006439 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006440 IndexTypeQuals, BracketsRange);
6441}
6442
6443template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006444QualType
6445TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006446 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006447 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006448 unsigned IndexTypeQuals,
6449 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006450 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006451 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006452 IndexTypeQuals, BracketsRange);
6453}
6454
6455template<typename Derived>
6456QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner788b0fd2010-06-23 06:00:24 +00006457 unsigned NumElements,
6458 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006459 // FIXME: semantic checking!
Chris Lattner788b0fd2010-06-23 06:00:24 +00006460 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006461}
Mike Stump1eb44332009-09-09 15:08:12 +00006462
Douglas Gregor577f75a2009-08-04 16:50:30 +00006463template<typename Derived>
6464QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6465 unsigned NumElements,
6466 SourceLocation AttributeLoc) {
6467 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6468 NumElements, true);
6469 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006470 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6471 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00006472 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006473}
Mike Stump1eb44332009-09-09 15:08:12 +00006474
Douglas Gregor577f75a2009-08-04 16:50:30 +00006475template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006476QualType
6477TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00006478 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006479 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00006480 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006481}
Mike Stump1eb44332009-09-09 15:08:12 +00006482
Douglas Gregor577f75a2009-08-04 16:50:30 +00006483template<typename Derived>
6484QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006485 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006486 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006487 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00006488 unsigned Quals,
6489 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00006490 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006491 Quals,
6492 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006493 getDerived().getBaseEntity(),
6494 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006495}
Mike Stump1eb44332009-09-09 15:08:12 +00006496
Douglas Gregor577f75a2009-08-04 16:50:30 +00006497template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006498QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6499 return SemaRef.Context.getFunctionNoProtoType(T);
6500}
6501
6502template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006503QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6504 assert(D && "no decl found");
6505 if (D->isInvalidDecl()) return QualType();
6506
Douglas Gregor92e986e2010-04-22 16:44:27 +00006507 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006508 TypeDecl *Ty;
6509 if (isa<UsingDecl>(D)) {
6510 UsingDecl *Using = cast<UsingDecl>(D);
6511 assert(Using->isTypeName() &&
6512 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6513
6514 // A valid resolved using typename decl points to exactly one type decl.
6515 assert(++Using->shadow_begin() == Using->shadow_end());
6516 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006517
John McCalled976492009-12-04 22:46:56 +00006518 } else {
6519 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6520 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6521 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6522 }
6523
6524 return SemaRef.Context.getTypeDeclType(Ty);
6525}
6526
6527template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00006528QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6529 SourceLocation Loc) {
6530 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006531}
6532
6533template<typename Derived>
6534QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6535 return SemaRef.Context.getTypeOfType(Underlying);
6536}
6537
6538template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00006539QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6540 SourceLocation Loc) {
6541 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006542}
6543
6544template<typename Derived>
6545QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006546 TemplateName Template,
6547 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006548 const TemplateArgumentListInfo &TemplateArgs) {
6549 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006550}
Mike Stump1eb44332009-09-09 15:08:12 +00006551
Douglas Gregordcee1a12009-08-06 05:28:30 +00006552template<typename Derived>
6553NestedNameSpecifier *
6554TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6555 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006556 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006557 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006558 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006559 CXXScopeSpec SS;
6560 // FIXME: The source location information is all wrong.
6561 SS.setRange(Range);
6562 SS.setScopeRep(Prefix);
6563 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006564 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006565 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006566 ObjectType,
6567 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006568 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006569}
6570
6571template<typename Derived>
6572NestedNameSpecifier *
6573TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6574 SourceRange Range,
6575 NamespaceDecl *NS) {
6576 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6577}
6578
6579template<typename Derived>
6580NestedNameSpecifier *
6581TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6582 SourceRange Range,
6583 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006584 QualType T) {
6585 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006586 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006587 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006588 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6589 T.getTypePtr());
6590 }
Mike Stump1eb44332009-09-09 15:08:12 +00006591
Douglas Gregordcee1a12009-08-06 05:28:30 +00006592 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6593 return 0;
6594}
Mike Stump1eb44332009-09-09 15:08:12 +00006595
Douglas Gregord1067e52009-08-06 06:41:21 +00006596template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006597TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006598TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6599 bool TemplateKW,
6600 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006601 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006602 Template);
6603}
6604
6605template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006606TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006607TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006608 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006609 const IdentifierInfo &II,
6610 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006611 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006612 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00006613 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006614 UnqualifiedId Name;
6615 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00006616 Sema::TemplateTy Template;
6617 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6618 /*FIXME:*/getDerived().getBaseLocation(),
6619 SS,
6620 Name,
John McCallb3d87482010-08-24 05:47:05 +00006621 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006622 /*EnteringContext=*/false,
6623 Template);
6624 return Template.template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00006625}
Mike Stump1eb44332009-09-09 15:08:12 +00006626
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006628TemplateName
6629TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6630 OverloadedOperatorKind Operator,
6631 QualType ObjectType) {
6632 CXXScopeSpec SS;
6633 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6634 SS.setScopeRep(Qualifier);
6635 UnqualifiedId Name;
6636 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6637 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6638 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00006639 Sema::TemplateTy Template;
6640 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006641 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006642 SS,
6643 Name,
John McCallb3d87482010-08-24 05:47:05 +00006644 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006645 /*EnteringContext=*/false,
6646 Template);
6647 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006648}
Sean Huntc3021132010-05-05 15:23:54 +00006649
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006650template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006651ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006652TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6653 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006654 Expr *OrigCallee,
6655 Expr *First,
6656 Expr *Second) {
6657 Expr *Callee = OrigCallee->IgnoreParenCasts();
6658 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006659
Douglas Gregorb98b1992009-08-11 05:31:07 +00006660 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006661 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00006662 if (!First->getType()->isOverloadableType() &&
6663 !Second->getType()->isOverloadableType())
6664 return getSema().CreateBuiltinArraySubscriptExpr(First,
6665 Callee->getLocStart(),
6666 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006667 } else if (Op == OO_Arrow) {
6668 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00006669 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6670 } else if (Second == 0 || isPostIncDec) {
6671 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672 // The argument is not of overloadable type, so try to create a
6673 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00006674 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006675 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006676
John McCall9ae2f072010-08-23 23:25:46 +00006677 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 }
6679 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006680 if (!First->getType()->isOverloadableType() &&
6681 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006682 // Neither of the arguments is an overloadable type, so try to
6683 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00006684 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006685 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00006686 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006687 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006688 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006689
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690 return move(Result);
6691 }
6692 }
Mike Stump1eb44332009-09-09 15:08:12 +00006693
6694 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006696 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006697
John McCall9ae2f072010-08-23 23:25:46 +00006698 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00006699 assert(ULE->requiresADL());
6700
6701 // FIXME: Do we have to check
6702 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006703 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006704 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006705 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006706 }
Mike Stump1eb44332009-09-09 15:08:12 +00006707
Douglas Gregorb98b1992009-08-11 05:31:07 +00006708 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00006709 Expr *Args[2] = { First, Second };
6710 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006711
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 // Create the overloaded operator invocation for unary operators.
6713 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00006714 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00006716 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717 }
Mike Stump1eb44332009-09-09 15:08:12 +00006718
Sebastian Redlf322ed62009-10-29 20:17:01 +00006719 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00006720 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00006721 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006722 First,
6723 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006724
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00006726 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006727 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6729 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006730 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006731
Mike Stump1eb44332009-09-09 15:08:12 +00006732 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733}
Mike Stump1eb44332009-09-09 15:08:12 +00006734
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006735template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006736ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00006737TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006738 SourceLocation OperatorLoc,
6739 bool isArrow,
6740 NestedNameSpecifier *Qualifier,
6741 SourceRange QualifierRange,
6742 TypeSourceInfo *ScopeType,
6743 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006744 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006745 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006746 CXXScopeSpec SS;
6747 if (Qualifier) {
6748 SS.setRange(QualifierRange);
6749 SS.setScopeRep(Qualifier);
6750 }
6751
John McCall9ae2f072010-08-23 23:25:46 +00006752 QualType BaseType = Base->getType();
6753 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006754 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006755 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006756 !BaseType->getAs<PointerType>()->getPointeeType()
6757 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006758 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00006759 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006760 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006761 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006762 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006763 /*FIXME?*/true);
6764 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006765
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006766 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00006767 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6768 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6769 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6770 NameInfo.setNamedTypeInfo(DestroyedType);
6771
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006772 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00006773
John McCall9ae2f072010-08-23 23:25:46 +00006774 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006775 OperatorLoc, isArrow,
6776 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00006777 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006778 /*TemplateArgs*/ 0);
6779}
6780
Douglas Gregor577f75a2009-08-04 16:50:30 +00006781} // end namespace clang
6782
6783#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H