blob: 71492254c6ef69b60b92de743572d63b431d90bf [file] [log] [blame]
John McCalla2becad2009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
John McCall2d887082010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000019#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000020#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000021#include "clang/AST/DeclObjC.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000022#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000023#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
John McCalla2becad2009-10-21 00:40:46 +000028#include "clang/AST/TypeLocBuilder.h"
John McCall19510852010-08-20 18:27:03 +000029#include "clang/Sema/Ownership.h"
30#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000031#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000032#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000033#include <algorithm>
34
35namespace clang {
John McCall781472f2010-08-25 08:40:02 +000036using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000037
Douglas Gregor577f75a2009-08-04 16:50:30 +000038/// \brief A semantic tree transformation that allows one to transform one
39/// abstract syntax tree into another.
40///
Mike Stump1eb44332009-09-09 15:08:12 +000041/// A new tree transformation is defined by creating a new subclass \c X of
42/// \c TreeTransform<X> and then overriding certain operations to provide
43/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000044/// instantiation is implemented as a tree transformation where the
45/// transformation of TemplateTypeParmType nodes involves substituting the
46/// template arguments for their corresponding template parameters; a similar
47/// transformation is performed for non-type template parameters and
48/// template template parameters.
49///
50/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000051/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000052/// override any of the transformation or rebuild operators by providing an
53/// operation with the same signature as the default implementation. The
54/// overridding function should not be virtual.
55///
56/// Semantic tree transformations are split into two stages, either of which
57/// can be replaced by a subclass. The "transform" step transforms an AST node
58/// or the parts of an AST node using the various transformation functions,
59/// then passes the pieces on to the "rebuild" step, which constructs a new AST
60/// node of the appropriate kind from the pieces. The default transformation
61/// routines recursively transform the operands to composite AST nodes (e.g.,
62/// the pointee type of a PointerType node) and, if any of those operand nodes
63/// were changed by the transformation, invokes the rebuild operation to create
64/// a new AST node.
65///
Mike Stump1eb44332009-09-09 15:08:12 +000066/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000067/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000068/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
69/// TransformTemplateName(), or TransformTemplateArgument() with entirely
70/// new implementations.
71///
72/// For more fine-grained transformations, subclasses can replace any of the
73/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000074/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000075/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000076/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000077/// parameters. Additionally, subclasses can override the \c RebuildXXX
78/// functions to control how AST nodes are rebuilt when their operands change.
79/// By default, \c TreeTransform will invoke semantic analysis to rebuild
80/// AST nodes. However, certain other tree transformations (e.g, cloning) may
81/// be able to use more efficient rebuild steps.
82///
83/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000084/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000085/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
86/// operands have not changed (\c AlwaysRebuild()), and customize the
87/// default locations and entity names used for type-checking
88/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000089template<typename Derived>
90class TreeTransform {
91protected:
92 Sema &SemaRef;
Mike Stump1eb44332009-09-09 15:08:12 +000093
94public:
Douglas Gregor577f75a2009-08-04 16:50:30 +000095 /// \brief Initializes a new tree transformer.
96 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +000097
Douglas Gregor577f75a2009-08-04 16:50:30 +000098 /// \brief Retrieves a reference to the derived class.
99 Derived &getDerived() { return static_cast<Derived&>(*this); }
100
101 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000102 const Derived &getDerived() const {
103 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000104 }
105
John McCall60d7b3a2010-08-24 06:29:42 +0000106 static inline ExprResult Owned(Expr *E) { return E; }
107 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000108
Douglas Gregor577f75a2009-08-04 16:50:30 +0000109 /// \brief Retrieves a reference to the semantic analysis object used for
110 /// this tree transform.
111 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000112
Douglas Gregor577f75a2009-08-04 16:50:30 +0000113 /// \brief Whether the transformation should always rebuild AST nodes, even
114 /// if none of the children have changed.
115 ///
116 /// Subclasses may override this function to specify when the transformation
117 /// should rebuild all AST nodes.
118 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000119
Douglas Gregor577f75a2009-08-04 16:50:30 +0000120 /// \brief Returns the location of the entity being transformed, if that
121 /// information was not available elsewhere in the AST.
122 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000123 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 /// provide an alternative implementation that provides better location
125 /// information.
126 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000127
Douglas Gregor577f75a2009-08-04 16:50:30 +0000128 /// \brief Returns the name of the entity being transformed, if that
129 /// information was not available elsewhere in the AST.
130 ///
131 /// By default, returns an empty name. Subclasses can provide an alternative
132 /// implementation with a more precise name.
133 DeclarationName getBaseEntity() { return DeclarationName(); }
134
Douglas Gregorb98b1992009-08-11 05:31:07 +0000135 /// \brief Sets the "base" location and entity when that
136 /// information is known based on another transformation.
137 ///
138 /// By default, the source location and entity are ignored. Subclasses can
139 /// override this function to provide a customized implementation.
140 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000141
Douglas Gregorb98b1992009-08-11 05:31:07 +0000142 /// \brief RAII object that temporarily sets the base location and entity
143 /// used for reporting diagnostics in types.
144 class TemporaryBase {
145 TreeTransform &Self;
146 SourceLocation OldLocation;
147 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000148
Douglas Gregorb98b1992009-08-11 05:31:07 +0000149 public:
150 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000151 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000152 OldLocation = Self.getDerived().getBaseLocation();
153 OldEntity = Self.getDerived().getBaseEntity();
154 Self.getDerived().setBase(Location, Entity);
155 }
Mike Stump1eb44332009-09-09 15:08:12 +0000156
Douglas Gregorb98b1992009-08-11 05:31:07 +0000157 ~TemporaryBase() {
158 Self.getDerived().setBase(OldLocation, OldEntity);
159 }
160 };
Mike Stump1eb44332009-09-09 15:08:12 +0000161
162 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000163 /// transformed.
164 ///
165 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000166 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000167 /// not change. For example, template instantiation need not traverse
168 /// non-dependent types.
169 bool AlreadyTransformed(QualType T) {
170 return T.isNull();
171 }
172
Douglas Gregor6eef5192009-12-14 19:27:10 +0000173 /// \brief Determine whether the given call argument should be dropped, e.g.,
174 /// because it is a default argument.
175 ///
176 /// Subclasses can provide an alternative implementation of this routine to
177 /// determine which kinds of call arguments get dropped. By default,
178 /// CXXDefaultArgument nodes are dropped (prior to transformation).
179 bool DropCallArgument(Expr *E) {
180 return E->isDefaultArgument();
181 }
Sean Huntc3021132010-05-05 15:23:54 +0000182
Douglas Gregor577f75a2009-08-04 16:50:30 +0000183 /// \brief Transforms the given type into another type.
184 ///
John McCalla2becad2009-10-21 00:40:46 +0000185 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000186 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000187 /// function. This is expensive, but we don't mind, because
188 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000189 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000190 ///
191 /// \returns the transformed type.
Douglas Gregor124b8782010-02-16 19:09:40 +0000192 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000193
John McCalla2becad2009-10-21 00:40:46 +0000194 /// \brief Transforms the given type-with-location into a new
195 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000196 ///
John McCalla2becad2009-10-21 00:40:46 +0000197 /// By default, this routine transforms a type by delegating to the
198 /// appropriate TransformXXXType to build a new type. Subclasses
199 /// may override this function (to take over all type
200 /// transformations) or some set of the TransformXXXType functions
201 /// to alter the transformation.
Sean Huntc3021132010-05-05 15:23:54 +0000202 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
Douglas Gregor124b8782010-02-16 19:09:40 +0000203 QualType ObjectType = QualType());
John McCalla2becad2009-10-21 00:40:46 +0000204
205 /// \brief Transform the given type-with-location into a new
206 /// type, collecting location information in the given builder
207 /// as necessary.
208 ///
Sean Huntc3021132010-05-05 15:23:54 +0000209 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +0000210 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000211
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000212 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000213 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000214 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000215 /// appropriate TransformXXXStmt function to transform a specific kind of
216 /// statement or the TransformExpr() function to transform an expression.
217 /// Subclasses may override this function to transform statements using some
218 /// other mechanism.
219 ///
220 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000221 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000222
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000223 /// \brief Transform the given expression.
224 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000225 /// By default, this routine transforms an expression by delegating to the
226 /// appropriate TransformXXXExpr function to build a new expression.
227 /// Subclasses may override this function to transform expressions using some
228 /// other mechanism.
229 ///
230 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000231 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000232
Douglas Gregor577f75a2009-08-04 16:50:30 +0000233 /// \brief Transform the given declaration, which is referenced from a type
234 /// or expression.
235 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000236 /// By default, acts as the identity function on declarations. Subclasses
237 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000238 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000239
240 /// \brief Transform the definition of the given declaration.
241 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000242 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000243 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000244 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
245 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000246 }
Mike Stump1eb44332009-09-09 15:08:12 +0000247
Douglas Gregor6cd21982009-10-20 05:58:46 +0000248 /// \brief Transform the given declaration, which was the first part of a
249 /// nested-name-specifier in a member access expression.
250 ///
Sean Huntc3021132010-05-05 15:23:54 +0000251 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000252 /// identifier in a nested-name-specifier of a member access expression, e.g.,
253 /// the \c T in \c x->T::member
254 ///
255 /// By default, invokes TransformDecl() to transform the declaration.
256 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000257 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
258 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000259 }
Sean Huntc3021132010-05-05 15:23:54 +0000260
Douglas Gregor577f75a2009-08-04 16:50:30 +0000261 /// \brief Transform the given nested-name-specifier.
262 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000263 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000264 /// nested-name-specifier. Subclasses may override this function to provide
265 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000266 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000267 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000268 QualType ObjectType = QualType(),
269 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000270
Douglas Gregor81499bb2009-09-03 22:13:48 +0000271 /// \brief Transform the given declaration name.
272 ///
273 /// By default, transforms the types of conversion function, constructor,
274 /// and destructor names and then (if needed) rebuilds the declaration name.
275 /// Identifiers and selectors are returned unmodified. Sublcasses may
276 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000277 DeclarationNameInfo
278 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
279 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000280
Douglas Gregor577f75a2009-08-04 16:50:30 +0000281 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000282 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000283 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000284 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000285 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000286 TemplateName TransformTemplateName(TemplateName Name,
287 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000288
Douglas Gregor577f75a2009-08-04 16:50:30 +0000289 /// \brief Transform the given template argument.
290 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000291 /// By default, this operation transforms the type, expression, or
292 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000293 /// new template argument from the transformed result. Subclasses may
294 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000295 ///
296 /// Returns true if there was an error.
297 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
298 TemplateArgumentLoc &Output);
299
300 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
301 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
302 TemplateArgumentLoc &ArgLoc);
303
John McCalla93c9342009-12-07 02:54:59 +0000304 /// \brief Fakes up a TypeSourceInfo for a type.
305 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
306 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000307 getDerived().getBaseLocation());
308 }
Mike Stump1eb44332009-09-09 15:08:12 +0000309
John McCalla2becad2009-10-21 00:40:46 +0000310#define ABSTRACT_TYPELOC(CLASS, PARENT)
311#define TYPELOC(CLASS, PARENT) \
Douglas Gregor124b8782010-02-16 19:09:40 +0000312 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
313 QualType ObjectType = QualType());
John McCalla2becad2009-10-21 00:40:46 +0000314#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000315
John McCall21ef0fa2010-03-11 09:03:00 +0000316 /// \brief Transforms the parameters of a function type into the
317 /// given vectors.
318 ///
319 /// The result vectors should be kept in sync; null entries in the
320 /// variables vector are acceptable.
321 ///
322 /// Return true on error.
323 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
324 llvm::SmallVectorImpl<QualType> &PTypes,
325 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
326
327 /// \brief Transforms a single function-type parameter. Return null
328 /// on error.
329 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
330
Sean Huntc3021132010-05-05 15:23:54 +0000331 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +0000332 QualType ObjectType);
John McCall85737a72009-10-30 00:06:24 +0000333
Sean Huntc3021132010-05-05 15:23:54 +0000334 QualType
Douglas Gregordd62b152009-10-19 22:04:39 +0000335 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
336 QualType ObjectType);
John McCall833ca992009-10-29 08:12:44 +0000337
John McCall60d7b3a2010-08-24 06:29:42 +0000338 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
339 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000340
Douglas Gregor43959a92009-08-20 07:17:43 +0000341#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000342 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000343#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000344 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000345#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000346#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000347
Douglas Gregor577f75a2009-08-04 16:50:30 +0000348 /// \brief Build a new pointer type given its pointee type.
349 ///
350 /// By default, performs semantic analysis when building the pointer type.
351 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000352 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000353
354 /// \brief Build a new block pointer type given its pointee type.
355 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000356 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000357 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000358 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000359
John McCall85737a72009-10-30 00:06:24 +0000360 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000361 ///
John McCall85737a72009-10-30 00:06:24 +0000362 /// By default, performs semantic analysis when building the
363 /// reference type. Subclasses may override this routine to provide
364 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000365 ///
John McCall85737a72009-10-30 00:06:24 +0000366 /// \param LValue whether the type was written with an lvalue sigil
367 /// or an rvalue sigil.
368 QualType RebuildReferenceType(QualType ReferentType,
369 bool LValue,
370 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000371
Douglas Gregor577f75a2009-08-04 16:50:30 +0000372 /// \brief Build a new member pointer type given the pointee type and the
373 /// class type it refers into.
374 ///
375 /// By default, performs semantic analysis when building the member pointer
376 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000377 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
378 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000379
Douglas Gregor577f75a2009-08-04 16:50:30 +0000380 /// \brief Build a new array type given the element type, size
381 /// modifier, size of the array (if known), size expression, and index type
382 /// qualifiers.
383 ///
384 /// By default, performs semantic analysis when building the array type.
385 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000386 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000387 QualType RebuildArrayType(QualType ElementType,
388 ArrayType::ArraySizeModifier SizeMod,
389 const llvm::APInt *Size,
390 Expr *SizeExpr,
391 unsigned IndexTypeQuals,
392 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000393
Douglas Gregor577f75a2009-08-04 16:50:30 +0000394 /// \brief Build a new constant array type given the element type, size
395 /// modifier, (known) size of the array, and index type qualifiers.
396 ///
397 /// By default, performs semantic analysis when building the array type.
398 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000399 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000400 ArrayType::ArraySizeModifier SizeMod,
401 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000402 unsigned IndexTypeQuals,
403 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000404
Douglas Gregor577f75a2009-08-04 16:50:30 +0000405 /// \brief Build a new incomplete array type given the element type, size
406 /// modifier, and index type qualifiers.
407 ///
408 /// By default, performs semantic analysis when building the array type.
409 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000410 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000411 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000412 unsigned IndexTypeQuals,
413 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000414
Mike Stump1eb44332009-09-09 15:08:12 +0000415 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000416 /// size modifier, size expression, and index type qualifiers.
417 ///
418 /// By default, performs semantic analysis when building the array type.
419 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000420 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000421 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000422 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000423 unsigned IndexTypeQuals,
424 SourceRange BracketsRange);
425
Mike Stump1eb44332009-09-09 15:08:12 +0000426 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000427 /// size modifier, size expression, and index type qualifiers.
428 ///
429 /// By default, performs semantic analysis when building the array type.
430 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000431 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000432 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000433 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000434 unsigned IndexTypeQuals,
435 SourceRange BracketsRange);
436
437 /// \brief Build a new vector type given the element type and
438 /// number of elements.
439 ///
440 /// By default, performs semantic analysis when building the vector type.
441 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000442 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Chris Lattner788b0fd2010-06-23 06:00:24 +0000443 VectorType::AltiVecSpecific AltiVecSpec);
Mike Stump1eb44332009-09-09 15:08:12 +0000444
Douglas Gregor577f75a2009-08-04 16:50:30 +0000445 /// \brief Build a new extended vector type given the element type and
446 /// number of elements.
447 ///
448 /// By default, performs semantic analysis when building the vector type.
449 /// Subclasses may override this routine to provide different behavior.
450 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
451 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000452
453 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000454 /// given the element type and number of elements.
455 ///
456 /// By default, performs semantic analysis when building the vector type.
457 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000458 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000459 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000460 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000461
Douglas Gregor577f75a2009-08-04 16:50:30 +0000462 /// \brief Build a new function type.
463 ///
464 /// By default, performs semantic analysis when building the function type.
465 /// Subclasses may override this routine to provide different behavior.
466 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000467 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000468 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000469 bool Variadic, unsigned Quals,
470 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000471
John McCalla2becad2009-10-21 00:40:46 +0000472 /// \brief Build a new unprototyped function type.
473 QualType RebuildFunctionNoProtoType(QualType ResultType);
474
John McCalled976492009-12-04 22:46:56 +0000475 /// \brief Rebuild an unresolved typename type, given the decl that
476 /// the UnresolvedUsingTypenameDecl was transformed to.
477 QualType RebuildUnresolvedUsingType(Decl *D);
478
Douglas Gregor577f75a2009-08-04 16:50:30 +0000479 /// \brief Build a new typedef type.
480 QualType RebuildTypedefType(TypedefDecl *Typedef) {
481 return SemaRef.Context.getTypeDeclType(Typedef);
482 }
483
484 /// \brief Build a new class/struct/union type.
485 QualType RebuildRecordType(RecordDecl *Record) {
486 return SemaRef.Context.getTypeDeclType(Record);
487 }
488
489 /// \brief Build a new Enum type.
490 QualType RebuildEnumType(EnumDecl *Enum) {
491 return SemaRef.Context.getTypeDeclType(Enum);
492 }
John McCall7da24312009-09-05 00:15:47 +0000493
Mike Stump1eb44332009-09-09 15:08:12 +0000494 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000495 ///
496 /// By default, performs semantic analysis when building the typeof type.
497 /// Subclasses may override this routine to provide different behavior.
John McCall9ae2f072010-08-23 23:25:46 +0000498 QualType RebuildTypeOfExprType(Expr *Underlying);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000499
Mike Stump1eb44332009-09-09 15:08:12 +0000500 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000501 ///
502 /// By default, builds a new TypeOfType with the given underlying type.
503 QualType RebuildTypeOfType(QualType Underlying);
504
Mike Stump1eb44332009-09-09 15:08:12 +0000505 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000506 ///
507 /// By default, performs semantic analysis when building the decltype type.
508 /// Subclasses may override this routine to provide different behavior.
John McCall9ae2f072010-08-23 23:25:46 +0000509 QualType RebuildDecltypeType(Expr *Underlying);
Mike Stump1eb44332009-09-09 15:08:12 +0000510
Douglas Gregor577f75a2009-08-04 16:50:30 +0000511 /// \brief Build a new template specialization type.
512 ///
513 /// By default, performs semantic analysis when building the template
514 /// specialization type. Subclasses may override this routine to provide
515 /// different behavior.
516 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000517 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000518 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000519
Douglas Gregor577f75a2009-08-04 16:50:30 +0000520 /// \brief Build a new qualified name type.
521 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000522 /// By default, builds a new ElaboratedType type from the keyword,
523 /// the nested-name-specifier and the named type.
524 /// Subclasses may override this routine to provide different behavior.
525 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
526 NestedNameSpecifier *NNS, QualType Named) {
527 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000528 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000529
530 /// \brief Build a new typename type that refers to a template-id.
531 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000532 /// By default, builds a new DependentNameType type from the
533 /// nested-name-specifier and the given type. Subclasses may override
534 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000535 QualType RebuildDependentTemplateSpecializationType(
536 ElaboratedTypeKeyword Keyword,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000537 NestedNameSpecifier *Qualifier,
538 SourceRange QualifierRange,
John McCall33500952010-06-11 00:33:02 +0000539 const IdentifierInfo *Name,
540 SourceLocation NameLoc,
541 const TemplateArgumentListInfo &Args) {
542 // Rebuild the template name.
543 // TODO: avoid TemplateName abstraction
544 TemplateName InstName =
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000545 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
546 QualType());
John McCall33500952010-06-11 00:33:02 +0000547
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000548 if (InstName.isNull())
549 return QualType();
550
John McCall33500952010-06-11 00:33:02 +0000551 // If it's still dependent, make a dependent specialization.
552 if (InstName.getAsDependentTemplateName())
553 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000554 Keyword, Qualifier, Name, Args);
John McCall33500952010-06-11 00:33:02 +0000555
556 // Otherwise, make an elaborated type wrapping a non-dependent
557 // specialization.
558 QualType T =
559 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
560 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000561
Abramo Bagnara22f638a2010-08-10 13:46:45 +0000562 // NOTE: NNS is already recorded in template specialization type T.
563 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000564 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000565
566 /// \brief Build a new typename type that refers to an identifier.
567 ///
568 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000569 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000570 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000571 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000572 NestedNameSpecifier *NNS,
573 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000574 SourceLocation KeywordLoc,
575 SourceRange NNSRange,
576 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000577 CXXScopeSpec SS;
578 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000579 SS.setRange(NNSRange);
580
Douglas Gregor40336422010-03-31 22:19:08 +0000581 if (NNS->isDependent()) {
582 // If the name is still dependent, just build a new dependent name type.
583 if (!SemaRef.computeDeclContext(SS))
584 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
585 }
586
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000587 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000588 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
589 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000590
591 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
592
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000593 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000594 // into a non-dependent elaborated-type-specifier. Find the tag we're
595 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000596 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000597 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
598 if (!DC)
599 return QualType();
600
John McCall56138762010-05-27 06:40:31 +0000601 if (SemaRef.RequireCompleteDeclContext(SS, DC))
602 return QualType();
603
Douglas Gregor40336422010-03-31 22:19:08 +0000604 TagDecl *Tag = 0;
605 SemaRef.LookupQualifiedName(Result, DC);
606 switch (Result.getResultKind()) {
607 case LookupResult::NotFound:
608 case LookupResult::NotFoundInCurrentInstantiation:
609 break;
Sean Huntc3021132010-05-05 15:23:54 +0000610
Douglas Gregor40336422010-03-31 22:19:08 +0000611 case LookupResult::Found:
612 Tag = Result.getAsSingle<TagDecl>();
613 break;
Sean Huntc3021132010-05-05 15:23:54 +0000614
Douglas Gregor40336422010-03-31 22:19:08 +0000615 case LookupResult::FoundOverloaded:
616 case LookupResult::FoundUnresolvedValue:
617 llvm_unreachable("Tag lookup cannot find non-tags");
618 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000619
Douglas Gregor40336422010-03-31 22:19:08 +0000620 case LookupResult::Ambiguous:
621 // Let the LookupResult structure handle ambiguities.
622 return QualType();
623 }
624
625 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000626 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000627 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000628 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000629 return QualType();
630 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000631
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000632 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
633 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000634 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
635 return QualType();
636 }
637
638 // Build the elaborated-type-specifier type.
639 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000640 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000641 }
Mike Stump1eb44332009-09-09 15:08:12 +0000642
Douglas Gregordcee1a12009-08-06 05:28:30 +0000643 /// \brief Build a new nested-name-specifier given the prefix and an
644 /// identifier that names the next step in the nested-name-specifier.
645 ///
646 /// By default, performs semantic analysis when building the new
647 /// nested-name-specifier. Subclasses may override this routine to provide
648 /// different behavior.
649 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
650 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000651 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000652 QualType ObjectType,
653 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000654
655 /// \brief Build a new nested-name-specifier given the prefix and the
656 /// namespace named in the next step in the nested-name-specifier.
657 ///
658 /// By default, performs semantic analysis when building the new
659 /// nested-name-specifier. Subclasses may override this routine to provide
660 /// different behavior.
661 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
662 SourceRange Range,
663 NamespaceDecl *NS);
664
665 /// \brief Build a new nested-name-specifier given the prefix and the
666 /// type named in the next step in the nested-name-specifier.
667 ///
668 /// By default, performs semantic analysis when building the new
669 /// nested-name-specifier. Subclasses may override this routine to provide
670 /// different behavior.
671 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
672 SourceRange Range,
673 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000674 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000675
676 /// \brief Build a new template name given a nested name specifier, a flag
677 /// indicating whether the "template" keyword was provided, and the template
678 /// that the template name refers to.
679 ///
680 /// By default, builds the new template name directly. Subclasses may override
681 /// this routine to provide different behavior.
682 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
683 bool TemplateKW,
684 TemplateDecl *Template);
685
Douglas Gregord1067e52009-08-06 06:41:21 +0000686 /// \brief Build a new template name given a nested name specifier and the
687 /// name that is referred to as a template.
688 ///
689 /// By default, performs semantic analysis to determine whether the name can
690 /// be resolved to a specific template, then builds the appropriate kind of
691 /// template name. Subclasses may override this routine to provide different
692 /// behavior.
693 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000694 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000695 const IdentifierInfo &II,
696 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000697
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000698 /// \brief Build a new template name given a nested name specifier and the
699 /// overloaded operator name that is referred to as a template.
700 ///
701 /// By default, performs semantic analysis to determine whether the name can
702 /// be resolved to a specific template, then builds the appropriate kind of
703 /// template name. Subclasses may override this routine to provide different
704 /// behavior.
705 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
706 OverloadedOperatorKind Operator,
707 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000708
Douglas Gregor43959a92009-08-20 07:17:43 +0000709 /// \brief Build a new compound statement.
710 ///
711 /// By default, performs semantic analysis to build the new statement.
712 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000713 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000714 MultiStmtArg Statements,
715 SourceLocation RBraceLoc,
716 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000717 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000718 IsStmtExpr);
719 }
720
721 /// \brief Build a new case statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000725 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000726 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000727 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000728 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000729 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000730 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000731 ColonLoc);
732 }
Mike Stump1eb44332009-09-09 15:08:12 +0000733
Douglas Gregor43959a92009-08-20 07:17:43 +0000734 /// \brief Attach the body to a new case statement.
735 ///
736 /// By default, performs semantic analysis to build the new statement.
737 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000738 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000739 getSema().ActOnCaseStmtBody(S, Body);
740 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000741 }
Mike Stump1eb44332009-09-09 15:08:12 +0000742
Douglas Gregor43959a92009-08-20 07:17:43 +0000743 /// \brief Build a new default statement.
744 ///
745 /// By default, performs semantic analysis to build the new statement.
746 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000747 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000748 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000749 Stmt *SubStmt) {
750 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000751 /*CurScope=*/0);
752 }
Mike Stump1eb44332009-09-09 15:08:12 +0000753
Douglas Gregor43959a92009-08-20 07:17:43 +0000754 /// \brief Build a new label statement.
755 ///
756 /// By default, performs semantic analysis to build the new statement.
757 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000758 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000759 IdentifierInfo *Id,
760 SourceLocation ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +0000761 Stmt *SubStmt, bool HasUnusedAttr) {
762 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
763 HasUnusedAttr);
Douglas Gregor43959a92009-08-20 07:17:43 +0000764 }
Mike Stump1eb44332009-09-09 15:08:12 +0000765
Douglas Gregor43959a92009-08-20 07:17:43 +0000766 /// \brief Build a new "if" statement.
767 ///
768 /// By default, performs semantic analysis to build the new statement.
769 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000770 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCall9ae2f072010-08-23 23:25:46 +0000771 VarDecl *CondVar, Stmt *Then,
772 SourceLocation ElseLoc, Stmt *Else) {
773 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000774 }
Mike Stump1eb44332009-09-09 15:08:12 +0000775
Douglas Gregor43959a92009-08-20 07:17:43 +0000776 /// \brief Start building a new switch statement.
777 ///
778 /// By default, performs semantic analysis to build the new statement.
779 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000780 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000781 Expr *Cond, VarDecl *CondVar) {
782 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +0000783 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +0000784 }
Mike Stump1eb44332009-09-09 15:08:12 +0000785
Douglas Gregor43959a92009-08-20 07:17:43 +0000786 /// \brief Attach the body to the switch statement.
787 ///
788 /// By default, performs semantic analysis to build the new statement.
789 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000790 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000791 Stmt *Switch, Stmt *Body) {
792 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000793 }
794
795 /// \brief Build a new while statement.
796 ///
797 /// By default, performs semantic analysis to build the new statement.
798 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000799 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000800 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000801 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000802 Stmt *Body) {
803 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000804 }
Mike Stump1eb44332009-09-09 15:08:12 +0000805
Douglas Gregor43959a92009-08-20 07:17:43 +0000806 /// \brief Build a new do-while statement.
807 ///
808 /// By default, performs semantic analysis to build the new statement.
809 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000810 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregor43959a92009-08-20 07:17:43 +0000811 SourceLocation WhileLoc,
812 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000813 Expr *Cond,
Douglas Gregor43959a92009-08-20 07:17:43 +0000814 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000815 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
816 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +0000817 }
818
819 /// \brief Build a new for statement.
820 ///
821 /// By default, performs semantic analysis to build the new statement.
822 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000823 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000824 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000825 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000826 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCall9ae2f072010-08-23 23:25:46 +0000827 SourceLocation RParenLoc, Stmt *Body) {
828 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCalld226f652010-08-21 09:40:31 +0000829 CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000830 Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000831 }
Mike Stump1eb44332009-09-09 15:08:12 +0000832
Douglas Gregor43959a92009-08-20 07:17:43 +0000833 /// \brief Build a new goto statement.
834 ///
835 /// By default, performs semantic analysis to build the new statement.
836 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000837 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000838 SourceLocation LabelLoc,
839 LabelStmt *Label) {
840 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
841 }
842
843 /// \brief Build a new indirect goto statement.
844 ///
845 /// By default, performs semantic analysis to build the new statement.
846 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000847 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000848 SourceLocation StarLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000849 Expr *Target) {
850 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +0000851 }
Mike Stump1eb44332009-09-09 15:08:12 +0000852
Douglas Gregor43959a92009-08-20 07:17:43 +0000853 /// \brief Build a new return statement.
854 ///
855 /// By default, performs semantic analysis to build the new statement.
856 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000857 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000858 Expr *Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000859
John McCall9ae2f072010-08-23 23:25:46 +0000860 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +0000861 }
Mike Stump1eb44332009-09-09 15:08:12 +0000862
Douglas Gregor43959a92009-08-20 07:17:43 +0000863 /// \brief Build a new declaration statement.
864 ///
865 /// By default, performs semantic analysis to build the new statement.
866 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000867 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000868 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000869 SourceLocation EndLoc) {
870 return getSema().Owned(
871 new (getSema().Context) DeclStmt(
872 DeclGroupRef::Create(getSema().Context,
873 Decls, NumDecls),
874 StartLoc, EndLoc));
875 }
Mike Stump1eb44332009-09-09 15:08:12 +0000876
Anders Carlsson703e3942010-01-24 05:50:09 +0000877 /// \brief Build a new inline asm statement.
878 ///
879 /// By default, performs semantic analysis to build the new statement.
880 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000881 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +0000882 bool IsSimple,
883 bool IsVolatile,
884 unsigned NumOutputs,
885 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000886 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000887 MultiExprArg Constraints,
888 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +0000889 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +0000890 MultiExprArg Clobbers,
891 SourceLocation RParenLoc,
892 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000893 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000894 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +0000895 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +0000896 RParenLoc, MSAsm);
897 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000898
899 /// \brief Build a new Objective-C @try statement.
900 ///
901 /// By default, performs semantic analysis to build the new statement.
902 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000903 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000904 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000905 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +0000906 Stmt *Finally) {
907 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
908 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000909 }
910
Douglas Gregorbe270a02010-04-26 17:57:08 +0000911 /// \brief Rebuild an Objective-C exception declaration.
912 ///
913 /// By default, performs semantic analysis to build the new declaration.
914 /// Subclasses may override this routine to provide different behavior.
915 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
916 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +0000917 return getSema().BuildObjCExceptionDecl(TInfo, T,
918 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +0000919 ExceptionDecl->getLocation());
920 }
Sean Huntc3021132010-05-05 15:23:54 +0000921
Douglas Gregorbe270a02010-04-26 17:57:08 +0000922 /// \brief Build a new Objective-C @catch statement.
923 ///
924 /// By default, performs semantic analysis to build the new statement.
925 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000926 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +0000927 SourceLocation RParenLoc,
928 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +0000929 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +0000930 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000931 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +0000932 }
Sean Huntc3021132010-05-05 15:23:54 +0000933
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000934 /// \brief Build a new Objective-C @finally statement.
935 ///
936 /// By default, performs semantic analysis to build the new statement.
937 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000938 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000939 Stmt *Body) {
940 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000941 }
Sean Huntc3021132010-05-05 15:23:54 +0000942
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000943 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +0000944 ///
945 /// By default, performs semantic analysis to build the new statement.
946 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000947 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000948 Expr *Operand) {
949 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +0000950 }
Sean Huntc3021132010-05-05 15:23:54 +0000951
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000952 /// \brief Build a new Objective-C @synchronized statement.
953 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000954 /// By default, performs semantic analysis to build the new statement.
955 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000956 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000957 Expr *Object,
958 Stmt *Body) {
959 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
960 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000961 }
Douglas Gregorc3203e72010-04-22 23:10:45 +0000962
963 /// \brief Build a new Objective-C fast enumeration statement.
964 ///
965 /// By default, performs semantic analysis to build the new statement.
966 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000967 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +0000968 SourceLocation LParenLoc,
969 Stmt *Element,
970 Expr *Collection,
971 SourceLocation RParenLoc,
972 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +0000973 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000974 Element,
975 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +0000976 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000977 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +0000978 }
Sean Huntc3021132010-05-05 15:23:54 +0000979
Douglas Gregor43959a92009-08-20 07:17:43 +0000980 /// \brief Build a new C++ exception declaration.
981 ///
982 /// By default, performs semantic analysis to build the new decaration.
983 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor83cb9422010-09-09 17:09:21 +0000984 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +0000985 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000986 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +0000987 SourceLocation Loc) {
988 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-08-20 07:17:43 +0000989 }
990
991 /// \brief Build a new C++ catch statement.
992 ///
993 /// By default, performs semantic analysis to build the new statement.
994 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000995 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +0000996 VarDecl *ExceptionDecl,
997 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +0000998 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
999 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001000 }
Mike Stump1eb44332009-09-09 15:08:12 +00001001
Douglas Gregor43959a92009-08-20 07:17:43 +00001002 /// \brief Build a new C++ try statement.
1003 ///
1004 /// By default, performs semantic analysis to build the new statement.
1005 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001006 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001007 Stmt *TryBlock,
1008 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001009 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001010 }
Mike Stump1eb44332009-09-09 15:08:12 +00001011
Douglas Gregorb98b1992009-08-11 05:31:07 +00001012 /// \brief Build a new expression that references a declaration.
1013 ///
1014 /// By default, performs semantic analysis to build the new expression.
1015 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001016 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001017 LookupResult &R,
1018 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001019 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1020 }
1021
1022
1023 /// \brief Build a new expression that references a declaration.
1024 ///
1025 /// By default, performs semantic analysis to build the new expression.
1026 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001027 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001028 SourceRange QualifierRange,
1029 ValueDecl *VD,
1030 const DeclarationNameInfo &NameInfo,
1031 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001032 CXXScopeSpec SS;
1033 SS.setScopeRep(Qualifier);
1034 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001035
1036 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001037
1038 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001039 }
Mike Stump1eb44332009-09-09 15:08:12 +00001040
Douglas Gregorb98b1992009-08-11 05:31:07 +00001041 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001042 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001043 /// By default, performs semantic analysis to build the new expression.
1044 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001045 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001046 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001047 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001048 }
1049
Douglas Gregora71d8192009-09-04 17:36:40 +00001050 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001051 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001052 /// By default, performs semantic analysis to build the new expression.
1053 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001054 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001055 SourceLocation OperatorLoc,
1056 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001057 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001058 SourceRange QualifierRange,
1059 TypeSourceInfo *ScopeType,
1060 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001061 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001062 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001063
Douglas Gregorb98b1992009-08-11 05:31:07 +00001064 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001065 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001066 /// By default, performs semantic analysis to build the new expression.
1067 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001068 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001069 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001070 Expr *SubExpr) {
1071 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001072 }
Mike Stump1eb44332009-09-09 15:08:12 +00001073
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001074 /// \brief Build a new builtin offsetof expression.
1075 ///
1076 /// By default, performs semantic analysis to build the new expression.
1077 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001078 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001079 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001080 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001081 unsigned NumComponents,
1082 SourceLocation RParenLoc) {
1083 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1084 NumComponents, RParenLoc);
1085 }
Sean Huntc3021132010-05-05 15:23:54 +00001086
Douglas Gregorb98b1992009-08-11 05:31:07 +00001087 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001088 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001089 /// By default, performs semantic analysis to build the new expression.
1090 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001091 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001092 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001093 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001094 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001095 }
1096
Mike Stump1eb44332009-09-09 15:08:12 +00001097 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001098 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001099 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001100 /// By default, performs semantic analysis to build the new expression.
1101 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001102 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001103 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001104 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001105 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001106 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001107 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001108
Douglas Gregorb98b1992009-08-11 05:31:07 +00001109 return move(Result);
1110 }
Mike Stump1eb44332009-09-09 15:08:12 +00001111
Douglas Gregorb98b1992009-08-11 05:31:07 +00001112 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001113 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001114 /// By default, performs semantic analysis to build the new expression.
1115 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001116 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001117 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001118 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001119 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001120 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1121 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001122 RBracketLoc);
1123 }
1124
1125 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001126 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001127 /// By default, performs semantic analysis to build the new expression.
1128 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001129 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001130 MultiExprArg Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001131 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001132 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora1a04782010-09-09 16:33:13 +00001133 move(Args), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001134 }
1135
1136 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001137 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001138 /// By default, performs semantic analysis to build the new expression.
1139 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001140 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001141 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001142 NestedNameSpecifier *Qualifier,
1143 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001144 const DeclarationNameInfo &MemberNameInfo,
Eli Friedmanf595cc42009-12-04 06:40:45 +00001145 ValueDecl *Member,
John McCall6bb80172010-03-30 21:47:33 +00001146 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001147 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +00001148 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001149 if (!Member->getDeclName()) {
1150 // We have a reference to an unnamed field.
1151 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +00001152
John McCall9ae2f072010-08-23 23:25:46 +00001153 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001154 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001155 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001156
Mike Stump1eb44332009-09-09 15:08:12 +00001157 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001158 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001159 Member, MemberNameInfo,
Anders Carlssond8b285f2009-09-01 04:26:58 +00001160 cast<FieldDecl>(Member)->getType());
1161 return getSema().Owned(ME);
1162 }
Mike Stump1eb44332009-09-09 15:08:12 +00001163
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001164 CXXScopeSpec SS;
1165 if (Qualifier) {
1166 SS.setRange(QualifierRange);
1167 SS.setScopeRep(Qualifier);
1168 }
1169
John McCall9ae2f072010-08-23 23:25:46 +00001170 getSema().DefaultFunctionArrayConversion(Base);
1171 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001172
John McCall6bb80172010-03-30 21:47:33 +00001173 // FIXME: this involves duplicating earlier analysis in a lot of
1174 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001175 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001176 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001177 R.resolveKind();
1178
John McCall9ae2f072010-08-23 23:25:46 +00001179 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001180 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001181 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001182 }
Mike Stump1eb44332009-09-09 15:08:12 +00001183
Douglas Gregorb98b1992009-08-11 05:31:07 +00001184 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001185 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001186 /// By default, performs semantic analysis to build the new expression.
1187 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001188 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001189 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001190 Expr *LHS, Expr *RHS) {
1191 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001192 }
1193
1194 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001195 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001196 /// By default, performs semantic analysis to build the new expression.
1197 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001198 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001199 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001200 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001201 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001202 Expr *RHS) {
1203 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1204 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001205 }
1206
Douglas Gregorb98b1992009-08-11 05:31:07 +00001207 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001208 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001209 /// By default, performs semantic analysis to build the new expression.
1210 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001211 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001212 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001213 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001214 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001215 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001216 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001217 }
Mike Stump1eb44332009-09-09 15:08:12 +00001218
Douglas Gregorb98b1992009-08-11 05:31:07 +00001219 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001220 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001221 /// By default, performs semantic analysis to build the new expression.
1222 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001223 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001224 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001225 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001226 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001227 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001228 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001229 }
Mike Stump1eb44332009-09-09 15:08:12 +00001230
Douglas Gregorb98b1992009-08-11 05:31:07 +00001231 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001232 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001233 /// By default, performs semantic analysis to build the new expression.
1234 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001235 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001236 SourceLocation OpLoc,
1237 SourceLocation AccessorLoc,
1238 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001239
John McCall129e2df2009-11-30 22:42:35 +00001240 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001241 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001242 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001243 OpLoc, /*IsArrow*/ false,
1244 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001245 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001246 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001247 }
Mike Stump1eb44332009-09-09 15:08:12 +00001248
Douglas Gregorb98b1992009-08-11 05:31:07 +00001249 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001250 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001251 /// By default, performs semantic analysis to build the new expression.
1252 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001253 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001254 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001255 SourceLocation RBraceLoc,
1256 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001257 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001258 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1259 if (Result.isInvalid() || ResultTy->isDependentType())
1260 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001261
Douglas Gregore48319a2009-11-09 17:16:50 +00001262 // Patch in the result type we were given, which may have been computed
1263 // when the initial InitListExpr was built.
1264 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1265 ILE->setType(ResultTy);
1266 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001267 }
Mike Stump1eb44332009-09-09 15:08:12 +00001268
Douglas Gregorb98b1992009-08-11 05:31:07 +00001269 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001270 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001271 /// By default, performs semantic analysis to build the new expression.
1272 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001273 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001274 MultiExprArg ArrayExprs,
1275 SourceLocation EqualOrColonLoc,
1276 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001277 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001278 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001279 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001280 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001281 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001282 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001283
Douglas Gregorb98b1992009-08-11 05:31:07 +00001284 ArrayExprs.release();
1285 return move(Result);
1286 }
Mike Stump1eb44332009-09-09 15:08:12 +00001287
Douglas Gregorb98b1992009-08-11 05:31:07 +00001288 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001289 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001290 /// By default, builds the implicit value initialization without performing
1291 /// any semantic analysis. Subclasses may override this routine to provide
1292 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001293 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001294 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1295 }
Mike Stump1eb44332009-09-09 15:08:12 +00001296
Douglas Gregorb98b1992009-08-11 05:31:07 +00001297 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001298 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001299 /// By default, performs semantic analysis to build the new expression.
1300 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001301 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001302 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001303 SourceLocation RParenLoc) {
1304 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001305 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001306 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001307 }
1308
1309 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001310 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001311 /// By default, performs semantic analysis to build the new expression.
1312 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001313 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001314 MultiExprArg SubExprs,
1315 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001316 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001317 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001318 }
Mike Stump1eb44332009-09-09 15:08:12 +00001319
Douglas Gregorb98b1992009-08-11 05:31:07 +00001320 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001321 ///
1322 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001323 /// rather than attempting to map the label statement itself.
1324 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001325 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001326 SourceLocation LabelLoc,
1327 LabelStmt *Label) {
1328 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1329 }
Mike Stump1eb44332009-09-09 15:08:12 +00001330
Douglas Gregorb98b1992009-08-11 05:31:07 +00001331 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001332 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001333 /// By default, performs semantic analysis to build the new expression.
1334 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001335 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001336 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001337 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001338 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001339 }
Mike Stump1eb44332009-09-09 15:08:12 +00001340
Douglas Gregorb98b1992009-08-11 05:31:07 +00001341 /// \brief Build a new __builtin_types_compatible_p expression.
1342 ///
1343 /// By default, performs semantic analysis to build the new expression.
1344 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001345 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001346 TypeSourceInfo *TInfo1,
1347 TypeSourceInfo *TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001348 SourceLocation RParenLoc) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001349 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1350 TInfo1, TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001351 RParenLoc);
1352 }
Mike Stump1eb44332009-09-09 15:08:12 +00001353
Douglas Gregorb98b1992009-08-11 05:31:07 +00001354 /// \brief Build a new __builtin_choose_expr expression.
1355 ///
1356 /// By default, performs semantic analysis to build the new expression.
1357 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001358 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001359 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001360 SourceLocation RParenLoc) {
1361 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001362 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001363 RParenLoc);
1364 }
Mike Stump1eb44332009-09-09 15:08:12 +00001365
Douglas Gregorb98b1992009-08-11 05:31:07 +00001366 /// \brief Build a new overloaded operator call expression.
1367 ///
1368 /// By default, performs semantic analysis to build the new expression.
1369 /// The semantic analysis provides the behavior of template instantiation,
1370 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001371 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001372 /// argument-dependent lookup, etc. Subclasses may override this routine to
1373 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001374 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001375 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001376 Expr *Callee,
1377 Expr *First,
1378 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001379
1380 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001381 /// reinterpret_cast.
1382 ///
1383 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001384 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001385 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001386 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001387 Stmt::StmtClass Class,
1388 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001389 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001390 SourceLocation RAngleLoc,
1391 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001392 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001393 SourceLocation RParenLoc) {
1394 switch (Class) {
1395 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001396 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001397 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001398 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001399
1400 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001401 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001402 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001403 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001404
Douglas Gregorb98b1992009-08-11 05:31:07 +00001405 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001406 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001407 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001408 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001410
Douglas Gregorb98b1992009-08-11 05:31:07 +00001411 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001412 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001413 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001414 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001415
Douglas Gregorb98b1992009-08-11 05:31:07 +00001416 default:
1417 assert(false && "Invalid C++ named cast");
1418 break;
1419 }
Mike Stump1eb44332009-09-09 15:08:12 +00001420
John McCallf312b1e2010-08-26 23:41:50 +00001421 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001422 }
Mike Stump1eb44332009-09-09 15:08:12 +00001423
Douglas Gregorb98b1992009-08-11 05:31:07 +00001424 /// \brief Build a new C++ static_cast expression.
1425 ///
1426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001428 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001430 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 SourceLocation RAngleLoc,
1432 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001433 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001435 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001436 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001437 SourceRange(LAngleLoc, RAngleLoc),
1438 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 }
1440
1441 /// \brief Build a new C++ dynamic_cast expression.
1442 ///
1443 /// By default, performs semantic analysis to build the new expression.
1444 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001445 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001446 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001447 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001448 SourceLocation RAngleLoc,
1449 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001450 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001451 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001452 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001453 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001454 SourceRange(LAngleLoc, RAngleLoc),
1455 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 }
1457
1458 /// \brief Build a new C++ reinterpret_cast expression.
1459 ///
1460 /// By default, performs semantic analysis to build the new expression.
1461 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001462 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001464 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001465 SourceLocation RAngleLoc,
1466 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001467 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001468 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001469 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001470 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001471 SourceRange(LAngleLoc, RAngleLoc),
1472 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 }
1474
1475 /// \brief Build a new C++ const_cast expression.
1476 ///
1477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001479 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001481 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 SourceLocation RAngleLoc,
1483 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001484 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001486 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001487 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001488 SourceRange(LAngleLoc, RAngleLoc),
1489 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 }
Mike Stump1eb44332009-09-09 15:08:12 +00001491
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 /// \brief Build a new C++ functional-style cast expression.
1493 ///
1494 /// By default, performs semantic analysis to build the new expression.
1495 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001496 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1497 SourceLocation LParenLoc,
1498 Expr *Sub,
1499 SourceLocation RParenLoc) {
1500 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001501 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 RParenLoc);
1503 }
Mike Stump1eb44332009-09-09 15:08:12 +00001504
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 /// \brief Build a new C++ typeid(type) expression.
1506 ///
1507 /// By default, performs semantic analysis to build the new expression.
1508 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001509 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001510 SourceLocation TypeidLoc,
1511 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001513 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001514 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 }
Mike Stump1eb44332009-09-09 15:08:12 +00001516
Francois Pichet01b7c302010-09-08 12:20:18 +00001517
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 /// \brief Build a new C++ typeid(expr) expression.
1519 ///
1520 /// By default, performs semantic analysis to build the new expression.
1521 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001522 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001523 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001524 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001526 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001527 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001528 }
1529
Francois Pichet01b7c302010-09-08 12:20:18 +00001530 /// \brief Build a new C++ __uuidof(type) expression.
1531 ///
1532 /// By default, performs semantic analysis to build the new expression.
1533 /// Subclasses may override this routine to provide different behavior.
1534 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1535 SourceLocation TypeidLoc,
1536 TypeSourceInfo *Operand,
1537 SourceLocation RParenLoc) {
1538 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1539 RParenLoc);
1540 }
1541
1542 /// \brief Build a new C++ __uuidof(expr) expression.
1543 ///
1544 /// By default, performs semantic analysis to build the new expression.
1545 /// Subclasses may override this routine to provide different behavior.
1546 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1547 SourceLocation TypeidLoc,
1548 Expr *Operand,
1549 SourceLocation RParenLoc) {
1550 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1551 RParenLoc);
1552 }
1553
Douglas Gregorb98b1992009-08-11 05:31:07 +00001554 /// \brief Build a new C++ "this" expression.
1555 ///
1556 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001557 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001558 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001559 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001560 QualType ThisType,
1561 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001562 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001563 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1564 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 }
1566
1567 /// \brief Build a new C++ throw expression.
1568 ///
1569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001571 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001572 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 }
1574
1575 /// \brief Build a new C++ default-argument expression.
1576 ///
1577 /// By default, builds a new default-argument expression, which does not
1578 /// require any semantic analysis. Subclasses may override this routine to
1579 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001580 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001581 ParmVarDecl *Param) {
1582 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1583 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 }
1585
1586 /// \brief Build a new C++ zero-initialization expression.
1587 ///
1588 /// By default, performs semantic analysis to build the new expression.
1589 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001590 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1591 SourceLocation LParenLoc,
1592 SourceLocation RParenLoc) {
1593 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001594 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001595 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 }
Mike Stump1eb44332009-09-09 15:08:12 +00001597
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 /// \brief Build a new C++ "new" expression.
1599 ///
1600 /// By default, performs semantic analysis to build the new expression.
1601 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001602 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001603 bool UseGlobal,
1604 SourceLocation PlacementLParen,
1605 MultiExprArg PlacementArgs,
1606 SourceLocation PlacementRParen,
1607 SourceRange TypeIdParens,
1608 QualType AllocatedType,
1609 TypeSourceInfo *AllocatedTypeInfo,
1610 Expr *ArraySize,
1611 SourceLocation ConstructorLParen,
1612 MultiExprArg ConstructorArgs,
1613 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001614 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001615 PlacementLParen,
1616 move(PlacementArgs),
1617 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001618 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001619 AllocatedType,
1620 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001621 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 ConstructorLParen,
1623 move(ConstructorArgs),
1624 ConstructorRParen);
1625 }
Mike Stump1eb44332009-09-09 15:08:12 +00001626
Douglas Gregorb98b1992009-08-11 05:31:07 +00001627 /// \brief Build a new C++ "delete" expression.
1628 ///
1629 /// By default, performs semantic analysis to build the new expression.
1630 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001631 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 bool IsGlobalDelete,
1633 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001634 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001636 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 }
Mike Stump1eb44332009-09-09 15:08:12 +00001638
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 /// \brief Build a new unary type trait expression.
1640 ///
1641 /// By default, performs semantic analysis to build the new expression.
1642 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001643 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001644 SourceLocation StartLoc,
1645 TypeSourceInfo *T,
1646 SourceLocation RParenLoc) {
1647 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 }
1649
Mike Stump1eb44332009-09-09 15:08:12 +00001650 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001651 /// expression.
1652 ///
1653 /// By default, performs semantic analysis to build the new expression.
1654 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001655 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001657 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001658 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 CXXScopeSpec SS;
1660 SS.setRange(QualifierRange);
1661 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001662
1663 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001664 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001665 *TemplateArgs);
1666
Abramo Bagnara25777432010-08-11 22:01:17 +00001667 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 }
1669
1670 /// \brief Build a new template-id expression.
1671 ///
1672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001674 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001675 LookupResult &R,
1676 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001677 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001678 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 }
1680
1681 /// \brief Build a new object-construction expression.
1682 ///
1683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001685 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001686 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 CXXConstructorDecl *Constructor,
1688 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001689 MultiExprArg Args,
1690 bool RequiresZeroInit,
1691 CXXConstructExpr::ConstructionKind ConstructKind) {
John McCallca0408f2010-08-23 06:44:23 +00001692 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001693 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001694 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001695 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001696
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001697 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001698 move_arg(ConvertedArgs),
1699 RequiresZeroInit, ConstructKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 }
1701
1702 /// \brief Build a new object-construction expression.
1703 ///
1704 /// By default, performs semantic analysis to build the new expression.
1705 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001706 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1707 SourceLocation LParenLoc,
1708 MultiExprArg Args,
1709 SourceLocation RParenLoc) {
1710 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 LParenLoc,
1712 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 RParenLoc);
1714 }
1715
1716 /// \brief Build a new object-construction expression.
1717 ///
1718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001720 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1721 SourceLocation LParenLoc,
1722 MultiExprArg Args,
1723 SourceLocation RParenLoc) {
1724 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 LParenLoc,
1726 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001727 RParenLoc);
1728 }
Mike Stump1eb44332009-09-09 15:08:12 +00001729
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 /// \brief Build a new member reference expression.
1731 ///
1732 /// By default, performs semantic analysis to build the new expression.
1733 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001734 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001735 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 bool IsArrow,
1737 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001738 NestedNameSpecifier *Qualifier,
1739 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001740 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001741 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001742 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001743 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001744 SS.setRange(QualifierRange);
1745 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001746
John McCall9ae2f072010-08-23 23:25:46 +00001747 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001748 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001749 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001750 MemberNameInfo,
1751 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001752 }
1753
John McCall129e2df2009-11-30 22:42:35 +00001754 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001755 ///
1756 /// By default, performs semantic analysis to build the new expression.
1757 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001758 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001759 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001760 SourceLocation OperatorLoc,
1761 bool IsArrow,
1762 NestedNameSpecifier *Qualifier,
1763 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001764 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001765 LookupResult &R,
1766 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001767 CXXScopeSpec SS;
1768 SS.setRange(QualifierRange);
1769 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001770
John McCall9ae2f072010-08-23 23:25:46 +00001771 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001772 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001773 SS, FirstQualifierInScope,
1774 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001775 }
Mike Stump1eb44332009-09-09 15:08:12 +00001776
Sebastian Redl2e156222010-09-10 20:55:43 +00001777 /// \brief Build a new noexcept expression.
1778 ///
1779 /// By default, performs semantic analysis to build the new expression.
1780 /// Subclasses may override this routine to provide different behavior.
1781 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1782 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1783 }
1784
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 /// \brief Build a new Objective-C @encode expression.
1786 ///
1787 /// By default, performs semantic analysis to build the new expression.
1788 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001789 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001790 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001792 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001794 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795
Douglas Gregor92e986e2010-04-22 16:44:27 +00001796 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00001797 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001798 Selector Sel,
1799 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001800 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001801 MultiExprArg Args,
1802 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001803 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1804 ReceiverTypeInfo->getType(),
1805 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001806 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001807 move(Args));
1808 }
1809
1810 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00001811 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001812 Selector Sel,
1813 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001814 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001815 MultiExprArg Args,
1816 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001817 return SemaRef.BuildInstanceMessage(Receiver,
1818 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00001819 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001820 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001821 move(Args));
1822 }
1823
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001824 /// \brief Build a new Objective-C ivar reference expression.
1825 ///
1826 /// By default, performs semantic analysis to build the new expression.
1827 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001828 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001829 SourceLocation IvarLoc,
1830 bool IsArrow, bool IsFreeIvar) {
1831 // FIXME: We lose track of the IsFreeIvar bit.
1832 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001833 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001834 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1835 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001836 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001837 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00001838 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00001839 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001840 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001841 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001842
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001843 if (Result.get())
1844 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001845
John McCall9ae2f072010-08-23 23:25:46 +00001846 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001847 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001848 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001849 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001850 /*TemplateArgs=*/0);
1851 }
Douglas Gregore3303542010-04-26 20:47:02 +00001852
1853 /// \brief Build a new Objective-C property reference expression.
1854 ///
1855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001857 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001858 ObjCPropertyDecl *Property,
1859 SourceLocation PropertyLoc) {
1860 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001861 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00001862 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1863 Sema::LookupMemberName);
1864 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00001865 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00001866 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00001867 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00001868 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001869 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001870
Douglas Gregore3303542010-04-26 20:47:02 +00001871 if (Result.get())
1872 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001873
John McCall9ae2f072010-08-23 23:25:46 +00001874 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001875 /*FIXME:*/PropertyLoc, IsArrow,
1876 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001877 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001878 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001879 /*TemplateArgs=*/0);
1880 }
Sean Huntc3021132010-05-05 15:23:54 +00001881
1882 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001883 /// expression.
1884 ///
1885 /// By default, performs semantic analysis to build the new expression.
Sean Huntc3021132010-05-05 15:23:54 +00001886 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001887 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001888 ObjCMethodDecl *Getter,
1889 QualType T,
1890 ObjCMethodDecl *Setter,
1891 SourceLocation NameLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001892 Expr *Base) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001893 // Since these expressions can only be value-dependent, we do not need to
1894 // perform semantic analysis again.
John McCall9ae2f072010-08-23 23:25:46 +00001895 return Owned(
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001896 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1897 Setter,
1898 NameLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001899 Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001900 }
1901
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001902 /// \brief Build a new Objective-C "isa" expression.
1903 ///
1904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001906 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001907 bool IsArrow) {
1908 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001909 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001910 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1911 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001912 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001913 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00001914 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001915 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001916 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001917
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001918 if (Result.get())
1919 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001920
John McCall9ae2f072010-08-23 23:25:46 +00001921 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001922 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001923 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001924 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001925 /*TemplateArgs=*/0);
1926 }
Sean Huntc3021132010-05-05 15:23:54 +00001927
Douglas Gregorb98b1992009-08-11 05:31:07 +00001928 /// \brief Build a new shuffle vector expression.
1929 ///
1930 /// By default, performs semantic analysis to build the new expression.
1931 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001932 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001933 MultiExprArg SubExprs,
1934 SourceLocation RParenLoc) {
1935 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001936 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001937 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1938 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1939 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1940 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001941
Douglas Gregorb98b1992009-08-11 05:31:07 +00001942 // Build a reference to the __builtin_shufflevector builtin
1943 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001944 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001945 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001946 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001948
1949 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001950 unsigned NumSubExprs = SubExprs.size();
1951 Expr **Subs = (Expr **)SubExprs.release();
1952 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1953 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00001954 Builtin->getCallResultType(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001955 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00001956 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001957
Douglas Gregorb98b1992009-08-11 05:31:07 +00001958 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00001959 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001961 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001962
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001964 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001965 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001966};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001967
Douglas Gregor43959a92009-08-20 07:17:43 +00001968template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00001969StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00001970 if (!S)
1971 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001972
Douglas Gregor43959a92009-08-20 07:17:43 +00001973 switch (S->getStmtClass()) {
1974 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001975
Douglas Gregor43959a92009-08-20 07:17:43 +00001976 // Transform individual statement nodes
1977#define STMT(Node, Parent) \
1978 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1979#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00001980#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001981
Douglas Gregor43959a92009-08-20 07:17:43 +00001982 // Transform expressions by calling TransformExpr.
1983#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00001984#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00001985#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00001986#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00001987 {
John McCall60d7b3a2010-08-24 06:29:42 +00001988 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00001989 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001990 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001991
John McCall9ae2f072010-08-23 23:25:46 +00001992 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00001993 }
Mike Stump1eb44332009-09-09 15:08:12 +00001994 }
1995
Douglas Gregor43959a92009-08-20 07:17:43 +00001996 return SemaRef.Owned(S->Retain());
1997}
Mike Stump1eb44332009-09-09 15:08:12 +00001998
1999
Douglas Gregor670444e2009-08-04 22:27:00 +00002000template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002001ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002002 if (!E)
2003 return SemaRef.Owned(E);
2004
2005 switch (E->getStmtClass()) {
2006 case Stmt::NoStmtClass: break;
2007#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002008#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002009#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002010 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002011#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002012 }
2013
Douglas Gregorb98b1992009-08-11 05:31:07 +00002014 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002015}
2016
2017template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002018NestedNameSpecifier *
2019TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002020 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002021 QualType ObjectType,
2022 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00002023 if (!NNS)
2024 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002025
Douglas Gregor43959a92009-08-20 07:17:43 +00002026 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002027 NestedNameSpecifier *Prefix = NNS->getPrefix();
2028 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002029 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002030 ObjectType,
2031 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002032 if (!Prefix)
2033 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002034
2035 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00002036 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00002037 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00002038 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002039 }
Mike Stump1eb44332009-09-09 15:08:12 +00002040
Douglas Gregordcee1a12009-08-06 05:28:30 +00002041 switch (NNS->getKind()) {
2042 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00002043 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002044 "Identifier nested-name-specifier with no prefix or object type");
2045 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2046 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002047 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002048
2049 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002050 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002051 ObjectType,
2052 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002053
Douglas Gregordcee1a12009-08-06 05:28:30 +00002054 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002055 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002056 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002057 getDerived().TransformDecl(Range.getBegin(),
2058 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002059 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002060 Prefix == NNS->getPrefix() &&
2061 NS == NNS->getAsNamespace())
2062 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002063
Douglas Gregordcee1a12009-08-06 05:28:30 +00002064 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2065 }
Mike Stump1eb44332009-09-09 15:08:12 +00002066
Douglas Gregordcee1a12009-08-06 05:28:30 +00002067 case NestedNameSpecifier::Global:
2068 // There is no meaningful transformation that one could perform on the
2069 // global scope.
2070 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002071
Douglas Gregordcee1a12009-08-06 05:28:30 +00002072 case NestedNameSpecifier::TypeSpecWithTemplate:
2073 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002074 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00002075 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2076 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002077 if (T.isNull())
2078 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002079
Douglas Gregordcee1a12009-08-06 05:28:30 +00002080 if (!getDerived().AlwaysRebuild() &&
2081 Prefix == NNS->getPrefix() &&
2082 T == QualType(NNS->getAsType(), 0))
2083 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002084
2085 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2086 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002087 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002088 }
2089 }
Mike Stump1eb44332009-09-09 15:08:12 +00002090
Douglas Gregordcee1a12009-08-06 05:28:30 +00002091 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002092 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002093}
2094
2095template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002096DeclarationNameInfo
2097TreeTransform<Derived>
2098::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2099 QualType ObjectType) {
2100 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002101 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002102 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002103
2104 switch (Name.getNameKind()) {
2105 case DeclarationName::Identifier:
2106 case DeclarationName::ObjCZeroArgSelector:
2107 case DeclarationName::ObjCOneArgSelector:
2108 case DeclarationName::ObjCMultiArgSelector:
2109 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002110 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002111 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002112 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002113
Douglas Gregor81499bb2009-09-03 22:13:48 +00002114 case DeclarationName::CXXConstructorName:
2115 case DeclarationName::CXXDestructorName:
2116 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002117 TypeSourceInfo *NewTInfo;
2118 CanQualType NewCanTy;
2119 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2120 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2121 if (!NewTInfo)
2122 return DeclarationNameInfo();
2123 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2124 }
2125 else {
2126 NewTInfo = 0;
2127 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2128 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2129 ObjectType);
2130 if (NewT.isNull())
2131 return DeclarationNameInfo();
2132 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2133 }
Mike Stump1eb44332009-09-09 15:08:12 +00002134
Abramo Bagnara25777432010-08-11 22:01:17 +00002135 DeclarationName NewName
2136 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2137 NewCanTy);
2138 DeclarationNameInfo NewNameInfo(NameInfo);
2139 NewNameInfo.setName(NewName);
2140 NewNameInfo.setNamedTypeInfo(NewTInfo);
2141 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002142 }
Mike Stump1eb44332009-09-09 15:08:12 +00002143 }
2144
Abramo Bagnara25777432010-08-11 22:01:17 +00002145 assert(0 && "Unknown name kind.");
2146 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002147}
2148
2149template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002150TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002151TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2152 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002153 SourceLocation Loc = getDerived().getBaseLocation();
2154
Douglas Gregord1067e52009-08-06 06:41:21 +00002155 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002156 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002157 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002158 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2159 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002160 if (!NNS)
2161 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002162
Douglas Gregord1067e52009-08-06 06:41:21 +00002163 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002164 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002165 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002166 if (!TransTemplate)
2167 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002168
Douglas Gregord1067e52009-08-06 06:41:21 +00002169 if (!getDerived().AlwaysRebuild() &&
2170 NNS == QTN->getQualifier() &&
2171 TransTemplate == Template)
2172 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002173
Douglas Gregord1067e52009-08-06 06:41:21 +00002174 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2175 TransTemplate);
2176 }
Mike Stump1eb44332009-09-09 15:08:12 +00002177
John McCallf7a1a742009-11-24 19:00:30 +00002178 // These should be getting filtered out before they make it into the AST.
2179 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002180 }
Mike Stump1eb44332009-09-09 15:08:12 +00002181
Douglas Gregord1067e52009-08-06 06:41:21 +00002182 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002183 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002184 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002185 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2186 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002187 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00002188 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002189
Douglas Gregord1067e52009-08-06 06:41:21 +00002190 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002191 NNS == DTN->getQualifier() &&
2192 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002193 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002194
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002195 if (DTN->isIdentifier()) {
2196 // FIXME: Bad range
2197 SourceRange QualifierRange(getDerived().getBaseLocation());
2198 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2199 *DTN->getIdentifier(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002200 ObjectType);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002201 }
Sean Huntc3021132010-05-05 15:23:54 +00002202
2203 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002204 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002205 }
Mike Stump1eb44332009-09-09 15:08:12 +00002206
Douglas Gregord1067e52009-08-06 06:41:21 +00002207 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002208 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002209 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002210 if (!TransTemplate)
2211 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002212
Douglas Gregord1067e52009-08-06 06:41:21 +00002213 if (!getDerived().AlwaysRebuild() &&
2214 TransTemplate == Template)
2215 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002216
Douglas Gregord1067e52009-08-06 06:41:21 +00002217 return TemplateName(TransTemplate);
2218 }
Mike Stump1eb44332009-09-09 15:08:12 +00002219
John McCallf7a1a742009-11-24 19:00:30 +00002220 // These should be getting filtered out before they reach the AST.
2221 assert(false && "overloaded function decl survived to here");
2222 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002223}
2224
2225template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002226void TreeTransform<Derived>::InventTemplateArgumentLoc(
2227 const TemplateArgument &Arg,
2228 TemplateArgumentLoc &Output) {
2229 SourceLocation Loc = getDerived().getBaseLocation();
2230 switch (Arg.getKind()) {
2231 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002232 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002233 break;
2234
2235 case TemplateArgument::Type:
2236 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002237 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002238
John McCall833ca992009-10-29 08:12:44 +00002239 break;
2240
Douglas Gregor788cd062009-11-11 01:00:40 +00002241 case TemplateArgument::Template:
2242 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2243 break;
Sean Huntc3021132010-05-05 15:23:54 +00002244
John McCall833ca992009-10-29 08:12:44 +00002245 case TemplateArgument::Expression:
2246 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2247 break;
2248
2249 case TemplateArgument::Declaration:
2250 case TemplateArgument::Integral:
2251 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002252 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002253 break;
2254 }
2255}
2256
2257template<typename Derived>
2258bool TreeTransform<Derived>::TransformTemplateArgument(
2259 const TemplateArgumentLoc &Input,
2260 TemplateArgumentLoc &Output) {
2261 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002262 switch (Arg.getKind()) {
2263 case TemplateArgument::Null:
2264 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002265 Output = Input;
2266 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002267
Douglas Gregor670444e2009-08-04 22:27:00 +00002268 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002269 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002270 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002271 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002272
2273 DI = getDerived().TransformType(DI);
2274 if (!DI) return true;
2275
2276 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2277 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002278 }
Mike Stump1eb44332009-09-09 15:08:12 +00002279
Douglas Gregor670444e2009-08-04 22:27:00 +00002280 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002281 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002282 DeclarationName Name;
2283 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2284 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002285 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002286 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002287 if (!D) return true;
2288
John McCall828bff22009-10-29 18:45:58 +00002289 Expr *SourceExpr = Input.getSourceDeclExpression();
2290 if (SourceExpr) {
2291 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002292 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002293 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002294 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002295 }
2296
2297 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002298 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002299 }
Mike Stump1eb44332009-09-09 15:08:12 +00002300
Douglas Gregor788cd062009-11-11 01:00:40 +00002301 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002302 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002303 TemplateName Template
2304 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2305 if (Template.isNull())
2306 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002307
Douglas Gregor788cd062009-11-11 01:00:40 +00002308 Output = TemplateArgumentLoc(TemplateArgument(Template),
2309 Input.getTemplateQualifierRange(),
2310 Input.getTemplateNameLoc());
2311 return false;
2312 }
Sean Huntc3021132010-05-05 15:23:54 +00002313
Douglas Gregor670444e2009-08-04 22:27:00 +00002314 case TemplateArgument::Expression: {
2315 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002316 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002317 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002318
John McCall833ca992009-10-29 08:12:44 +00002319 Expr *InputExpr = Input.getSourceExpression();
2320 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2321
John McCall60d7b3a2010-08-24 06:29:42 +00002322 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002323 = getDerived().TransformExpr(InputExpr);
2324 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002325 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002326 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002327 }
Mike Stump1eb44332009-09-09 15:08:12 +00002328
Douglas Gregor670444e2009-08-04 22:27:00 +00002329 case TemplateArgument::Pack: {
2330 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2331 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002332 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002333 AEnd = Arg.pack_end();
2334 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002335
John McCall833ca992009-10-29 08:12:44 +00002336 // FIXME: preserve source information here when we start
2337 // caring about parameter packs.
2338
John McCall828bff22009-10-29 18:45:58 +00002339 TemplateArgumentLoc InputArg;
2340 TemplateArgumentLoc OutputArg;
2341 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2342 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002343 return true;
2344
John McCall828bff22009-10-29 18:45:58 +00002345 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002346 }
2347 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002348 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002349 true);
John McCall828bff22009-10-29 18:45:58 +00002350 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002351 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002352 }
2353 }
Mike Stump1eb44332009-09-09 15:08:12 +00002354
Douglas Gregor670444e2009-08-04 22:27:00 +00002355 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002356 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002357}
2358
Douglas Gregor577f75a2009-08-04 16:50:30 +00002359//===----------------------------------------------------------------------===//
2360// Type transformation
2361//===----------------------------------------------------------------------===//
2362
2363template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00002364QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregor124b8782010-02-16 19:09:40 +00002365 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002366 if (getDerived().AlreadyTransformed(T))
2367 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002368
John McCalla2becad2009-10-21 00:40:46 +00002369 // Temporary workaround. All of these transformations should
2370 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002371 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002372 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002373
Douglas Gregor124b8782010-02-16 19:09:40 +00002374 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002375
John McCalla2becad2009-10-21 00:40:46 +00002376 if (!NewDI)
2377 return QualType();
2378
2379 return NewDI->getType();
2380}
2381
2382template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002383TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2384 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002385 if (getDerived().AlreadyTransformed(DI->getType()))
2386 return DI;
2387
2388 TypeLocBuilder TLB;
2389
2390 TypeLoc TL = DI->getTypeLoc();
2391 TLB.reserve(TL.getFullDataSize());
2392
Douglas Gregor124b8782010-02-16 19:09:40 +00002393 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002394 if (Result.isNull())
2395 return 0;
2396
John McCalla93c9342009-12-07 02:54:59 +00002397 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002398}
2399
2400template<typename Derived>
2401QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002402TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2403 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002404 switch (T.getTypeLocClass()) {
2405#define ABSTRACT_TYPELOC(CLASS, PARENT)
2406#define TYPELOC(CLASS, PARENT) \
2407 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002408 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2409 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002410#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002411 }
Mike Stump1eb44332009-09-09 15:08:12 +00002412
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002413 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002414 return QualType();
2415}
2416
2417/// FIXME: By default, this routine adds type qualifiers only to types
2418/// that can have qualifiers, and silently suppresses those qualifiers
2419/// that are not permitted (e.g., qualifiers on reference or function
2420/// types). This is the right thing for template instantiation, but
2421/// probably not for other clients.
2422template<typename Derived>
2423QualType
2424TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002425 QualifiedTypeLoc T,
2426 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002427 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002428
Douglas Gregor124b8782010-02-16 19:09:40 +00002429 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2430 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002431 if (Result.isNull())
2432 return QualType();
2433
2434 // Silently suppress qualifiers if the result type can't be qualified.
2435 // FIXME: this is the right thing for template instantiation, but
2436 // probably not for other clients.
2437 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002438 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002439
John McCall28654742010-06-05 06:41:15 +00002440 if (!Quals.empty()) {
2441 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2442 TLB.push<QualifiedTypeLoc>(Result);
2443 // No location information to preserve.
2444 }
John McCalla2becad2009-10-21 00:40:46 +00002445
2446 return Result;
2447}
2448
2449template <class TyLoc> static inline
2450QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2451 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2452 NewT.setNameLoc(T.getNameLoc());
2453 return T.getType();
2454}
2455
John McCalla2becad2009-10-21 00:40:46 +00002456template<typename Derived>
2457QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002458 BuiltinTypeLoc T,
2459 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002460 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2461 NewT.setBuiltinLoc(T.getBuiltinLoc());
2462 if (T.needsExtraLocalData())
2463 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2464 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002465}
Mike Stump1eb44332009-09-09 15:08:12 +00002466
Douglas Gregor577f75a2009-08-04 16:50:30 +00002467template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002468QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002469 ComplexTypeLoc T,
2470 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002471 // FIXME: recurse?
2472 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002473}
Mike Stump1eb44332009-09-09 15:08:12 +00002474
Douglas Gregor577f75a2009-08-04 16:50:30 +00002475template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002476QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Sean Huntc3021132010-05-05 15:23:54 +00002477 PointerTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00002478 QualType ObjectType) {
Sean Huntc3021132010-05-05 15:23:54 +00002479 QualType PointeeType
2480 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002481 if (PointeeType.isNull())
2482 return QualType();
2483
2484 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002485 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002486 // A dependent pointer type 'T *' has is being transformed such
2487 // that an Objective-C class type is being replaced for 'T'. The
2488 // resulting pointer type is an ObjCObjectPointerType, not a
2489 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002490 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002491
John McCallc12c5bb2010-05-15 11:32:37 +00002492 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2493 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002494 return Result;
2495 }
Sean Huntc3021132010-05-05 15:23:54 +00002496
Douglas Gregor92e986e2010-04-22 16:44:27 +00002497 if (getDerived().AlwaysRebuild() ||
2498 PointeeType != TL.getPointeeLoc().getType()) {
2499 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2500 if (Result.isNull())
2501 return QualType();
2502 }
Sean Huntc3021132010-05-05 15:23:54 +00002503
Douglas Gregor92e986e2010-04-22 16:44:27 +00002504 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2505 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002506 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002507}
Mike Stump1eb44332009-09-09 15:08:12 +00002508
2509template<typename Derived>
2510QualType
John McCalla2becad2009-10-21 00:40:46 +00002511TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002512 BlockPointerTypeLoc TL,
2513 QualType ObjectType) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002514 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002515 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2516 if (PointeeType.isNull())
2517 return QualType();
2518
2519 QualType Result = TL.getType();
2520 if (getDerived().AlwaysRebuild() ||
2521 PointeeType != TL.getPointeeLoc().getType()) {
2522 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002523 TL.getSigilLoc());
2524 if (Result.isNull())
2525 return QualType();
2526 }
2527
Douglas Gregor39968ad2010-04-22 16:50:51 +00002528 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002529 NewT.setSigilLoc(TL.getSigilLoc());
2530 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002531}
2532
John McCall85737a72009-10-30 00:06:24 +00002533/// Transforms a reference type. Note that somewhat paradoxically we
2534/// don't care whether the type itself is an l-value type or an r-value
2535/// type; we only care if the type was *written* as an l-value type
2536/// or an r-value type.
2537template<typename Derived>
2538QualType
2539TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002540 ReferenceTypeLoc TL,
2541 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002542 const ReferenceType *T = TL.getTypePtr();
2543
2544 // Note that this works with the pointee-as-written.
2545 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2546 if (PointeeType.isNull())
2547 return QualType();
2548
2549 QualType Result = TL.getType();
2550 if (getDerived().AlwaysRebuild() ||
2551 PointeeType != T->getPointeeTypeAsWritten()) {
2552 Result = getDerived().RebuildReferenceType(PointeeType,
2553 T->isSpelledAsLValue(),
2554 TL.getSigilLoc());
2555 if (Result.isNull())
2556 return QualType();
2557 }
2558
2559 // r-value references can be rebuilt as l-value references.
2560 ReferenceTypeLoc NewTL;
2561 if (isa<LValueReferenceType>(Result))
2562 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2563 else
2564 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2565 NewTL.setSigilLoc(TL.getSigilLoc());
2566
2567 return Result;
2568}
2569
Mike Stump1eb44332009-09-09 15:08:12 +00002570template<typename Derived>
2571QualType
John McCalla2becad2009-10-21 00:40:46 +00002572TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002573 LValueReferenceTypeLoc TL,
2574 QualType ObjectType) {
2575 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002576}
2577
Mike Stump1eb44332009-09-09 15:08:12 +00002578template<typename Derived>
2579QualType
John McCalla2becad2009-10-21 00:40:46 +00002580TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002581 RValueReferenceTypeLoc TL,
2582 QualType ObjectType) {
2583 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002584}
Mike Stump1eb44332009-09-09 15:08:12 +00002585
Douglas Gregor577f75a2009-08-04 16:50:30 +00002586template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002587QualType
John McCalla2becad2009-10-21 00:40:46 +00002588TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002589 MemberPointerTypeLoc TL,
2590 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002591 MemberPointerType *T = TL.getTypePtr();
2592
2593 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002594 if (PointeeType.isNull())
2595 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002596
John McCalla2becad2009-10-21 00:40:46 +00002597 // TODO: preserve source information for this.
2598 QualType ClassType
2599 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002600 if (ClassType.isNull())
2601 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002602
John McCalla2becad2009-10-21 00:40:46 +00002603 QualType Result = TL.getType();
2604 if (getDerived().AlwaysRebuild() ||
2605 PointeeType != T->getPointeeType() ||
2606 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002607 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2608 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002609 if (Result.isNull())
2610 return QualType();
2611 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002612
John McCalla2becad2009-10-21 00:40:46 +00002613 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2614 NewTL.setSigilLoc(TL.getSigilLoc());
2615
2616 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002617}
2618
Mike Stump1eb44332009-09-09 15:08:12 +00002619template<typename Derived>
2620QualType
John McCalla2becad2009-10-21 00:40:46 +00002621TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002622 ConstantArrayTypeLoc TL,
2623 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002624 ConstantArrayType *T = TL.getTypePtr();
2625 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002626 if (ElementType.isNull())
2627 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002628
John McCalla2becad2009-10-21 00:40:46 +00002629 QualType Result = TL.getType();
2630 if (getDerived().AlwaysRebuild() ||
2631 ElementType != T->getElementType()) {
2632 Result = getDerived().RebuildConstantArrayType(ElementType,
2633 T->getSizeModifier(),
2634 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002635 T->getIndexTypeCVRQualifiers(),
2636 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002637 if (Result.isNull())
2638 return QualType();
2639 }
Sean Huntc3021132010-05-05 15:23:54 +00002640
John McCalla2becad2009-10-21 00:40:46 +00002641 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2642 NewTL.setLBracketLoc(TL.getLBracketLoc());
2643 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002644
John McCalla2becad2009-10-21 00:40:46 +00002645 Expr *Size = TL.getSizeExpr();
2646 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00002647 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002648 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2649 }
2650 NewTL.setSizeExpr(Size);
2651
2652 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002653}
Mike Stump1eb44332009-09-09 15:08:12 +00002654
Douglas Gregor577f75a2009-08-04 16:50:30 +00002655template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002656QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002657 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002658 IncompleteArrayTypeLoc TL,
2659 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002660 IncompleteArrayType *T = TL.getTypePtr();
2661 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002662 if (ElementType.isNull())
2663 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002664
John McCalla2becad2009-10-21 00:40:46 +00002665 QualType Result = TL.getType();
2666 if (getDerived().AlwaysRebuild() ||
2667 ElementType != T->getElementType()) {
2668 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002669 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002670 T->getIndexTypeCVRQualifiers(),
2671 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002672 if (Result.isNull())
2673 return QualType();
2674 }
Sean Huntc3021132010-05-05 15:23:54 +00002675
John McCalla2becad2009-10-21 00:40:46 +00002676 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2677 NewTL.setLBracketLoc(TL.getLBracketLoc());
2678 NewTL.setRBracketLoc(TL.getRBracketLoc());
2679 NewTL.setSizeExpr(0);
2680
2681 return Result;
2682}
2683
2684template<typename Derived>
2685QualType
2686TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002687 VariableArrayTypeLoc TL,
2688 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002689 VariableArrayType *T = TL.getTypePtr();
2690 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2691 if (ElementType.isNull())
2692 return QualType();
2693
2694 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002695 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002696
John McCall60d7b3a2010-08-24 06:29:42 +00002697 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002698 = getDerived().TransformExpr(T->getSizeExpr());
2699 if (SizeResult.isInvalid())
2700 return QualType();
2701
John McCall9ae2f072010-08-23 23:25:46 +00002702 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00002703
2704 QualType Result = TL.getType();
2705 if (getDerived().AlwaysRebuild() ||
2706 ElementType != T->getElementType() ||
2707 Size != T->getSizeExpr()) {
2708 Result = getDerived().RebuildVariableArrayType(ElementType,
2709 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002710 Size,
John McCalla2becad2009-10-21 00:40:46 +00002711 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002712 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002713 if (Result.isNull())
2714 return QualType();
2715 }
Sean Huntc3021132010-05-05 15:23:54 +00002716
John McCalla2becad2009-10-21 00:40:46 +00002717 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2718 NewTL.setLBracketLoc(TL.getLBracketLoc());
2719 NewTL.setRBracketLoc(TL.getRBracketLoc());
2720 NewTL.setSizeExpr(Size);
2721
2722 return Result;
2723}
2724
2725template<typename Derived>
2726QualType
2727TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002728 DependentSizedArrayTypeLoc TL,
2729 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002730 DependentSizedArrayType *T = TL.getTypePtr();
2731 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2732 if (ElementType.isNull())
2733 return QualType();
2734
2735 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002736 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002737
John McCall60d7b3a2010-08-24 06:29:42 +00002738 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002739 = getDerived().TransformExpr(T->getSizeExpr());
2740 if (SizeResult.isInvalid())
2741 return QualType();
2742
2743 Expr *Size = static_cast<Expr*>(SizeResult.get());
2744
2745 QualType Result = TL.getType();
2746 if (getDerived().AlwaysRebuild() ||
2747 ElementType != T->getElementType() ||
2748 Size != T->getSizeExpr()) {
2749 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2750 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002751 Size,
John McCalla2becad2009-10-21 00:40:46 +00002752 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002753 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002754 if (Result.isNull())
2755 return QualType();
2756 }
2757 else SizeResult.take();
2758
2759 // We might have any sort of array type now, but fortunately they
2760 // all have the same location layout.
2761 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2762 NewTL.setLBracketLoc(TL.getLBracketLoc());
2763 NewTL.setRBracketLoc(TL.getRBracketLoc());
2764 NewTL.setSizeExpr(Size);
2765
2766 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002767}
Mike Stump1eb44332009-09-09 15:08:12 +00002768
2769template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002770QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002771 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002772 DependentSizedExtVectorTypeLoc TL,
2773 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002774 DependentSizedExtVectorType *T = TL.getTypePtr();
2775
2776 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002777 QualType ElementType = getDerived().TransformType(T->getElementType());
2778 if (ElementType.isNull())
2779 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002780
Douglas Gregor670444e2009-08-04 22:27:00 +00002781 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002782 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00002783
John McCall60d7b3a2010-08-24 06:29:42 +00002784 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002785 if (Size.isInvalid())
2786 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002787
John McCalla2becad2009-10-21 00:40:46 +00002788 QualType Result = TL.getType();
2789 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002790 ElementType != T->getElementType() ||
2791 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002792 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00002793 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00002794 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002795 if (Result.isNull())
2796 return QualType();
2797 }
John McCalla2becad2009-10-21 00:40:46 +00002798
2799 // Result might be dependent or not.
2800 if (isa<DependentSizedExtVectorType>(Result)) {
2801 DependentSizedExtVectorTypeLoc NewTL
2802 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2803 NewTL.setNameLoc(TL.getNameLoc());
2804 } else {
2805 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2806 NewTL.setNameLoc(TL.getNameLoc());
2807 }
2808
2809 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002810}
Mike Stump1eb44332009-09-09 15:08:12 +00002811
2812template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002813QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002814 VectorTypeLoc TL,
2815 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002816 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002817 QualType ElementType = getDerived().TransformType(T->getElementType());
2818 if (ElementType.isNull())
2819 return QualType();
2820
John McCalla2becad2009-10-21 00:40:46 +00002821 QualType Result = TL.getType();
2822 if (getDerived().AlwaysRebuild() ||
2823 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002824 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner788b0fd2010-06-23 06:00:24 +00002825 T->getAltiVecSpecific());
John McCalla2becad2009-10-21 00:40:46 +00002826 if (Result.isNull())
2827 return QualType();
2828 }
Sean Huntc3021132010-05-05 15:23:54 +00002829
John McCalla2becad2009-10-21 00:40:46 +00002830 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2831 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002832
John McCalla2becad2009-10-21 00:40:46 +00002833 return Result;
2834}
2835
2836template<typename Derived>
2837QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002838 ExtVectorTypeLoc TL,
2839 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002840 VectorType *T = TL.getTypePtr();
2841 QualType ElementType = getDerived().TransformType(T->getElementType());
2842 if (ElementType.isNull())
2843 return QualType();
2844
2845 QualType Result = TL.getType();
2846 if (getDerived().AlwaysRebuild() ||
2847 ElementType != T->getElementType()) {
2848 Result = getDerived().RebuildExtVectorType(ElementType,
2849 T->getNumElements(),
2850 /*FIXME*/ SourceLocation());
2851 if (Result.isNull())
2852 return QualType();
2853 }
Sean Huntc3021132010-05-05 15:23:54 +00002854
John McCalla2becad2009-10-21 00:40:46 +00002855 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2856 NewTL.setNameLoc(TL.getNameLoc());
2857
2858 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002859}
Mike Stump1eb44332009-09-09 15:08:12 +00002860
2861template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002862ParmVarDecl *
2863TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2864 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2865 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2866 if (!NewDI)
2867 return 0;
2868
2869 if (NewDI == OldDI)
2870 return OldParm;
2871 else
2872 return ParmVarDecl::Create(SemaRef.Context,
2873 OldParm->getDeclContext(),
2874 OldParm->getLocation(),
2875 OldParm->getIdentifier(),
2876 NewDI->getType(),
2877 NewDI,
2878 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002879 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002880 /* DefArg */ NULL);
2881}
2882
2883template<typename Derived>
2884bool TreeTransform<Derived>::
2885 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2886 llvm::SmallVectorImpl<QualType> &PTypes,
2887 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2888 FunctionProtoType *T = TL.getTypePtr();
2889
2890 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2891 ParmVarDecl *OldParm = TL.getArg(i);
2892
2893 QualType NewType;
2894 ParmVarDecl *NewParm;
2895
2896 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002897 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2898 if (!NewParm)
2899 return true;
2900 NewType = NewParm->getType();
2901
2902 // Deal with the possibility that we don't have a parameter
2903 // declaration for this parameter.
2904 } else {
2905 NewParm = 0;
2906
2907 QualType OldType = T->getArgType(i);
2908 NewType = getDerived().TransformType(OldType);
2909 if (NewType.isNull())
2910 return true;
2911 }
2912
2913 PTypes.push_back(NewType);
2914 PVars.push_back(NewParm);
2915 }
2916
2917 return false;
2918}
2919
2920template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002921QualType
John McCalla2becad2009-10-21 00:40:46 +00002922TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002923 FunctionProtoTypeLoc TL,
2924 QualType ObjectType) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00002925 // Transform the parameters and return type.
2926 //
2927 // We instantiate in source order, with the return type first followed by
2928 // the parameters, because users tend to expect this (even if they shouldn't
2929 // rely on it!).
2930 //
2931 // FIXME: When we implement late-specified return types, we'll need to
2932 // instantiate the return tpe *after* the parameter types in that case,
2933 // since the return type can then refer to the parameters themselves (via
2934 // decltype, sizeof, etc.).
Douglas Gregor577f75a2009-08-04 16:50:30 +00002935 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002936 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor895162d2010-04-30 18:55:50 +00002937 FunctionProtoType *T = TL.getTypePtr();
2938 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2939 if (ResultType.isNull())
2940 return QualType();
Douglas Gregor7e010a02010-08-31 00:26:14 +00002941
2942 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2943 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002944
John McCalla2becad2009-10-21 00:40:46 +00002945 QualType Result = TL.getType();
2946 if (getDerived().AlwaysRebuild() ||
2947 ResultType != T->getResultType() ||
2948 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2949 Result = getDerived().RebuildFunctionProtoType(ResultType,
2950 ParamTypes.data(),
2951 ParamTypes.size(),
2952 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00002953 T->getTypeQuals(),
2954 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00002955 if (Result.isNull())
2956 return QualType();
2957 }
Mike Stump1eb44332009-09-09 15:08:12 +00002958
John McCalla2becad2009-10-21 00:40:46 +00002959 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2960 NewTL.setLParenLoc(TL.getLParenLoc());
2961 NewTL.setRParenLoc(TL.getRParenLoc());
2962 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2963 NewTL.setArg(i, ParamDecls[i]);
2964
2965 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002966}
Mike Stump1eb44332009-09-09 15:08:12 +00002967
Douglas Gregor577f75a2009-08-04 16:50:30 +00002968template<typename Derived>
2969QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002970 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002971 FunctionNoProtoTypeLoc TL,
2972 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002973 FunctionNoProtoType *T = TL.getTypePtr();
2974 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2975 if (ResultType.isNull())
2976 return QualType();
2977
2978 QualType Result = TL.getType();
2979 if (getDerived().AlwaysRebuild() ||
2980 ResultType != T->getResultType())
2981 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2982
2983 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2984 NewTL.setLParenLoc(TL.getLParenLoc());
2985 NewTL.setRParenLoc(TL.getRParenLoc());
2986
2987 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002988}
Mike Stump1eb44332009-09-09 15:08:12 +00002989
John McCalled976492009-12-04 22:46:56 +00002990template<typename Derived> QualType
2991TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002992 UnresolvedUsingTypeLoc TL,
2993 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00002994 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002995 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00002996 if (!D)
2997 return QualType();
2998
2999 QualType Result = TL.getType();
3000 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3001 Result = getDerived().RebuildUnresolvedUsingType(D);
3002 if (Result.isNull())
3003 return QualType();
3004 }
3005
3006 // We might get an arbitrary type spec type back. We should at
3007 // least always get a type spec type, though.
3008 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3009 NewTL.setNameLoc(TL.getNameLoc());
3010
3011 return Result;
3012}
3013
Douglas Gregor577f75a2009-08-04 16:50:30 +00003014template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003015QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003016 TypedefTypeLoc TL,
3017 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003018 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003019 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003020 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3021 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003022 if (!Typedef)
3023 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003024
John McCalla2becad2009-10-21 00:40:46 +00003025 QualType Result = TL.getType();
3026 if (getDerived().AlwaysRebuild() ||
3027 Typedef != T->getDecl()) {
3028 Result = getDerived().RebuildTypedefType(Typedef);
3029 if (Result.isNull())
3030 return QualType();
3031 }
Mike Stump1eb44332009-09-09 15:08:12 +00003032
John McCalla2becad2009-10-21 00:40:46 +00003033 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3034 NewTL.setNameLoc(TL.getNameLoc());
3035
3036 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003037}
Mike Stump1eb44332009-09-09 15:08:12 +00003038
Douglas Gregor577f75a2009-08-04 16:50:30 +00003039template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003040QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003041 TypeOfExprTypeLoc TL,
3042 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003043 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003044 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003045
John McCall60d7b3a2010-08-24 06:29:42 +00003046 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003047 if (E.isInvalid())
3048 return QualType();
3049
John McCalla2becad2009-10-21 00:40:46 +00003050 QualType Result = TL.getType();
3051 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003052 E.get() != TL.getUnderlyingExpr()) {
John McCall9ae2f072010-08-23 23:25:46 +00003053 Result = getDerived().RebuildTypeOfExprType(E.get());
John McCalla2becad2009-10-21 00:40:46 +00003054 if (Result.isNull())
3055 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003056 }
John McCalla2becad2009-10-21 00:40:46 +00003057 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003058
John McCalla2becad2009-10-21 00:40:46 +00003059 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003060 NewTL.setTypeofLoc(TL.getTypeofLoc());
3061 NewTL.setLParenLoc(TL.getLParenLoc());
3062 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003063
3064 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003065}
Mike Stump1eb44332009-09-09 15:08:12 +00003066
3067template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003068QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003069 TypeOfTypeLoc TL,
3070 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00003071 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3072 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3073 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003074 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003075
John McCalla2becad2009-10-21 00:40:46 +00003076 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003077 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3078 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003079 if (Result.isNull())
3080 return QualType();
3081 }
Mike Stump1eb44332009-09-09 15:08:12 +00003082
John McCalla2becad2009-10-21 00:40:46 +00003083 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003084 NewTL.setTypeofLoc(TL.getTypeofLoc());
3085 NewTL.setLParenLoc(TL.getLParenLoc());
3086 NewTL.setRParenLoc(TL.getRParenLoc());
3087 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003088
3089 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003090}
Mike Stump1eb44332009-09-09 15:08:12 +00003091
3092template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003093QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003094 DecltypeTypeLoc TL,
3095 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003096 DecltypeType *T = TL.getTypePtr();
3097
Douglas Gregor670444e2009-08-04 22:27:00 +00003098 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003099 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003100
John McCall60d7b3a2010-08-24 06:29:42 +00003101 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003102 if (E.isInvalid())
3103 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003104
John McCalla2becad2009-10-21 00:40:46 +00003105 QualType Result = TL.getType();
3106 if (getDerived().AlwaysRebuild() ||
3107 E.get() != T->getUnderlyingExpr()) {
John McCall9ae2f072010-08-23 23:25:46 +00003108 Result = getDerived().RebuildDecltypeType(E.get());
John McCalla2becad2009-10-21 00:40:46 +00003109 if (Result.isNull())
3110 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003111 }
John McCalla2becad2009-10-21 00:40:46 +00003112 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003113
John McCalla2becad2009-10-21 00:40:46 +00003114 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3115 NewTL.setNameLoc(TL.getNameLoc());
3116
3117 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003118}
3119
3120template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003121QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003122 RecordTypeLoc TL,
3123 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003124 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003125 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003126 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3127 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003128 if (!Record)
3129 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003130
John McCalla2becad2009-10-21 00:40:46 +00003131 QualType Result = TL.getType();
3132 if (getDerived().AlwaysRebuild() ||
3133 Record != T->getDecl()) {
3134 Result = getDerived().RebuildRecordType(Record);
3135 if (Result.isNull())
3136 return QualType();
3137 }
Mike Stump1eb44332009-09-09 15:08:12 +00003138
John McCalla2becad2009-10-21 00:40:46 +00003139 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3140 NewTL.setNameLoc(TL.getNameLoc());
3141
3142 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003143}
Mike Stump1eb44332009-09-09 15:08:12 +00003144
3145template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003146QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003147 EnumTypeLoc TL,
3148 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003149 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003150 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003151 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3152 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003153 if (!Enum)
3154 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003155
John McCalla2becad2009-10-21 00:40:46 +00003156 QualType Result = TL.getType();
3157 if (getDerived().AlwaysRebuild() ||
3158 Enum != T->getDecl()) {
3159 Result = getDerived().RebuildEnumType(Enum);
3160 if (Result.isNull())
3161 return QualType();
3162 }
Mike Stump1eb44332009-09-09 15:08:12 +00003163
John McCalla2becad2009-10-21 00:40:46 +00003164 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3165 NewTL.setNameLoc(TL.getNameLoc());
3166
3167 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003168}
John McCall7da24312009-09-05 00:15:47 +00003169
John McCall3cb0ebd2010-03-10 03:28:59 +00003170template<typename Derived>
3171QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3172 TypeLocBuilder &TLB,
3173 InjectedClassNameTypeLoc TL,
3174 QualType ObjectType) {
3175 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3176 TL.getTypePtr()->getDecl());
3177 if (!D) return QualType();
3178
3179 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3180 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3181 return T;
3182}
3183
Mike Stump1eb44332009-09-09 15:08:12 +00003184
Douglas Gregor577f75a2009-08-04 16:50:30 +00003185template<typename Derived>
3186QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003187 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003188 TemplateTypeParmTypeLoc TL,
3189 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003190 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003191}
3192
Mike Stump1eb44332009-09-09 15:08:12 +00003193template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003194QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003195 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003196 SubstTemplateTypeParmTypeLoc TL,
3197 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003198 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003199}
3200
3201template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003202QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3203 const TemplateSpecializationType *TST,
3204 QualType ObjectType) {
3205 // FIXME: this entire method is a temporary workaround; callers
3206 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00003207
John McCall833ca992009-10-29 08:12:44 +00003208 // Fake up a TemplateSpecializationTypeLoc.
3209 TypeLocBuilder TLB;
3210 TemplateSpecializationTypeLoc TL
3211 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3212
John McCall828bff22009-10-29 18:45:58 +00003213 SourceLocation BaseLoc = getDerived().getBaseLocation();
3214
3215 TL.setTemplateNameLoc(BaseLoc);
3216 TL.setLAngleLoc(BaseLoc);
3217 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00003218 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3219 const TemplateArgument &TA = TST->getArg(i);
3220 TemplateArgumentLoc TAL;
3221 getDerived().InventTemplateArgumentLoc(TA, TAL);
3222 TL.setArgLocInfo(i, TAL.getLocInfo());
3223 }
3224
3225 TypeLocBuilder IgnoredTLB;
3226 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00003227}
Sean Huntc3021132010-05-05 15:23:54 +00003228
Douglas Gregordd62b152009-10-19 22:04:39 +00003229template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003230QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003231 TypeLocBuilder &TLB,
3232 TemplateSpecializationTypeLoc TL,
3233 QualType ObjectType) {
3234 const TemplateSpecializationType *T = TL.getTypePtr();
3235
Mike Stump1eb44332009-09-09 15:08:12 +00003236 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00003237 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003238 if (Template.isNull())
3239 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003240
John McCalld5532b62009-11-23 01:53:49 +00003241 TemplateArgumentListInfo NewTemplateArgs;
3242 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3243 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3244
3245 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3246 TemplateArgumentLoc Loc;
3247 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003248 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003249 NewTemplateArgs.addArgument(Loc);
3250 }
Mike Stump1eb44332009-09-09 15:08:12 +00003251
John McCall833ca992009-10-29 08:12:44 +00003252 // FIXME: maybe don't rebuild if all the template arguments are the same.
3253
3254 QualType Result =
3255 getDerived().RebuildTemplateSpecializationType(Template,
3256 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003257 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003258
3259 if (!Result.isNull()) {
3260 TemplateSpecializationTypeLoc NewTL
3261 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3262 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3263 NewTL.setLAngleLoc(TL.getLAngleLoc());
3264 NewTL.setRAngleLoc(TL.getRAngleLoc());
3265 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3266 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003267 }
Mike Stump1eb44332009-09-09 15:08:12 +00003268
John McCall833ca992009-10-29 08:12:44 +00003269 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003270}
Mike Stump1eb44332009-09-09 15:08:12 +00003271
3272template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003273QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003274TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3275 ElaboratedTypeLoc TL,
3276 QualType ObjectType) {
3277 ElaboratedType *T = TL.getTypePtr();
3278
3279 NestedNameSpecifier *NNS = 0;
3280 // NOTE: the qualifier in an ElaboratedType is optional.
3281 if (T->getQualifier() != 0) {
3282 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003283 TL.getQualifierRange(),
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003284 ObjectType);
3285 if (!NNS)
3286 return QualType();
3287 }
Mike Stump1eb44332009-09-09 15:08:12 +00003288
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003289 QualType NamedT;
3290 // FIXME: this test is meant to workaround a problem (failing assertion)
3291 // occurring if directly executing the code in the else branch.
3292 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3293 TemplateSpecializationTypeLoc OldNamedTL
3294 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3295 const TemplateSpecializationType* OldTST
Jim Grosbach9cbb4d82010-05-19 23:53:08 +00003296 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003297 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3298 if (NamedT.isNull())
3299 return QualType();
3300 TemplateSpecializationTypeLoc NewNamedTL
3301 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3302 NewNamedTL.copy(OldNamedTL);
3303 }
3304 else {
3305 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3306 if (NamedT.isNull())
3307 return QualType();
3308 }
Daniel Dunbara63db842010-05-14 16:34:09 +00003309
John McCalla2becad2009-10-21 00:40:46 +00003310 QualType Result = TL.getType();
3311 if (getDerived().AlwaysRebuild() ||
3312 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003313 NamedT != T->getNamedType()) {
3314 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003315 if (Result.isNull())
3316 return QualType();
3317 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003318
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003319 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003320 NewTL.setKeywordLoc(TL.getKeywordLoc());
3321 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003322
3323 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003324}
Mike Stump1eb44332009-09-09 15:08:12 +00003325
3326template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003327QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3328 DependentNameTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00003329 QualType ObjectType) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003330 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003331
Douglas Gregor577f75a2009-08-04 16:50:30 +00003332 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003333 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3334 TL.getQualifierRange(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003335 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003336 if (!NNS)
3337 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003338
John McCall33500952010-06-11 00:33:02 +00003339 QualType Result
3340 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3341 T->getIdentifier(),
3342 TL.getKeywordLoc(),
3343 TL.getQualifierRange(),
3344 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003345 if (Result.isNull())
3346 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003347
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003348 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3349 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003350 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3351
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003352 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3353 NewTL.setKeywordLoc(TL.getKeywordLoc());
3354 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003355 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003356 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3357 NewTL.setKeywordLoc(TL.getKeywordLoc());
3358 NewTL.setQualifierRange(TL.getQualifierRange());
3359 NewTL.setNameLoc(TL.getNameLoc());
3360 }
John McCalla2becad2009-10-21 00:40:46 +00003361 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003362}
Mike Stump1eb44332009-09-09 15:08:12 +00003363
Douglas Gregor577f75a2009-08-04 16:50:30 +00003364template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003365QualType TreeTransform<Derived>::
3366 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3367 DependentTemplateSpecializationTypeLoc TL,
3368 QualType ObjectType) {
3369 DependentTemplateSpecializationType *T = TL.getTypePtr();
3370
3371 NestedNameSpecifier *NNS
3372 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3373 TL.getQualifierRange(),
3374 ObjectType);
3375 if (!NNS)
3376 return QualType();
3377
3378 TemplateArgumentListInfo NewTemplateArgs;
3379 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3380 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3381
3382 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3383 TemplateArgumentLoc Loc;
3384 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3385 return QualType();
3386 NewTemplateArgs.addArgument(Loc);
3387 }
3388
Douglas Gregor1efb6c72010-09-08 23:56:00 +00003389 QualType Result
3390 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3391 NNS,
3392 TL.getQualifierRange(),
3393 T->getIdentifier(),
3394 TL.getNameLoc(),
3395 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00003396 if (Result.isNull())
3397 return QualType();
3398
3399 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3400 QualType NamedT = ElabT->getNamedType();
3401
3402 // Copy information relevant to the template specialization.
3403 TemplateSpecializationTypeLoc NamedTL
3404 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3405 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3406 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3407 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3408 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3409
3410 // Copy information relevant to the elaborated type.
3411 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3412 NewTL.setKeywordLoc(TL.getKeywordLoc());
3413 NewTL.setQualifierRange(TL.getQualifierRange());
3414 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003415 TypeLoc NewTL(Result, TL.getOpaqueData());
3416 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003417 }
3418 return Result;
3419}
3420
3421template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003422QualType
3423TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003424 ObjCInterfaceTypeLoc TL,
3425 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003426 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003427 TLB.pushFullCopy(TL);
3428 return TL.getType();
3429}
3430
3431template<typename Derived>
3432QualType
3433TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3434 ObjCObjectTypeLoc TL,
3435 QualType ObjectType) {
3436 // ObjCObjectType is never dependent.
3437 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003438 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003439}
Mike Stump1eb44332009-09-09 15:08:12 +00003440
3441template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003442QualType
3443TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003444 ObjCObjectPointerTypeLoc TL,
3445 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003446 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003447 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003448 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003449}
3450
Douglas Gregor577f75a2009-08-04 16:50:30 +00003451//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003452// Statement transformation
3453//===----------------------------------------------------------------------===//
3454template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003455StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003456TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3457 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003458}
3459
3460template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003461StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003462TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3463 return getDerived().TransformCompoundStmt(S, false);
3464}
3465
3466template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003467StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003468TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003469 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00003470 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00003471 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003472 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00003473 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3474 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00003475 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00003476 if (Result.isInvalid()) {
3477 // Immediately fail if this was a DeclStmt, since it's very
3478 // likely that this will cause problems for future statements.
3479 if (isa<DeclStmt>(*B))
3480 return StmtError();
3481
3482 // Otherwise, just keep processing substatements and fail later.
3483 SubStmtInvalid = true;
3484 continue;
3485 }
Mike Stump1eb44332009-09-09 15:08:12 +00003486
Douglas Gregor43959a92009-08-20 07:17:43 +00003487 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3488 Statements.push_back(Result.takeAs<Stmt>());
3489 }
Mike Stump1eb44332009-09-09 15:08:12 +00003490
John McCall7114cba2010-08-27 19:56:05 +00003491 if (SubStmtInvalid)
3492 return StmtError();
3493
Douglas Gregor43959a92009-08-20 07:17:43 +00003494 if (!getDerived().AlwaysRebuild() &&
3495 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003496 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003497
3498 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3499 move_arg(Statements),
3500 S->getRBracLoc(),
3501 IsStmtExpr);
3502}
Mike Stump1eb44332009-09-09 15:08:12 +00003503
Douglas Gregor43959a92009-08-20 07:17:43 +00003504template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003505StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003506TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003507 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00003508 {
3509 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00003510 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003511
Eli Friedman264c1f82009-11-19 03:14:00 +00003512 // Transform the left-hand case value.
3513 LHS = getDerived().TransformExpr(S->getLHS());
3514 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003515 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003516
Eli Friedman264c1f82009-11-19 03:14:00 +00003517 // Transform the right-hand case value (for the GNU case-range extension).
3518 RHS = getDerived().TransformExpr(S->getRHS());
3519 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003520 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00003521 }
Mike Stump1eb44332009-09-09 15:08:12 +00003522
Douglas Gregor43959a92009-08-20 07:17:43 +00003523 // Build the case statement.
3524 // Case statements are always rebuilt so that they will attached to their
3525 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003526 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003527 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003528 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003529 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003530 S->getColonLoc());
3531 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003532 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003533
Douglas Gregor43959a92009-08-20 07:17:43 +00003534 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00003535 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003536 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003537 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003538
Douglas Gregor43959a92009-08-20 07:17:43 +00003539 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00003540 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003541}
3542
3543template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003544StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003545TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003546 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00003547 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003548 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003549 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003550
Douglas Gregor43959a92009-08-20 07:17:43 +00003551 // Default statements are always rebuilt
3552 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003553 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003554}
Mike Stump1eb44332009-09-09 15:08:12 +00003555
Douglas Gregor43959a92009-08-20 07:17:43 +00003556template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003557StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003558TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003559 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003560 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003561 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003562
Douglas Gregor43959a92009-08-20 07:17:43 +00003563 // FIXME: Pass the real colon location in.
3564 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3565 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +00003566 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00003567}
Mike Stump1eb44332009-09-09 15:08:12 +00003568
Douglas Gregor43959a92009-08-20 07:17:43 +00003569template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003570StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003571TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003572 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003573 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003574 VarDecl *ConditionVar = 0;
3575 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003576 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003577 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003578 getDerived().TransformDefinition(
3579 S->getConditionVariable()->getLocation(),
3580 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003581 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003582 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003583 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003584 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003585
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003586 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003587 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003588
3589 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003590 if (S->getCond()) {
John McCall60d7b3a2010-08-24 06:29:42 +00003591 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003592 S->getIfLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003593 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003594 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003595 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003596
John McCall9ae2f072010-08-23 23:25:46 +00003597 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003598 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003599 }
Sean Huntc3021132010-05-05 15:23:54 +00003600
John McCall9ae2f072010-08-23 23:25:46 +00003601 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3602 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003603 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003604
Douglas Gregor43959a92009-08-20 07:17:43 +00003605 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003606 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00003607 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003608 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003609
Douglas Gregor43959a92009-08-20 07:17:43 +00003610 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003611 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00003612 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003613 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003614
Douglas Gregor43959a92009-08-20 07:17:43 +00003615 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003616 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003617 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003618 Then.get() == S->getThen() &&
3619 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003620 return SemaRef.Owned(S->Retain());
3621
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003622 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCall9ae2f072010-08-23 23:25:46 +00003623 Then.get(),
3624 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003625}
3626
3627template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003628StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003629TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003630 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00003631 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00003632 VarDecl *ConditionVar = 0;
3633 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003634 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003635 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003636 getDerived().TransformDefinition(
3637 S->getConditionVariable()->getLocation(),
3638 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003639 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003640 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003641 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003642 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003643
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003644 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003645 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003646 }
Mike Stump1eb44332009-09-09 15:08:12 +00003647
Douglas Gregor43959a92009-08-20 07:17:43 +00003648 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003649 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00003650 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00003651 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003652 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003653 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003654
Douglas Gregor43959a92009-08-20 07:17:43 +00003655 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003656 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003657 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003658 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003659
Douglas Gregor43959a92009-08-20 07:17:43 +00003660 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00003661 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3662 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003663}
Mike Stump1eb44332009-09-09 15:08:12 +00003664
Douglas Gregor43959a92009-08-20 07:17:43 +00003665template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003666StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003667TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003668 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003669 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00003670 VarDecl *ConditionVar = 0;
3671 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003672 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003673 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003674 getDerived().TransformDefinition(
3675 S->getConditionVariable()->getLocation(),
3676 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003677 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003678 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003679 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003680 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003681
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003682 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003683 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003684
3685 if (S->getCond()) {
3686 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003687 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003688 S->getWhileLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003689 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003690 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003691 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00003692 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003693 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003694 }
Mike Stump1eb44332009-09-09 15:08:12 +00003695
John McCall9ae2f072010-08-23 23:25:46 +00003696 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3697 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003698 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003699
Douglas Gregor43959a92009-08-20 07:17:43 +00003700 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003701 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003702 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003703 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003704
Douglas Gregor43959a92009-08-20 07:17:43 +00003705 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003706 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003707 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003708 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00003709 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003710
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003711 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00003712 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003713}
Mike Stump1eb44332009-09-09 15:08:12 +00003714
Douglas Gregor43959a92009-08-20 07:17:43 +00003715template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003716StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003717TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003718 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003719 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003720 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003721 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003722
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003723 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003724 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003725 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003726 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003727
Douglas Gregor43959a92009-08-20 07:17:43 +00003728 if (!getDerived().AlwaysRebuild() &&
3729 Cond.get() == S->getCond() &&
3730 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003731 return SemaRef.Owned(S->Retain());
3732
John McCall9ae2f072010-08-23 23:25:46 +00003733 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3734 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003735 S->getRParenLoc());
3736}
Mike Stump1eb44332009-09-09 15:08:12 +00003737
Douglas Gregor43959a92009-08-20 07:17:43 +00003738template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003739StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003740TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003741 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00003742 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00003743 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003744 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003745
Douglas Gregor43959a92009-08-20 07:17:43 +00003746 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003747 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003748 VarDecl *ConditionVar = 0;
3749 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003750 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003751 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003752 getDerived().TransformDefinition(
3753 S->getConditionVariable()->getLocation(),
3754 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003755 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003756 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003757 } else {
3758 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003759
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003760 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003761 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003762
3763 if (S->getCond()) {
3764 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003765 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003766 S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003767 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003768 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003769 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003770
John McCall9ae2f072010-08-23 23:25:46 +00003771 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003772 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003773 }
Mike Stump1eb44332009-09-09 15:08:12 +00003774
John McCall9ae2f072010-08-23 23:25:46 +00003775 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3776 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003777 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003778
Douglas Gregor43959a92009-08-20 07:17:43 +00003779 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00003780 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00003781 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003782 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003783
John McCall9ae2f072010-08-23 23:25:46 +00003784 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3785 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00003786 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003787
Douglas Gregor43959a92009-08-20 07:17:43 +00003788 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003789 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003790 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003791 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003792
Douglas Gregor43959a92009-08-20 07:17:43 +00003793 if (!getDerived().AlwaysRebuild() &&
3794 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00003795 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003796 Inc.get() == S->getInc() &&
3797 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003798 return SemaRef.Owned(S->Retain());
3799
Douglas Gregor43959a92009-08-20 07:17:43 +00003800 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003801 Init.get(), FullCond, ConditionVar,
3802 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003803}
3804
3805template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003806StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003807TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003808 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003809 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003810 S->getLabel());
3811}
3812
3813template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003814StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003815TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003816 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00003817 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003818 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003819
Douglas Gregor43959a92009-08-20 07:17:43 +00003820 if (!getDerived().AlwaysRebuild() &&
3821 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003822 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003823
3824 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003825 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003826}
3827
3828template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003829StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003830TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3831 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003832}
Mike Stump1eb44332009-09-09 15:08:12 +00003833
Douglas Gregor43959a92009-08-20 07:17:43 +00003834template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003835StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003836TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3837 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003838}
Mike Stump1eb44332009-09-09 15:08:12 +00003839
Douglas Gregor43959a92009-08-20 07:17:43 +00003840template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003841StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003842TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003843 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00003844 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003845 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00003846
Mike Stump1eb44332009-09-09 15:08:12 +00003847 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003848 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00003849 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003850}
Mike Stump1eb44332009-09-09 15:08:12 +00003851
Douglas Gregor43959a92009-08-20 07:17:43 +00003852template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003853StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003854TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003855 bool DeclChanged = false;
3856 llvm::SmallVector<Decl *, 4> Decls;
3857 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3858 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003859 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3860 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003861 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00003862 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003863
Douglas Gregor43959a92009-08-20 07:17:43 +00003864 if (Transformed != *D)
3865 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003866
Douglas Gregor43959a92009-08-20 07:17:43 +00003867 Decls.push_back(Transformed);
3868 }
Mike Stump1eb44332009-09-09 15:08:12 +00003869
Douglas Gregor43959a92009-08-20 07:17:43 +00003870 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003871 return SemaRef.Owned(S->Retain());
3872
3873 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003874 S->getStartLoc(), S->getEndLoc());
3875}
Mike Stump1eb44332009-09-09 15:08:12 +00003876
Douglas Gregor43959a92009-08-20 07:17:43 +00003877template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003878StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003879TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003880 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003881 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003882}
3883
3884template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003885StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003886TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003887
John McCallca0408f2010-08-23 06:44:23 +00003888 ASTOwningVector<Expr*> Constraints(getSema());
3889 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003890 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003891
John McCall60d7b3a2010-08-24 06:29:42 +00003892 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00003893 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00003894
3895 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003896
Anders Carlsson703e3942010-01-24 05:50:09 +00003897 // Go through the outputs.
3898 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003899 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003900
Anders Carlsson703e3942010-01-24 05:50:09 +00003901 // No need to transform the constraint literal.
3902 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003903
Anders Carlsson703e3942010-01-24 05:50:09 +00003904 // Transform the output expr.
3905 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003906 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003907 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003908 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003909
Anders Carlsson703e3942010-01-24 05:50:09 +00003910 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003911
John McCall9ae2f072010-08-23 23:25:46 +00003912 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003913 }
Sean Huntc3021132010-05-05 15:23:54 +00003914
Anders Carlsson703e3942010-01-24 05:50:09 +00003915 // Go through the inputs.
3916 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003917 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003918
Anders Carlsson703e3942010-01-24 05:50:09 +00003919 // No need to transform the constraint literal.
3920 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003921
Anders Carlsson703e3942010-01-24 05:50:09 +00003922 // Transform the input expr.
3923 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003924 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003925 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003926 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003927
Anders Carlsson703e3942010-01-24 05:50:09 +00003928 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003929
John McCall9ae2f072010-08-23 23:25:46 +00003930 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003931 }
Sean Huntc3021132010-05-05 15:23:54 +00003932
Anders Carlsson703e3942010-01-24 05:50:09 +00003933 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3934 return SemaRef.Owned(S->Retain());
3935
3936 // Go through the clobbers.
3937 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3938 Clobbers.push_back(S->getClobber(I)->Retain());
3939
3940 // No need to transform the asm string literal.
3941 AsmString = SemaRef.Owned(S->getAsmString());
3942
3943 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3944 S->isSimple(),
3945 S->isVolatile(),
3946 S->getNumOutputs(),
3947 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003948 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003949 move_arg(Constraints),
3950 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00003951 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003952 move_arg(Clobbers),
3953 S->getRParenLoc(),
3954 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003955}
3956
3957
3958template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003959StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003960TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003961 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00003962 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003963 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003964 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003965
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003966 // Transform the @catch statements (if present).
3967 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003968 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003969 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00003970 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003971 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003972 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003973 if (Catch.get() != S->getCatchStmt(I))
3974 AnyCatchChanged = true;
3975 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003976 }
Sean Huntc3021132010-05-05 15:23:54 +00003977
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003978 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00003979 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003980 if (S->getFinallyStmt()) {
3981 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3982 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003983 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003984 }
3985
3986 // If nothing changed, just retain this statement.
3987 if (!getDerived().AlwaysRebuild() &&
3988 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003989 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003990 Finally.get() == S->getFinallyStmt())
3991 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003992
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003993 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00003994 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
3995 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003996}
Mike Stump1eb44332009-09-09 15:08:12 +00003997
Douglas Gregor43959a92009-08-20 07:17:43 +00003998template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003999StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004000TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004001 // Transform the @catch parameter, if there is one.
4002 VarDecl *Var = 0;
4003 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4004 TypeSourceInfo *TSInfo = 0;
4005 if (FromVar->getTypeSourceInfo()) {
4006 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4007 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004008 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004009 }
Sean Huntc3021132010-05-05 15:23:54 +00004010
Douglas Gregorbe270a02010-04-26 17:57:08 +00004011 QualType T;
4012 if (TSInfo)
4013 T = TSInfo->getType();
4014 else {
4015 T = getDerived().TransformType(FromVar->getType());
4016 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004017 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004018 }
Sean Huntc3021132010-05-05 15:23:54 +00004019
Douglas Gregorbe270a02010-04-26 17:57:08 +00004020 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4021 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004022 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004023 }
Sean Huntc3021132010-05-05 15:23:54 +00004024
John McCall60d7b3a2010-08-24 06:29:42 +00004025 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004026 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004027 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004028
4029 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004030 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004031 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004032}
Mike Stump1eb44332009-09-09 15:08:12 +00004033
Douglas Gregor43959a92009-08-20 07:17:43 +00004034template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004035StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004036TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004037 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004038 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004039 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004040 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004041
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004042 // If nothing changed, just retain this statement.
4043 if (!getDerived().AlwaysRebuild() &&
4044 Body.get() == S->getFinallyBody())
4045 return SemaRef.Owned(S->Retain());
4046
4047 // Build a new statement.
4048 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004049 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004050}
Mike Stump1eb44332009-09-09 15:08:12 +00004051
Douglas Gregor43959a92009-08-20 07:17:43 +00004052template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004053StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004054TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004055 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004056 if (S->getThrowExpr()) {
4057 Operand = getDerived().TransformExpr(S->getThrowExpr());
4058 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004059 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004060 }
Sean Huntc3021132010-05-05 15:23:54 +00004061
Douglas Gregord1377b22010-04-22 21:44:01 +00004062 if (!getDerived().AlwaysRebuild() &&
4063 Operand.get() == S->getThrowExpr())
4064 return getSema().Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004065
John McCall9ae2f072010-08-23 23:25:46 +00004066 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004067}
Mike Stump1eb44332009-09-09 15:08:12 +00004068
Douglas Gregor43959a92009-08-20 07:17:43 +00004069template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004070StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004071TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004072 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004073 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004074 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004075 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004076 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004077
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004078 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004079 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004080 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004081 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004082
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004083 // If nothing change, just retain the current statement.
4084 if (!getDerived().AlwaysRebuild() &&
4085 Object.get() == S->getSynchExpr() &&
4086 Body.get() == S->getSynchBody())
4087 return SemaRef.Owned(S->Retain());
4088
4089 // Build a new statement.
4090 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004091 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004092}
4093
4094template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004095StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004096TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004097 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004098 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004099 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004100 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004101 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004102
Douglas Gregorc3203e72010-04-22 23:10:45 +00004103 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00004104 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004105 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004106 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004107
Douglas Gregorc3203e72010-04-22 23:10:45 +00004108 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004109 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004110 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004111 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004112
Douglas Gregorc3203e72010-04-22 23:10:45 +00004113 // If nothing changed, just retain this statement.
4114 if (!getDerived().AlwaysRebuild() &&
4115 Element.get() == S->getElement() &&
4116 Collection.get() == S->getCollection() &&
4117 Body.get() == S->getBody())
4118 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004119
Douglas Gregorc3203e72010-04-22 23:10:45 +00004120 // Build a new statement.
4121 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4122 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004123 Element.get(),
4124 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00004125 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004126 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004127}
4128
4129
4130template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004131StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004132TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4133 // Transform the exception declaration, if any.
4134 VarDecl *Var = 0;
4135 if (S->getExceptionDecl()) {
4136 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00004137 TypeSourceInfo *T = getDerived().TransformType(
4138 ExceptionDecl->getTypeSourceInfo());
4139 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00004140 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004141
Douglas Gregor83cb9422010-09-09 17:09:21 +00004142 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00004143 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00004144 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00004145 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00004146 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004147 }
Mike Stump1eb44332009-09-09 15:08:12 +00004148
Douglas Gregor43959a92009-08-20 07:17:43 +00004149 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00004150 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004151 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004152 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004153
Douglas Gregor43959a92009-08-20 07:17:43 +00004154 if (!getDerived().AlwaysRebuild() &&
4155 !Var &&
4156 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00004157 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004158
4159 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4160 Var,
John McCall9ae2f072010-08-23 23:25:46 +00004161 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004162}
Mike Stump1eb44332009-09-09 15:08:12 +00004163
Douglas Gregor43959a92009-08-20 07:17:43 +00004164template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004165StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004166TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4167 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004168 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004169 = getDerived().TransformCompoundStmt(S->getTryBlock());
4170 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004171 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004172
Douglas Gregor43959a92009-08-20 07:17:43 +00004173 // Transform the handlers.
4174 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004175 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00004176 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004177 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004178 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4179 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004180 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004181
Douglas Gregor43959a92009-08-20 07:17:43 +00004182 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4183 Handlers.push_back(Handler.takeAs<Stmt>());
4184 }
Mike Stump1eb44332009-09-09 15:08:12 +00004185
Douglas Gregor43959a92009-08-20 07:17:43 +00004186 if (!getDerived().AlwaysRebuild() &&
4187 TryBlock.get() == S->getTryBlock() &&
4188 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004189 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004190
John McCall9ae2f072010-08-23 23:25:46 +00004191 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00004192 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004193}
Mike Stump1eb44332009-09-09 15:08:12 +00004194
Douglas Gregor43959a92009-08-20 07:17:43 +00004195//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004196// Expression transformation
4197//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004198template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004199ExprResult
John McCall454feb92009-12-08 09:21:05 +00004200TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004201 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004202}
Mike Stump1eb44332009-09-09 15:08:12 +00004203
4204template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004205ExprResult
John McCall454feb92009-12-08 09:21:05 +00004206TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004207 NestedNameSpecifier *Qualifier = 0;
4208 if (E->getQualifier()) {
4209 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004210 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004211 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00004212 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00004213 }
John McCalldbd872f2009-12-08 09:08:17 +00004214
4215 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004216 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4217 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004218 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00004219 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004220
John McCallec8045d2010-08-17 21:27:17 +00004221 DeclarationNameInfo NameInfo = E->getNameInfo();
4222 if (NameInfo.getName()) {
4223 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4224 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00004225 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00004226 }
Abramo Bagnara25777432010-08-11 22:01:17 +00004227
4228 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004229 Qualifier == E->getQualifier() &&
4230 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00004231 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00004232 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004233
4234 // Mark it referenced in the new context regardless.
4235 // FIXME: this is a bit instantiation-specific.
4236 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4237
Mike Stump1eb44332009-09-09 15:08:12 +00004238 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004239 }
John McCalldbd872f2009-12-08 09:08:17 +00004240
4241 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00004242 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004243 TemplateArgs = &TransArgs;
4244 TransArgs.setLAngleLoc(E->getLAngleLoc());
4245 TransArgs.setRAngleLoc(E->getRAngleLoc());
4246 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4247 TemplateArgumentLoc Loc;
4248 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004249 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00004250 TransArgs.addArgument(Loc);
4251 }
4252 }
4253
Douglas Gregora2813ce2009-10-23 18:54:35 +00004254 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004255 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004256}
Mike Stump1eb44332009-09-09 15:08:12 +00004257
Douglas Gregorb98b1992009-08-11 05:31:07 +00004258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004259ExprResult
John McCall454feb92009-12-08 09:21:05 +00004260TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004261 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004262}
Mike Stump1eb44332009-09-09 15:08:12 +00004263
Douglas Gregorb98b1992009-08-11 05:31:07 +00004264template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004265ExprResult
John McCall454feb92009-12-08 09:21:05 +00004266TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004267 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004268}
Mike Stump1eb44332009-09-09 15:08:12 +00004269
Douglas Gregorb98b1992009-08-11 05:31:07 +00004270template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004271ExprResult
John McCall454feb92009-12-08 09:21:05 +00004272TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004273 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004274}
Mike Stump1eb44332009-09-09 15:08:12 +00004275
Douglas Gregorb98b1992009-08-11 05:31:07 +00004276template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004277ExprResult
John McCall454feb92009-12-08 09:21:05 +00004278TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004279 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004280}
Mike Stump1eb44332009-09-09 15:08:12 +00004281
Douglas Gregorb98b1992009-08-11 05:31:07 +00004282template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004283ExprResult
John McCall454feb92009-12-08 09:21:05 +00004284TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004285 return SemaRef.Owned(E->Retain());
4286}
4287
4288template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004289ExprResult
John McCall454feb92009-12-08 09:21:05 +00004290TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004291 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004292 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004293 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004294
Douglas Gregorb98b1992009-08-11 05:31:07 +00004295 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004296 return SemaRef.Owned(E->Retain());
4297
John McCall9ae2f072010-08-23 23:25:46 +00004298 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004299 E->getRParen());
4300}
4301
Mike Stump1eb44332009-09-09 15:08:12 +00004302template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004303ExprResult
John McCall454feb92009-12-08 09:21:05 +00004304TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004305 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004306 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004307 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004308
Douglas Gregorb98b1992009-08-11 05:31:07 +00004309 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004310 return SemaRef.Owned(E->Retain());
4311
Douglas Gregorb98b1992009-08-11 05:31:07 +00004312 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4313 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004314 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004315}
Mike Stump1eb44332009-09-09 15:08:12 +00004316
Douglas Gregorb98b1992009-08-11 05:31:07 +00004317template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004318ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004319TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4320 // Transform the type.
4321 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4322 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00004323 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004324
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004325 // Transform all of the components into components similar to what the
4326 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004327 // FIXME: It would be slightly more efficient in the non-dependent case to
4328 // just map FieldDecls, rather than requiring the rebuilder to look for
4329 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004330 // template code that we don't care.
4331 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00004332 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004333 typedef OffsetOfExpr::OffsetOfNode Node;
4334 llvm::SmallVector<Component, 4> Components;
4335 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4336 const Node &ON = E->getComponent(I);
4337 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004338 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004339 Comp.LocStart = ON.getRange().getBegin();
4340 Comp.LocEnd = ON.getRange().getEnd();
4341 switch (ON.getKind()) {
4342 case Node::Array: {
4343 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00004344 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004345 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004346 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004347
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004348 ExprChanged = ExprChanged || Index.get() != FromIndex;
4349 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00004350 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004351 break;
4352 }
Sean Huntc3021132010-05-05 15:23:54 +00004353
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004354 case Node::Field:
4355 case Node::Identifier:
4356 Comp.isBrackets = false;
4357 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004358 if (!Comp.U.IdentInfo)
4359 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004360
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004361 break;
Sean Huntc3021132010-05-05 15:23:54 +00004362
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004363 case Node::Base:
4364 // Will be recomputed during the rebuild.
4365 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004366 }
Sean Huntc3021132010-05-05 15:23:54 +00004367
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004368 Components.push_back(Comp);
4369 }
Sean Huntc3021132010-05-05 15:23:54 +00004370
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004371 // If nothing changed, retain the existing expression.
4372 if (!getDerived().AlwaysRebuild() &&
4373 Type == E->getTypeSourceInfo() &&
4374 !ExprChanged)
4375 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004376
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004377 // Build a new offsetof expression.
4378 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4379 Components.data(), Components.size(),
4380 E->getRParenLoc());
4381}
4382
4383template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004384ExprResult
John McCall454feb92009-12-08 09:21:05 +00004385TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004386 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004387 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004388
John McCalla93c9342009-12-07 02:54:59 +00004389 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004390 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004391 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004392
John McCall5ab75172009-11-04 07:28:41 +00004393 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004394 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004395
John McCall5ab75172009-11-04 07:28:41 +00004396 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004397 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004398 E->getSourceRange());
4399 }
Mike Stump1eb44332009-09-09 15:08:12 +00004400
John McCall60d7b3a2010-08-24 06:29:42 +00004401 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00004402 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004403 // C++0x [expr.sizeof]p1:
4404 // The operand is either an expression, which is an unevaluated operand
4405 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00004406 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004407
Douglas Gregorb98b1992009-08-11 05:31:07 +00004408 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4409 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004410 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004411
Douglas Gregorb98b1992009-08-11 05:31:07 +00004412 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4413 return SemaRef.Owned(E->Retain());
4414 }
Mike Stump1eb44332009-09-09 15:08:12 +00004415
John McCall9ae2f072010-08-23 23:25:46 +00004416 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004417 E->isSizeOf(),
4418 E->getSourceRange());
4419}
Mike Stump1eb44332009-09-09 15:08:12 +00004420
Douglas Gregorb98b1992009-08-11 05:31:07 +00004421template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004422ExprResult
John McCall454feb92009-12-08 09:21:05 +00004423TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004424 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004425 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004426 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004427
John McCall60d7b3a2010-08-24 06:29:42 +00004428 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004429 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004430 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004431
4432
Douglas Gregorb98b1992009-08-11 05:31:07 +00004433 if (!getDerived().AlwaysRebuild() &&
4434 LHS.get() == E->getLHS() &&
4435 RHS.get() == E->getRHS())
4436 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004437
John McCall9ae2f072010-08-23 23:25:46 +00004438 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004439 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00004440 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004441 E->getRBracketLoc());
4442}
Mike Stump1eb44332009-09-09 15:08:12 +00004443
4444template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004445ExprResult
John McCall454feb92009-12-08 09:21:05 +00004446TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004447 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00004448 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004449 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004450 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004451
4452 // Transform arguments.
4453 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004454 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004455 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004456 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004457 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004458 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004459
Mike Stump1eb44332009-09-09 15:08:12 +00004460 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00004461 Args.push_back(Arg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004462 }
Mike Stump1eb44332009-09-09 15:08:12 +00004463
Douglas Gregorb98b1992009-08-11 05:31:07 +00004464 if (!getDerived().AlwaysRebuild() &&
4465 Callee.get() == E->getCallee() &&
4466 !ArgChanged)
4467 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004468
Douglas Gregorb98b1992009-08-11 05:31:07 +00004469 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004470 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004471 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00004472 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004473 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004474 E->getRParenLoc());
4475}
Mike Stump1eb44332009-09-09 15:08:12 +00004476
4477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004478ExprResult
John McCall454feb92009-12-08 09:21:05 +00004479TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004480 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004481 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004482 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004483
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004484 NestedNameSpecifier *Qualifier = 0;
4485 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004486 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004487 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004488 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004489 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00004490 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004491 }
Mike Stump1eb44332009-09-09 15:08:12 +00004492
Eli Friedmanf595cc42009-12-04 06:40:45 +00004493 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004494 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4495 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004496 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00004497 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004498
John McCall6bb80172010-03-30 21:47:33 +00004499 NamedDecl *FoundDecl = E->getFoundDecl();
4500 if (FoundDecl == E->getMemberDecl()) {
4501 FoundDecl = Member;
4502 } else {
4503 FoundDecl = cast_or_null<NamedDecl>(
4504 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4505 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00004506 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00004507 }
4508
Douglas Gregorb98b1992009-08-11 05:31:07 +00004509 if (!getDerived().AlwaysRebuild() &&
4510 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004511 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004512 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004513 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00004514 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00004515
Anders Carlsson1f240322009-12-22 05:24:09 +00004516 // Mark it referenced in the new context regardless.
4517 // FIXME: this is a bit instantiation-specific.
4518 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00004519 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00004520 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004521
John McCalld5532b62009-11-23 01:53:49 +00004522 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00004523 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00004524 TransArgs.setLAngleLoc(E->getLAngleLoc());
4525 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004526 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004527 TemplateArgumentLoc Loc;
4528 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004529 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004530 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004531 }
4532 }
Sean Huntc3021132010-05-05 15:23:54 +00004533
Douglas Gregorb98b1992009-08-11 05:31:07 +00004534 // FIXME: Bogus source location for the operator
4535 SourceLocation FakeOperatorLoc
4536 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4537
John McCallc2233c52010-01-15 08:34:02 +00004538 // FIXME: to do this check properly, we will need to preserve the
4539 // first-qualifier-in-scope here, just in case we had a dependent
4540 // base (and therefore couldn't do the check) and a
4541 // nested-name-qualifier (and therefore could do the lookup).
4542 NamedDecl *FirstQualifierInScope = 0;
4543
John McCall9ae2f072010-08-23 23:25:46 +00004544 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004545 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004546 Qualifier,
4547 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004548 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004549 Member,
John McCall6bb80172010-03-30 21:47:33 +00004550 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00004551 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00004552 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004553 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004554}
Mike Stump1eb44332009-09-09 15:08:12 +00004555
Douglas Gregorb98b1992009-08-11 05:31:07 +00004556template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004557ExprResult
John McCall454feb92009-12-08 09:21:05 +00004558TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004559 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004560 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004561 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004562
John McCall60d7b3a2010-08-24 06:29:42 +00004563 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004564 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004565 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004566
Douglas Gregorb98b1992009-08-11 05:31:07 +00004567 if (!getDerived().AlwaysRebuild() &&
4568 LHS.get() == E->getLHS() &&
4569 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004570 return SemaRef.Owned(E->Retain());
4571
Douglas Gregorb98b1992009-08-11 05:31:07 +00004572 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004573 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004574}
4575
Mike Stump1eb44332009-09-09 15:08:12 +00004576template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004577ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004578TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004579 CompoundAssignOperator *E) {
4580 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004581}
Mike Stump1eb44332009-09-09 15:08:12 +00004582
Douglas Gregorb98b1992009-08-11 05:31:07 +00004583template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004584ExprResult
John McCall454feb92009-12-08 09:21:05 +00004585TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004586 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004587 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004588 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004589
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 Cond.get() == E->getCond() &&
4600 LHS.get() == E->getLHS() &&
4601 RHS.get() == E->getRHS())
4602 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004603
John McCall9ae2f072010-08-23 23:25:46 +00004604 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004605 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004606 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004607 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004608 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004609}
Mike Stump1eb44332009-09-09 15:08:12 +00004610
4611template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004612ExprResult
John McCall454feb92009-12-08 09:21:05 +00004613TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004614 // Implicit casts are eliminated during transformation, since they
4615 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004616 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004617}
Mike Stump1eb44332009-09-09 15:08:12 +00004618
Douglas Gregorb98b1992009-08-11 05:31:07 +00004619template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004620ExprResult
John McCall454feb92009-12-08 09:21:05 +00004621TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004622 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4623 if (!Type)
4624 return ExprError();
4625
John McCall60d7b3a2010-08-24 06:29:42 +00004626 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004627 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004628 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004629 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004630
Douglas Gregorb98b1992009-08-11 05:31:07 +00004631 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004632 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004633 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004634 return SemaRef.Owned(E->Retain());
4635
John McCall9d125032010-01-15 18:39:57 +00004636 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004637 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004638 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004639 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004640}
Mike Stump1eb44332009-09-09 15:08:12 +00004641
Douglas Gregorb98b1992009-08-11 05:31:07 +00004642template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004643ExprResult
John McCall454feb92009-12-08 09:21:05 +00004644TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004645 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4646 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4647 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004648 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004649
John McCall60d7b3a2010-08-24 06:29:42 +00004650 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004651 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004652 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004653
Douglas Gregorb98b1992009-08-11 05:31:07 +00004654 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004655 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004656 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00004657 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004658
John McCall1d7d8d62010-01-19 22:33:45 +00004659 // Note: the expression type doesn't necessarily match the
4660 // type-as-written, but that's okay, because it should always be
4661 // derivable from the initializer.
4662
John McCall42f56b52010-01-18 19:35:47 +00004663 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004664 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00004665 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004666}
Mike Stump1eb44332009-09-09 15:08:12 +00004667
Douglas Gregorb98b1992009-08-11 05:31:07 +00004668template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004669ExprResult
John McCall454feb92009-12-08 09:21:05 +00004670TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004671 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004672 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004673 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004674
Douglas Gregorb98b1992009-08-11 05:31:07 +00004675 if (!getDerived().AlwaysRebuild() &&
4676 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00004677 return SemaRef.Owned(E->Retain());
4678
Douglas Gregorb98b1992009-08-11 05:31:07 +00004679 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004680 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004681 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00004682 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004683 E->getAccessorLoc(),
4684 E->getAccessor());
4685}
Mike Stump1eb44332009-09-09 15:08:12 +00004686
Douglas Gregorb98b1992009-08-11 05:31:07 +00004687template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004688ExprResult
John McCall454feb92009-12-08 09:21:05 +00004689TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004690 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004691
John McCallca0408f2010-08-23 06:44:23 +00004692 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004693 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004694 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004695 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004696 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004697
Douglas Gregorb98b1992009-08-11 05:31:07 +00004698 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCall9ae2f072010-08-23 23:25:46 +00004699 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004700 }
Mike Stump1eb44332009-09-09 15:08:12 +00004701
Douglas Gregorb98b1992009-08-11 05:31:07 +00004702 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004703 return SemaRef.Owned(E->Retain());
4704
Douglas Gregorb98b1992009-08-11 05:31:07 +00004705 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004706 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004707}
Mike Stump1eb44332009-09-09 15:08:12 +00004708
Douglas Gregorb98b1992009-08-11 05:31:07 +00004709template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004710ExprResult
John McCall454feb92009-12-08 09:21:05 +00004711TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004712 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004713
Douglas Gregor43959a92009-08-20 07:17:43 +00004714 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00004715 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004716 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004717 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004718
Douglas Gregor43959a92009-08-20 07:17:43 +00004719 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00004720 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004721 bool ExprChanged = false;
4722 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4723 DEnd = E->designators_end();
4724 D != DEnd; ++D) {
4725 if (D->isFieldDesignator()) {
4726 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4727 D->getDotLoc(),
4728 D->getFieldLoc()));
4729 continue;
4730 }
Mike Stump1eb44332009-09-09 15:08:12 +00004731
Douglas Gregorb98b1992009-08-11 05:31:07 +00004732 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00004733 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004734 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004735 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004736
4737 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004738 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004739
Douglas Gregorb98b1992009-08-11 05:31:07 +00004740 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4741 ArrayExprs.push_back(Index.release());
4742 continue;
4743 }
Mike Stump1eb44332009-09-09 15:08:12 +00004744
Douglas Gregorb98b1992009-08-11 05:31:07 +00004745 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00004746 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004747 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4748 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004749 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004750
John McCall60d7b3a2010-08-24 06:29:42 +00004751 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004752 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004753 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004754
4755 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004756 End.get(),
4757 D->getLBracketLoc(),
4758 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004759
Douglas Gregorb98b1992009-08-11 05:31:07 +00004760 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4761 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004762
Douglas Gregorb98b1992009-08-11 05:31:07 +00004763 ArrayExprs.push_back(Start.release());
4764 ArrayExprs.push_back(End.release());
4765 }
Mike Stump1eb44332009-09-09 15:08:12 +00004766
Douglas Gregorb98b1992009-08-11 05:31:07 +00004767 if (!getDerived().AlwaysRebuild() &&
4768 Init.get() == E->getInit() &&
4769 !ExprChanged)
4770 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004771
Douglas Gregorb98b1992009-08-11 05:31:07 +00004772 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4773 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004774 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004775}
Mike Stump1eb44332009-09-09 15:08:12 +00004776
Douglas Gregorb98b1992009-08-11 05:31:07 +00004777template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004778ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004779TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004780 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004781 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004782
Douglas Gregor5557b252009-10-28 00:29:27 +00004783 // FIXME: Will we ever have proper type location here? Will we actually
4784 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004785 QualType T = getDerived().TransformType(E->getType());
4786 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004787 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004788
Douglas Gregorb98b1992009-08-11 05:31:07 +00004789 if (!getDerived().AlwaysRebuild() &&
4790 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004791 return SemaRef.Owned(E->Retain());
4792
Douglas Gregorb98b1992009-08-11 05:31:07 +00004793 return getDerived().RebuildImplicitValueInitExpr(T);
4794}
Mike Stump1eb44332009-09-09 15:08:12 +00004795
Douglas Gregorb98b1992009-08-11 05:31:07 +00004796template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004797ExprResult
John McCall454feb92009-12-08 09:21:05 +00004798TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004799 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4800 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004801 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004802
John McCall60d7b3a2010-08-24 06:29:42 +00004803 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004804 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004805 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004806
Douglas Gregorb98b1992009-08-11 05:31:07 +00004807 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004808 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004809 SubExpr.get() == E->getSubExpr())
4810 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004811
John McCall9ae2f072010-08-23 23:25:46 +00004812 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004813 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004814}
4815
4816template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004817ExprResult
John McCall454feb92009-12-08 09:21:05 +00004818TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004819 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004820 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004821 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004822 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004823 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004824 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004825
Douglas Gregorb98b1992009-08-11 05:31:07 +00004826 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00004827 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004828 }
Mike Stump1eb44332009-09-09 15:08:12 +00004829
Douglas Gregorb98b1992009-08-11 05:31:07 +00004830 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4831 move_arg(Inits),
4832 E->getRParenLoc());
4833}
Mike Stump1eb44332009-09-09 15:08:12 +00004834
Douglas Gregorb98b1992009-08-11 05:31:07 +00004835/// \brief Transform an address-of-label expression.
4836///
4837/// By default, the transformation of an address-of-label expression always
4838/// rebuilds the expression, so that the label identifier can be resolved to
4839/// the corresponding label statement by semantic analysis.
4840template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004841ExprResult
John McCall454feb92009-12-08 09:21:05 +00004842TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004843 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4844 E->getLabel());
4845}
Mike Stump1eb44332009-09-09 15:08:12 +00004846
4847template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004848ExprResult
John McCall454feb92009-12-08 09:21:05 +00004849TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004850 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004851 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4852 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004853 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004854
Douglas Gregorb98b1992009-08-11 05:31:07 +00004855 if (!getDerived().AlwaysRebuild() &&
4856 SubStmt.get() == E->getSubStmt())
4857 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004858
4859 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004860 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004861 E->getRParenLoc());
4862}
Mike Stump1eb44332009-09-09 15:08:12 +00004863
Douglas Gregorb98b1992009-08-11 05:31:07 +00004864template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004865ExprResult
John McCall454feb92009-12-08 09:21:05 +00004866TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004867 TypeSourceInfo *TInfo1;
4868 TypeSourceInfo *TInfo2;
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004869
4870 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4871 if (!TInfo1)
John McCallf312b1e2010-08-26 23:41:50 +00004872 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004873
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004874 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4875 if (!TInfo2)
John McCallf312b1e2010-08-26 23:41:50 +00004876 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004877
4878 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004879 TInfo1 == E->getArgTInfo1() &&
4880 TInfo2 == E->getArgTInfo2())
Mike Stump1eb44332009-09-09 15:08:12 +00004881 return SemaRef.Owned(E->Retain());
4882
Douglas Gregorb98b1992009-08-11 05:31:07 +00004883 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004884 TInfo1, TInfo2,
4885 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004886}
Mike Stump1eb44332009-09-09 15:08:12 +00004887
Douglas Gregorb98b1992009-08-11 05:31:07 +00004888template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004889ExprResult
John McCall454feb92009-12-08 09:21:05 +00004890TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004891 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004892 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004893 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004894
John McCall60d7b3a2010-08-24 06:29:42 +00004895 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004896 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004897 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004898
John McCall60d7b3a2010-08-24 06:29:42 +00004899 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004900 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004901 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004902
Douglas Gregorb98b1992009-08-11 05:31:07 +00004903 if (!getDerived().AlwaysRebuild() &&
4904 Cond.get() == E->getCond() &&
4905 LHS.get() == E->getLHS() &&
4906 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004907 return SemaRef.Owned(E->Retain());
4908
Douglas Gregorb98b1992009-08-11 05:31:07 +00004909 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004910 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004911 E->getRParenLoc());
4912}
Mike Stump1eb44332009-09-09 15:08:12 +00004913
Douglas Gregorb98b1992009-08-11 05:31:07 +00004914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004915ExprResult
John McCall454feb92009-12-08 09:21:05 +00004916TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004917 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004918}
4919
4920template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004921ExprResult
John McCall454feb92009-12-08 09:21:05 +00004922TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004923 switch (E->getOperator()) {
4924 case OO_New:
4925 case OO_Delete:
4926 case OO_Array_New:
4927 case OO_Array_Delete:
4928 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00004929 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004930
Douglas Gregor668d6d92009-12-13 20:44:55 +00004931 case OO_Call: {
4932 // This is a call to an object's operator().
4933 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4934
4935 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004936 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00004937 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004938 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004939
4940 // FIXME: Poor location information
4941 SourceLocation FakeLParenLoc
4942 = SemaRef.PP.getLocForEndOfToken(
4943 static_cast<Expr *>(Object.get())->getLocEnd());
4944
4945 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00004946 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor668d6d92009-12-13 20:44:55 +00004947 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004948 if (getDerived().DropCallArgument(E->getArg(I)))
4949 break;
Sean Huntc3021132010-05-05 15:23:54 +00004950
John McCall60d7b3a2010-08-24 06:29:42 +00004951 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor668d6d92009-12-13 20:44:55 +00004952 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004953 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004954
Douglas Gregor668d6d92009-12-13 20:44:55 +00004955 Args.push_back(Arg.release());
4956 }
4957
John McCall9ae2f072010-08-23 23:25:46 +00004958 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00004959 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00004960 E->getLocEnd());
4961 }
4962
4963#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4964 case OO_##Name:
4965#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4966#include "clang/Basic/OperatorKinds.def"
4967 case OO_Subscript:
4968 // Handled below.
4969 break;
4970
4971 case OO_Conditional:
4972 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00004973 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004974
4975 case OO_None:
4976 case NUM_OVERLOADED_OPERATORS:
4977 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00004978 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004979 }
4980
John McCall60d7b3a2010-08-24 06:29:42 +00004981 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004982 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004983 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004984
John McCall60d7b3a2010-08-24 06:29:42 +00004985 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004986 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004987 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004988
John McCall60d7b3a2010-08-24 06:29:42 +00004989 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004990 if (E->getNumArgs() == 2) {
4991 Second = getDerived().TransformExpr(E->getArg(1));
4992 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004993 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004994 }
Mike Stump1eb44332009-09-09 15:08:12 +00004995
Douglas Gregorb98b1992009-08-11 05:31:07 +00004996 if (!getDerived().AlwaysRebuild() &&
4997 Callee.get() == E->getCallee() &&
4998 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00004999 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5000 return SemaRef.Owned(E->Retain());
5001
Douglas Gregorb98b1992009-08-11 05:31:07 +00005002 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5003 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005004 Callee.get(),
5005 First.get(),
5006 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005007}
Mike Stump1eb44332009-09-09 15:08:12 +00005008
Douglas Gregorb98b1992009-08-11 05:31:07 +00005009template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005010ExprResult
John McCall454feb92009-12-08 09:21:05 +00005011TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5012 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005013}
Mike Stump1eb44332009-09-09 15:08:12 +00005014
Douglas Gregorb98b1992009-08-11 05:31:07 +00005015template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005016ExprResult
John McCall454feb92009-12-08 09:21:05 +00005017TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005018 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5019 if (!Type)
5020 return ExprError();
5021
John McCall60d7b3a2010-08-24 06:29:42 +00005022 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005023 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005024 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005025 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005026
Douglas Gregorb98b1992009-08-11 05:31:07 +00005027 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005028 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005029 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005030 return SemaRef.Owned(E->Retain());
5031
Douglas Gregorb98b1992009-08-11 05:31:07 +00005032 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005033 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005034 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5035 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5036 SourceLocation FakeRParenLoc
5037 = SemaRef.PP.getLocForEndOfToken(
5038 E->getSubExpr()->getSourceRange().getEnd());
5039 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005040 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005041 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005042 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005043 FakeRAngleLoc,
5044 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005045 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005046 FakeRParenLoc);
5047}
Mike Stump1eb44332009-09-09 15:08:12 +00005048
Douglas Gregorb98b1992009-08-11 05:31:07 +00005049template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005050ExprResult
John McCall454feb92009-12-08 09:21:05 +00005051TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5052 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005053}
Mike Stump1eb44332009-09-09 15:08:12 +00005054
5055template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005056ExprResult
John McCall454feb92009-12-08 09:21:05 +00005057TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5058 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005059}
5060
Douglas Gregorb98b1992009-08-11 05:31:07 +00005061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005062ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005063TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005064 CXXReinterpretCastExpr *E) {
5065 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005066}
Mike Stump1eb44332009-09-09 15:08:12 +00005067
Douglas Gregorb98b1992009-08-11 05:31:07 +00005068template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005069ExprResult
John McCall454feb92009-12-08 09:21:05 +00005070TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5071 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005072}
Mike Stump1eb44332009-09-09 15:08:12 +00005073
Douglas Gregorb98b1992009-08-11 05:31:07 +00005074template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005075ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005076TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005077 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005078 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5079 if (!Type)
5080 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005081
John McCall60d7b3a2010-08-24 06:29:42 +00005082 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005083 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005084 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005085 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005086
Douglas Gregorb98b1992009-08-11 05:31:07 +00005087 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005088 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005089 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005090 return SemaRef.Owned(E->Retain());
5091
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005092 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005093 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005094 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005095 E->getRParenLoc());
5096}
Mike Stump1eb44332009-09-09 15:08:12 +00005097
Douglas Gregorb98b1992009-08-11 05:31:07 +00005098template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005099ExprResult
John McCall454feb92009-12-08 09:21:05 +00005100TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005101 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005102 TypeSourceInfo *TInfo
5103 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5104 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005105 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005106
Douglas Gregorb98b1992009-08-11 05:31:07 +00005107 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005108 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005109 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005110
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005111 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5112 E->getLocStart(),
5113 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005114 E->getLocEnd());
5115 }
Mike Stump1eb44332009-09-09 15:08:12 +00005116
Douglas Gregorb98b1992009-08-11 05:31:07 +00005117 // We don't know whether the expression is potentially evaluated until
5118 // after we perform semantic analysis, so the expression is potentially
5119 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005120 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00005121 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005122
John McCall60d7b3a2010-08-24 06:29:42 +00005123 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005124 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005125 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005126
Douglas Gregorb98b1992009-08-11 05:31:07 +00005127 if (!getDerived().AlwaysRebuild() &&
5128 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00005129 return SemaRef.Owned(E->Retain());
5130
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005131 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5132 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005133 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005134 E->getLocEnd());
5135}
5136
5137template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005138ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00005139TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5140 if (E->isTypeOperand()) {
5141 TypeSourceInfo *TInfo
5142 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5143 if (!TInfo)
5144 return ExprError();
5145
5146 if (!getDerived().AlwaysRebuild() &&
5147 TInfo == E->getTypeOperandSourceInfo())
5148 return SemaRef.Owned(E->Retain());
5149
5150 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5151 E->getLocStart(),
5152 TInfo,
5153 E->getLocEnd());
5154 }
5155
5156 // We don't know whether the expression is potentially evaluated until
5157 // after we perform semantic analysis, so the expression is potentially
5158 // potentially evaluated.
5159 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5160
5161 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5162 if (SubExpr.isInvalid())
5163 return ExprError();
5164
5165 if (!getDerived().AlwaysRebuild() &&
5166 SubExpr.get() == E->getExprOperand())
5167 return SemaRef.Owned(E->Retain());
5168
5169 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5170 E->getLocStart(),
5171 SubExpr.get(),
5172 E->getLocEnd());
5173}
5174
5175template<typename Derived>
5176ExprResult
John McCall454feb92009-12-08 09:21:05 +00005177TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005178 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005179}
Mike Stump1eb44332009-09-09 15:08:12 +00005180
Douglas Gregorb98b1992009-08-11 05:31:07 +00005181template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005182ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005183TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005184 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005185 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005186}
Mike Stump1eb44332009-09-09 15:08:12 +00005187
Douglas Gregorb98b1992009-08-11 05:31:07 +00005188template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005189ExprResult
John McCall454feb92009-12-08 09:21:05 +00005190TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005191 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5192 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5193 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00005194
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005195 if (!getDerived().AlwaysRebuild() && T == E->getType())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005196 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005197
Douglas Gregor828a1972010-01-07 23:12:05 +00005198 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005199}
Mike Stump1eb44332009-09-09 15:08:12 +00005200
Douglas Gregorb98b1992009-08-11 05:31:07 +00005201template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005202ExprResult
John McCall454feb92009-12-08 09:21:05 +00005203TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005204 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005205 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005206 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005207
Douglas Gregorb98b1992009-08-11 05:31:07 +00005208 if (!getDerived().AlwaysRebuild() &&
5209 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005210 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005211
John McCall9ae2f072010-08-23 23:25:46 +00005212 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005213}
Mike Stump1eb44332009-09-09 15:08:12 +00005214
Douglas Gregorb98b1992009-08-11 05:31:07 +00005215template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005216ExprResult
John McCall454feb92009-12-08 09:21:05 +00005217TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005218 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005219 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5220 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005221 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00005222 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005223
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005224 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005225 Param == E->getParam())
5226 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005227
Douglas Gregor036aed12009-12-23 23:03:06 +00005228 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005229}
Mike Stump1eb44332009-09-09 15:08:12 +00005230
Douglas Gregorb98b1992009-08-11 05:31:07 +00005231template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005232ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00005233TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5234 CXXScalarValueInitExpr *E) {
5235 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5236 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005237 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00005238
Douglas Gregorb98b1992009-08-11 05:31:07 +00005239 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005240 T == E->getTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00005241 return SemaRef.Owned(E->Retain());
5242
Douglas Gregorab6677e2010-09-08 00:15:04 +00005243 return getDerived().RebuildCXXScalarValueInitExpr(T,
5244 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00005245 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005246}
Mike Stump1eb44332009-09-09 15:08:12 +00005247
Douglas Gregorb98b1992009-08-11 05:31:07 +00005248template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005249ExprResult
John McCall454feb92009-12-08 09:21:05 +00005250TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005251 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005252 TypeSourceInfo *AllocTypeInfo
5253 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5254 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005255 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005256
Douglas Gregorb98b1992009-08-11 05:31:07 +00005257 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00005258 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005259 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005260 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005261
Douglas Gregorb98b1992009-08-11 05:31:07 +00005262 // Transform the placement arguments (if any).
5263 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005264 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005265 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005266 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005267 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005268 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005269
Douglas Gregorb98b1992009-08-11 05:31:07 +00005270 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5271 PlacementArgs.push_back(Arg.take());
5272 }
Mike Stump1eb44332009-09-09 15:08:12 +00005273
Douglas Gregor43959a92009-08-20 07:17:43 +00005274 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00005275 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005276 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005277 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5278 break;
5279
John McCall60d7b3a2010-08-24 06:29:42 +00005280 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005281 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005282 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005283
Douglas Gregorb98b1992009-08-11 05:31:07 +00005284 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5285 ConstructorArgs.push_back(Arg.take());
5286 }
Mike Stump1eb44332009-09-09 15:08:12 +00005287
Douglas Gregor1af74512010-02-26 00:38:10 +00005288 // Transform constructor, new operator, and delete operator.
5289 CXXConstructorDecl *Constructor = 0;
5290 if (E->getConstructor()) {
5291 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005292 getDerived().TransformDecl(E->getLocStart(),
5293 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005294 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005295 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005296 }
5297
5298 FunctionDecl *OperatorNew = 0;
5299 if (E->getOperatorNew()) {
5300 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005301 getDerived().TransformDecl(E->getLocStart(),
5302 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005303 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00005304 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005305 }
5306
5307 FunctionDecl *OperatorDelete = 0;
5308 if (E->getOperatorDelete()) {
5309 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005310 getDerived().TransformDecl(E->getLocStart(),
5311 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005312 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005313 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005314 }
Sean Huntc3021132010-05-05 15:23:54 +00005315
Douglas Gregorb98b1992009-08-11 05:31:07 +00005316 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005317 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005318 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005319 Constructor == E->getConstructor() &&
5320 OperatorNew == E->getOperatorNew() &&
5321 OperatorDelete == E->getOperatorDelete() &&
5322 !ArgumentChanged) {
5323 // Mark any declarations we need as referenced.
5324 // FIXME: instantiation-specific.
5325 if (Constructor)
5326 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5327 if (OperatorNew)
5328 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5329 if (OperatorDelete)
5330 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005331 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005332 }
Mike Stump1eb44332009-09-09 15:08:12 +00005333
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005334 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005335 if (!ArraySize.get()) {
5336 // If no array size was specified, but the new expression was
5337 // instantiated with an array type (e.g., "new T" where T is
5338 // instantiated with "int[4]"), extract the outer bound from the
5339 // array type as our array size. We do this with constant and
5340 // dependently-sized array types.
5341 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5342 if (!ArrayT) {
5343 // Do nothing
5344 } else if (const ConstantArrayType *ConsArrayT
5345 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005346 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00005347 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5348 ConsArrayT->getSize(),
5349 SemaRef.Context.getSizeType(),
5350 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005351 AllocType = ConsArrayT->getElementType();
5352 } else if (const DependentSizedArrayType *DepArrayT
5353 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5354 if (DepArrayT->getSizeExpr()) {
5355 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5356 AllocType = DepArrayT->getElementType();
5357 }
5358 }
5359 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005360
Douglas Gregorb98b1992009-08-11 05:31:07 +00005361 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5362 E->isGlobalNew(),
5363 /*FIXME:*/E->getLocStart(),
5364 move_arg(PlacementArgs),
5365 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00005366 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005367 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005368 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00005369 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005370 /*FIXME:*/E->getLocStart(),
5371 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005372 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005373}
Mike Stump1eb44332009-09-09 15:08:12 +00005374
Douglas Gregorb98b1992009-08-11 05:31:07 +00005375template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005376ExprResult
John McCall454feb92009-12-08 09:21:05 +00005377TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005378 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005379 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005380 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005381
Douglas Gregor1af74512010-02-26 00:38:10 +00005382 // Transform the delete operator, if known.
5383 FunctionDecl *OperatorDelete = 0;
5384 if (E->getOperatorDelete()) {
5385 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005386 getDerived().TransformDecl(E->getLocStart(),
5387 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005388 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005389 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005390 }
Sean Huntc3021132010-05-05 15:23:54 +00005391
Douglas Gregorb98b1992009-08-11 05:31:07 +00005392 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005393 Operand.get() == E->getArgument() &&
5394 OperatorDelete == E->getOperatorDelete()) {
5395 // Mark any declarations we need as referenced.
5396 // FIXME: instantiation-specific.
5397 if (OperatorDelete)
5398 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00005399
5400 if (!E->getArgument()->isTypeDependent()) {
5401 QualType Destroyed = SemaRef.Context.getBaseElementType(
5402 E->getDestroyedType());
5403 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5404 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5405 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5406 SemaRef.LookupDestructor(Record));
5407 }
5408 }
5409
Mike Stump1eb44332009-09-09 15:08:12 +00005410 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005411 }
Mike Stump1eb44332009-09-09 15:08:12 +00005412
Douglas Gregorb98b1992009-08-11 05:31:07 +00005413 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5414 E->isGlobalDelete(),
5415 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00005416 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005417}
Mike Stump1eb44332009-09-09 15:08:12 +00005418
Douglas Gregorb98b1992009-08-11 05:31:07 +00005419template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005420ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005421TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005422 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005423 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00005424 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005425 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005426
John McCallb3d87482010-08-24 05:47:05 +00005427 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005428 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005429 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005430 E->getOperatorLoc(),
5431 E->isArrow()? tok::arrow : tok::period,
5432 ObjectTypePtr,
5433 MayBePseudoDestructor);
5434 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005435 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005436
John McCallb3d87482010-08-24 05:47:05 +00005437 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora71d8192009-09-04 17:36:40 +00005438 NestedNameSpecifier *Qualifier
5439 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00005440 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005441 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00005442 if (E->getQualifier() && !Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005443 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005444
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005445 PseudoDestructorTypeStorage Destroyed;
5446 if (E->getDestroyedTypeInfo()) {
5447 TypeSourceInfo *DestroyedTypeInfo
5448 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5449 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005450 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005451 Destroyed = DestroyedTypeInfo;
5452 } else if (ObjectType->isDependentType()) {
5453 // We aren't likely to be able to resolve the identifier down to a type
5454 // now anyway, so just retain the identifier.
5455 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5456 E->getDestroyedTypeLoc());
5457 } else {
5458 // Look for a destructor known with the given name.
5459 CXXScopeSpec SS;
5460 if (Qualifier) {
5461 SS.setScopeRep(Qualifier);
5462 SS.setRange(E->getQualifierRange());
5463 }
Sean Huntc3021132010-05-05 15:23:54 +00005464
John McCallb3d87482010-08-24 05:47:05 +00005465 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005466 *E->getDestroyedTypeIdentifier(),
5467 E->getDestroyedTypeLoc(),
5468 /*Scope=*/0,
5469 SS, ObjectTypePtr,
5470 false);
5471 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005472 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005473
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005474 Destroyed
5475 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5476 E->getDestroyedTypeLoc());
5477 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005478
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005479 TypeSourceInfo *ScopeTypeInfo = 0;
5480 if (E->getScopeTypeInfo()) {
Sean Huntc3021132010-05-05 15:23:54 +00005481 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005482 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005483 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005484 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00005485 }
Sean Huntc3021132010-05-05 15:23:54 +00005486
John McCall9ae2f072010-08-23 23:25:46 +00005487 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005488 E->getOperatorLoc(),
5489 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005490 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005491 E->getQualifierRange(),
5492 ScopeTypeInfo,
5493 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005494 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005495 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005496}
Mike Stump1eb44332009-09-09 15:08:12 +00005497
Douglas Gregora71d8192009-09-04 17:36:40 +00005498template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005499ExprResult
John McCallba135432009-11-21 08:51:07 +00005500TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005501 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005502 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5503
5504 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5505 Sema::LookupOrdinaryName);
5506
5507 // Transform all the decls.
5508 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5509 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005510 NamedDecl *InstD = static_cast<NamedDecl*>(
5511 getDerived().TransformDecl(Old->getNameLoc(),
5512 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005513 if (!InstD) {
5514 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5515 // This can happen because of dependent hiding.
5516 if (isa<UsingShadowDecl>(*I))
5517 continue;
5518 else
John McCallf312b1e2010-08-26 23:41:50 +00005519 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005520 }
John McCallf7a1a742009-11-24 19:00:30 +00005521
5522 // Expand using declarations.
5523 if (isa<UsingDecl>(InstD)) {
5524 UsingDecl *UD = cast<UsingDecl>(InstD);
5525 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5526 E = UD->shadow_end(); I != E; ++I)
5527 R.addDecl(*I);
5528 continue;
5529 }
5530
5531 R.addDecl(InstD);
5532 }
5533
5534 // Resolve a kind, but don't do any further analysis. If it's
5535 // ambiguous, the callee needs to deal with it.
5536 R.resolveKind();
5537
5538 // Rebuild the nested-name qualifier, if present.
5539 CXXScopeSpec SS;
5540 NestedNameSpecifier *Qualifier = 0;
5541 if (Old->getQualifier()) {
5542 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005543 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005544 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005545 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005546
John McCallf7a1a742009-11-24 19:00:30 +00005547 SS.setScopeRep(Qualifier);
5548 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005549 }
5550
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005551 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005552 CXXRecordDecl *NamingClass
5553 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5554 Old->getNameLoc(),
5555 Old->getNamingClass()));
5556 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00005557 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005558
Douglas Gregor66c45152010-04-27 16:10:10 +00005559 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005560 }
5561
5562 // If we have no template arguments, it's a normal declaration name.
5563 if (!Old->hasExplicitTemplateArgs())
5564 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5565
5566 // If we have template arguments, rebuild them, then rebuild the
5567 // templateid expression.
5568 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5569 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5570 TemplateArgumentLoc Loc;
5571 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005572 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00005573 TransArgs.addArgument(Loc);
5574 }
5575
5576 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5577 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005578}
Mike Stump1eb44332009-09-09 15:08:12 +00005579
Douglas Gregorb98b1992009-08-11 05:31:07 +00005580template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005581ExprResult
John McCall454feb92009-12-08 09:21:05 +00005582TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005583 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5584 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005585 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005586
Douglas Gregorb98b1992009-08-11 05:31:07 +00005587 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005588 T == E->getQueriedTypeSourceInfo())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005589 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005590
Mike Stump1eb44332009-09-09 15:08:12 +00005591 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005592 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005593 T,
5594 E->getLocEnd());
5595}
Mike Stump1eb44332009-09-09 15:08:12 +00005596
Douglas Gregorb98b1992009-08-11 05:31:07 +00005597template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005598ExprResult
John McCall865d4472009-11-19 22:55:06 +00005599TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005600 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005601 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005602 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005603 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005604 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00005605 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005606
Abramo Bagnara25777432010-08-11 22:01:17 +00005607 DeclarationNameInfo NameInfo
5608 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5609 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005610 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005611
John McCallf7a1a742009-11-24 19:00:30 +00005612 if (!E->hasExplicitTemplateArgs()) {
5613 if (!getDerived().AlwaysRebuild() &&
5614 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005615 // Note: it is sufficient to compare the Name component of NameInfo:
5616 // if name has not changed, DNLoc has not changed either.
5617 NameInfo.getName() == E->getDeclName())
John McCallf7a1a742009-11-24 19:00:30 +00005618 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005619
John McCallf7a1a742009-11-24 19:00:30 +00005620 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5621 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005622 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005623 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005624 }
John McCalld5532b62009-11-23 01:53:49 +00005625
5626 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005627 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005628 TemplateArgumentLoc Loc;
5629 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005630 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005631 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005632 }
5633
John McCallf7a1a742009-11-24 19:00:30 +00005634 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5635 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005636 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005637 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005638}
5639
5640template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005641ExprResult
John McCall454feb92009-12-08 09:21:05 +00005642TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005643 // CXXConstructExprs are always implicit, so when we have a
5644 // 1-argument construction we just transform that argument.
5645 if (E->getNumArgs() == 1 ||
5646 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5647 return getDerived().TransformExpr(E->getArg(0));
5648
Douglas Gregorb98b1992009-08-11 05:31:07 +00005649 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5650
5651 QualType T = getDerived().TransformType(E->getType());
5652 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005653 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005654
5655 CXXConstructorDecl *Constructor
5656 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005657 getDerived().TransformDecl(E->getLocStart(),
5658 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005659 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005660 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005661
Douglas Gregorb98b1992009-08-11 05:31:07 +00005662 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005663 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005664 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005665 ArgEnd = E->arg_end();
5666 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005667 if (getDerived().DropCallArgument(*Arg)) {
5668 ArgumentChanged = true;
5669 break;
5670 }
5671
John McCall60d7b3a2010-08-24 06:29:42 +00005672 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005673 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005674 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005675
Douglas Gregorb98b1992009-08-11 05:31:07 +00005676 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005677 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005678 }
5679
5680 if (!getDerived().AlwaysRebuild() &&
5681 T == E->getType() &&
5682 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005683 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005684 // Mark the constructor as referenced.
5685 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005686 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005687 return SemaRef.Owned(E->Retain());
Douglas Gregorc845aad2010-02-26 00:01:57 +00005688 }
Mike Stump1eb44332009-09-09 15:08:12 +00005689
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005690 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5691 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00005692 move_arg(Args),
5693 E->requiresZeroInitialization(),
5694 E->getConstructionKind());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005695}
Mike Stump1eb44332009-09-09 15:08:12 +00005696
Douglas Gregorb98b1992009-08-11 05:31:07 +00005697/// \brief Transform a C++ temporary-binding expression.
5698///
Douglas Gregor51326552009-12-24 18:51:59 +00005699/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5700/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005701template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005702ExprResult
John McCall454feb92009-12-08 09:21:05 +00005703TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005704 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005705}
Mike Stump1eb44332009-09-09 15:08:12 +00005706
5707/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005708/// be destroyed after the expression is evaluated.
5709///
Douglas Gregor51326552009-12-24 18:51:59 +00005710/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5711/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005712template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005713ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005714TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005715 CXXExprWithTemporaries *E) {
5716 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005717}
Mike Stump1eb44332009-09-09 15:08:12 +00005718
Douglas Gregorb98b1992009-08-11 05:31:07 +00005719template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005720ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005721TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00005722 CXXTemporaryObjectExpr *E) {
5723 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5724 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005725 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005726
Douglas Gregorb98b1992009-08-11 05:31:07 +00005727 CXXConstructorDecl *Constructor
5728 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005729 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005730 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005731 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005732 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005733
Douglas Gregorb98b1992009-08-11 05:31:07 +00005734 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005735 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005736 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005737 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005738 ArgEnd = E->arg_end();
5739 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005740 if (getDerived().DropCallArgument(*Arg)) {
5741 ArgumentChanged = true;
5742 break;
5743 }
5744
John McCall60d7b3a2010-08-24 06:29:42 +00005745 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005746 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005747 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005748
Douglas Gregorb98b1992009-08-11 05:31:07 +00005749 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5750 Args.push_back((Expr *)TransArg.release());
5751 }
Mike Stump1eb44332009-09-09 15:08:12 +00005752
Douglas Gregorb98b1992009-08-11 05:31:07 +00005753 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005754 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005755 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005756 !ArgumentChanged) {
5757 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00005758 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Chandler Carrutha3ce8ae2010-03-31 18:34:58 +00005759 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor91be6f52010-03-02 17:18:33 +00005760 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00005761
5762 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5763 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005764 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005765 E->getLocEnd());
5766}
Mike Stump1eb44332009-09-09 15:08:12 +00005767
Douglas Gregorb98b1992009-08-11 05:31:07 +00005768template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005769ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005770TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005771 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00005772 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5773 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005774 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005775
Douglas Gregorb98b1992009-08-11 05:31:07 +00005776 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005777 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005778 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5779 ArgEnd = E->arg_end();
5780 Arg != ArgEnd; ++Arg) {
John McCall60d7b3a2010-08-24 06:29:42 +00005781 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005782 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005783 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005784
Douglas Gregorb98b1992009-08-11 05:31:07 +00005785 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005786 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005787 }
Mike Stump1eb44332009-09-09 15:08:12 +00005788
Douglas Gregorb98b1992009-08-11 05:31:07 +00005789 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005790 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005791 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005792 return SemaRef.Owned(E->Retain());
5793
Douglas Gregorb98b1992009-08-11 05:31:07 +00005794 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00005795 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005796 E->getLParenLoc(),
5797 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005798 E->getRParenLoc());
5799}
Mike Stump1eb44332009-09-09 15:08:12 +00005800
Douglas Gregorb98b1992009-08-11 05:31:07 +00005801template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005802ExprResult
John McCall865d4472009-11-19 22:55:06 +00005803TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005804 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005805 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005806 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005807 Expr *OldBase;
5808 QualType BaseType;
5809 QualType ObjectType;
5810 if (!E->isImplicitAccess()) {
5811 OldBase = E->getBase();
5812 Base = getDerived().TransformExpr(OldBase);
5813 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005814 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005815
John McCallaa81e162009-12-01 22:10:20 +00005816 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00005817 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00005818 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005819 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005820 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005821 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005822 ObjectTy,
5823 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005824 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005825 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005826
John McCallb3d87482010-08-24 05:47:05 +00005827 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00005828 BaseType = ((Expr*) Base.get())->getType();
5829 } else {
5830 OldBase = 0;
5831 BaseType = getDerived().TransformType(E->getBaseType());
5832 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5833 }
Mike Stump1eb44332009-09-09 15:08:12 +00005834
Douglas Gregor6cd21982009-10-20 05:58:46 +00005835 // Transform the first part of the nested-name-specifier that qualifies
5836 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005837 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005838 = getDerived().TransformFirstQualifierInScope(
5839 E->getFirstQualifierFoundInScope(),
5840 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005841
Douglas Gregora38c6872009-09-03 16:14:30 +00005842 NestedNameSpecifier *Qualifier = 0;
5843 if (E->getQualifier()) {
5844 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5845 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005846 ObjectType,
5847 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005848 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005849 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00005850 }
Mike Stump1eb44332009-09-09 15:08:12 +00005851
Abramo Bagnara25777432010-08-11 22:01:17 +00005852 DeclarationNameInfo NameInfo
5853 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5854 ObjectType);
5855 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005856 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005857
John McCallaa81e162009-12-01 22:10:20 +00005858 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005859 // This is a reference to a member without an explicitly-specified
5860 // template argument list. Optimize for this common case.
5861 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005862 Base.get() == OldBase &&
5863 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005864 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005865 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005866 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005867 return SemaRef.Owned(E->Retain());
5868
John McCall9ae2f072010-08-23 23:25:46 +00005869 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005870 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005871 E->isArrow(),
5872 E->getOperatorLoc(),
5873 Qualifier,
5874 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005875 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005876 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005877 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005878 }
5879
John McCalld5532b62009-11-23 01:53:49 +00005880 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005881 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005882 TemplateArgumentLoc Loc;
5883 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005884 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005885 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005886 }
Mike Stump1eb44332009-09-09 15:08:12 +00005887
John McCall9ae2f072010-08-23 23:25:46 +00005888 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005889 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005890 E->isArrow(),
5891 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005892 Qualifier,
5893 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005894 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005895 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005896 &TransArgs);
5897}
5898
5899template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005900ExprResult
John McCall454feb92009-12-08 09:21:05 +00005901TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005902 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005903 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005904 QualType BaseType;
5905 if (!Old->isImplicitAccess()) {
5906 Base = getDerived().TransformExpr(Old->getBase());
5907 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005908 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005909 BaseType = ((Expr*) Base.get())->getType();
5910 } else {
5911 BaseType = getDerived().TransformType(Old->getBaseType());
5912 }
John McCall129e2df2009-11-30 22:42:35 +00005913
5914 NestedNameSpecifier *Qualifier = 0;
5915 if (Old->getQualifier()) {
5916 Qualifier
5917 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005918 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005919 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00005920 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00005921 }
5922
Abramo Bagnara25777432010-08-11 22:01:17 +00005923 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00005924 Sema::LookupOrdinaryName);
5925
5926 // Transform all the decls.
5927 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5928 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005929 NamedDecl *InstD = static_cast<NamedDecl*>(
5930 getDerived().TransformDecl(Old->getMemberLoc(),
5931 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005932 if (!InstD) {
5933 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5934 // This can happen because of dependent hiding.
5935 if (isa<UsingShadowDecl>(*I))
5936 continue;
5937 else
John McCallf312b1e2010-08-26 23:41:50 +00005938 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005939 }
John McCall129e2df2009-11-30 22:42:35 +00005940
5941 // Expand using declarations.
5942 if (isa<UsingDecl>(InstD)) {
5943 UsingDecl *UD = cast<UsingDecl>(InstD);
5944 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5945 E = UD->shadow_end(); I != E; ++I)
5946 R.addDecl(*I);
5947 continue;
5948 }
5949
5950 R.addDecl(InstD);
5951 }
5952
5953 R.resolveKind();
5954
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005955 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00005956 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00005957 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005958 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00005959 Old->getMemberLoc(),
5960 Old->getNamingClass()));
5961 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00005962 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005963
Douglas Gregor66c45152010-04-27 16:10:10 +00005964 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005965 }
Sean Huntc3021132010-05-05 15:23:54 +00005966
John McCall129e2df2009-11-30 22:42:35 +00005967 TemplateArgumentListInfo TransArgs;
5968 if (Old->hasExplicitTemplateArgs()) {
5969 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5970 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5971 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5972 TemplateArgumentLoc Loc;
5973 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5974 Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005975 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00005976 TransArgs.addArgument(Loc);
5977 }
5978 }
John McCallc2233c52010-01-15 08:34:02 +00005979
5980 // FIXME: to do this check properly, we will need to preserve the
5981 // first-qualifier-in-scope here, just in case we had a dependent
5982 // base (and therefore couldn't do the check) and a
5983 // nested-name-qualifier (and therefore could do the lookup).
5984 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00005985
John McCall9ae2f072010-08-23 23:25:46 +00005986 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005987 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005988 Old->getOperatorLoc(),
5989 Old->isArrow(),
5990 Qualifier,
5991 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00005992 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005993 R,
5994 (Old->hasExplicitTemplateArgs()
5995 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005996}
5997
5998template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005999ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006000TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6001 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6002 if (SubExpr.isInvalid())
6003 return ExprError();
6004
6005 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
6006 return SemaRef.Owned(E->Retain());
6007
6008 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6009}
6010
6011template<typename Derived>
6012ExprResult
John McCall454feb92009-12-08 09:21:05 +00006013TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006014 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006015}
6016
Mike Stump1eb44332009-09-09 15:08:12 +00006017template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006018ExprResult
John McCall454feb92009-12-08 09:21:05 +00006019TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006020 TypeSourceInfo *EncodedTypeInfo
6021 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6022 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006023 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006024
Douglas Gregorb98b1992009-08-11 05:31:07 +00006025 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006026 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00006027 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006028
6029 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006030 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006031 E->getRParenLoc());
6032}
Mike Stump1eb44332009-09-09 15:08:12 +00006033
Douglas Gregorb98b1992009-08-11 05:31:07 +00006034template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006035ExprResult
John McCall454feb92009-12-08 09:21:05 +00006036TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006037 // Transform arguments.
6038 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006039 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006040 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006041 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor92e986e2010-04-22 16:44:27 +00006042 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006043 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006044
Douglas Gregor92e986e2010-04-22 16:44:27 +00006045 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00006046 Args.push_back(Arg.get());
Douglas Gregor92e986e2010-04-22 16:44:27 +00006047 }
6048
6049 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6050 // Class message: transform the receiver type.
6051 TypeSourceInfo *ReceiverTypeInfo
6052 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6053 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006054 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006055
Douglas Gregor92e986e2010-04-22 16:44:27 +00006056 // If nothing changed, just retain the existing message send.
6057 if (!getDerived().AlwaysRebuild() &&
6058 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6059 return SemaRef.Owned(E->Retain());
6060
6061 // Build a new class message send.
6062 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6063 E->getSelector(),
6064 E->getMethodDecl(),
6065 E->getLeftLoc(),
6066 move_arg(Args),
6067 E->getRightLoc());
6068 }
6069
6070 // Instance message: transform the receiver
6071 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6072 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006073 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006074 = getDerived().TransformExpr(E->getInstanceReceiver());
6075 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006076 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006077
6078 // If nothing changed, just retain the existing message send.
6079 if (!getDerived().AlwaysRebuild() &&
6080 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6081 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006082
Douglas Gregor92e986e2010-04-22 16:44:27 +00006083 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006084 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006085 E->getSelector(),
6086 E->getMethodDecl(),
6087 E->getLeftLoc(),
6088 move_arg(Args),
6089 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006090}
6091
Mike Stump1eb44332009-09-09 15:08:12 +00006092template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006093ExprResult
John McCall454feb92009-12-08 09:21:05 +00006094TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006095 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006096}
6097
Mike Stump1eb44332009-09-09 15:08:12 +00006098template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006099ExprResult
John McCall454feb92009-12-08 09:21:05 +00006100TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006101 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006102}
6103
Mike Stump1eb44332009-09-09 15:08:12 +00006104template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006105ExprResult
John McCall454feb92009-12-08 09:21:05 +00006106TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006107 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006108 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006109 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006110 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006111
6112 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006113
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006114 // If nothing changed, just retain the existing expression.
6115 if (!getDerived().AlwaysRebuild() &&
6116 Base.get() == E->getBase())
6117 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006118
John McCall9ae2f072010-08-23 23:25:46 +00006119 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006120 E->getLocation(),
6121 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006122}
6123
Mike Stump1eb44332009-09-09 15:08:12 +00006124template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006125ExprResult
John McCall454feb92009-12-08 09:21:05 +00006126TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregore3303542010-04-26 20:47:02 +00006127 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006128 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00006129 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006130 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006131
Douglas Gregore3303542010-04-26 20:47:02 +00006132 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006133
Douglas Gregore3303542010-04-26 20:47:02 +00006134 // If nothing changed, just retain the existing expression.
6135 if (!getDerived().AlwaysRebuild() &&
6136 Base.get() == E->getBase())
6137 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006138
John McCall9ae2f072010-08-23 23:25:46 +00006139 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregore3303542010-04-26 20:47:02 +00006140 E->getLocation());
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
Fariborz Jahanian09105f52009-08-20 17:02:02 +00006145TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00006146 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006147 // If this implicit setter/getter refers to class methods, it cannot have any
6148 // dependent parts. Just retain the existing declaration.
6149 if (E->getInterfaceDecl())
6150 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006151
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006152 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006153 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006154 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006155 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006156
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006157 // We don't need to transform the getters/setters; they will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006158
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006159 // If nothing changed, just retain the existing expression.
6160 if (!getDerived().AlwaysRebuild() &&
6161 Base.get() == E->getBase())
6162 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006163
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006164 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6165 E->getGetterMethod(),
6166 E->getType(),
6167 E->getSetterMethod(),
6168 E->getLocation(),
John McCall9ae2f072010-08-23 23:25:46 +00006169 Base.get());
Sean Huntc3021132010-05-05 15:23:54 +00006170
Douglas Gregorb98b1992009-08-11 05:31:07 +00006171}
6172
Mike Stump1eb44332009-09-09 15:08:12 +00006173template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006174ExprResult
John McCall454feb92009-12-08 09:21:05 +00006175TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006176 // Can never occur in a dependent context.
Mike Stump1eb44332009-09-09 15:08:12 +00006177 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006178}
6179
Mike Stump1eb44332009-09-09 15:08:12 +00006180template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006181ExprResult
John McCall454feb92009-12-08 09:21:05 +00006182TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006183 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006184 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006185 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006186 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006187
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006188 // If nothing changed, just retain the existing expression.
6189 if (!getDerived().AlwaysRebuild() &&
6190 Base.get() == E->getBase())
6191 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006192
John McCall9ae2f072010-08-23 23:25:46 +00006193 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006194 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006195}
6196
Mike Stump1eb44332009-09-09 15:08:12 +00006197template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006198ExprResult
John McCall454feb92009-12-08 09:21:05 +00006199TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006200 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006201 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006202 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006203 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006204 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006205 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006206
Douglas Gregorb98b1992009-08-11 05:31:07 +00006207 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00006208 SubExprs.push_back(SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006209 }
Mike Stump1eb44332009-09-09 15:08:12 +00006210
Douglas Gregorb98b1992009-08-11 05:31:07 +00006211 if (!getDerived().AlwaysRebuild() &&
6212 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00006213 return SemaRef.Owned(E->Retain());
6214
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6216 move_arg(SubExprs),
6217 E->getRParenLoc());
6218}
6219
Mike Stump1eb44332009-09-09 15:08:12 +00006220template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006221ExprResult
John McCall454feb92009-12-08 09:21:05 +00006222TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006223 SourceLocation CaretLoc(E->getExprLoc());
6224
6225 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6226 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6227 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6228 llvm::SmallVector<ParmVarDecl*, 4> Params;
6229 llvm::SmallVector<QualType, 4> ParamTypes;
6230
6231 // Parameter substitution.
6232 const BlockDecl *BD = E->getBlockDecl();
6233 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6234 EN = BD->param_end(); P != EN; ++P) {
6235 ParmVarDecl *OldParm = (*P);
6236 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6237 QualType NewType = NewParm->getType();
6238 Params.push_back(NewParm);
6239 ParamTypes.push_back(NewParm->getType());
6240 }
6241
6242 const FunctionType *BExprFunctionType = E->getFunctionType();
6243 QualType BExprResultType = BExprFunctionType->getResultType();
6244 if (!BExprResultType.isNull()) {
6245 if (!BExprResultType->isDependentType())
6246 CurBlock->ReturnType = BExprResultType;
6247 else if (BExprResultType != SemaRef.Context.DependentTy)
6248 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6249 }
6250
6251 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00006252 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006253 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006254 return ExprError();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006255 // Set the parameters on the block decl.
6256 if (!Params.empty())
6257 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6258
6259 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6260 CurBlock->ReturnType,
6261 ParamTypes.data(),
6262 ParamTypes.size(),
6263 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006264 0,
6265 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006266
6267 CurBlock->FunctionType = FunctionType;
John McCall9ae2f072010-08-23 23:25:46 +00006268 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006269}
6270
Mike Stump1eb44332009-09-09 15:08:12 +00006271template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006272ExprResult
John McCall454feb92009-12-08 09:21:05 +00006273TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006274 NestedNameSpecifier *Qualifier = 0;
6275
6276 ValueDecl *ND
6277 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6278 E->getDecl()));
6279 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006280 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00006281
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006282 if (!getDerived().AlwaysRebuild() &&
6283 ND == E->getDecl()) {
6284 // Mark it referenced in the new context regardless.
6285 // FIXME: this is a bit instantiation-specific.
6286 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6287
6288 return SemaRef.Owned(E->Retain());
6289 }
6290
Abramo Bagnara25777432010-08-11 22:01:17 +00006291 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006292 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006293 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006294}
Mike Stump1eb44332009-09-09 15:08:12 +00006295
Douglas Gregorb98b1992009-08-11 05:31:07 +00006296//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006297// Type reconstruction
6298//===----------------------------------------------------------------------===//
6299
Mike Stump1eb44332009-09-09 15:08:12 +00006300template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006301QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6302 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006303 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006304 getDerived().getBaseEntity());
6305}
6306
Mike Stump1eb44332009-09-09 15:08:12 +00006307template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006308QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6309 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006310 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006311 getDerived().getBaseEntity());
6312}
6313
Mike Stump1eb44332009-09-09 15:08:12 +00006314template<typename Derived>
6315QualType
John McCall85737a72009-10-30 00:06:24 +00006316TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6317 bool WrittenAsLValue,
6318 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006319 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006320 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006321}
6322
6323template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006324QualType
John McCall85737a72009-10-30 00:06:24 +00006325TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6326 QualType ClassType,
6327 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006328 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006329 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006330}
6331
6332template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006333QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006334TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6335 ArrayType::ArraySizeModifier SizeMod,
6336 const llvm::APInt *Size,
6337 Expr *SizeExpr,
6338 unsigned IndexTypeQuals,
6339 SourceRange BracketsRange) {
6340 if (SizeExpr || !Size)
6341 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6342 IndexTypeQuals, BracketsRange,
6343 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006344
6345 QualType Types[] = {
6346 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6347 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6348 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006349 };
6350 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6351 QualType SizeType;
6352 for (unsigned I = 0; I != NumTypes; ++I)
6353 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6354 SizeType = Types[I];
6355 break;
6356 }
Mike Stump1eb44332009-09-09 15:08:12 +00006357
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006358 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6359 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006360 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006361 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006362 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006363}
Mike Stump1eb44332009-09-09 15:08:12 +00006364
Douglas Gregor577f75a2009-08-04 16:50:30 +00006365template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006366QualType
6367TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006368 ArrayType::ArraySizeModifier SizeMod,
6369 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006370 unsigned IndexTypeQuals,
6371 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006372 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006373 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006374}
6375
6376template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006377QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006378TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006379 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006380 unsigned IndexTypeQuals,
6381 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006382 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006383 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006384}
Mike Stump1eb44332009-09-09 15:08:12 +00006385
Douglas Gregor577f75a2009-08-04 16:50:30 +00006386template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006387QualType
6388TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006389 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006390 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006391 unsigned IndexTypeQuals,
6392 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006393 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006394 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006395 IndexTypeQuals, BracketsRange);
6396}
6397
6398template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006399QualType
6400TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006401 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006402 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006403 unsigned IndexTypeQuals,
6404 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006405 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006406 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006407 IndexTypeQuals, BracketsRange);
6408}
6409
6410template<typename Derived>
6411QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner788b0fd2010-06-23 06:00:24 +00006412 unsigned NumElements,
6413 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006414 // FIXME: semantic checking!
Chris Lattner788b0fd2010-06-23 06:00:24 +00006415 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006416}
Mike Stump1eb44332009-09-09 15:08:12 +00006417
Douglas Gregor577f75a2009-08-04 16:50:30 +00006418template<typename Derived>
6419QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6420 unsigned NumElements,
6421 SourceLocation AttributeLoc) {
6422 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6423 NumElements, true);
6424 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006425 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6426 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00006427 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006428}
Mike Stump1eb44332009-09-09 15:08:12 +00006429
Douglas Gregor577f75a2009-08-04 16:50:30 +00006430template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006431QualType
6432TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00006433 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006434 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00006435 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006436}
Mike Stump1eb44332009-09-09 15:08:12 +00006437
Douglas Gregor577f75a2009-08-04 16:50:30 +00006438template<typename Derived>
6439QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006440 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006441 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006442 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00006443 unsigned Quals,
6444 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00006445 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006446 Quals,
6447 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006448 getDerived().getBaseEntity(),
6449 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006450}
Mike Stump1eb44332009-09-09 15:08:12 +00006451
Douglas Gregor577f75a2009-08-04 16:50:30 +00006452template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006453QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6454 return SemaRef.Context.getFunctionNoProtoType(T);
6455}
6456
6457template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006458QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6459 assert(D && "no decl found");
6460 if (D->isInvalidDecl()) return QualType();
6461
Douglas Gregor92e986e2010-04-22 16:44:27 +00006462 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006463 TypeDecl *Ty;
6464 if (isa<UsingDecl>(D)) {
6465 UsingDecl *Using = cast<UsingDecl>(D);
6466 assert(Using->isTypeName() &&
6467 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6468
6469 // A valid resolved using typename decl points to exactly one type decl.
6470 assert(++Using->shadow_begin() == Using->shadow_end());
6471 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006472
John McCalled976492009-12-04 22:46:56 +00006473 } else {
6474 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6475 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6476 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6477 }
6478
6479 return SemaRef.Context.getTypeDeclType(Ty);
6480}
6481
6482template<typename Derived>
John McCall9ae2f072010-08-23 23:25:46 +00006483QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E) {
6484 return SemaRef.BuildTypeofExprType(E);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006485}
6486
6487template<typename Derived>
6488QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6489 return SemaRef.Context.getTypeOfType(Underlying);
6490}
6491
6492template<typename Derived>
John McCall9ae2f072010-08-23 23:25:46 +00006493QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E) {
6494 return SemaRef.BuildDecltypeType(E);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006495}
6496
6497template<typename Derived>
6498QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006499 TemplateName Template,
6500 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006501 const TemplateArgumentListInfo &TemplateArgs) {
6502 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006503}
Mike Stump1eb44332009-09-09 15:08:12 +00006504
Douglas Gregordcee1a12009-08-06 05:28:30 +00006505template<typename Derived>
6506NestedNameSpecifier *
6507TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6508 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006509 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006510 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006511 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006512 CXXScopeSpec SS;
6513 // FIXME: The source location information is all wrong.
6514 SS.setRange(Range);
6515 SS.setScopeRep(Prefix);
6516 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006517 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006518 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006519 ObjectType,
6520 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006521 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006522}
6523
6524template<typename Derived>
6525NestedNameSpecifier *
6526TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6527 SourceRange Range,
6528 NamespaceDecl *NS) {
6529 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6530}
6531
6532template<typename Derived>
6533NestedNameSpecifier *
6534TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6535 SourceRange Range,
6536 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006537 QualType T) {
6538 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006539 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006540 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006541 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6542 T.getTypePtr());
6543 }
Mike Stump1eb44332009-09-09 15:08:12 +00006544
Douglas Gregordcee1a12009-08-06 05:28:30 +00006545 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6546 return 0;
6547}
Mike Stump1eb44332009-09-09 15:08:12 +00006548
Douglas Gregord1067e52009-08-06 06:41:21 +00006549template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006550TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006551TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6552 bool TemplateKW,
6553 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006554 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006555 Template);
6556}
6557
6558template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006559TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006560TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006561 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006562 const IdentifierInfo &II,
6563 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006564 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006565 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00006566 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006567 UnqualifiedId Name;
6568 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00006569 Sema::TemplateTy Template;
6570 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6571 /*FIXME:*/getDerived().getBaseLocation(),
6572 SS,
6573 Name,
John McCallb3d87482010-08-24 05:47:05 +00006574 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006575 /*EnteringContext=*/false,
6576 Template);
6577 return Template.template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00006578}
Mike Stump1eb44332009-09-09 15:08:12 +00006579
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006581TemplateName
6582TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6583 OverloadedOperatorKind Operator,
6584 QualType ObjectType) {
6585 CXXScopeSpec SS;
6586 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6587 SS.setScopeRep(Qualifier);
6588 UnqualifiedId Name;
6589 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6590 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6591 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00006592 Sema::TemplateTy Template;
6593 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006594 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006595 SS,
6596 Name,
John McCallb3d87482010-08-24 05:47:05 +00006597 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006598 /*EnteringContext=*/false,
6599 Template);
6600 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006601}
Sean Huntc3021132010-05-05 15:23:54 +00006602
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006603template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006604ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006605TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6606 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006607 Expr *OrigCallee,
6608 Expr *First,
6609 Expr *Second) {
6610 Expr *Callee = OrigCallee->IgnoreParenCasts();
6611 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006612
Douglas Gregorb98b1992009-08-11 05:31:07 +00006613 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006614 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00006615 if (!First->getType()->isOverloadableType() &&
6616 !Second->getType()->isOverloadableType())
6617 return getSema().CreateBuiltinArraySubscriptExpr(First,
6618 Callee->getLocStart(),
6619 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006620 } else if (Op == OO_Arrow) {
6621 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00006622 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6623 } else if (Second == 0 || isPostIncDec) {
6624 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006625 // The argument is not of overloadable type, so try to create a
6626 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00006627 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006629
John McCall9ae2f072010-08-23 23:25:46 +00006630 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631 }
6632 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006633 if (!First->getType()->isOverloadableType() &&
6634 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 // Neither of the arguments is an overloadable type, so try to
6636 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00006637 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006638 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00006639 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006641 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006642
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643 return move(Result);
6644 }
6645 }
Mike Stump1eb44332009-09-09 15:08:12 +00006646
6647 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006648 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006649 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006650
John McCall9ae2f072010-08-23 23:25:46 +00006651 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00006652 assert(ULE->requiresADL());
6653
6654 // FIXME: Do we have to check
6655 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006656 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006657 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006658 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006659 }
Mike Stump1eb44332009-09-09 15:08:12 +00006660
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00006662 Expr *Args[2] = { First, Second };
6663 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006664
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 // Create the overloaded operator invocation for unary operators.
6666 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00006667 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006668 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00006669 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 }
Mike Stump1eb44332009-09-09 15:08:12 +00006671
Sebastian Redlf322ed62009-10-29 20:17:01 +00006672 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00006673 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00006674 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006675 First,
6676 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006677
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00006679 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006680 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6682 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006683 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006684
Mike Stump1eb44332009-09-09 15:08:12 +00006685 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006686}
Mike Stump1eb44332009-09-09 15:08:12 +00006687
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006688template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006689ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00006690TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006691 SourceLocation OperatorLoc,
6692 bool isArrow,
6693 NestedNameSpecifier *Qualifier,
6694 SourceRange QualifierRange,
6695 TypeSourceInfo *ScopeType,
6696 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006697 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006698 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006699 CXXScopeSpec SS;
6700 if (Qualifier) {
6701 SS.setRange(QualifierRange);
6702 SS.setScopeRep(Qualifier);
6703 }
6704
John McCall9ae2f072010-08-23 23:25:46 +00006705 QualType BaseType = Base->getType();
6706 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006707 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006708 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006709 !BaseType->getAs<PointerType>()->getPointeeType()
6710 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006711 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00006712 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006713 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006714 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006715 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006716 /*FIXME?*/true);
6717 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006718
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006719 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00006720 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6721 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6722 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6723 NameInfo.setNamedTypeInfo(DestroyedType);
6724
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006725 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00006726
John McCall9ae2f072010-08-23 23:25:46 +00006727 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006728 OperatorLoc, isArrow,
6729 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00006730 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006731 /*TemplateArgs*/ 0);
6732}
6733
Douglas Gregor577f75a2009-08-04 16:50:30 +00006734} // end namespace clang
6735
6736#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H