blob: 0a57c3536f6cf420217f5b19379002c4fdcdcc43 [file] [log] [blame]
John McCalla2becad2009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
John McCall2d887082010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000019#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000020#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000021#include "clang/AST/DeclObjC.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000022#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000023#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
John McCalla2becad2009-10-21 00:40:46 +000028#include "clang/AST/TypeLocBuilder.h"
John McCall19510852010-08-20 18:27:03 +000029#include "clang/Sema/Ownership.h"
30#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000031#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000032#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000033#include <algorithm>
34
35namespace clang {
John McCall781472f2010-08-25 08:40:02 +000036using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000037
Douglas Gregor577f75a2009-08-04 16:50:30 +000038/// \brief A semantic tree transformation that allows one to transform one
39/// abstract syntax tree into another.
40///
Mike Stump1eb44332009-09-09 15:08:12 +000041/// A new tree transformation is defined by creating a new subclass \c X of
42/// \c TreeTransform<X> and then overriding certain operations to provide
43/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000044/// instantiation is implemented as a tree transformation where the
45/// transformation of TemplateTypeParmType nodes involves substituting the
46/// template arguments for their corresponding template parameters; a similar
47/// transformation is performed for non-type template parameters and
48/// template template parameters.
49///
50/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000051/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000052/// override any of the transformation or rebuild operators by providing an
53/// operation with the same signature as the default implementation. The
54/// overridding function should not be virtual.
55///
56/// Semantic tree transformations are split into two stages, either of which
57/// can be replaced by a subclass. The "transform" step transforms an AST node
58/// or the parts of an AST node using the various transformation functions,
59/// then passes the pieces on to the "rebuild" step, which constructs a new AST
60/// node of the appropriate kind from the pieces. The default transformation
61/// routines recursively transform the operands to composite AST nodes (e.g.,
62/// the pointee type of a PointerType node) and, if any of those operand nodes
63/// were changed by the transformation, invokes the rebuild operation to create
64/// a new AST node.
65///
Mike Stump1eb44332009-09-09 15:08:12 +000066/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000067/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000068/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
69/// TransformTemplateName(), or TransformTemplateArgument() with entirely
70/// new implementations.
71///
72/// For more fine-grained transformations, subclasses can replace any of the
73/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000074/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000075/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000076/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000077/// parameters. Additionally, subclasses can override the \c RebuildXXX
78/// functions to control how AST nodes are rebuilt when their operands change.
79/// By default, \c TreeTransform will invoke semantic analysis to rebuild
80/// AST nodes. However, certain other tree transformations (e.g, cloning) may
81/// be able to use more efficient rebuild steps.
82///
83/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000084/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000085/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
86/// operands have not changed (\c AlwaysRebuild()), and customize the
87/// default locations and entity names used for type-checking
88/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000089template<typename Derived>
90class TreeTransform {
91protected:
92 Sema &SemaRef;
Mike Stump1eb44332009-09-09 15:08:12 +000093
94public:
Douglas Gregor577f75a2009-08-04 16:50:30 +000095 /// \brief Initializes a new tree transformer.
96 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +000097
Douglas Gregor577f75a2009-08-04 16:50:30 +000098 /// \brief Retrieves a reference to the derived class.
99 Derived &getDerived() { return static_cast<Derived&>(*this); }
100
101 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000102 const Derived &getDerived() const {
103 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000104 }
105
John McCall60d7b3a2010-08-24 06:29:42 +0000106 static inline ExprResult Owned(Expr *E) { return E; }
107 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000108
Douglas Gregor577f75a2009-08-04 16:50:30 +0000109 /// \brief Retrieves a reference to the semantic analysis object used for
110 /// this tree transform.
111 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000112
Douglas Gregor577f75a2009-08-04 16:50:30 +0000113 /// \brief Whether the transformation should always rebuild AST nodes, even
114 /// if none of the children have changed.
115 ///
116 /// Subclasses may override this function to specify when the transformation
117 /// should rebuild all AST nodes.
118 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000119
Douglas Gregor577f75a2009-08-04 16:50:30 +0000120 /// \brief Returns the location of the entity being transformed, if that
121 /// information was not available elsewhere in the AST.
122 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000123 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 /// provide an alternative implementation that provides better location
125 /// information.
126 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000127
Douglas Gregor577f75a2009-08-04 16:50:30 +0000128 /// \brief Returns the name of the entity being transformed, if that
129 /// information was not available elsewhere in the AST.
130 ///
131 /// By default, returns an empty name. Subclasses can provide an alternative
132 /// implementation with a more precise name.
133 DeclarationName getBaseEntity() { return DeclarationName(); }
134
Douglas Gregorb98b1992009-08-11 05:31:07 +0000135 /// \brief Sets the "base" location and entity when that
136 /// information is known based on another transformation.
137 ///
138 /// By default, the source location and entity are ignored. Subclasses can
139 /// override this function to provide a customized implementation.
140 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000141
Douglas Gregorb98b1992009-08-11 05:31:07 +0000142 /// \brief RAII object that temporarily sets the base location and entity
143 /// used for reporting diagnostics in types.
144 class TemporaryBase {
145 TreeTransform &Self;
146 SourceLocation OldLocation;
147 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000148
Douglas Gregorb98b1992009-08-11 05:31:07 +0000149 public:
150 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000151 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000152 OldLocation = Self.getDerived().getBaseLocation();
153 OldEntity = Self.getDerived().getBaseEntity();
154 Self.getDerived().setBase(Location, Entity);
155 }
Mike Stump1eb44332009-09-09 15:08:12 +0000156
Douglas Gregorb98b1992009-08-11 05:31:07 +0000157 ~TemporaryBase() {
158 Self.getDerived().setBase(OldLocation, OldEntity);
159 }
160 };
Mike Stump1eb44332009-09-09 15:08:12 +0000161
162 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000163 /// transformed.
164 ///
165 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000166 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000167 /// not change. For example, template instantiation need not traverse
168 /// non-dependent types.
169 bool AlreadyTransformed(QualType T) {
170 return T.isNull();
171 }
172
Douglas Gregor6eef5192009-12-14 19:27:10 +0000173 /// \brief Determine whether the given call argument should be dropped, e.g.,
174 /// because it is a default argument.
175 ///
176 /// Subclasses can provide an alternative implementation of this routine to
177 /// determine which kinds of call arguments get dropped. By default,
178 /// CXXDefaultArgument nodes are dropped (prior to transformation).
179 bool DropCallArgument(Expr *E) {
180 return E->isDefaultArgument();
181 }
Sean Huntc3021132010-05-05 15:23:54 +0000182
Douglas Gregor577f75a2009-08-04 16:50:30 +0000183 /// \brief Transforms the given type into another type.
184 ///
John McCalla2becad2009-10-21 00:40:46 +0000185 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000186 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000187 /// function. This is expensive, but we don't mind, because
188 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000189 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000190 ///
191 /// \returns the transformed type.
Douglas Gregor124b8782010-02-16 19:09:40 +0000192 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000193
John McCalla2becad2009-10-21 00:40:46 +0000194 /// \brief Transforms the given type-with-location into a new
195 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000196 ///
John McCalla2becad2009-10-21 00:40:46 +0000197 /// By default, this routine transforms a type by delegating to the
198 /// appropriate TransformXXXType to build a new type. Subclasses
199 /// may override this function (to take over all type
200 /// transformations) or some set of the TransformXXXType functions
201 /// to alter the transformation.
Sean Huntc3021132010-05-05 15:23:54 +0000202 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
Douglas Gregor124b8782010-02-16 19:09:40 +0000203 QualType ObjectType = QualType());
John McCalla2becad2009-10-21 00:40:46 +0000204
205 /// \brief Transform the given type-with-location into a new
206 /// type, collecting location information in the given builder
207 /// as necessary.
208 ///
Sean Huntc3021132010-05-05 15:23:54 +0000209 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +0000210 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000211
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000212 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000213 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000214 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000215 /// appropriate TransformXXXStmt function to transform a specific kind of
216 /// statement or the TransformExpr() function to transform an expression.
217 /// Subclasses may override this function to transform statements using some
218 /// other mechanism.
219 ///
220 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000221 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000222
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000223 /// \brief Transform the given expression.
224 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000225 /// By default, this routine transforms an expression by delegating to the
226 /// appropriate TransformXXXExpr function to build a new expression.
227 /// Subclasses may override this function to transform expressions using some
228 /// other mechanism.
229 ///
230 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000231 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000232
Douglas Gregor577f75a2009-08-04 16:50:30 +0000233 /// \brief Transform the given declaration, which is referenced from a type
234 /// or expression.
235 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000236 /// By default, acts as the identity function on declarations. Subclasses
237 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000238 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000239
240 /// \brief Transform the definition of the given declaration.
241 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000242 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000243 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000244 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
245 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000246 }
Mike Stump1eb44332009-09-09 15:08:12 +0000247
Douglas Gregor6cd21982009-10-20 05:58:46 +0000248 /// \brief Transform the given declaration, which was the first part of a
249 /// nested-name-specifier in a member access expression.
250 ///
Sean Huntc3021132010-05-05 15:23:54 +0000251 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000252 /// identifier in a nested-name-specifier of a member access expression, e.g.,
253 /// the \c T in \c x->T::member
254 ///
255 /// By default, invokes TransformDecl() to transform the declaration.
256 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000257 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
258 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000259 }
Sean Huntc3021132010-05-05 15:23:54 +0000260
Douglas Gregor577f75a2009-08-04 16:50:30 +0000261 /// \brief Transform the given nested-name-specifier.
262 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000263 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000264 /// nested-name-specifier. Subclasses may override this function to provide
265 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000266 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000267 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000268 QualType ObjectType = QualType(),
269 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000270
Douglas Gregor81499bb2009-09-03 22:13:48 +0000271 /// \brief Transform the given declaration name.
272 ///
273 /// By default, transforms the types of conversion function, constructor,
274 /// and destructor names and then (if needed) rebuilds the declaration name.
275 /// Identifiers and selectors are returned unmodified. Sublcasses may
276 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000277 DeclarationNameInfo
278 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
279 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000280
Douglas Gregor577f75a2009-08-04 16:50:30 +0000281 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000282 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000283 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000284 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000285 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000286 TemplateName TransformTemplateName(TemplateName Name,
287 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000288
Douglas Gregor577f75a2009-08-04 16:50:30 +0000289 /// \brief Transform the given template argument.
290 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000291 /// By default, this operation transforms the type, expression, or
292 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000293 /// new template argument from the transformed result. Subclasses may
294 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000295 ///
296 /// Returns true if there was an error.
297 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
298 TemplateArgumentLoc &Output);
299
300 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
301 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
302 TemplateArgumentLoc &ArgLoc);
303
John McCalla93c9342009-12-07 02:54:59 +0000304 /// \brief Fakes up a TypeSourceInfo for a type.
305 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
306 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000307 getDerived().getBaseLocation());
308 }
Mike Stump1eb44332009-09-09 15:08:12 +0000309
John McCalla2becad2009-10-21 00:40:46 +0000310#define ABSTRACT_TYPELOC(CLASS, PARENT)
311#define TYPELOC(CLASS, PARENT) \
Douglas Gregor124b8782010-02-16 19:09:40 +0000312 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
313 QualType ObjectType = QualType());
John McCalla2becad2009-10-21 00:40:46 +0000314#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000315
John McCall21ef0fa2010-03-11 09:03:00 +0000316 /// \brief Transforms the parameters of a function type into the
317 /// given vectors.
318 ///
319 /// The result vectors should be kept in sync; null entries in the
320 /// variables vector are acceptable.
321 ///
322 /// Return true on error.
323 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
324 llvm::SmallVectorImpl<QualType> &PTypes,
325 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
326
327 /// \brief Transforms a single function-type parameter. Return null
328 /// on error.
329 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
330
Sean Huntc3021132010-05-05 15:23:54 +0000331 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +0000332 QualType ObjectType);
John McCall85737a72009-10-30 00:06:24 +0000333
Sean Huntc3021132010-05-05 15:23:54 +0000334 QualType
Douglas Gregordd62b152009-10-19 22:04:39 +0000335 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
336 QualType ObjectType);
John McCall833ca992009-10-29 08:12:44 +0000337
John McCall60d7b3a2010-08-24 06:29:42 +0000338 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
339 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000340
Douglas Gregor43959a92009-08-20 07:17:43 +0000341#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000342 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000343#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000344 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000345#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000346#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000347
Douglas Gregor577f75a2009-08-04 16:50:30 +0000348 /// \brief Build a new pointer type given its pointee type.
349 ///
350 /// By default, performs semantic analysis when building the pointer type.
351 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000352 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000353
354 /// \brief Build a new block pointer type given its pointee type.
355 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000356 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000357 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000358 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000359
John McCall85737a72009-10-30 00:06:24 +0000360 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000361 ///
John McCall85737a72009-10-30 00:06:24 +0000362 /// By default, performs semantic analysis when building the
363 /// reference type. Subclasses may override this routine to provide
364 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000365 ///
John McCall85737a72009-10-30 00:06:24 +0000366 /// \param LValue whether the type was written with an lvalue sigil
367 /// or an rvalue sigil.
368 QualType RebuildReferenceType(QualType ReferentType,
369 bool LValue,
370 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000371
Douglas Gregor577f75a2009-08-04 16:50:30 +0000372 /// \brief Build a new member pointer type given the pointee type and the
373 /// class type it refers into.
374 ///
375 /// By default, performs semantic analysis when building the member pointer
376 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000377 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
378 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000379
Douglas Gregor577f75a2009-08-04 16:50:30 +0000380 /// \brief Build a new array type given the element type, size
381 /// modifier, size of the array (if known), size expression, and index type
382 /// qualifiers.
383 ///
384 /// By default, performs semantic analysis when building the array type.
385 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000386 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000387 QualType RebuildArrayType(QualType ElementType,
388 ArrayType::ArraySizeModifier SizeMod,
389 const llvm::APInt *Size,
390 Expr *SizeExpr,
391 unsigned IndexTypeQuals,
392 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000393
Douglas Gregor577f75a2009-08-04 16:50:30 +0000394 /// \brief Build a new constant array type given the element type, size
395 /// modifier, (known) size of the array, and index type qualifiers.
396 ///
397 /// By default, performs semantic analysis when building the array type.
398 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000399 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000400 ArrayType::ArraySizeModifier SizeMod,
401 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000402 unsigned IndexTypeQuals,
403 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000404
Douglas Gregor577f75a2009-08-04 16:50:30 +0000405 /// \brief Build a new incomplete array type given the element type, size
406 /// modifier, and index type qualifiers.
407 ///
408 /// By default, performs semantic analysis when building the array type.
409 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000410 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000411 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000412 unsigned IndexTypeQuals,
413 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000414
Mike Stump1eb44332009-09-09 15:08:12 +0000415 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000416 /// size modifier, size expression, and index type qualifiers.
417 ///
418 /// By default, performs semantic analysis when building the array type.
419 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000420 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000421 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000422 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000423 unsigned IndexTypeQuals,
424 SourceRange BracketsRange);
425
Mike Stump1eb44332009-09-09 15:08:12 +0000426 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000427 /// size modifier, size expression, and index type qualifiers.
428 ///
429 /// By default, performs semantic analysis when building the array type.
430 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000431 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000432 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000433 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000434 unsigned IndexTypeQuals,
435 SourceRange BracketsRange);
436
437 /// \brief Build a new vector type given the element type and
438 /// number of elements.
439 ///
440 /// By default, performs semantic analysis when building the vector type.
441 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000442 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Chris Lattner788b0fd2010-06-23 06:00:24 +0000443 VectorType::AltiVecSpecific AltiVecSpec);
Mike Stump1eb44332009-09-09 15:08:12 +0000444
Douglas Gregor577f75a2009-08-04 16:50:30 +0000445 /// \brief Build a new extended vector type given the element type and
446 /// number of elements.
447 ///
448 /// By default, performs semantic analysis when building the vector type.
449 /// Subclasses may override this routine to provide different behavior.
450 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
451 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000452
453 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000454 /// given the element type and number of elements.
455 ///
456 /// By default, performs semantic analysis when building the vector type.
457 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000458 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000459 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000460 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000461
Douglas Gregor577f75a2009-08-04 16:50:30 +0000462 /// \brief Build a new function type.
463 ///
464 /// By default, performs semantic analysis when building the function type.
465 /// Subclasses may override this routine to provide different behavior.
466 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000467 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000468 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000469 bool Variadic, unsigned Quals,
470 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000471
John McCalla2becad2009-10-21 00:40:46 +0000472 /// \brief Build a new unprototyped function type.
473 QualType RebuildFunctionNoProtoType(QualType ResultType);
474
John McCalled976492009-12-04 22:46:56 +0000475 /// \brief Rebuild an unresolved typename type, given the decl that
476 /// the UnresolvedUsingTypenameDecl was transformed to.
477 QualType RebuildUnresolvedUsingType(Decl *D);
478
Douglas Gregor577f75a2009-08-04 16:50:30 +0000479 /// \brief Build a new typedef type.
480 QualType RebuildTypedefType(TypedefDecl *Typedef) {
481 return SemaRef.Context.getTypeDeclType(Typedef);
482 }
483
484 /// \brief Build a new class/struct/union type.
485 QualType RebuildRecordType(RecordDecl *Record) {
486 return SemaRef.Context.getTypeDeclType(Record);
487 }
488
489 /// \brief Build a new Enum type.
490 QualType RebuildEnumType(EnumDecl *Enum) {
491 return SemaRef.Context.getTypeDeclType(Enum);
492 }
John McCall7da24312009-09-05 00:15:47 +0000493
Mike Stump1eb44332009-09-09 15:08:12 +0000494 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000495 ///
496 /// By default, performs semantic analysis when building the typeof type.
497 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000498 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000499
Mike Stump1eb44332009-09-09 15:08:12 +0000500 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000501 ///
502 /// By default, builds a new TypeOfType with the given underlying type.
503 QualType RebuildTypeOfType(QualType Underlying);
504
Mike Stump1eb44332009-09-09 15:08:12 +0000505 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000506 ///
507 /// By default, performs semantic analysis when building the decltype type.
508 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000509 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000510
Douglas Gregor577f75a2009-08-04 16:50:30 +0000511 /// \brief Build a new template specialization type.
512 ///
513 /// By default, performs semantic analysis when building the template
514 /// specialization type. Subclasses may override this routine to provide
515 /// different behavior.
516 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000517 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000518 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000519
Douglas Gregor577f75a2009-08-04 16:50:30 +0000520 /// \brief Build a new qualified name type.
521 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000522 /// By default, builds a new ElaboratedType type from the keyword,
523 /// the nested-name-specifier and the named type.
524 /// Subclasses may override this routine to provide different behavior.
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,
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001889 QualType T,
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001890 ObjCMethodDecl *Setter,
1891 SourceLocation NameLoc,
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001892 Expr *Base,
1893 SourceLocation SuperLoc,
1894 QualType SuperTy,
1895 bool Super) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001896 // Since these expressions can only be value-dependent, we do not need to
1897 // perform semantic analysis again.
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001898 if (Super)
1899 return Owned(
1900 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1901 Setter,
1902 NameLoc,
1903 SuperLoc,
1904 SuperTy));
1905 else
1906 return Owned(
1907 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(
1908 Getter, T,
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001909 Setter,
1910 NameLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001911 Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001912 }
1913
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001914 /// \brief Build a new Objective-C "isa" expression.
1915 ///
1916 /// By default, performs semantic analysis to build the new expression.
1917 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001918 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001919 bool IsArrow) {
1920 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001921 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001922 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1923 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001924 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001925 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00001926 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001927 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001928 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001929
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001930 if (Result.get())
1931 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001932
John McCall9ae2f072010-08-23 23:25:46 +00001933 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001934 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001935 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001936 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001937 /*TemplateArgs=*/0);
1938 }
Sean Huntc3021132010-05-05 15:23:54 +00001939
Douglas Gregorb98b1992009-08-11 05:31:07 +00001940 /// \brief Build a new shuffle vector expression.
1941 ///
1942 /// By default, performs semantic analysis to build the new expression.
1943 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001944 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001945 MultiExprArg SubExprs,
1946 SourceLocation RParenLoc) {
1947 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001948 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001949 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1950 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1951 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1952 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001953
Douglas Gregorb98b1992009-08-11 05:31:07 +00001954 // Build a reference to the __builtin_shufflevector builtin
1955 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001956 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001957 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001958 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001960
1961 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001962 unsigned NumSubExprs = SubExprs.size();
1963 Expr **Subs = (Expr **)SubExprs.release();
1964 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1965 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00001966 Builtin->getCallResultType(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001967 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00001968 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001969
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00001971 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001972 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001973 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001974
Douglas Gregorb98b1992009-08-11 05:31:07 +00001975 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001976 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001977 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001978};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001979
Douglas Gregor43959a92009-08-20 07:17:43 +00001980template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00001981StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00001982 if (!S)
1983 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001984
Douglas Gregor43959a92009-08-20 07:17:43 +00001985 switch (S->getStmtClass()) {
1986 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001987
Douglas Gregor43959a92009-08-20 07:17:43 +00001988 // Transform individual statement nodes
1989#define STMT(Node, Parent) \
1990 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1991#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00001992#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001993
Douglas Gregor43959a92009-08-20 07:17:43 +00001994 // Transform expressions by calling TransformExpr.
1995#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00001996#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00001997#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00001998#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00001999 {
John McCall60d7b3a2010-08-24 06:29:42 +00002000 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002001 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002002 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002003
John McCall9ae2f072010-08-23 23:25:46 +00002004 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002005 }
Mike Stump1eb44332009-09-09 15:08:12 +00002006 }
2007
Douglas Gregor43959a92009-08-20 07:17:43 +00002008 return SemaRef.Owned(S->Retain());
2009}
Mike Stump1eb44332009-09-09 15:08:12 +00002010
2011
Douglas Gregor670444e2009-08-04 22:27:00 +00002012template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002013ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002014 if (!E)
2015 return SemaRef.Owned(E);
2016
2017 switch (E->getStmtClass()) {
2018 case Stmt::NoStmtClass: break;
2019#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002020#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002021#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002022 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002023#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002024 }
2025
Douglas Gregorb98b1992009-08-11 05:31:07 +00002026 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002027}
2028
2029template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002030NestedNameSpecifier *
2031TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002032 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002033 QualType ObjectType,
2034 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00002035 if (!NNS)
2036 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002037
Douglas Gregor43959a92009-08-20 07:17:43 +00002038 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002039 NestedNameSpecifier *Prefix = NNS->getPrefix();
2040 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002041 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002042 ObjectType,
2043 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002044 if (!Prefix)
2045 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002046
2047 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00002048 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00002049 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00002050 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002051 }
Mike Stump1eb44332009-09-09 15:08:12 +00002052
Douglas Gregordcee1a12009-08-06 05:28:30 +00002053 switch (NNS->getKind()) {
2054 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00002055 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002056 "Identifier nested-name-specifier with no prefix or object type");
2057 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2058 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002059 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002060
2061 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002062 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002063 ObjectType,
2064 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002065
Douglas Gregordcee1a12009-08-06 05:28:30 +00002066 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002067 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002068 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002069 getDerived().TransformDecl(Range.getBegin(),
2070 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002071 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002072 Prefix == NNS->getPrefix() &&
2073 NS == NNS->getAsNamespace())
2074 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002075
Douglas Gregordcee1a12009-08-06 05:28:30 +00002076 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2077 }
Mike Stump1eb44332009-09-09 15:08:12 +00002078
Douglas Gregordcee1a12009-08-06 05:28:30 +00002079 case NestedNameSpecifier::Global:
2080 // There is no meaningful transformation that one could perform on the
2081 // global scope.
2082 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002083
Douglas Gregordcee1a12009-08-06 05:28:30 +00002084 case NestedNameSpecifier::TypeSpecWithTemplate:
2085 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002086 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00002087 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2088 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002089 if (T.isNull())
2090 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002091
Douglas Gregordcee1a12009-08-06 05:28:30 +00002092 if (!getDerived().AlwaysRebuild() &&
2093 Prefix == NNS->getPrefix() &&
2094 T == QualType(NNS->getAsType(), 0))
2095 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002096
2097 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2098 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002099 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002100 }
2101 }
Mike Stump1eb44332009-09-09 15:08:12 +00002102
Douglas Gregordcee1a12009-08-06 05:28:30 +00002103 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002104 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002105}
2106
2107template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002108DeclarationNameInfo
2109TreeTransform<Derived>
2110::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2111 QualType ObjectType) {
2112 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002113 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002114 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002115
2116 switch (Name.getNameKind()) {
2117 case DeclarationName::Identifier:
2118 case DeclarationName::ObjCZeroArgSelector:
2119 case DeclarationName::ObjCOneArgSelector:
2120 case DeclarationName::ObjCMultiArgSelector:
2121 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002122 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002123 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002124 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002125
Douglas Gregor81499bb2009-09-03 22:13:48 +00002126 case DeclarationName::CXXConstructorName:
2127 case DeclarationName::CXXDestructorName:
2128 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002129 TypeSourceInfo *NewTInfo;
2130 CanQualType NewCanTy;
2131 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2132 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2133 if (!NewTInfo)
2134 return DeclarationNameInfo();
2135 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2136 }
2137 else {
2138 NewTInfo = 0;
2139 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2140 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2141 ObjectType);
2142 if (NewT.isNull())
2143 return DeclarationNameInfo();
2144 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2145 }
Mike Stump1eb44332009-09-09 15:08:12 +00002146
Abramo Bagnara25777432010-08-11 22:01:17 +00002147 DeclarationName NewName
2148 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2149 NewCanTy);
2150 DeclarationNameInfo NewNameInfo(NameInfo);
2151 NewNameInfo.setName(NewName);
2152 NewNameInfo.setNamedTypeInfo(NewTInfo);
2153 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002154 }
Mike Stump1eb44332009-09-09 15:08:12 +00002155 }
2156
Abramo Bagnara25777432010-08-11 22:01:17 +00002157 assert(0 && "Unknown name kind.");
2158 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002159}
2160
2161template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002162TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002163TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2164 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002165 SourceLocation Loc = getDerived().getBaseLocation();
2166
Douglas Gregord1067e52009-08-06 06:41:21 +00002167 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002168 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002169 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002170 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2171 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002172 if (!NNS)
2173 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002174
Douglas Gregord1067e52009-08-06 06:41:21 +00002175 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002176 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002177 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002178 if (!TransTemplate)
2179 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002180
Douglas Gregord1067e52009-08-06 06:41:21 +00002181 if (!getDerived().AlwaysRebuild() &&
2182 NNS == QTN->getQualifier() &&
2183 TransTemplate == Template)
2184 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002185
Douglas Gregord1067e52009-08-06 06:41:21 +00002186 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2187 TransTemplate);
2188 }
Mike Stump1eb44332009-09-09 15:08:12 +00002189
John McCallf7a1a742009-11-24 19:00:30 +00002190 // These should be getting filtered out before they make it into the AST.
2191 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002192 }
Mike Stump1eb44332009-09-09 15:08:12 +00002193
Douglas Gregord1067e52009-08-06 06:41:21 +00002194 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002195 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002196 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002197 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2198 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002199 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00002200 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002201
Douglas Gregord1067e52009-08-06 06:41:21 +00002202 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002203 NNS == DTN->getQualifier() &&
2204 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002205 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002206
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002207 if (DTN->isIdentifier()) {
2208 // FIXME: Bad range
2209 SourceRange QualifierRange(getDerived().getBaseLocation());
2210 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2211 *DTN->getIdentifier(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002212 ObjectType);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002213 }
Sean Huntc3021132010-05-05 15:23:54 +00002214
2215 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002216 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002217 }
Mike Stump1eb44332009-09-09 15:08:12 +00002218
Douglas Gregord1067e52009-08-06 06:41:21 +00002219 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002220 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002221 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002222 if (!TransTemplate)
2223 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002224
Douglas Gregord1067e52009-08-06 06:41:21 +00002225 if (!getDerived().AlwaysRebuild() &&
2226 TransTemplate == Template)
2227 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002228
Douglas Gregord1067e52009-08-06 06:41:21 +00002229 return TemplateName(TransTemplate);
2230 }
Mike Stump1eb44332009-09-09 15:08:12 +00002231
John McCallf7a1a742009-11-24 19:00:30 +00002232 // These should be getting filtered out before they reach the AST.
2233 assert(false && "overloaded function decl survived to here");
2234 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002235}
2236
2237template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002238void TreeTransform<Derived>::InventTemplateArgumentLoc(
2239 const TemplateArgument &Arg,
2240 TemplateArgumentLoc &Output) {
2241 SourceLocation Loc = getDerived().getBaseLocation();
2242 switch (Arg.getKind()) {
2243 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002244 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002245 break;
2246
2247 case TemplateArgument::Type:
2248 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002249 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002250
John McCall833ca992009-10-29 08:12:44 +00002251 break;
2252
Douglas Gregor788cd062009-11-11 01:00:40 +00002253 case TemplateArgument::Template:
2254 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2255 break;
Sean Huntc3021132010-05-05 15:23:54 +00002256
John McCall833ca992009-10-29 08:12:44 +00002257 case TemplateArgument::Expression:
2258 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2259 break;
2260
2261 case TemplateArgument::Declaration:
2262 case TemplateArgument::Integral:
2263 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002264 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002265 break;
2266 }
2267}
2268
2269template<typename Derived>
2270bool TreeTransform<Derived>::TransformTemplateArgument(
2271 const TemplateArgumentLoc &Input,
2272 TemplateArgumentLoc &Output) {
2273 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002274 switch (Arg.getKind()) {
2275 case TemplateArgument::Null:
2276 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002277 Output = Input;
2278 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002279
Douglas Gregor670444e2009-08-04 22:27:00 +00002280 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002281 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002282 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002283 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002284
2285 DI = getDerived().TransformType(DI);
2286 if (!DI) return true;
2287
2288 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2289 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002290 }
Mike Stump1eb44332009-09-09 15:08:12 +00002291
Douglas Gregor670444e2009-08-04 22:27:00 +00002292 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002293 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002294 DeclarationName Name;
2295 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2296 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002297 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002298 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002299 if (!D) return true;
2300
John McCall828bff22009-10-29 18:45:58 +00002301 Expr *SourceExpr = Input.getSourceDeclExpression();
2302 if (SourceExpr) {
2303 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002304 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002305 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002306 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002307 }
2308
2309 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002310 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002311 }
Mike Stump1eb44332009-09-09 15:08:12 +00002312
Douglas Gregor788cd062009-11-11 01:00:40 +00002313 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002314 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002315 TemplateName Template
2316 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2317 if (Template.isNull())
2318 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002319
Douglas Gregor788cd062009-11-11 01:00:40 +00002320 Output = TemplateArgumentLoc(TemplateArgument(Template),
2321 Input.getTemplateQualifierRange(),
2322 Input.getTemplateNameLoc());
2323 return false;
2324 }
Sean Huntc3021132010-05-05 15:23:54 +00002325
Douglas Gregor670444e2009-08-04 22:27:00 +00002326 case TemplateArgument::Expression: {
2327 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002328 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002329 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002330
John McCall833ca992009-10-29 08:12:44 +00002331 Expr *InputExpr = Input.getSourceExpression();
2332 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2333
John McCall60d7b3a2010-08-24 06:29:42 +00002334 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002335 = getDerived().TransformExpr(InputExpr);
2336 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002337 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002338 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002339 }
Mike Stump1eb44332009-09-09 15:08:12 +00002340
Douglas Gregor670444e2009-08-04 22:27:00 +00002341 case TemplateArgument::Pack: {
2342 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2343 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002344 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002345 AEnd = Arg.pack_end();
2346 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002347
John McCall833ca992009-10-29 08:12:44 +00002348 // FIXME: preserve source information here when we start
2349 // caring about parameter packs.
2350
John McCall828bff22009-10-29 18:45:58 +00002351 TemplateArgumentLoc InputArg;
2352 TemplateArgumentLoc OutputArg;
2353 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2354 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002355 return true;
2356
John McCall828bff22009-10-29 18:45:58 +00002357 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002358 }
2359 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002360 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002361 true);
John McCall828bff22009-10-29 18:45:58 +00002362 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002363 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002364 }
2365 }
Mike Stump1eb44332009-09-09 15:08:12 +00002366
Douglas Gregor670444e2009-08-04 22:27:00 +00002367 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002368 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002369}
2370
Douglas Gregor577f75a2009-08-04 16:50:30 +00002371//===----------------------------------------------------------------------===//
2372// Type transformation
2373//===----------------------------------------------------------------------===//
2374
2375template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00002376QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregor124b8782010-02-16 19:09:40 +00002377 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002378 if (getDerived().AlreadyTransformed(T))
2379 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002380
John McCalla2becad2009-10-21 00:40:46 +00002381 // Temporary workaround. All of these transformations should
2382 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002383 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002384 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002385
Douglas Gregor124b8782010-02-16 19:09:40 +00002386 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002387
John McCalla2becad2009-10-21 00:40:46 +00002388 if (!NewDI)
2389 return QualType();
2390
2391 return NewDI->getType();
2392}
2393
2394template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002395TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2396 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002397 if (getDerived().AlreadyTransformed(DI->getType()))
2398 return DI;
2399
2400 TypeLocBuilder TLB;
2401
2402 TypeLoc TL = DI->getTypeLoc();
2403 TLB.reserve(TL.getFullDataSize());
2404
Douglas Gregor124b8782010-02-16 19:09:40 +00002405 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002406 if (Result.isNull())
2407 return 0;
2408
John McCalla93c9342009-12-07 02:54:59 +00002409 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002410}
2411
2412template<typename Derived>
2413QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002414TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2415 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002416 switch (T.getTypeLocClass()) {
2417#define ABSTRACT_TYPELOC(CLASS, PARENT)
2418#define TYPELOC(CLASS, PARENT) \
2419 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002420 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2421 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002422#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002423 }
Mike Stump1eb44332009-09-09 15:08:12 +00002424
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002425 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002426 return QualType();
2427}
2428
2429/// FIXME: By default, this routine adds type qualifiers only to types
2430/// that can have qualifiers, and silently suppresses those qualifiers
2431/// that are not permitted (e.g., qualifiers on reference or function
2432/// types). This is the right thing for template instantiation, but
2433/// probably not for other clients.
2434template<typename Derived>
2435QualType
2436TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002437 QualifiedTypeLoc T,
2438 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002439 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002440
Douglas Gregor124b8782010-02-16 19:09:40 +00002441 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2442 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002443 if (Result.isNull())
2444 return QualType();
2445
2446 // Silently suppress qualifiers if the result type can't be qualified.
2447 // FIXME: this is the right thing for template instantiation, but
2448 // probably not for other clients.
2449 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002450 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002451
John McCall28654742010-06-05 06:41:15 +00002452 if (!Quals.empty()) {
2453 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2454 TLB.push<QualifiedTypeLoc>(Result);
2455 // No location information to preserve.
2456 }
John McCalla2becad2009-10-21 00:40:46 +00002457
2458 return Result;
2459}
2460
2461template <class TyLoc> static inline
2462QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2463 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2464 NewT.setNameLoc(T.getNameLoc());
2465 return T.getType();
2466}
2467
John McCalla2becad2009-10-21 00:40:46 +00002468template<typename Derived>
2469QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002470 BuiltinTypeLoc T,
2471 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002472 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2473 NewT.setBuiltinLoc(T.getBuiltinLoc());
2474 if (T.needsExtraLocalData())
2475 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2476 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002477}
Mike Stump1eb44332009-09-09 15:08:12 +00002478
Douglas Gregor577f75a2009-08-04 16:50:30 +00002479template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002480QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002481 ComplexTypeLoc T,
2482 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002483 // FIXME: recurse?
2484 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002485}
Mike Stump1eb44332009-09-09 15:08:12 +00002486
Douglas Gregor577f75a2009-08-04 16:50:30 +00002487template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002488QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Sean Huntc3021132010-05-05 15:23:54 +00002489 PointerTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00002490 QualType ObjectType) {
Sean Huntc3021132010-05-05 15:23:54 +00002491 QualType PointeeType
2492 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002493 if (PointeeType.isNull())
2494 return QualType();
2495
2496 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002497 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002498 // A dependent pointer type 'T *' has is being transformed such
2499 // that an Objective-C class type is being replaced for 'T'. The
2500 // resulting pointer type is an ObjCObjectPointerType, not a
2501 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002502 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002503
John McCallc12c5bb2010-05-15 11:32:37 +00002504 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2505 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002506 return Result;
2507 }
Sean Huntc3021132010-05-05 15:23:54 +00002508
Douglas Gregor92e986e2010-04-22 16:44:27 +00002509 if (getDerived().AlwaysRebuild() ||
2510 PointeeType != TL.getPointeeLoc().getType()) {
2511 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2512 if (Result.isNull())
2513 return QualType();
2514 }
Sean Huntc3021132010-05-05 15:23:54 +00002515
Douglas Gregor92e986e2010-04-22 16:44:27 +00002516 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2517 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002518 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002519}
Mike Stump1eb44332009-09-09 15:08:12 +00002520
2521template<typename Derived>
2522QualType
John McCalla2becad2009-10-21 00:40:46 +00002523TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002524 BlockPointerTypeLoc TL,
2525 QualType ObjectType) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002526 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002527 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2528 if (PointeeType.isNull())
2529 return QualType();
2530
2531 QualType Result = TL.getType();
2532 if (getDerived().AlwaysRebuild() ||
2533 PointeeType != TL.getPointeeLoc().getType()) {
2534 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002535 TL.getSigilLoc());
2536 if (Result.isNull())
2537 return QualType();
2538 }
2539
Douglas Gregor39968ad2010-04-22 16:50:51 +00002540 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002541 NewT.setSigilLoc(TL.getSigilLoc());
2542 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002543}
2544
John McCall85737a72009-10-30 00:06:24 +00002545/// Transforms a reference type. Note that somewhat paradoxically we
2546/// don't care whether the type itself is an l-value type or an r-value
2547/// type; we only care if the type was *written* as an l-value type
2548/// or an r-value type.
2549template<typename Derived>
2550QualType
2551TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002552 ReferenceTypeLoc TL,
2553 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002554 const ReferenceType *T = TL.getTypePtr();
2555
2556 // Note that this works with the pointee-as-written.
2557 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2558 if (PointeeType.isNull())
2559 return QualType();
2560
2561 QualType Result = TL.getType();
2562 if (getDerived().AlwaysRebuild() ||
2563 PointeeType != T->getPointeeTypeAsWritten()) {
2564 Result = getDerived().RebuildReferenceType(PointeeType,
2565 T->isSpelledAsLValue(),
2566 TL.getSigilLoc());
2567 if (Result.isNull())
2568 return QualType();
2569 }
2570
2571 // r-value references can be rebuilt as l-value references.
2572 ReferenceTypeLoc NewTL;
2573 if (isa<LValueReferenceType>(Result))
2574 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2575 else
2576 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2577 NewTL.setSigilLoc(TL.getSigilLoc());
2578
2579 return Result;
2580}
2581
Mike Stump1eb44332009-09-09 15:08:12 +00002582template<typename Derived>
2583QualType
John McCalla2becad2009-10-21 00:40:46 +00002584TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002585 LValueReferenceTypeLoc TL,
2586 QualType ObjectType) {
2587 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002588}
2589
Mike Stump1eb44332009-09-09 15:08:12 +00002590template<typename Derived>
2591QualType
John McCalla2becad2009-10-21 00:40:46 +00002592TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002593 RValueReferenceTypeLoc TL,
2594 QualType ObjectType) {
2595 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002596}
Mike Stump1eb44332009-09-09 15:08:12 +00002597
Douglas Gregor577f75a2009-08-04 16:50:30 +00002598template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002599QualType
John McCalla2becad2009-10-21 00:40:46 +00002600TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002601 MemberPointerTypeLoc TL,
2602 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002603 MemberPointerType *T = TL.getTypePtr();
2604
2605 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002606 if (PointeeType.isNull())
2607 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002608
John McCalla2becad2009-10-21 00:40:46 +00002609 // TODO: preserve source information for this.
2610 QualType ClassType
2611 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002612 if (ClassType.isNull())
2613 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002614
John McCalla2becad2009-10-21 00:40:46 +00002615 QualType Result = TL.getType();
2616 if (getDerived().AlwaysRebuild() ||
2617 PointeeType != T->getPointeeType() ||
2618 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002619 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2620 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002621 if (Result.isNull())
2622 return QualType();
2623 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002624
John McCalla2becad2009-10-21 00:40:46 +00002625 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2626 NewTL.setSigilLoc(TL.getSigilLoc());
2627
2628 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002629}
2630
Mike Stump1eb44332009-09-09 15:08:12 +00002631template<typename Derived>
2632QualType
John McCalla2becad2009-10-21 00:40:46 +00002633TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002634 ConstantArrayTypeLoc TL,
2635 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002636 ConstantArrayType *T = TL.getTypePtr();
2637 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002638 if (ElementType.isNull())
2639 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002640
John McCalla2becad2009-10-21 00:40:46 +00002641 QualType Result = TL.getType();
2642 if (getDerived().AlwaysRebuild() ||
2643 ElementType != T->getElementType()) {
2644 Result = getDerived().RebuildConstantArrayType(ElementType,
2645 T->getSizeModifier(),
2646 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002647 T->getIndexTypeCVRQualifiers(),
2648 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002649 if (Result.isNull())
2650 return QualType();
2651 }
Sean Huntc3021132010-05-05 15:23:54 +00002652
John McCalla2becad2009-10-21 00:40:46 +00002653 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2654 NewTL.setLBracketLoc(TL.getLBracketLoc());
2655 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002656
John McCalla2becad2009-10-21 00:40:46 +00002657 Expr *Size = TL.getSizeExpr();
2658 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00002659 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002660 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2661 }
2662 NewTL.setSizeExpr(Size);
2663
2664 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002665}
Mike Stump1eb44332009-09-09 15:08:12 +00002666
Douglas Gregor577f75a2009-08-04 16:50:30 +00002667template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002668QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002669 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002670 IncompleteArrayTypeLoc TL,
2671 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002672 IncompleteArrayType *T = TL.getTypePtr();
2673 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002674 if (ElementType.isNull())
2675 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002676
John McCalla2becad2009-10-21 00:40:46 +00002677 QualType Result = TL.getType();
2678 if (getDerived().AlwaysRebuild() ||
2679 ElementType != T->getElementType()) {
2680 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002681 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002682 T->getIndexTypeCVRQualifiers(),
2683 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002684 if (Result.isNull())
2685 return QualType();
2686 }
Sean Huntc3021132010-05-05 15:23:54 +00002687
John McCalla2becad2009-10-21 00:40:46 +00002688 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2689 NewTL.setLBracketLoc(TL.getLBracketLoc());
2690 NewTL.setRBracketLoc(TL.getRBracketLoc());
2691 NewTL.setSizeExpr(0);
2692
2693 return Result;
2694}
2695
2696template<typename Derived>
2697QualType
2698TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002699 VariableArrayTypeLoc TL,
2700 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002701 VariableArrayType *T = TL.getTypePtr();
2702 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2703 if (ElementType.isNull())
2704 return QualType();
2705
2706 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002707 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002708
John McCall60d7b3a2010-08-24 06:29:42 +00002709 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002710 = getDerived().TransformExpr(T->getSizeExpr());
2711 if (SizeResult.isInvalid())
2712 return QualType();
2713
John McCall9ae2f072010-08-23 23:25:46 +00002714 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00002715
2716 QualType Result = TL.getType();
2717 if (getDerived().AlwaysRebuild() ||
2718 ElementType != T->getElementType() ||
2719 Size != T->getSizeExpr()) {
2720 Result = getDerived().RebuildVariableArrayType(ElementType,
2721 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002722 Size,
John McCalla2becad2009-10-21 00:40:46 +00002723 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002724 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002725 if (Result.isNull())
2726 return QualType();
2727 }
Sean Huntc3021132010-05-05 15:23:54 +00002728
John McCalla2becad2009-10-21 00:40:46 +00002729 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2730 NewTL.setLBracketLoc(TL.getLBracketLoc());
2731 NewTL.setRBracketLoc(TL.getRBracketLoc());
2732 NewTL.setSizeExpr(Size);
2733
2734 return Result;
2735}
2736
2737template<typename Derived>
2738QualType
2739TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002740 DependentSizedArrayTypeLoc TL,
2741 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002742 DependentSizedArrayType *T = TL.getTypePtr();
2743 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2744 if (ElementType.isNull())
2745 return QualType();
2746
2747 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002748 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002749
John McCall60d7b3a2010-08-24 06:29:42 +00002750 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002751 = getDerived().TransformExpr(T->getSizeExpr());
2752 if (SizeResult.isInvalid())
2753 return QualType();
2754
2755 Expr *Size = static_cast<Expr*>(SizeResult.get());
2756
2757 QualType Result = TL.getType();
2758 if (getDerived().AlwaysRebuild() ||
2759 ElementType != T->getElementType() ||
2760 Size != T->getSizeExpr()) {
2761 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2762 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002763 Size,
John McCalla2becad2009-10-21 00:40:46 +00002764 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002765 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002766 if (Result.isNull())
2767 return QualType();
2768 }
2769 else SizeResult.take();
2770
2771 // We might have any sort of array type now, but fortunately they
2772 // all have the same location layout.
2773 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2774 NewTL.setLBracketLoc(TL.getLBracketLoc());
2775 NewTL.setRBracketLoc(TL.getRBracketLoc());
2776 NewTL.setSizeExpr(Size);
2777
2778 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002779}
Mike Stump1eb44332009-09-09 15:08:12 +00002780
2781template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002782QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002783 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002784 DependentSizedExtVectorTypeLoc TL,
2785 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002786 DependentSizedExtVectorType *T = TL.getTypePtr();
2787
2788 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002789 QualType ElementType = getDerived().TransformType(T->getElementType());
2790 if (ElementType.isNull())
2791 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002792
Douglas Gregor670444e2009-08-04 22:27:00 +00002793 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002794 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00002795
John McCall60d7b3a2010-08-24 06:29:42 +00002796 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002797 if (Size.isInvalid())
2798 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002799
John McCalla2becad2009-10-21 00:40:46 +00002800 QualType Result = TL.getType();
2801 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002802 ElementType != T->getElementType() ||
2803 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002804 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00002805 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00002806 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002807 if (Result.isNull())
2808 return QualType();
2809 }
John McCalla2becad2009-10-21 00:40:46 +00002810
2811 // Result might be dependent or not.
2812 if (isa<DependentSizedExtVectorType>(Result)) {
2813 DependentSizedExtVectorTypeLoc NewTL
2814 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2815 NewTL.setNameLoc(TL.getNameLoc());
2816 } else {
2817 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2818 NewTL.setNameLoc(TL.getNameLoc());
2819 }
2820
2821 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002822}
Mike Stump1eb44332009-09-09 15:08:12 +00002823
2824template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002825QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002826 VectorTypeLoc TL,
2827 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002828 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002829 QualType ElementType = getDerived().TransformType(T->getElementType());
2830 if (ElementType.isNull())
2831 return QualType();
2832
John McCalla2becad2009-10-21 00:40:46 +00002833 QualType Result = TL.getType();
2834 if (getDerived().AlwaysRebuild() ||
2835 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002836 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner788b0fd2010-06-23 06:00:24 +00002837 T->getAltiVecSpecific());
John McCalla2becad2009-10-21 00:40:46 +00002838 if (Result.isNull())
2839 return QualType();
2840 }
Sean Huntc3021132010-05-05 15:23:54 +00002841
John McCalla2becad2009-10-21 00:40:46 +00002842 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2843 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002844
John McCalla2becad2009-10-21 00:40:46 +00002845 return Result;
2846}
2847
2848template<typename Derived>
2849QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002850 ExtVectorTypeLoc TL,
2851 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002852 VectorType *T = TL.getTypePtr();
2853 QualType ElementType = getDerived().TransformType(T->getElementType());
2854 if (ElementType.isNull())
2855 return QualType();
2856
2857 QualType Result = TL.getType();
2858 if (getDerived().AlwaysRebuild() ||
2859 ElementType != T->getElementType()) {
2860 Result = getDerived().RebuildExtVectorType(ElementType,
2861 T->getNumElements(),
2862 /*FIXME*/ SourceLocation());
2863 if (Result.isNull())
2864 return QualType();
2865 }
Sean Huntc3021132010-05-05 15:23:54 +00002866
John McCalla2becad2009-10-21 00:40:46 +00002867 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2868 NewTL.setNameLoc(TL.getNameLoc());
2869
2870 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002871}
Mike Stump1eb44332009-09-09 15:08:12 +00002872
2873template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002874ParmVarDecl *
2875TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2876 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2877 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2878 if (!NewDI)
2879 return 0;
2880
2881 if (NewDI == OldDI)
2882 return OldParm;
2883 else
2884 return ParmVarDecl::Create(SemaRef.Context,
2885 OldParm->getDeclContext(),
2886 OldParm->getLocation(),
2887 OldParm->getIdentifier(),
2888 NewDI->getType(),
2889 NewDI,
2890 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002891 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002892 /* DefArg */ NULL);
2893}
2894
2895template<typename Derived>
2896bool TreeTransform<Derived>::
2897 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2898 llvm::SmallVectorImpl<QualType> &PTypes,
2899 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2900 FunctionProtoType *T = TL.getTypePtr();
2901
2902 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2903 ParmVarDecl *OldParm = TL.getArg(i);
2904
2905 QualType NewType;
2906 ParmVarDecl *NewParm;
2907
2908 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002909 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2910 if (!NewParm)
2911 return true;
2912 NewType = NewParm->getType();
2913
2914 // Deal with the possibility that we don't have a parameter
2915 // declaration for this parameter.
2916 } else {
2917 NewParm = 0;
2918
2919 QualType OldType = T->getArgType(i);
2920 NewType = getDerived().TransformType(OldType);
2921 if (NewType.isNull())
2922 return true;
2923 }
2924
2925 PTypes.push_back(NewType);
2926 PVars.push_back(NewParm);
2927 }
2928
2929 return false;
2930}
2931
2932template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002933QualType
John McCalla2becad2009-10-21 00:40:46 +00002934TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002935 FunctionProtoTypeLoc TL,
2936 QualType ObjectType) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00002937 // Transform the parameters and return type.
2938 //
2939 // We instantiate in source order, with the return type first followed by
2940 // the parameters, because users tend to expect this (even if they shouldn't
2941 // rely on it!).
2942 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00002943 // When the function has a trailing return type, we instantiate the
2944 // parameters before the return type, since the return type can then refer
2945 // to the parameters themselves (via decltype, sizeof, etc.).
2946 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00002947 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002948 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor895162d2010-04-30 18:55:50 +00002949 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00002950
Douglas Gregordab60ad2010-10-01 18:44:50 +00002951 QualType ResultType;
2952
2953 if (TL.getTrailingReturn()) {
2954 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2955 return QualType();
2956
2957 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2958 if (ResultType.isNull())
2959 return QualType();
2960 }
2961 else {
2962 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2963 if (ResultType.isNull())
2964 return QualType();
2965
2966 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2967 return QualType();
2968 }
2969
John McCalla2becad2009-10-21 00:40:46 +00002970 QualType Result = TL.getType();
2971 if (getDerived().AlwaysRebuild() ||
2972 ResultType != T->getResultType() ||
2973 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2974 Result = getDerived().RebuildFunctionProtoType(ResultType,
2975 ParamTypes.data(),
2976 ParamTypes.size(),
2977 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00002978 T->getTypeQuals(),
2979 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00002980 if (Result.isNull())
2981 return QualType();
2982 }
Mike Stump1eb44332009-09-09 15:08:12 +00002983
John McCalla2becad2009-10-21 00:40:46 +00002984 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2985 NewTL.setLParenLoc(TL.getLParenLoc());
2986 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00002987 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00002988 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2989 NewTL.setArg(i, ParamDecls[i]);
2990
2991 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002992}
Mike Stump1eb44332009-09-09 15:08:12 +00002993
Douglas Gregor577f75a2009-08-04 16:50:30 +00002994template<typename Derived>
2995QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002996 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002997 FunctionNoProtoTypeLoc TL,
2998 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002999 FunctionNoProtoType *T = TL.getTypePtr();
3000 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3001 if (ResultType.isNull())
3002 return QualType();
3003
3004 QualType Result = TL.getType();
3005 if (getDerived().AlwaysRebuild() ||
3006 ResultType != T->getResultType())
3007 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3008
3009 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3010 NewTL.setLParenLoc(TL.getLParenLoc());
3011 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003012 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003013
3014 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003015}
Mike Stump1eb44332009-09-09 15:08:12 +00003016
John McCalled976492009-12-04 22:46:56 +00003017template<typename Derived> QualType
3018TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003019 UnresolvedUsingTypeLoc TL,
3020 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00003021 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003022 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00003023 if (!D)
3024 return QualType();
3025
3026 QualType Result = TL.getType();
3027 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3028 Result = getDerived().RebuildUnresolvedUsingType(D);
3029 if (Result.isNull())
3030 return QualType();
3031 }
3032
3033 // We might get an arbitrary type spec type back. We should at
3034 // least always get a type spec type, though.
3035 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3036 NewTL.setNameLoc(TL.getNameLoc());
3037
3038 return Result;
3039}
3040
Douglas Gregor577f75a2009-08-04 16:50:30 +00003041template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003042QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003043 TypedefTypeLoc TL,
3044 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003045 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003046 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003047 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3048 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003049 if (!Typedef)
3050 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003051
John McCalla2becad2009-10-21 00:40:46 +00003052 QualType Result = TL.getType();
3053 if (getDerived().AlwaysRebuild() ||
3054 Typedef != T->getDecl()) {
3055 Result = getDerived().RebuildTypedefType(Typedef);
3056 if (Result.isNull())
3057 return QualType();
3058 }
Mike Stump1eb44332009-09-09 15:08:12 +00003059
John McCalla2becad2009-10-21 00:40:46 +00003060 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3061 NewTL.setNameLoc(TL.getNameLoc());
3062
3063 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003064}
Mike Stump1eb44332009-09-09 15:08:12 +00003065
Douglas Gregor577f75a2009-08-04 16:50:30 +00003066template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003067QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003068 TypeOfExprTypeLoc TL,
3069 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003070 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003071 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003072
John McCall60d7b3a2010-08-24 06:29:42 +00003073 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003074 if (E.isInvalid())
3075 return QualType();
3076
John McCalla2becad2009-10-21 00:40:46 +00003077 QualType Result = TL.getType();
3078 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003079 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003080 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00003081 if (Result.isNull())
3082 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003083 }
John McCalla2becad2009-10-21 00:40:46 +00003084 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003085
John McCalla2becad2009-10-21 00:40:46 +00003086 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003087 NewTL.setTypeofLoc(TL.getTypeofLoc());
3088 NewTL.setLParenLoc(TL.getLParenLoc());
3089 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003090
3091 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003092}
Mike Stump1eb44332009-09-09 15:08:12 +00003093
3094template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003095QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003096 TypeOfTypeLoc TL,
3097 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00003098 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3099 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3100 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003101 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003102
John McCalla2becad2009-10-21 00:40:46 +00003103 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003104 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3105 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003106 if (Result.isNull())
3107 return QualType();
3108 }
Mike Stump1eb44332009-09-09 15:08:12 +00003109
John McCalla2becad2009-10-21 00:40:46 +00003110 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003111 NewTL.setTypeofLoc(TL.getTypeofLoc());
3112 NewTL.setLParenLoc(TL.getLParenLoc());
3113 NewTL.setRParenLoc(TL.getRParenLoc());
3114 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003115
3116 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003117}
Mike Stump1eb44332009-09-09 15:08:12 +00003118
3119template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003120QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003121 DecltypeTypeLoc TL,
3122 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003123 DecltypeType *T = TL.getTypePtr();
3124
Douglas Gregor670444e2009-08-04 22:27:00 +00003125 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003126 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003127
John McCall60d7b3a2010-08-24 06:29:42 +00003128 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003129 if (E.isInvalid())
3130 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003131
John McCalla2becad2009-10-21 00:40:46 +00003132 QualType Result = TL.getType();
3133 if (getDerived().AlwaysRebuild() ||
3134 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003135 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003136 if (Result.isNull())
3137 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003138 }
John McCalla2becad2009-10-21 00:40:46 +00003139 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003140
John McCalla2becad2009-10-21 00:40:46 +00003141 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3142 NewTL.setNameLoc(TL.getNameLoc());
3143
3144 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003145}
3146
3147template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003148QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003149 RecordTypeLoc TL,
3150 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003151 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003152 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003153 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3154 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003155 if (!Record)
3156 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003157
John McCalla2becad2009-10-21 00:40:46 +00003158 QualType Result = TL.getType();
3159 if (getDerived().AlwaysRebuild() ||
3160 Record != T->getDecl()) {
3161 Result = getDerived().RebuildRecordType(Record);
3162 if (Result.isNull())
3163 return QualType();
3164 }
Mike Stump1eb44332009-09-09 15:08:12 +00003165
John McCalla2becad2009-10-21 00:40:46 +00003166 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3167 NewTL.setNameLoc(TL.getNameLoc());
3168
3169 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003170}
Mike Stump1eb44332009-09-09 15:08:12 +00003171
3172template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003173QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003174 EnumTypeLoc TL,
3175 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003176 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003177 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003178 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3179 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003180 if (!Enum)
3181 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003182
John McCalla2becad2009-10-21 00:40:46 +00003183 QualType Result = TL.getType();
3184 if (getDerived().AlwaysRebuild() ||
3185 Enum != T->getDecl()) {
3186 Result = getDerived().RebuildEnumType(Enum);
3187 if (Result.isNull())
3188 return QualType();
3189 }
Mike Stump1eb44332009-09-09 15:08:12 +00003190
John McCalla2becad2009-10-21 00:40:46 +00003191 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3192 NewTL.setNameLoc(TL.getNameLoc());
3193
3194 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003195}
John McCall7da24312009-09-05 00:15:47 +00003196
John McCall3cb0ebd2010-03-10 03:28:59 +00003197template<typename Derived>
3198QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3199 TypeLocBuilder &TLB,
3200 InjectedClassNameTypeLoc TL,
3201 QualType ObjectType) {
3202 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3203 TL.getTypePtr()->getDecl());
3204 if (!D) return QualType();
3205
3206 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3207 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3208 return T;
3209}
3210
Mike Stump1eb44332009-09-09 15:08:12 +00003211
Douglas Gregor577f75a2009-08-04 16:50:30 +00003212template<typename Derived>
3213QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003214 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003215 TemplateTypeParmTypeLoc TL,
3216 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003217 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003218}
3219
Mike Stump1eb44332009-09-09 15:08:12 +00003220template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003221QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003222 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003223 SubstTemplateTypeParmTypeLoc TL,
3224 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003225 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003226}
3227
3228template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003229QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3230 const TemplateSpecializationType *TST,
3231 QualType ObjectType) {
3232 // FIXME: this entire method is a temporary workaround; callers
3233 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00003234
John McCall833ca992009-10-29 08:12:44 +00003235 // Fake up a TemplateSpecializationTypeLoc.
3236 TypeLocBuilder TLB;
3237 TemplateSpecializationTypeLoc TL
3238 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3239
John McCall828bff22009-10-29 18:45:58 +00003240 SourceLocation BaseLoc = getDerived().getBaseLocation();
3241
3242 TL.setTemplateNameLoc(BaseLoc);
3243 TL.setLAngleLoc(BaseLoc);
3244 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00003245 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3246 const TemplateArgument &TA = TST->getArg(i);
3247 TemplateArgumentLoc TAL;
3248 getDerived().InventTemplateArgumentLoc(TA, TAL);
3249 TL.setArgLocInfo(i, TAL.getLocInfo());
3250 }
3251
3252 TypeLocBuilder IgnoredTLB;
3253 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00003254}
Sean Huntc3021132010-05-05 15:23:54 +00003255
Douglas Gregordd62b152009-10-19 22:04:39 +00003256template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003257QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003258 TypeLocBuilder &TLB,
3259 TemplateSpecializationTypeLoc TL,
3260 QualType ObjectType) {
3261 const TemplateSpecializationType *T = TL.getTypePtr();
3262
Mike Stump1eb44332009-09-09 15:08:12 +00003263 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00003264 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003265 if (Template.isNull())
3266 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003267
John McCalld5532b62009-11-23 01:53:49 +00003268 TemplateArgumentListInfo NewTemplateArgs;
3269 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3270 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3271
3272 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3273 TemplateArgumentLoc Loc;
3274 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003275 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003276 NewTemplateArgs.addArgument(Loc);
3277 }
Mike Stump1eb44332009-09-09 15:08:12 +00003278
John McCall833ca992009-10-29 08:12:44 +00003279 // FIXME: maybe don't rebuild if all the template arguments are the same.
3280
3281 QualType Result =
3282 getDerived().RebuildTemplateSpecializationType(Template,
3283 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003284 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003285
3286 if (!Result.isNull()) {
3287 TemplateSpecializationTypeLoc NewTL
3288 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3289 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3290 NewTL.setLAngleLoc(TL.getLAngleLoc());
3291 NewTL.setRAngleLoc(TL.getRAngleLoc());
3292 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3293 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003294 }
Mike Stump1eb44332009-09-09 15:08:12 +00003295
John McCall833ca992009-10-29 08:12:44 +00003296 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003297}
Mike Stump1eb44332009-09-09 15:08:12 +00003298
3299template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003300QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003301TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3302 ElaboratedTypeLoc TL,
3303 QualType ObjectType) {
3304 ElaboratedType *T = TL.getTypePtr();
3305
3306 NestedNameSpecifier *NNS = 0;
3307 // NOTE: the qualifier in an ElaboratedType is optional.
3308 if (T->getQualifier() != 0) {
3309 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003310 TL.getQualifierRange(),
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003311 ObjectType);
3312 if (!NNS)
3313 return QualType();
3314 }
Mike Stump1eb44332009-09-09 15:08:12 +00003315
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003316 QualType NamedT;
3317 // FIXME: this test is meant to workaround a problem (failing assertion)
3318 // occurring if directly executing the code in the else branch.
3319 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3320 TemplateSpecializationTypeLoc OldNamedTL
3321 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3322 const TemplateSpecializationType* OldTST
Jim Grosbach9cbb4d82010-05-19 23:53:08 +00003323 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003324 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3325 if (NamedT.isNull())
3326 return QualType();
3327 TemplateSpecializationTypeLoc NewNamedTL
3328 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3329 NewNamedTL.copy(OldNamedTL);
3330 }
3331 else {
3332 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3333 if (NamedT.isNull())
3334 return QualType();
3335 }
Daniel Dunbara63db842010-05-14 16:34:09 +00003336
John McCalla2becad2009-10-21 00:40:46 +00003337 QualType Result = TL.getType();
3338 if (getDerived().AlwaysRebuild() ||
3339 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003340 NamedT != T->getNamedType()) {
3341 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003342 if (Result.isNull())
3343 return QualType();
3344 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003345
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003346 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003347 NewTL.setKeywordLoc(TL.getKeywordLoc());
3348 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003349
3350 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003351}
Mike Stump1eb44332009-09-09 15:08:12 +00003352
3353template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003354QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3355 DependentNameTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00003356 QualType ObjectType) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003357 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003358
Douglas Gregor577f75a2009-08-04 16:50:30 +00003359 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003360 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3361 TL.getQualifierRange(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003362 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003363 if (!NNS)
3364 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003365
John McCall33500952010-06-11 00:33:02 +00003366 QualType Result
3367 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3368 T->getIdentifier(),
3369 TL.getKeywordLoc(),
3370 TL.getQualifierRange(),
3371 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003372 if (Result.isNull())
3373 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003374
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003375 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3376 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003377 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3378
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003379 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3380 NewTL.setKeywordLoc(TL.getKeywordLoc());
3381 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003382 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003383 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3384 NewTL.setKeywordLoc(TL.getKeywordLoc());
3385 NewTL.setQualifierRange(TL.getQualifierRange());
3386 NewTL.setNameLoc(TL.getNameLoc());
3387 }
John McCalla2becad2009-10-21 00:40:46 +00003388 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003389}
Mike Stump1eb44332009-09-09 15:08:12 +00003390
Douglas Gregor577f75a2009-08-04 16:50:30 +00003391template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003392QualType TreeTransform<Derived>::
3393 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3394 DependentTemplateSpecializationTypeLoc TL,
3395 QualType ObjectType) {
3396 DependentTemplateSpecializationType *T = TL.getTypePtr();
3397
3398 NestedNameSpecifier *NNS
3399 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3400 TL.getQualifierRange(),
3401 ObjectType);
3402 if (!NNS)
3403 return QualType();
3404
3405 TemplateArgumentListInfo NewTemplateArgs;
3406 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3407 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3408
3409 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3410 TemplateArgumentLoc Loc;
3411 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3412 return QualType();
3413 NewTemplateArgs.addArgument(Loc);
3414 }
3415
Douglas Gregor1efb6c72010-09-08 23:56:00 +00003416 QualType Result
3417 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3418 NNS,
3419 TL.getQualifierRange(),
3420 T->getIdentifier(),
3421 TL.getNameLoc(),
3422 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00003423 if (Result.isNull())
3424 return QualType();
3425
3426 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3427 QualType NamedT = ElabT->getNamedType();
3428
3429 // Copy information relevant to the template specialization.
3430 TemplateSpecializationTypeLoc NamedTL
3431 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3432 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3433 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3434 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3435 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3436
3437 // Copy information relevant to the elaborated type.
3438 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3439 NewTL.setKeywordLoc(TL.getKeywordLoc());
3440 NewTL.setQualifierRange(TL.getQualifierRange());
3441 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003442 TypeLoc NewTL(Result, TL.getOpaqueData());
3443 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003444 }
3445 return Result;
3446}
3447
3448template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003449QualType
3450TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003451 ObjCInterfaceTypeLoc TL,
3452 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003453 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003454 TLB.pushFullCopy(TL);
3455 return TL.getType();
3456}
3457
3458template<typename Derived>
3459QualType
3460TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3461 ObjCObjectTypeLoc TL,
3462 QualType ObjectType) {
3463 // ObjCObjectType is never dependent.
3464 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003465 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003466}
Mike Stump1eb44332009-09-09 15:08:12 +00003467
3468template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003469QualType
3470TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003471 ObjCObjectPointerTypeLoc TL,
3472 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003473 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003474 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003475 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003476}
3477
Douglas Gregor577f75a2009-08-04 16:50:30 +00003478//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003479// Statement transformation
3480//===----------------------------------------------------------------------===//
3481template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003482StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003483TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3484 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003485}
3486
3487template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003488StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003489TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3490 return getDerived().TransformCompoundStmt(S, false);
3491}
3492
3493template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003494StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003495TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003496 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00003497 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00003498 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003499 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00003500 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3501 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00003502 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00003503 if (Result.isInvalid()) {
3504 // Immediately fail if this was a DeclStmt, since it's very
3505 // likely that this will cause problems for future statements.
3506 if (isa<DeclStmt>(*B))
3507 return StmtError();
3508
3509 // Otherwise, just keep processing substatements and fail later.
3510 SubStmtInvalid = true;
3511 continue;
3512 }
Mike Stump1eb44332009-09-09 15:08:12 +00003513
Douglas Gregor43959a92009-08-20 07:17:43 +00003514 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3515 Statements.push_back(Result.takeAs<Stmt>());
3516 }
Mike Stump1eb44332009-09-09 15:08:12 +00003517
John McCall7114cba2010-08-27 19:56:05 +00003518 if (SubStmtInvalid)
3519 return StmtError();
3520
Douglas Gregor43959a92009-08-20 07:17:43 +00003521 if (!getDerived().AlwaysRebuild() &&
3522 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003523 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003524
3525 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3526 move_arg(Statements),
3527 S->getRBracLoc(),
3528 IsStmtExpr);
3529}
Mike Stump1eb44332009-09-09 15:08:12 +00003530
Douglas Gregor43959a92009-08-20 07:17:43 +00003531template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003532StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003533TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003534 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00003535 {
3536 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00003537 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003538
Eli Friedman264c1f82009-11-19 03:14:00 +00003539 // Transform the left-hand case value.
3540 LHS = getDerived().TransformExpr(S->getLHS());
3541 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003542 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003543
Eli Friedman264c1f82009-11-19 03:14:00 +00003544 // Transform the right-hand case value (for the GNU case-range extension).
3545 RHS = getDerived().TransformExpr(S->getRHS());
3546 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003547 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00003548 }
Mike Stump1eb44332009-09-09 15:08:12 +00003549
Douglas Gregor43959a92009-08-20 07:17:43 +00003550 // Build the case statement.
3551 // Case statements are always rebuilt so that they will attached to their
3552 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003553 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003554 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003555 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003556 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003557 S->getColonLoc());
3558 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003559 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003560
Douglas Gregor43959a92009-08-20 07:17:43 +00003561 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00003562 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003563 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003564 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003565
Douglas Gregor43959a92009-08-20 07:17:43 +00003566 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00003567 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003568}
3569
3570template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003571StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003572TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003573 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00003574 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003575 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003576 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003577
Douglas Gregor43959a92009-08-20 07:17:43 +00003578 // Default statements are always rebuilt
3579 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003580 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003581}
Mike Stump1eb44332009-09-09 15:08:12 +00003582
Douglas Gregor43959a92009-08-20 07:17:43 +00003583template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003584StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003585TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003586 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003587 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003588 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003589
Douglas Gregor43959a92009-08-20 07:17:43 +00003590 // FIXME: Pass the real colon location in.
3591 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3592 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +00003593 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00003594}
Mike Stump1eb44332009-09-09 15:08:12 +00003595
Douglas Gregor43959a92009-08-20 07:17:43 +00003596template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003597StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003598TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003599 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003600 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003601 VarDecl *ConditionVar = 0;
3602 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003603 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003604 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003605 getDerived().TransformDefinition(
3606 S->getConditionVariable()->getLocation(),
3607 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003608 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003609 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003610 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003611 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003612
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003613 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003614 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003615
3616 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003617 if (S->getCond()) {
John McCall60d7b3a2010-08-24 06:29:42 +00003618 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003619 S->getIfLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003620 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003621 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003622 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003623
John McCall9ae2f072010-08-23 23:25:46 +00003624 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003625 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003626 }
Sean Huntc3021132010-05-05 15:23:54 +00003627
John McCall9ae2f072010-08-23 23:25:46 +00003628 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3629 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003630 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003631
Douglas Gregor43959a92009-08-20 07:17:43 +00003632 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003633 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00003634 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003635 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003636
Douglas Gregor43959a92009-08-20 07:17:43 +00003637 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003638 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00003639 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003640 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003641
Douglas Gregor43959a92009-08-20 07:17:43 +00003642 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003643 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003644 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003645 Then.get() == S->getThen() &&
3646 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003647 return SemaRef.Owned(S->Retain());
3648
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003649 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCall9ae2f072010-08-23 23:25:46 +00003650 Then.get(),
3651 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003652}
3653
3654template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003655StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003656TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003657 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00003658 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00003659 VarDecl *ConditionVar = 0;
3660 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003661 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003662 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003663 getDerived().TransformDefinition(
3664 S->getConditionVariable()->getLocation(),
3665 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003666 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003667 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003668 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003669 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003670
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003671 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003672 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003673 }
Mike Stump1eb44332009-09-09 15:08:12 +00003674
Douglas Gregor43959a92009-08-20 07:17:43 +00003675 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003676 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00003677 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00003678 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003679 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003680 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003681
Douglas Gregor43959a92009-08-20 07:17:43 +00003682 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003683 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003684 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003685 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003686
Douglas Gregor43959a92009-08-20 07:17:43 +00003687 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00003688 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3689 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003690}
Mike Stump1eb44332009-09-09 15:08:12 +00003691
Douglas Gregor43959a92009-08-20 07:17:43 +00003692template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003693StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003694TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003695 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003696 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00003697 VarDecl *ConditionVar = 0;
3698 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003699 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003700 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003701 getDerived().TransformDefinition(
3702 S->getConditionVariable()->getLocation(),
3703 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003704 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003705 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003706 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003707 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003708
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003709 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003710 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003711
3712 if (S->getCond()) {
3713 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003714 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003715 S->getWhileLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003716 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003717 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003718 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00003719 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003720 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003721 }
Mike Stump1eb44332009-09-09 15:08:12 +00003722
John McCall9ae2f072010-08-23 23:25:46 +00003723 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3724 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003725 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003726
Douglas Gregor43959a92009-08-20 07:17:43 +00003727 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003728 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003729 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003730 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003731
Douglas Gregor43959a92009-08-20 07:17:43 +00003732 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003733 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003734 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003735 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00003736 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003737
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003738 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00003739 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003740}
Mike Stump1eb44332009-09-09 15:08:12 +00003741
Douglas Gregor43959a92009-08-20 07:17:43 +00003742template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003743StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003744TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003745 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003746 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003747 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003748 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003749
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003750 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003751 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003752 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003753 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003754
Douglas Gregor43959a92009-08-20 07:17:43 +00003755 if (!getDerived().AlwaysRebuild() &&
3756 Cond.get() == S->getCond() &&
3757 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003758 return SemaRef.Owned(S->Retain());
3759
John McCall9ae2f072010-08-23 23:25:46 +00003760 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3761 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003762 S->getRParenLoc());
3763}
Mike Stump1eb44332009-09-09 15:08:12 +00003764
Douglas Gregor43959a92009-08-20 07:17:43 +00003765template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003766StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003767TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003768 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00003769 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00003770 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003771 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003772
Douglas Gregor43959a92009-08-20 07:17:43 +00003773 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003774 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003775 VarDecl *ConditionVar = 0;
3776 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003777 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003778 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003779 getDerived().TransformDefinition(
3780 S->getConditionVariable()->getLocation(),
3781 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003782 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003783 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003784 } else {
3785 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003786
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003787 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003788 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003789
3790 if (S->getCond()) {
3791 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003792 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003793 S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003794 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003795 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003796 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003797
John McCall9ae2f072010-08-23 23:25:46 +00003798 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003799 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003800 }
Mike Stump1eb44332009-09-09 15:08:12 +00003801
John McCall9ae2f072010-08-23 23:25:46 +00003802 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3803 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003804 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003805
Douglas Gregor43959a92009-08-20 07:17:43 +00003806 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00003807 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00003808 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003809 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003810
John McCall9ae2f072010-08-23 23:25:46 +00003811 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3812 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00003813 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003814
Douglas Gregor43959a92009-08-20 07:17:43 +00003815 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003816 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003817 if (Body.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 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00003822 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003823 Inc.get() == S->getInc() &&
3824 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003825 return SemaRef.Owned(S->Retain());
3826
Douglas Gregor43959a92009-08-20 07:17:43 +00003827 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003828 Init.get(), FullCond, ConditionVar,
3829 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003830}
3831
3832template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003833StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003834TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003835 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003836 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003837 S->getLabel());
3838}
3839
3840template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003841StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003842TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003843 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00003844 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003845 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003846
Douglas Gregor43959a92009-08-20 07:17:43 +00003847 if (!getDerived().AlwaysRebuild() &&
3848 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003849 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003850
3851 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003852 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003853}
3854
3855template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003856StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003857TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3858 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003859}
Mike Stump1eb44332009-09-09 15:08:12 +00003860
Douglas Gregor43959a92009-08-20 07:17:43 +00003861template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003862StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003863TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3864 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003865}
Mike Stump1eb44332009-09-09 15:08:12 +00003866
Douglas Gregor43959a92009-08-20 07:17:43 +00003867template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003868StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003869TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003870 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00003871 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003872 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00003873
Mike Stump1eb44332009-09-09 15:08:12 +00003874 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003875 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00003876 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003877}
Mike Stump1eb44332009-09-09 15:08:12 +00003878
Douglas Gregor43959a92009-08-20 07:17:43 +00003879template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003880StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003881TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003882 bool DeclChanged = false;
3883 llvm::SmallVector<Decl *, 4> Decls;
3884 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3885 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003886 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3887 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003888 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00003889 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003890
Douglas Gregor43959a92009-08-20 07:17:43 +00003891 if (Transformed != *D)
3892 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003893
Douglas Gregor43959a92009-08-20 07:17:43 +00003894 Decls.push_back(Transformed);
3895 }
Mike Stump1eb44332009-09-09 15:08:12 +00003896
Douglas Gregor43959a92009-08-20 07:17:43 +00003897 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003898 return SemaRef.Owned(S->Retain());
3899
3900 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003901 S->getStartLoc(), S->getEndLoc());
3902}
Mike Stump1eb44332009-09-09 15:08:12 +00003903
Douglas Gregor43959a92009-08-20 07:17:43 +00003904template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003905StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003906TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003907 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003908 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003909}
3910
3911template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003912StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003913TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003914
John McCallca0408f2010-08-23 06:44:23 +00003915 ASTOwningVector<Expr*> Constraints(getSema());
3916 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003917 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003918
John McCall60d7b3a2010-08-24 06:29:42 +00003919 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00003920 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00003921
3922 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003923
Anders Carlsson703e3942010-01-24 05:50:09 +00003924 // Go through the outputs.
3925 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003926 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003927
Anders Carlsson703e3942010-01-24 05:50:09 +00003928 // No need to transform the constraint literal.
3929 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003930
Anders Carlsson703e3942010-01-24 05:50:09 +00003931 // Transform the output expr.
3932 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003933 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003934 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003935 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003936
Anders Carlsson703e3942010-01-24 05:50:09 +00003937 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003938
John McCall9ae2f072010-08-23 23:25:46 +00003939 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003940 }
Sean Huntc3021132010-05-05 15:23:54 +00003941
Anders Carlsson703e3942010-01-24 05:50:09 +00003942 // Go through the inputs.
3943 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003944 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003945
Anders Carlsson703e3942010-01-24 05:50:09 +00003946 // No need to transform the constraint literal.
3947 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003948
Anders Carlsson703e3942010-01-24 05:50:09 +00003949 // Transform the input expr.
3950 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003951 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003952 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003953 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003954
Anders Carlsson703e3942010-01-24 05:50:09 +00003955 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003956
John McCall9ae2f072010-08-23 23:25:46 +00003957 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003958 }
Sean Huntc3021132010-05-05 15:23:54 +00003959
Anders Carlsson703e3942010-01-24 05:50:09 +00003960 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3961 return SemaRef.Owned(S->Retain());
3962
3963 // Go through the clobbers.
3964 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3965 Clobbers.push_back(S->getClobber(I)->Retain());
3966
3967 // No need to transform the asm string literal.
3968 AsmString = SemaRef.Owned(S->getAsmString());
3969
3970 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3971 S->isSimple(),
3972 S->isVolatile(),
3973 S->getNumOutputs(),
3974 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003975 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003976 move_arg(Constraints),
3977 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00003978 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003979 move_arg(Clobbers),
3980 S->getRParenLoc(),
3981 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003982}
3983
3984
3985template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003986StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003987TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003988 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00003989 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003990 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003991 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003992
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003993 // Transform the @catch statements (if present).
3994 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003995 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003996 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00003997 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003998 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003999 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004000 if (Catch.get() != S->getCatchStmt(I))
4001 AnyCatchChanged = true;
4002 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004003 }
Sean Huntc3021132010-05-05 15:23:54 +00004004
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004005 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00004006 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004007 if (S->getFinallyStmt()) {
4008 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4009 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004010 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004011 }
4012
4013 // If nothing changed, just retain this statement.
4014 if (!getDerived().AlwaysRebuild() &&
4015 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004016 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004017 Finally.get() == S->getFinallyStmt())
4018 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004019
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004020 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00004021 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4022 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004023}
Mike Stump1eb44332009-09-09 15:08:12 +00004024
Douglas Gregor43959a92009-08-20 07:17:43 +00004025template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004026StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004027TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004028 // Transform the @catch parameter, if there is one.
4029 VarDecl *Var = 0;
4030 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4031 TypeSourceInfo *TSInfo = 0;
4032 if (FromVar->getTypeSourceInfo()) {
4033 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4034 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004035 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004036 }
Sean Huntc3021132010-05-05 15:23:54 +00004037
Douglas Gregorbe270a02010-04-26 17:57:08 +00004038 QualType T;
4039 if (TSInfo)
4040 T = TSInfo->getType();
4041 else {
4042 T = getDerived().TransformType(FromVar->getType());
4043 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004044 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004045 }
Sean Huntc3021132010-05-05 15:23:54 +00004046
Douglas Gregorbe270a02010-04-26 17:57:08 +00004047 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4048 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004049 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004050 }
Sean Huntc3021132010-05-05 15:23:54 +00004051
John McCall60d7b3a2010-08-24 06:29:42 +00004052 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004053 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004054 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004055
4056 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004057 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004058 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004059}
Mike Stump1eb44332009-09-09 15:08:12 +00004060
Douglas Gregor43959a92009-08-20 07:17:43 +00004061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004062StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004063TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004064 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004065 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004066 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004067 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004068
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004069 // If nothing changed, just retain this statement.
4070 if (!getDerived().AlwaysRebuild() &&
4071 Body.get() == S->getFinallyBody())
4072 return SemaRef.Owned(S->Retain());
4073
4074 // Build a new statement.
4075 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004076 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004077}
Mike Stump1eb44332009-09-09 15:08:12 +00004078
Douglas Gregor43959a92009-08-20 07:17:43 +00004079template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004080StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004081TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004082 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004083 if (S->getThrowExpr()) {
4084 Operand = getDerived().TransformExpr(S->getThrowExpr());
4085 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004086 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004087 }
Sean Huntc3021132010-05-05 15:23:54 +00004088
Douglas Gregord1377b22010-04-22 21:44:01 +00004089 if (!getDerived().AlwaysRebuild() &&
4090 Operand.get() == S->getThrowExpr())
4091 return getSema().Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004092
John McCall9ae2f072010-08-23 23:25:46 +00004093 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004094}
Mike Stump1eb44332009-09-09 15:08:12 +00004095
Douglas Gregor43959a92009-08-20 07:17:43 +00004096template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004097StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004098TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004099 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004100 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004101 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004102 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004103 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004104
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004105 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004106 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004107 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004108 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004109
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004110 // If nothing change, just retain the current statement.
4111 if (!getDerived().AlwaysRebuild() &&
4112 Object.get() == S->getSynchExpr() &&
4113 Body.get() == S->getSynchBody())
4114 return SemaRef.Owned(S->Retain());
4115
4116 // Build a new statement.
4117 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004118 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004119}
4120
4121template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004122StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004123TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004124 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004125 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004126 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004127 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004128 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004129
Douglas Gregorc3203e72010-04-22 23:10:45 +00004130 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00004131 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004132 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004133 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004134
Douglas Gregorc3203e72010-04-22 23:10:45 +00004135 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004136 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004137 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004138 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004139
Douglas Gregorc3203e72010-04-22 23:10:45 +00004140 // If nothing changed, just retain this statement.
4141 if (!getDerived().AlwaysRebuild() &&
4142 Element.get() == S->getElement() &&
4143 Collection.get() == S->getCollection() &&
4144 Body.get() == S->getBody())
4145 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004146
Douglas Gregorc3203e72010-04-22 23:10:45 +00004147 // Build a new statement.
4148 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4149 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004150 Element.get(),
4151 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00004152 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004153 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004154}
4155
4156
4157template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004158StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004159TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4160 // Transform the exception declaration, if any.
4161 VarDecl *Var = 0;
4162 if (S->getExceptionDecl()) {
4163 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00004164 TypeSourceInfo *T = getDerived().TransformType(
4165 ExceptionDecl->getTypeSourceInfo());
4166 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00004167 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004168
Douglas Gregor83cb9422010-09-09 17:09:21 +00004169 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00004170 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00004171 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00004172 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00004173 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004174 }
Mike Stump1eb44332009-09-09 15:08:12 +00004175
Douglas Gregor43959a92009-08-20 07:17:43 +00004176 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00004177 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004178 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004179 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004180
Douglas Gregor43959a92009-08-20 07:17:43 +00004181 if (!getDerived().AlwaysRebuild() &&
4182 !Var &&
4183 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00004184 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004185
4186 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4187 Var,
John McCall9ae2f072010-08-23 23:25:46 +00004188 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004189}
Mike Stump1eb44332009-09-09 15:08:12 +00004190
Douglas Gregor43959a92009-08-20 07:17:43 +00004191template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004192StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004193TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4194 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004195 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004196 = getDerived().TransformCompoundStmt(S->getTryBlock());
4197 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004198 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004199
Douglas Gregor43959a92009-08-20 07:17:43 +00004200 // Transform the handlers.
4201 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004202 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00004203 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004204 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004205 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4206 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004207 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004208
Douglas Gregor43959a92009-08-20 07:17:43 +00004209 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4210 Handlers.push_back(Handler.takeAs<Stmt>());
4211 }
Mike Stump1eb44332009-09-09 15:08:12 +00004212
Douglas Gregor43959a92009-08-20 07:17:43 +00004213 if (!getDerived().AlwaysRebuild() &&
4214 TryBlock.get() == S->getTryBlock() &&
4215 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004216 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004217
John McCall9ae2f072010-08-23 23:25:46 +00004218 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00004219 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004220}
Mike Stump1eb44332009-09-09 15:08:12 +00004221
Douglas Gregor43959a92009-08-20 07:17:43 +00004222//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004223// Expression transformation
4224//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004225template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004226ExprResult
John McCall454feb92009-12-08 09:21:05 +00004227TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004228 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004229}
Mike Stump1eb44332009-09-09 15:08:12 +00004230
4231template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004232ExprResult
John McCall454feb92009-12-08 09:21:05 +00004233TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004234 NestedNameSpecifier *Qualifier = 0;
4235 if (E->getQualifier()) {
4236 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004237 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004238 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00004239 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00004240 }
John McCalldbd872f2009-12-08 09:08:17 +00004241
4242 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004243 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4244 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004245 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00004246 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004247
John McCallec8045d2010-08-17 21:27:17 +00004248 DeclarationNameInfo NameInfo = E->getNameInfo();
4249 if (NameInfo.getName()) {
4250 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4251 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00004252 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00004253 }
Abramo Bagnara25777432010-08-11 22:01:17 +00004254
4255 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004256 Qualifier == E->getQualifier() &&
4257 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00004258 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00004259 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004260
4261 // Mark it referenced in the new context regardless.
4262 // FIXME: this is a bit instantiation-specific.
4263 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4264
Mike Stump1eb44332009-09-09 15:08:12 +00004265 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004266 }
John McCalldbd872f2009-12-08 09:08:17 +00004267
4268 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00004269 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004270 TemplateArgs = &TransArgs;
4271 TransArgs.setLAngleLoc(E->getLAngleLoc());
4272 TransArgs.setRAngleLoc(E->getRAngleLoc());
4273 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4274 TemplateArgumentLoc Loc;
4275 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004276 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00004277 TransArgs.addArgument(Loc);
4278 }
4279 }
4280
Douglas Gregora2813ce2009-10-23 18:54:35 +00004281 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004282 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004283}
Mike Stump1eb44332009-09-09 15:08:12 +00004284
Douglas Gregorb98b1992009-08-11 05:31:07 +00004285template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004286ExprResult
John McCall454feb92009-12-08 09:21:05 +00004287TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004288 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004289}
Mike Stump1eb44332009-09-09 15:08:12 +00004290
Douglas Gregorb98b1992009-08-11 05:31:07 +00004291template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004292ExprResult
John McCall454feb92009-12-08 09:21:05 +00004293TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004294 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004295}
Mike Stump1eb44332009-09-09 15:08:12 +00004296
Douglas Gregorb98b1992009-08-11 05:31:07 +00004297template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004298ExprResult
John McCall454feb92009-12-08 09:21:05 +00004299TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004300 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004301}
Mike Stump1eb44332009-09-09 15:08:12 +00004302
Douglas Gregorb98b1992009-08-11 05:31:07 +00004303template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004304ExprResult
John McCall454feb92009-12-08 09:21:05 +00004305TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004306 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004307}
Mike Stump1eb44332009-09-09 15:08:12 +00004308
Douglas Gregorb98b1992009-08-11 05:31:07 +00004309template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004310ExprResult
John McCall454feb92009-12-08 09:21:05 +00004311TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004312 return SemaRef.Owned(E->Retain());
4313}
4314
4315template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004316ExprResult
John McCall454feb92009-12-08 09:21:05 +00004317TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004318 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004319 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004320 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004321
Douglas Gregorb98b1992009-08-11 05:31:07 +00004322 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004323 return SemaRef.Owned(E->Retain());
4324
John McCall9ae2f072010-08-23 23:25:46 +00004325 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004326 E->getRParen());
4327}
4328
Mike Stump1eb44332009-09-09 15:08:12 +00004329template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004330ExprResult
John McCall454feb92009-12-08 09:21:05 +00004331TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004332 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004333 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004334 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004335
Douglas Gregorb98b1992009-08-11 05:31:07 +00004336 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004337 return SemaRef.Owned(E->Retain());
4338
Douglas Gregorb98b1992009-08-11 05:31:07 +00004339 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4340 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004341 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004342}
Mike Stump1eb44332009-09-09 15:08:12 +00004343
Douglas Gregorb98b1992009-08-11 05:31:07 +00004344template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004345ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004346TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4347 // Transform the type.
4348 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4349 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00004350 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004351
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004352 // Transform all of the components into components similar to what the
4353 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004354 // FIXME: It would be slightly more efficient in the non-dependent case to
4355 // just map FieldDecls, rather than requiring the rebuilder to look for
4356 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004357 // template code that we don't care.
4358 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00004359 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004360 typedef OffsetOfExpr::OffsetOfNode Node;
4361 llvm::SmallVector<Component, 4> Components;
4362 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4363 const Node &ON = E->getComponent(I);
4364 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004365 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004366 Comp.LocStart = ON.getRange().getBegin();
4367 Comp.LocEnd = ON.getRange().getEnd();
4368 switch (ON.getKind()) {
4369 case Node::Array: {
4370 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00004371 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004372 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004373 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004374
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004375 ExprChanged = ExprChanged || Index.get() != FromIndex;
4376 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00004377 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004378 break;
4379 }
Sean Huntc3021132010-05-05 15:23:54 +00004380
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004381 case Node::Field:
4382 case Node::Identifier:
4383 Comp.isBrackets = false;
4384 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004385 if (!Comp.U.IdentInfo)
4386 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004387
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004388 break;
Sean Huntc3021132010-05-05 15:23:54 +00004389
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004390 case Node::Base:
4391 // Will be recomputed during the rebuild.
4392 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004393 }
Sean Huntc3021132010-05-05 15:23:54 +00004394
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004395 Components.push_back(Comp);
4396 }
Sean Huntc3021132010-05-05 15:23:54 +00004397
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004398 // If nothing changed, retain the existing expression.
4399 if (!getDerived().AlwaysRebuild() &&
4400 Type == E->getTypeSourceInfo() &&
4401 !ExprChanged)
4402 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004403
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004404 // Build a new offsetof expression.
4405 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4406 Components.data(), Components.size(),
4407 E->getRParenLoc());
4408}
4409
4410template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004411ExprResult
John McCall454feb92009-12-08 09:21:05 +00004412TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004413 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004414 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004415
John McCalla93c9342009-12-07 02:54:59 +00004416 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004417 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004418 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004419
John McCall5ab75172009-11-04 07:28:41 +00004420 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004421 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004422
John McCall5ab75172009-11-04 07:28:41 +00004423 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004424 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004425 E->getSourceRange());
4426 }
Mike Stump1eb44332009-09-09 15:08:12 +00004427
John McCall60d7b3a2010-08-24 06:29:42 +00004428 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00004429 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004430 // C++0x [expr.sizeof]p1:
4431 // The operand is either an expression, which is an unevaluated operand
4432 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00004433 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004434
Douglas Gregorb98b1992009-08-11 05:31:07 +00004435 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4436 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004437 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004438
Douglas Gregorb98b1992009-08-11 05:31:07 +00004439 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4440 return SemaRef.Owned(E->Retain());
4441 }
Mike Stump1eb44332009-09-09 15:08:12 +00004442
John McCall9ae2f072010-08-23 23:25:46 +00004443 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004444 E->isSizeOf(),
4445 E->getSourceRange());
4446}
Mike Stump1eb44332009-09-09 15:08:12 +00004447
Douglas Gregorb98b1992009-08-11 05:31:07 +00004448template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004449ExprResult
John McCall454feb92009-12-08 09:21:05 +00004450TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004451 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004452 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004453 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004454
John McCall60d7b3a2010-08-24 06:29:42 +00004455 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004456 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004457 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004458
4459
Douglas Gregorb98b1992009-08-11 05:31:07 +00004460 if (!getDerived().AlwaysRebuild() &&
4461 LHS.get() == E->getLHS() &&
4462 RHS.get() == E->getRHS())
4463 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004464
John McCall9ae2f072010-08-23 23:25:46 +00004465 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004466 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00004467 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004468 E->getRBracketLoc());
4469}
Mike Stump1eb44332009-09-09 15:08:12 +00004470
4471template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004472ExprResult
John McCall454feb92009-12-08 09:21:05 +00004473TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004474 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00004475 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004476 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004477 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004478
4479 // Transform arguments.
4480 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004481 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004482 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004483 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004484 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004485 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004486
Mike Stump1eb44332009-09-09 15:08:12 +00004487 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00004488 Args.push_back(Arg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004489 }
Mike Stump1eb44332009-09-09 15:08:12 +00004490
Douglas Gregorb98b1992009-08-11 05:31:07 +00004491 if (!getDerived().AlwaysRebuild() &&
4492 Callee.get() == E->getCallee() &&
4493 !ArgChanged)
4494 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004495
Douglas Gregorb98b1992009-08-11 05:31:07 +00004496 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004497 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004498 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00004499 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004500 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004501 E->getRParenLoc());
4502}
Mike Stump1eb44332009-09-09 15:08:12 +00004503
4504template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004505ExprResult
John McCall454feb92009-12-08 09:21:05 +00004506TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004507 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004508 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004509 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004510
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004511 NestedNameSpecifier *Qualifier = 0;
4512 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004513 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004514 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004515 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004516 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00004517 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004518 }
Mike Stump1eb44332009-09-09 15:08:12 +00004519
Eli Friedmanf595cc42009-12-04 06:40:45 +00004520 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004521 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4522 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004523 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00004524 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004525
John McCall6bb80172010-03-30 21:47:33 +00004526 NamedDecl *FoundDecl = E->getFoundDecl();
4527 if (FoundDecl == E->getMemberDecl()) {
4528 FoundDecl = Member;
4529 } else {
4530 FoundDecl = cast_or_null<NamedDecl>(
4531 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4532 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00004533 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00004534 }
4535
Douglas Gregorb98b1992009-08-11 05:31:07 +00004536 if (!getDerived().AlwaysRebuild() &&
4537 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004538 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004539 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004540 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00004541 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00004542
Anders Carlsson1f240322009-12-22 05:24:09 +00004543 // Mark it referenced in the new context regardless.
4544 // FIXME: this is a bit instantiation-specific.
4545 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00004546 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00004547 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004548
John McCalld5532b62009-11-23 01:53:49 +00004549 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00004550 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00004551 TransArgs.setLAngleLoc(E->getLAngleLoc());
4552 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004553 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004554 TemplateArgumentLoc Loc;
4555 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004556 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004557 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004558 }
4559 }
Sean Huntc3021132010-05-05 15:23:54 +00004560
Douglas Gregorb98b1992009-08-11 05:31:07 +00004561 // FIXME: Bogus source location for the operator
4562 SourceLocation FakeOperatorLoc
4563 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4564
John McCallc2233c52010-01-15 08:34:02 +00004565 // FIXME: to do this check properly, we will need to preserve the
4566 // first-qualifier-in-scope here, just in case we had a dependent
4567 // base (and therefore couldn't do the check) and a
4568 // nested-name-qualifier (and therefore could do the lookup).
4569 NamedDecl *FirstQualifierInScope = 0;
4570
John McCall9ae2f072010-08-23 23:25:46 +00004571 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004572 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004573 Qualifier,
4574 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004575 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004576 Member,
John McCall6bb80172010-03-30 21:47:33 +00004577 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00004578 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00004579 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004580 FirstQualifierInScope);
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>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004586 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004587 if (LHS.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 RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004591 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004592 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004593
Douglas Gregorb98b1992009-08-11 05:31:07 +00004594 if (!getDerived().AlwaysRebuild() &&
4595 LHS.get() == E->getLHS() &&
4596 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004597 return SemaRef.Owned(E->Retain());
4598
Douglas Gregorb98b1992009-08-11 05:31:07 +00004599 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004600 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004601}
4602
Mike Stump1eb44332009-09-09 15:08:12 +00004603template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004604ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004605TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004606 CompoundAssignOperator *E) {
4607 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004608}
Mike Stump1eb44332009-09-09 15:08:12 +00004609
Douglas Gregorb98b1992009-08-11 05:31:07 +00004610template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004611ExprResult
John McCall454feb92009-12-08 09:21:05 +00004612TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004613 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004614 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004615 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004616
John McCall60d7b3a2010-08-24 06:29:42 +00004617 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004618 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004619 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004620
John McCall60d7b3a2010-08-24 06:29:42 +00004621 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004622 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004623 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004624
Douglas Gregorb98b1992009-08-11 05:31:07 +00004625 if (!getDerived().AlwaysRebuild() &&
4626 Cond.get() == E->getCond() &&
4627 LHS.get() == E->getLHS() &&
4628 RHS.get() == E->getRHS())
4629 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004630
John McCall9ae2f072010-08-23 23:25:46 +00004631 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004632 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004633 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004634 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004635 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004636}
Mike Stump1eb44332009-09-09 15:08:12 +00004637
4638template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004639ExprResult
John McCall454feb92009-12-08 09:21:05 +00004640TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004641 // Implicit casts are eliminated during transformation, since they
4642 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004643 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004644}
Mike Stump1eb44332009-09-09 15:08:12 +00004645
Douglas Gregorb98b1992009-08-11 05:31:07 +00004646template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004647ExprResult
John McCall454feb92009-12-08 09:21:05 +00004648TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004649 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4650 if (!Type)
4651 return ExprError();
4652
John McCall60d7b3a2010-08-24 06:29:42 +00004653 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004654 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004655 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004656 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004657
Douglas Gregorb98b1992009-08-11 05:31:07 +00004658 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004659 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004660 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004661 return SemaRef.Owned(E->Retain());
4662
John McCall9d125032010-01-15 18:39:57 +00004663 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004664 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004665 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004666 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004667}
Mike Stump1eb44332009-09-09 15:08:12 +00004668
Douglas Gregorb98b1992009-08-11 05:31:07 +00004669template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004670ExprResult
John McCall454feb92009-12-08 09:21:05 +00004671TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004672 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4673 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4674 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004675 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004676
John McCall60d7b3a2010-08-24 06:29:42 +00004677 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004678 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004679 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004680
Douglas Gregorb98b1992009-08-11 05:31:07 +00004681 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004682 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004683 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00004684 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004685
John McCall1d7d8d62010-01-19 22:33:45 +00004686 // Note: the expression type doesn't necessarily match the
4687 // type-as-written, but that's okay, because it should always be
4688 // derivable from the initializer.
4689
John McCall42f56b52010-01-18 19:35:47 +00004690 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004691 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00004692 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004693}
Mike Stump1eb44332009-09-09 15:08:12 +00004694
Douglas Gregorb98b1992009-08-11 05:31:07 +00004695template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004696ExprResult
John McCall454feb92009-12-08 09:21:05 +00004697TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004698 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004699 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004700 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004701
Douglas Gregorb98b1992009-08-11 05:31:07 +00004702 if (!getDerived().AlwaysRebuild() &&
4703 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00004704 return SemaRef.Owned(E->Retain());
4705
Douglas Gregorb98b1992009-08-11 05:31:07 +00004706 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004707 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004708 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00004709 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004710 E->getAccessorLoc(),
4711 E->getAccessor());
4712}
Mike Stump1eb44332009-09-09 15:08:12 +00004713
Douglas Gregorb98b1992009-08-11 05:31:07 +00004714template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004715ExprResult
John McCall454feb92009-12-08 09:21:05 +00004716TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004717 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004718
John McCallca0408f2010-08-23 06:44:23 +00004719 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004720 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004721 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004722 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004723 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004724
Douglas Gregorb98b1992009-08-11 05:31:07 +00004725 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCall9ae2f072010-08-23 23:25:46 +00004726 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004727 }
Mike Stump1eb44332009-09-09 15:08:12 +00004728
Douglas Gregorb98b1992009-08-11 05:31:07 +00004729 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004730 return SemaRef.Owned(E->Retain());
4731
Douglas Gregorb98b1992009-08-11 05:31:07 +00004732 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004733 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004734}
Mike Stump1eb44332009-09-09 15:08:12 +00004735
Douglas Gregorb98b1992009-08-11 05:31:07 +00004736template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004737ExprResult
John McCall454feb92009-12-08 09:21:05 +00004738TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004739 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004740
Douglas Gregor43959a92009-08-20 07:17:43 +00004741 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00004742 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004743 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004744 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004745
Douglas Gregor43959a92009-08-20 07:17:43 +00004746 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00004747 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004748 bool ExprChanged = false;
4749 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4750 DEnd = E->designators_end();
4751 D != DEnd; ++D) {
4752 if (D->isFieldDesignator()) {
4753 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4754 D->getDotLoc(),
4755 D->getFieldLoc()));
4756 continue;
4757 }
Mike Stump1eb44332009-09-09 15:08:12 +00004758
Douglas Gregorb98b1992009-08-11 05:31:07 +00004759 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00004760 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004761 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004762 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004763
4764 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004765 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004766
Douglas Gregorb98b1992009-08-11 05:31:07 +00004767 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4768 ArrayExprs.push_back(Index.release());
4769 continue;
4770 }
Mike Stump1eb44332009-09-09 15:08:12 +00004771
Douglas Gregorb98b1992009-08-11 05:31:07 +00004772 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00004773 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004774 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4775 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004776 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004777
John McCall60d7b3a2010-08-24 06:29:42 +00004778 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004779 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004780 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004781
4782 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004783 End.get(),
4784 D->getLBracketLoc(),
4785 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004786
Douglas Gregorb98b1992009-08-11 05:31:07 +00004787 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4788 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004789
Douglas Gregorb98b1992009-08-11 05:31:07 +00004790 ArrayExprs.push_back(Start.release());
4791 ArrayExprs.push_back(End.release());
4792 }
Mike Stump1eb44332009-09-09 15:08:12 +00004793
Douglas Gregorb98b1992009-08-11 05:31:07 +00004794 if (!getDerived().AlwaysRebuild() &&
4795 Init.get() == E->getInit() &&
4796 !ExprChanged)
4797 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004798
Douglas Gregorb98b1992009-08-11 05:31:07 +00004799 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4800 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004801 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004802}
Mike Stump1eb44332009-09-09 15:08:12 +00004803
Douglas Gregorb98b1992009-08-11 05:31:07 +00004804template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004805ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004806TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004807 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004808 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004809
Douglas Gregor5557b252009-10-28 00:29:27 +00004810 // FIXME: Will we ever have proper type location here? Will we actually
4811 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004812 QualType T = getDerived().TransformType(E->getType());
4813 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004814 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004815
Douglas Gregorb98b1992009-08-11 05:31:07 +00004816 if (!getDerived().AlwaysRebuild() &&
4817 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004818 return SemaRef.Owned(E->Retain());
4819
Douglas Gregorb98b1992009-08-11 05:31:07 +00004820 return getDerived().RebuildImplicitValueInitExpr(T);
4821}
Mike Stump1eb44332009-09-09 15:08:12 +00004822
Douglas Gregorb98b1992009-08-11 05:31:07 +00004823template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004824ExprResult
John McCall454feb92009-12-08 09:21:05 +00004825TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004826 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4827 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004828 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004829
John McCall60d7b3a2010-08-24 06:29:42 +00004830 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004831 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004832 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004833
Douglas Gregorb98b1992009-08-11 05:31:07 +00004834 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004835 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004836 SubExpr.get() == E->getSubExpr())
4837 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004838
John McCall9ae2f072010-08-23 23:25:46 +00004839 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004840 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004841}
4842
4843template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004844ExprResult
John McCall454feb92009-12-08 09:21:05 +00004845TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004846 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004847 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004848 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004849 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004850 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004851 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004852
Douglas Gregorb98b1992009-08-11 05:31:07 +00004853 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00004854 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004855 }
Mike Stump1eb44332009-09-09 15:08:12 +00004856
Douglas Gregorb98b1992009-08-11 05:31:07 +00004857 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4858 move_arg(Inits),
4859 E->getRParenLoc());
4860}
Mike Stump1eb44332009-09-09 15:08:12 +00004861
Douglas Gregorb98b1992009-08-11 05:31:07 +00004862/// \brief Transform an address-of-label expression.
4863///
4864/// By default, the transformation of an address-of-label expression always
4865/// rebuilds the expression, so that the label identifier can be resolved to
4866/// the corresponding label statement by semantic analysis.
4867template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004868ExprResult
John McCall454feb92009-12-08 09:21:05 +00004869TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004870 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4871 E->getLabel());
4872}
Mike Stump1eb44332009-09-09 15:08:12 +00004873
4874template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004875ExprResult
John McCall454feb92009-12-08 09:21:05 +00004876TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004877 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004878 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4879 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004880 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004881
Douglas Gregorb98b1992009-08-11 05:31:07 +00004882 if (!getDerived().AlwaysRebuild() &&
4883 SubStmt.get() == E->getSubStmt())
4884 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004885
4886 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004887 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004888 E->getRParenLoc());
4889}
Mike Stump1eb44332009-09-09 15:08:12 +00004890
Douglas Gregorb98b1992009-08-11 05:31:07 +00004891template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004892ExprResult
John McCall454feb92009-12-08 09:21:05 +00004893TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004894 TypeSourceInfo *TInfo1;
4895 TypeSourceInfo *TInfo2;
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004896
4897 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4898 if (!TInfo1)
John McCallf312b1e2010-08-26 23:41:50 +00004899 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004900
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004901 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4902 if (!TInfo2)
John McCallf312b1e2010-08-26 23:41:50 +00004903 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004904
4905 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004906 TInfo1 == E->getArgTInfo1() &&
4907 TInfo2 == E->getArgTInfo2())
Mike Stump1eb44332009-09-09 15:08:12 +00004908 return SemaRef.Owned(E->Retain());
4909
Douglas Gregorb98b1992009-08-11 05:31:07 +00004910 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004911 TInfo1, TInfo2,
4912 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004913}
Mike Stump1eb44332009-09-09 15:08:12 +00004914
Douglas Gregorb98b1992009-08-11 05:31:07 +00004915template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004916ExprResult
John McCall454feb92009-12-08 09:21:05 +00004917TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004918 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004919 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004920 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004921
John McCall60d7b3a2010-08-24 06:29:42 +00004922 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004923 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004924 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004925
John McCall60d7b3a2010-08-24 06:29:42 +00004926 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004927 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004928 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004929
Douglas Gregorb98b1992009-08-11 05:31:07 +00004930 if (!getDerived().AlwaysRebuild() &&
4931 Cond.get() == E->getCond() &&
4932 LHS.get() == E->getLHS() &&
4933 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004934 return SemaRef.Owned(E->Retain());
4935
Douglas Gregorb98b1992009-08-11 05:31:07 +00004936 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004937 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004938 E->getRParenLoc());
4939}
Mike Stump1eb44332009-09-09 15:08:12 +00004940
Douglas Gregorb98b1992009-08-11 05:31:07 +00004941template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004942ExprResult
John McCall454feb92009-12-08 09:21:05 +00004943TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004944 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004945}
4946
4947template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004948ExprResult
John McCall454feb92009-12-08 09:21:05 +00004949TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004950 switch (E->getOperator()) {
4951 case OO_New:
4952 case OO_Delete:
4953 case OO_Array_New:
4954 case OO_Array_Delete:
4955 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00004956 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004957
Douglas Gregor668d6d92009-12-13 20:44:55 +00004958 case OO_Call: {
4959 // This is a call to an object's operator().
4960 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4961
4962 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004963 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00004964 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004965 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004966
4967 // FIXME: Poor location information
4968 SourceLocation FakeLParenLoc
4969 = SemaRef.PP.getLocForEndOfToken(
4970 static_cast<Expr *>(Object.get())->getLocEnd());
4971
4972 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00004973 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor668d6d92009-12-13 20:44:55 +00004974 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004975 if (getDerived().DropCallArgument(E->getArg(I)))
4976 break;
Sean Huntc3021132010-05-05 15:23:54 +00004977
John McCall60d7b3a2010-08-24 06:29:42 +00004978 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor668d6d92009-12-13 20:44:55 +00004979 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004980 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00004981
Douglas Gregor668d6d92009-12-13 20:44:55 +00004982 Args.push_back(Arg.release());
4983 }
4984
John McCall9ae2f072010-08-23 23:25:46 +00004985 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00004986 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00004987 E->getLocEnd());
4988 }
4989
4990#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4991 case OO_##Name:
4992#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4993#include "clang/Basic/OperatorKinds.def"
4994 case OO_Subscript:
4995 // Handled below.
4996 break;
4997
4998 case OO_Conditional:
4999 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00005000 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005001
5002 case OO_None:
5003 case NUM_OVERLOADED_OPERATORS:
5004 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00005005 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005006 }
5007
John McCall60d7b3a2010-08-24 06:29:42 +00005008 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005009 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005010 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005011
John McCall60d7b3a2010-08-24 06:29:42 +00005012 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005013 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005014 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005015
John McCall60d7b3a2010-08-24 06:29:42 +00005016 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005017 if (E->getNumArgs() == 2) {
5018 Second = getDerived().TransformExpr(E->getArg(1));
5019 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005020 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005021 }
Mike Stump1eb44332009-09-09 15:08:12 +00005022
Douglas Gregorb98b1992009-08-11 05:31:07 +00005023 if (!getDerived().AlwaysRebuild() &&
5024 Callee.get() == E->getCallee() &&
5025 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005026 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5027 return SemaRef.Owned(E->Retain());
5028
Douglas Gregorb98b1992009-08-11 05:31:07 +00005029 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5030 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005031 Callee.get(),
5032 First.get(),
5033 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005034}
Mike Stump1eb44332009-09-09 15:08:12 +00005035
Douglas Gregorb98b1992009-08-11 05:31:07 +00005036template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005037ExprResult
John McCall454feb92009-12-08 09:21:05 +00005038TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5039 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005040}
Mike Stump1eb44332009-09-09 15:08:12 +00005041
Douglas Gregorb98b1992009-08-11 05:31:07 +00005042template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005043ExprResult
John McCall454feb92009-12-08 09:21:05 +00005044TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005045 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5046 if (!Type)
5047 return ExprError();
5048
John McCall60d7b3a2010-08-24 06:29:42 +00005049 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005050 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005051 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005052 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005053
Douglas Gregorb98b1992009-08-11 05:31:07 +00005054 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005055 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005056 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005057 return SemaRef.Owned(E->Retain());
5058
Douglas Gregorb98b1992009-08-11 05:31:07 +00005059 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005060 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005061 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5062 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5063 SourceLocation FakeRParenLoc
5064 = SemaRef.PP.getLocForEndOfToken(
5065 E->getSubExpr()->getSourceRange().getEnd());
5066 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005067 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005068 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005069 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005070 FakeRAngleLoc,
5071 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005072 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005073 FakeRParenLoc);
5074}
Mike Stump1eb44332009-09-09 15:08:12 +00005075
Douglas Gregorb98b1992009-08-11 05:31:07 +00005076template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005077ExprResult
John McCall454feb92009-12-08 09:21:05 +00005078TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5079 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005080}
Mike Stump1eb44332009-09-09 15:08:12 +00005081
5082template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005083ExprResult
John McCall454feb92009-12-08 09:21:05 +00005084TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5085 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005086}
5087
Douglas Gregorb98b1992009-08-11 05:31:07 +00005088template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005089ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005090TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005091 CXXReinterpretCastExpr *E) {
5092 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005093}
Mike Stump1eb44332009-09-09 15:08:12 +00005094
Douglas Gregorb98b1992009-08-11 05:31:07 +00005095template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005096ExprResult
John McCall454feb92009-12-08 09:21:05 +00005097TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5098 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005099}
Mike Stump1eb44332009-09-09 15:08:12 +00005100
Douglas Gregorb98b1992009-08-11 05:31:07 +00005101template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005102ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005103TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005104 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005105 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5106 if (!Type)
5107 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005108
John McCall60d7b3a2010-08-24 06:29:42 +00005109 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005110 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005111 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005112 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005113
Douglas Gregorb98b1992009-08-11 05:31:07 +00005114 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005115 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005116 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005117 return SemaRef.Owned(E->Retain());
5118
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005119 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005120 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005121 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005122 E->getRParenLoc());
5123}
Mike Stump1eb44332009-09-09 15:08:12 +00005124
Douglas Gregorb98b1992009-08-11 05:31:07 +00005125template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005126ExprResult
John McCall454feb92009-12-08 09:21:05 +00005127TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005128 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005129 TypeSourceInfo *TInfo
5130 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5131 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005132 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005133
Douglas Gregorb98b1992009-08-11 05:31:07 +00005134 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005135 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005136 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005137
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005138 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5139 E->getLocStart(),
5140 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005141 E->getLocEnd());
5142 }
Mike Stump1eb44332009-09-09 15:08:12 +00005143
Douglas Gregorb98b1992009-08-11 05:31:07 +00005144 // We don't know whether the expression is potentially evaluated until
5145 // after we perform semantic analysis, so the expression is potentially
5146 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005147 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00005148 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005149
John McCall60d7b3a2010-08-24 06:29:42 +00005150 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005151 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005152 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005153
Douglas Gregorb98b1992009-08-11 05:31:07 +00005154 if (!getDerived().AlwaysRebuild() &&
5155 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00005156 return SemaRef.Owned(E->Retain());
5157
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005158 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5159 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005160 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005161 E->getLocEnd());
5162}
5163
5164template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005165ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00005166TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5167 if (E->isTypeOperand()) {
5168 TypeSourceInfo *TInfo
5169 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5170 if (!TInfo)
5171 return ExprError();
5172
5173 if (!getDerived().AlwaysRebuild() &&
5174 TInfo == E->getTypeOperandSourceInfo())
5175 return SemaRef.Owned(E->Retain());
5176
5177 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5178 E->getLocStart(),
5179 TInfo,
5180 E->getLocEnd());
5181 }
5182
5183 // We don't know whether the expression is potentially evaluated until
5184 // after we perform semantic analysis, so the expression is potentially
5185 // potentially evaluated.
5186 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5187
5188 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5189 if (SubExpr.isInvalid())
5190 return ExprError();
5191
5192 if (!getDerived().AlwaysRebuild() &&
5193 SubExpr.get() == E->getExprOperand())
5194 return SemaRef.Owned(E->Retain());
5195
5196 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5197 E->getLocStart(),
5198 SubExpr.get(),
5199 E->getLocEnd());
5200}
5201
5202template<typename Derived>
5203ExprResult
John McCall454feb92009-12-08 09:21:05 +00005204TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005205 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005206}
Mike Stump1eb44332009-09-09 15:08:12 +00005207
Douglas Gregorb98b1992009-08-11 05:31:07 +00005208template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005209ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005210TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005211 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005212 return SemaRef.Owned(E->Retain());
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>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005218 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5219 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5220 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00005221
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005222 if (!getDerived().AlwaysRebuild() && T == E->getType())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005223 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005224
Douglas Gregor828a1972010-01-07 23:12:05 +00005225 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005226}
Mike Stump1eb44332009-09-09 15:08:12 +00005227
Douglas Gregorb98b1992009-08-11 05:31:07 +00005228template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005229ExprResult
John McCall454feb92009-12-08 09:21:05 +00005230TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005231 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005232 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005233 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005234
Douglas Gregorb98b1992009-08-11 05:31:07 +00005235 if (!getDerived().AlwaysRebuild() &&
5236 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005237 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005238
John McCall9ae2f072010-08-23 23:25:46 +00005239 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005240}
Mike Stump1eb44332009-09-09 15:08:12 +00005241
Douglas Gregorb98b1992009-08-11 05:31:07 +00005242template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005243ExprResult
John McCall454feb92009-12-08 09:21:05 +00005244TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005245 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005246 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5247 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005248 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00005249 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005250
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005251 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005252 Param == E->getParam())
5253 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005254
Douglas Gregor036aed12009-12-23 23:03:06 +00005255 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005256}
Mike Stump1eb44332009-09-09 15:08:12 +00005257
Douglas Gregorb98b1992009-08-11 05:31:07 +00005258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005259ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00005260TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5261 CXXScalarValueInitExpr *E) {
5262 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5263 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005264 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00005265
Douglas Gregorb98b1992009-08-11 05:31:07 +00005266 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005267 T == E->getTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00005268 return SemaRef.Owned(E->Retain());
5269
Douglas Gregorab6677e2010-09-08 00:15:04 +00005270 return getDerived().RebuildCXXScalarValueInitExpr(T,
5271 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00005272 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005273}
Mike Stump1eb44332009-09-09 15:08:12 +00005274
Douglas Gregorb98b1992009-08-11 05:31:07 +00005275template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005276ExprResult
John McCall454feb92009-12-08 09:21:05 +00005277TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005278 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005279 TypeSourceInfo *AllocTypeInfo
5280 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5281 if (!AllocTypeInfo)
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 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00005285 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005286 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005287 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005288
Douglas Gregorb98b1992009-08-11 05:31:07 +00005289 // Transform the placement arguments (if any).
5290 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005291 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005292 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall63d5fb32010-10-05 22:36:42 +00005293 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5294 ArgumentChanged = true;
5295 break;
5296 }
5297
John McCall60d7b3a2010-08-24 06:29:42 +00005298 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005299 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005300 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005301
Douglas Gregorb98b1992009-08-11 05:31:07 +00005302 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5303 PlacementArgs.push_back(Arg.take());
5304 }
Mike Stump1eb44332009-09-09 15:08:12 +00005305
Douglas Gregor43959a92009-08-20 07:17:43 +00005306 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00005307 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005308 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall63d5fb32010-10-05 22:36:42 +00005309 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5310 ArgumentChanged = true;
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005311 break;
John McCall63d5fb32010-10-05 22:36:42 +00005312 }
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005313
John McCall60d7b3a2010-08-24 06:29:42 +00005314 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005315 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005316 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005317
Douglas Gregorb98b1992009-08-11 05:31:07 +00005318 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5319 ConstructorArgs.push_back(Arg.take());
5320 }
Mike Stump1eb44332009-09-09 15:08:12 +00005321
Douglas Gregor1af74512010-02-26 00:38:10 +00005322 // Transform constructor, new operator, and delete operator.
5323 CXXConstructorDecl *Constructor = 0;
5324 if (E->getConstructor()) {
5325 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005326 getDerived().TransformDecl(E->getLocStart(),
5327 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005328 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005329 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005330 }
5331
5332 FunctionDecl *OperatorNew = 0;
5333 if (E->getOperatorNew()) {
5334 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005335 getDerived().TransformDecl(E->getLocStart(),
5336 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005337 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00005338 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005339 }
5340
5341 FunctionDecl *OperatorDelete = 0;
5342 if (E->getOperatorDelete()) {
5343 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005344 getDerived().TransformDecl(E->getLocStart(),
5345 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005346 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005347 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005348 }
Sean Huntc3021132010-05-05 15:23:54 +00005349
Douglas Gregorb98b1992009-08-11 05:31:07 +00005350 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005351 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005352 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005353 Constructor == E->getConstructor() &&
5354 OperatorNew == E->getOperatorNew() &&
5355 OperatorDelete == E->getOperatorDelete() &&
5356 !ArgumentChanged) {
5357 // Mark any declarations we need as referenced.
5358 // FIXME: instantiation-specific.
5359 if (Constructor)
5360 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5361 if (OperatorNew)
5362 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5363 if (OperatorDelete)
5364 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005365 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005366 }
Mike Stump1eb44332009-09-09 15:08:12 +00005367
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005368 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005369 if (!ArraySize.get()) {
5370 // If no array size was specified, but the new expression was
5371 // instantiated with an array type (e.g., "new T" where T is
5372 // instantiated with "int[4]"), extract the outer bound from the
5373 // array type as our array size. We do this with constant and
5374 // dependently-sized array types.
5375 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5376 if (!ArrayT) {
5377 // Do nothing
5378 } else if (const ConstantArrayType *ConsArrayT
5379 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005380 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00005381 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5382 ConsArrayT->getSize(),
5383 SemaRef.Context.getSizeType(),
5384 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005385 AllocType = ConsArrayT->getElementType();
5386 } else if (const DependentSizedArrayType *DepArrayT
5387 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5388 if (DepArrayT->getSizeExpr()) {
5389 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5390 AllocType = DepArrayT->getElementType();
5391 }
5392 }
5393 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005394
Douglas Gregorb98b1992009-08-11 05:31:07 +00005395 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5396 E->isGlobalNew(),
5397 /*FIXME:*/E->getLocStart(),
5398 move_arg(PlacementArgs),
5399 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00005400 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005401 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005402 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00005403 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005404 /*FIXME:*/E->getLocStart(),
5405 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005406 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005407}
Mike Stump1eb44332009-09-09 15:08:12 +00005408
Douglas Gregorb98b1992009-08-11 05:31:07 +00005409template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005410ExprResult
John McCall454feb92009-12-08 09:21:05 +00005411TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005412 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005413 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005414 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005415
Douglas Gregor1af74512010-02-26 00:38:10 +00005416 // Transform the delete operator, if known.
5417 FunctionDecl *OperatorDelete = 0;
5418 if (E->getOperatorDelete()) {
5419 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005420 getDerived().TransformDecl(E->getLocStart(),
5421 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005422 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005423 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005424 }
Sean Huntc3021132010-05-05 15:23:54 +00005425
Douglas Gregorb98b1992009-08-11 05:31:07 +00005426 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005427 Operand.get() == E->getArgument() &&
5428 OperatorDelete == E->getOperatorDelete()) {
5429 // Mark any declarations we need as referenced.
5430 // FIXME: instantiation-specific.
5431 if (OperatorDelete)
5432 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00005433
5434 if (!E->getArgument()->isTypeDependent()) {
5435 QualType Destroyed = SemaRef.Context.getBaseElementType(
5436 E->getDestroyedType());
5437 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5438 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5439 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5440 SemaRef.LookupDestructor(Record));
5441 }
5442 }
5443
Mike Stump1eb44332009-09-09 15:08:12 +00005444 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005445 }
Mike Stump1eb44332009-09-09 15:08:12 +00005446
Douglas Gregorb98b1992009-08-11 05:31:07 +00005447 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5448 E->isGlobalDelete(),
5449 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00005450 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005451}
Mike Stump1eb44332009-09-09 15:08:12 +00005452
Douglas Gregorb98b1992009-08-11 05:31:07 +00005453template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005454ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005455TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005456 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005457 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00005458 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005459 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005460
John McCallb3d87482010-08-24 05:47:05 +00005461 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005462 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005463 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005464 E->getOperatorLoc(),
5465 E->isArrow()? tok::arrow : tok::period,
5466 ObjectTypePtr,
5467 MayBePseudoDestructor);
5468 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005469 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005470
John McCallb3d87482010-08-24 05:47:05 +00005471 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora71d8192009-09-04 17:36:40 +00005472 NestedNameSpecifier *Qualifier
5473 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00005474 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005475 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00005476 if (E->getQualifier() && !Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005477 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005478
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005479 PseudoDestructorTypeStorage Destroyed;
5480 if (E->getDestroyedTypeInfo()) {
5481 TypeSourceInfo *DestroyedTypeInfo
5482 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5483 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005484 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005485 Destroyed = DestroyedTypeInfo;
5486 } else if (ObjectType->isDependentType()) {
5487 // We aren't likely to be able to resolve the identifier down to a type
5488 // now anyway, so just retain the identifier.
5489 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5490 E->getDestroyedTypeLoc());
5491 } else {
5492 // Look for a destructor known with the given name.
5493 CXXScopeSpec SS;
5494 if (Qualifier) {
5495 SS.setScopeRep(Qualifier);
5496 SS.setRange(E->getQualifierRange());
5497 }
Sean Huntc3021132010-05-05 15:23:54 +00005498
John McCallb3d87482010-08-24 05:47:05 +00005499 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005500 *E->getDestroyedTypeIdentifier(),
5501 E->getDestroyedTypeLoc(),
5502 /*Scope=*/0,
5503 SS, ObjectTypePtr,
5504 false);
5505 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005506 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005507
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005508 Destroyed
5509 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5510 E->getDestroyedTypeLoc());
5511 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005512
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005513 TypeSourceInfo *ScopeTypeInfo = 0;
5514 if (E->getScopeTypeInfo()) {
Sean Huntc3021132010-05-05 15:23:54 +00005515 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005516 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005517 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005518 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00005519 }
Sean Huntc3021132010-05-05 15:23:54 +00005520
John McCall9ae2f072010-08-23 23:25:46 +00005521 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005522 E->getOperatorLoc(),
5523 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005524 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005525 E->getQualifierRange(),
5526 ScopeTypeInfo,
5527 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005528 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005529 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005530}
Mike Stump1eb44332009-09-09 15:08:12 +00005531
Douglas Gregora71d8192009-09-04 17:36:40 +00005532template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005533ExprResult
John McCallba135432009-11-21 08:51:07 +00005534TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005535 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005536 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5537
5538 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5539 Sema::LookupOrdinaryName);
5540
5541 // Transform all the decls.
5542 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5543 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005544 NamedDecl *InstD = static_cast<NamedDecl*>(
5545 getDerived().TransformDecl(Old->getNameLoc(),
5546 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005547 if (!InstD) {
5548 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5549 // This can happen because of dependent hiding.
5550 if (isa<UsingShadowDecl>(*I))
5551 continue;
5552 else
John McCallf312b1e2010-08-26 23:41:50 +00005553 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005554 }
John McCallf7a1a742009-11-24 19:00:30 +00005555
5556 // Expand using declarations.
5557 if (isa<UsingDecl>(InstD)) {
5558 UsingDecl *UD = cast<UsingDecl>(InstD);
5559 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5560 E = UD->shadow_end(); I != E; ++I)
5561 R.addDecl(*I);
5562 continue;
5563 }
5564
5565 R.addDecl(InstD);
5566 }
5567
5568 // Resolve a kind, but don't do any further analysis. If it's
5569 // ambiguous, the callee needs to deal with it.
5570 R.resolveKind();
5571
5572 // Rebuild the nested-name qualifier, if present.
5573 CXXScopeSpec SS;
5574 NestedNameSpecifier *Qualifier = 0;
5575 if (Old->getQualifier()) {
5576 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005577 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005578 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005579 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005580
John McCallf7a1a742009-11-24 19:00:30 +00005581 SS.setScopeRep(Qualifier);
5582 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005583 }
5584
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005585 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005586 CXXRecordDecl *NamingClass
5587 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5588 Old->getNameLoc(),
5589 Old->getNamingClass()));
5590 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00005591 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005592
Douglas Gregor66c45152010-04-27 16:10:10 +00005593 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005594 }
5595
5596 // If we have no template arguments, it's a normal declaration name.
5597 if (!Old->hasExplicitTemplateArgs())
5598 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5599
5600 // If we have template arguments, rebuild them, then rebuild the
5601 // templateid expression.
5602 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5603 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5604 TemplateArgumentLoc Loc;
5605 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005606 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00005607 TransArgs.addArgument(Loc);
5608 }
5609
5610 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5611 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005612}
Mike Stump1eb44332009-09-09 15:08:12 +00005613
Douglas Gregorb98b1992009-08-11 05:31:07 +00005614template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005615ExprResult
John McCall454feb92009-12-08 09:21:05 +00005616TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005617 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5618 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005619 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005620
Douglas Gregorb98b1992009-08-11 05:31:07 +00005621 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005622 T == E->getQueriedTypeSourceInfo())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005623 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005624
Mike Stump1eb44332009-09-09 15:08:12 +00005625 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005626 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005627 T,
5628 E->getLocEnd());
5629}
Mike Stump1eb44332009-09-09 15:08:12 +00005630
Douglas Gregorb98b1992009-08-11 05:31:07 +00005631template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005632ExprResult
John McCall865d4472009-11-19 22:55:06 +00005633TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005634 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005635 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005636 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005637 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005638 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00005639 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005640
Abramo Bagnara25777432010-08-11 22:01:17 +00005641 DeclarationNameInfo NameInfo
5642 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5643 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005644 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005645
John McCallf7a1a742009-11-24 19:00:30 +00005646 if (!E->hasExplicitTemplateArgs()) {
5647 if (!getDerived().AlwaysRebuild() &&
5648 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005649 // Note: it is sufficient to compare the Name component of NameInfo:
5650 // if name has not changed, DNLoc has not changed either.
5651 NameInfo.getName() == E->getDeclName())
John McCallf7a1a742009-11-24 19:00:30 +00005652 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005653
John McCallf7a1a742009-11-24 19:00:30 +00005654 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5655 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005656 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005657 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005658 }
John McCalld5532b62009-11-23 01:53:49 +00005659
5660 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005661 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005662 TemplateArgumentLoc Loc;
5663 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005664 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005665 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005666 }
5667
John McCallf7a1a742009-11-24 19:00:30 +00005668 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5669 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005670 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005671 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005672}
5673
5674template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005675ExprResult
John McCall454feb92009-12-08 09:21:05 +00005676TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005677 // CXXConstructExprs are always implicit, so when we have a
5678 // 1-argument construction we just transform that argument.
5679 if (E->getNumArgs() == 1 ||
5680 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5681 return getDerived().TransformExpr(E->getArg(0));
5682
Douglas Gregorb98b1992009-08-11 05:31:07 +00005683 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5684
5685 QualType T = getDerived().TransformType(E->getType());
5686 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005687 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005688
5689 CXXConstructorDecl *Constructor
5690 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005691 getDerived().TransformDecl(E->getLocStart(),
5692 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005693 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005694 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005695
Douglas Gregorb98b1992009-08-11 05:31:07 +00005696 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005697 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005698 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005699 ArgEnd = E->arg_end();
5700 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005701 if (getDerived().DropCallArgument(*Arg)) {
5702 ArgumentChanged = true;
5703 break;
5704 }
5705
John McCall60d7b3a2010-08-24 06:29:42 +00005706 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005707 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005708 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005709
Douglas Gregorb98b1992009-08-11 05:31:07 +00005710 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005711 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005712 }
5713
5714 if (!getDerived().AlwaysRebuild() &&
5715 T == E->getType() &&
5716 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005717 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005718 // Mark the constructor as referenced.
5719 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005720 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005721 return SemaRef.Owned(E->Retain());
Douglas Gregorc845aad2010-02-26 00:01:57 +00005722 }
Mike Stump1eb44332009-09-09 15:08:12 +00005723
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005724 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5725 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00005726 move_arg(Args),
5727 E->requiresZeroInitialization(),
5728 E->getConstructionKind());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005729}
Mike Stump1eb44332009-09-09 15:08:12 +00005730
Douglas Gregorb98b1992009-08-11 05:31:07 +00005731/// \brief Transform a C++ temporary-binding expression.
5732///
Douglas Gregor51326552009-12-24 18:51:59 +00005733/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5734/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005735template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005736ExprResult
John McCall454feb92009-12-08 09:21:05 +00005737TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005738 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005739}
Mike Stump1eb44332009-09-09 15:08:12 +00005740
5741/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005742/// be destroyed after the expression is evaluated.
5743///
Douglas Gregor51326552009-12-24 18:51:59 +00005744/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5745/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005746template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005747ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005748TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005749 CXXExprWithTemporaries *E) {
5750 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005751}
Mike Stump1eb44332009-09-09 15:08:12 +00005752
Douglas Gregorb98b1992009-08-11 05:31:07 +00005753template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005754ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005755TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00005756 CXXTemporaryObjectExpr *E) {
5757 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5758 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005759 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005760
Douglas Gregorb98b1992009-08-11 05:31:07 +00005761 CXXConstructorDecl *Constructor
5762 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005763 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005764 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005765 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005766 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005767
Douglas Gregorb98b1992009-08-11 05:31:07 +00005768 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005769 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005770 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005771 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005772 ArgEnd = E->arg_end();
5773 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005774 if (getDerived().DropCallArgument(*Arg)) {
5775 ArgumentChanged = true;
5776 break;
5777 }
5778
John McCall60d7b3a2010-08-24 06:29:42 +00005779 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005780 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005781 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005782
Douglas Gregorb98b1992009-08-11 05:31:07 +00005783 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5784 Args.push_back((Expr *)TransArg.release());
5785 }
Mike Stump1eb44332009-09-09 15:08:12 +00005786
Douglas Gregorb98b1992009-08-11 05:31:07 +00005787 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005788 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005789 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005790 !ArgumentChanged) {
5791 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00005792 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Chandler Carrutha3ce8ae2010-03-31 18:34:58 +00005793 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor91be6f52010-03-02 17:18:33 +00005794 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00005795
5796 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5797 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005798 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005799 E->getLocEnd());
5800}
Mike Stump1eb44332009-09-09 15:08:12 +00005801
Douglas Gregorb98b1992009-08-11 05:31:07 +00005802template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005803ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005804TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005805 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00005806 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5807 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005808 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005809
Douglas Gregorb98b1992009-08-11 05:31:07 +00005810 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005811 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005812 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5813 ArgEnd = E->arg_end();
5814 Arg != ArgEnd; ++Arg) {
John McCall60d7b3a2010-08-24 06:29:42 +00005815 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005816 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005817 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005818
Douglas Gregorb98b1992009-08-11 05:31:07 +00005819 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005820 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005821 }
Mike Stump1eb44332009-09-09 15:08:12 +00005822
Douglas Gregorb98b1992009-08-11 05:31:07 +00005823 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005824 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005825 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005826 return SemaRef.Owned(E->Retain());
5827
Douglas Gregorb98b1992009-08-11 05:31:07 +00005828 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00005829 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005830 E->getLParenLoc(),
5831 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005832 E->getRParenLoc());
5833}
Mike Stump1eb44332009-09-09 15:08:12 +00005834
Douglas Gregorb98b1992009-08-11 05:31:07 +00005835template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005836ExprResult
John McCall865d4472009-11-19 22:55:06 +00005837TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005838 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005839 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005840 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005841 Expr *OldBase;
5842 QualType BaseType;
5843 QualType ObjectType;
5844 if (!E->isImplicitAccess()) {
5845 OldBase = E->getBase();
5846 Base = getDerived().TransformExpr(OldBase);
5847 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005848 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005849
John McCallaa81e162009-12-01 22:10:20 +00005850 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00005851 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00005852 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005853 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005854 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005855 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005856 ObjectTy,
5857 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005858 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005859 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005860
John McCallb3d87482010-08-24 05:47:05 +00005861 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00005862 BaseType = ((Expr*) Base.get())->getType();
5863 } else {
5864 OldBase = 0;
5865 BaseType = getDerived().TransformType(E->getBaseType());
5866 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5867 }
Mike Stump1eb44332009-09-09 15:08:12 +00005868
Douglas Gregor6cd21982009-10-20 05:58:46 +00005869 // Transform the first part of the nested-name-specifier that qualifies
5870 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005871 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005872 = getDerived().TransformFirstQualifierInScope(
5873 E->getFirstQualifierFoundInScope(),
5874 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005875
Douglas Gregora38c6872009-09-03 16:14:30 +00005876 NestedNameSpecifier *Qualifier = 0;
5877 if (E->getQualifier()) {
5878 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5879 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005880 ObjectType,
5881 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005882 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005883 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00005884 }
Mike Stump1eb44332009-09-09 15:08:12 +00005885
Abramo Bagnara25777432010-08-11 22:01:17 +00005886 DeclarationNameInfo NameInfo
5887 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5888 ObjectType);
5889 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005890 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005891
John McCallaa81e162009-12-01 22:10:20 +00005892 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005893 // This is a reference to a member without an explicitly-specified
5894 // template argument list. Optimize for this common case.
5895 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005896 Base.get() == OldBase &&
5897 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005898 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005899 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005900 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005901 return SemaRef.Owned(E->Retain());
5902
John McCall9ae2f072010-08-23 23:25:46 +00005903 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005904 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005905 E->isArrow(),
5906 E->getOperatorLoc(),
5907 Qualifier,
5908 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005909 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005910 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005911 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005912 }
5913
John McCalld5532b62009-11-23 01:53:49 +00005914 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005915 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005916 TemplateArgumentLoc Loc;
5917 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005918 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005919 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005920 }
Mike Stump1eb44332009-09-09 15:08:12 +00005921
John McCall9ae2f072010-08-23 23:25:46 +00005922 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005923 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005924 E->isArrow(),
5925 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005926 Qualifier,
5927 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005928 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005929 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005930 &TransArgs);
5931}
5932
5933template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005934ExprResult
John McCall454feb92009-12-08 09:21:05 +00005935TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005936 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005937 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005938 QualType BaseType;
5939 if (!Old->isImplicitAccess()) {
5940 Base = getDerived().TransformExpr(Old->getBase());
5941 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005942 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005943 BaseType = ((Expr*) Base.get())->getType();
5944 } else {
5945 BaseType = getDerived().TransformType(Old->getBaseType());
5946 }
John McCall129e2df2009-11-30 22:42:35 +00005947
5948 NestedNameSpecifier *Qualifier = 0;
5949 if (Old->getQualifier()) {
5950 Qualifier
5951 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005952 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005953 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00005954 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00005955 }
5956
Abramo Bagnara25777432010-08-11 22:01:17 +00005957 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00005958 Sema::LookupOrdinaryName);
5959
5960 // Transform all the decls.
5961 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5962 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005963 NamedDecl *InstD = static_cast<NamedDecl*>(
5964 getDerived().TransformDecl(Old->getMemberLoc(),
5965 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005966 if (!InstD) {
5967 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5968 // This can happen because of dependent hiding.
5969 if (isa<UsingShadowDecl>(*I))
5970 continue;
5971 else
John McCallf312b1e2010-08-26 23:41:50 +00005972 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005973 }
John McCall129e2df2009-11-30 22:42:35 +00005974
5975 // Expand using declarations.
5976 if (isa<UsingDecl>(InstD)) {
5977 UsingDecl *UD = cast<UsingDecl>(InstD);
5978 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5979 E = UD->shadow_end(); I != E; ++I)
5980 R.addDecl(*I);
5981 continue;
5982 }
5983
5984 R.addDecl(InstD);
5985 }
5986
5987 R.resolveKind();
5988
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005989 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00005990 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00005991 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005992 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00005993 Old->getMemberLoc(),
5994 Old->getNamingClass()));
5995 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00005996 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005997
Douglas Gregor66c45152010-04-27 16:10:10 +00005998 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005999 }
Sean Huntc3021132010-05-05 15:23:54 +00006000
John McCall129e2df2009-11-30 22:42:35 +00006001 TemplateArgumentListInfo TransArgs;
6002 if (Old->hasExplicitTemplateArgs()) {
6003 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6004 TransArgs.setRAngleLoc(Old->getRAngleLoc());
6005 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6006 TemplateArgumentLoc Loc;
6007 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6008 Loc))
John McCallf312b1e2010-08-26 23:41:50 +00006009 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006010 TransArgs.addArgument(Loc);
6011 }
6012 }
John McCallc2233c52010-01-15 08:34:02 +00006013
6014 // FIXME: to do this check properly, we will need to preserve the
6015 // first-qualifier-in-scope here, just in case we had a dependent
6016 // base (and therefore couldn't do the check) and a
6017 // nested-name-qualifier (and therefore could do the lookup).
6018 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006019
John McCall9ae2f072010-08-23 23:25:46 +00006020 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006021 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006022 Old->getOperatorLoc(),
6023 Old->isArrow(),
6024 Qualifier,
6025 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006026 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006027 R,
6028 (Old->hasExplicitTemplateArgs()
6029 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006030}
6031
6032template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006033ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006034TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6035 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6036 if (SubExpr.isInvalid())
6037 return ExprError();
6038
6039 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
6040 return SemaRef.Owned(E->Retain());
6041
6042 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6043}
6044
6045template<typename Derived>
6046ExprResult
John McCall454feb92009-12-08 09:21:05 +00006047TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006048 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006049}
6050
Mike Stump1eb44332009-09-09 15:08:12 +00006051template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006052ExprResult
John McCall454feb92009-12-08 09:21:05 +00006053TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006054 TypeSourceInfo *EncodedTypeInfo
6055 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6056 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006057 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006058
Douglas Gregorb98b1992009-08-11 05:31:07 +00006059 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006060 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00006061 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006062
6063 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006064 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006065 E->getRParenLoc());
6066}
Mike Stump1eb44332009-09-09 15:08:12 +00006067
Douglas Gregorb98b1992009-08-11 05:31:07 +00006068template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006069ExprResult
John McCall454feb92009-12-08 09:21:05 +00006070TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006071 // Transform arguments.
6072 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006073 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006074 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006075 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor92e986e2010-04-22 16:44:27 +00006076 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006077 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006078
Douglas Gregor92e986e2010-04-22 16:44:27 +00006079 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00006080 Args.push_back(Arg.get());
Douglas Gregor92e986e2010-04-22 16:44:27 +00006081 }
6082
6083 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6084 // Class message: transform the receiver type.
6085 TypeSourceInfo *ReceiverTypeInfo
6086 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6087 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006088 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006089
Douglas Gregor92e986e2010-04-22 16:44:27 +00006090 // If nothing changed, just retain the existing message send.
6091 if (!getDerived().AlwaysRebuild() &&
6092 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6093 return SemaRef.Owned(E->Retain());
6094
6095 // Build a new class message send.
6096 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6097 E->getSelector(),
6098 E->getMethodDecl(),
6099 E->getLeftLoc(),
6100 move_arg(Args),
6101 E->getRightLoc());
6102 }
6103
6104 // Instance message: transform the receiver
6105 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6106 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006107 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006108 = getDerived().TransformExpr(E->getInstanceReceiver());
6109 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006110 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006111
6112 // If nothing changed, just retain the existing message send.
6113 if (!getDerived().AlwaysRebuild() &&
6114 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6115 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006116
Douglas Gregor92e986e2010-04-22 16:44:27 +00006117 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006118 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006119 E->getSelector(),
6120 E->getMethodDecl(),
6121 E->getLeftLoc(),
6122 move_arg(Args),
6123 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006124}
6125
Mike Stump1eb44332009-09-09 15:08:12 +00006126template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006127ExprResult
John McCall454feb92009-12-08 09:21:05 +00006128TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006129 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006130}
6131
Mike Stump1eb44332009-09-09 15:08:12 +00006132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006133ExprResult
John McCall454feb92009-12-08 09:21:05 +00006134TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006135 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006136}
6137
Mike Stump1eb44332009-09-09 15:08:12 +00006138template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006139ExprResult
John McCall454feb92009-12-08 09:21:05 +00006140TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006141 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006142 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006143 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006144 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006145
6146 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006147
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006148 // If nothing changed, just retain the existing expression.
6149 if (!getDerived().AlwaysRebuild() &&
6150 Base.get() == E->getBase())
6151 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006152
John McCall9ae2f072010-08-23 23:25:46 +00006153 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006154 E->getLocation(),
6155 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006156}
6157
Mike Stump1eb44332009-09-09 15:08:12 +00006158template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006159ExprResult
John McCall454feb92009-12-08 09:21:05 +00006160TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006161 // 'super' never changes. Property never changes. Just retain the existing
6162 // expression.
6163 if (E->isSuperReceiver())
6164 return SemaRef.Owned(E->Retain());
6165
Douglas Gregore3303542010-04-26 20:47:02 +00006166 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006167 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00006168 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006169 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006170
Douglas Gregore3303542010-04-26 20:47:02 +00006171 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006172
Douglas Gregore3303542010-04-26 20:47:02 +00006173 // If nothing changed, just retain the existing expression.
6174 if (!getDerived().AlwaysRebuild() &&
6175 Base.get() == E->getBase())
6176 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006177
John McCall9ae2f072010-08-23 23:25:46 +00006178 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregore3303542010-04-26 20:47:02 +00006179 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006180}
6181
Mike Stump1eb44332009-09-09 15:08:12 +00006182template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006183ExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00006184TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00006185 ObjCImplicitSetterGetterRefExpr *E) {
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006186 // If this implicit setter/getter refers to super, it cannot have any
6187 // dependent parts. Just retain the existing declaration.
6188 if (E->isSuperReceiver())
6189 return SemaRef.Owned(E->Retain());
6190
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006191 // If this implicit setter/getter refers to class methods, it cannot have any
6192 // dependent parts. Just retain the existing declaration.
6193 if (E->getInterfaceDecl())
6194 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006195
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006196 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006197 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006198 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006199 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006200
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006201 // We don't need to transform the getters/setters; they will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006202
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006203 // If nothing changed, just retain the existing expression.
6204 if (!getDerived().AlwaysRebuild() &&
6205 Base.get() == E->getBase())
6206 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006207
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006208 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6209 E->getGetterMethod(),
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006210 E->getType(),
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006211 E->getSetterMethod(),
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006212 E->getLocation(),
6213 Base.get(),
6214 E->getSuperLocation(),
6215 E->getSuperType(),
6216 E->isSuperReceiver());
Sean Huntc3021132010-05-05 15:23:54 +00006217
Douglas Gregorb98b1992009-08-11 05:31:07 +00006218}
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>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006223 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006224 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006225 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006226 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006227
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006228 // If nothing changed, just retain the existing expression.
6229 if (!getDerived().AlwaysRebuild() &&
6230 Base.get() == E->getBase())
6231 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006232
John McCall9ae2f072010-08-23 23:25:46 +00006233 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006234 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006235}
6236
Mike Stump1eb44332009-09-09 15:08:12 +00006237template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006238ExprResult
John McCall454feb92009-12-08 09:21:05 +00006239TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006240 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006241 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006242 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006243 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006244 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006245 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006246
Douglas Gregorb98b1992009-08-11 05:31:07 +00006247 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00006248 SubExprs.push_back(SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006249 }
Mike Stump1eb44332009-09-09 15:08:12 +00006250
Douglas Gregorb98b1992009-08-11 05:31:07 +00006251 if (!getDerived().AlwaysRebuild() &&
6252 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00006253 return SemaRef.Owned(E->Retain());
6254
Douglas Gregorb98b1992009-08-11 05:31:07 +00006255 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6256 move_arg(SubExprs),
6257 E->getRParenLoc());
6258}
6259
Mike Stump1eb44332009-09-09 15:08:12 +00006260template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006261ExprResult
John McCall454feb92009-12-08 09:21:05 +00006262TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006263 SourceLocation CaretLoc(E->getExprLoc());
6264
6265 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6266 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6267 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6268 llvm::SmallVector<ParmVarDecl*, 4> Params;
6269 llvm::SmallVector<QualType, 4> ParamTypes;
6270
6271 // Parameter substitution.
6272 const BlockDecl *BD = E->getBlockDecl();
6273 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6274 EN = BD->param_end(); P != EN; ++P) {
6275 ParmVarDecl *OldParm = (*P);
6276 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6277 QualType NewType = NewParm->getType();
6278 Params.push_back(NewParm);
6279 ParamTypes.push_back(NewParm->getType());
6280 }
6281
6282 const FunctionType *BExprFunctionType = E->getFunctionType();
6283 QualType BExprResultType = BExprFunctionType->getResultType();
6284 if (!BExprResultType.isNull()) {
6285 if (!BExprResultType->isDependentType())
6286 CurBlock->ReturnType = BExprResultType;
6287 else if (BExprResultType != SemaRef.Context.DependentTy)
6288 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6289 }
6290
6291 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00006292 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006293 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006294 return ExprError();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006295 // Set the parameters on the block decl.
6296 if (!Params.empty())
6297 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6298
6299 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6300 CurBlock->ReturnType,
6301 ParamTypes.data(),
6302 ParamTypes.size(),
6303 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006304 0,
6305 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006306
6307 CurBlock->FunctionType = FunctionType;
John McCall9ae2f072010-08-23 23:25:46 +00006308 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006309}
6310
Mike Stump1eb44332009-09-09 15:08:12 +00006311template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006312ExprResult
John McCall454feb92009-12-08 09:21:05 +00006313TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006314 NestedNameSpecifier *Qualifier = 0;
6315
6316 ValueDecl *ND
6317 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6318 E->getDecl()));
6319 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006320 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00006321
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006322 if (!getDerived().AlwaysRebuild() &&
6323 ND == E->getDecl()) {
6324 // Mark it referenced in the new context regardless.
6325 // FIXME: this is a bit instantiation-specific.
6326 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6327
6328 return SemaRef.Owned(E->Retain());
6329 }
6330
Abramo Bagnara25777432010-08-11 22:01:17 +00006331 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006332 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006333 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006334}
Mike Stump1eb44332009-09-09 15:08:12 +00006335
Douglas Gregorb98b1992009-08-11 05:31:07 +00006336//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006337// Type reconstruction
6338//===----------------------------------------------------------------------===//
6339
Mike Stump1eb44332009-09-09 15:08:12 +00006340template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006341QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6342 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006343 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006344 getDerived().getBaseEntity());
6345}
6346
Mike Stump1eb44332009-09-09 15:08:12 +00006347template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006348QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6349 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006350 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006351 getDerived().getBaseEntity());
6352}
6353
Mike Stump1eb44332009-09-09 15:08:12 +00006354template<typename Derived>
6355QualType
John McCall85737a72009-10-30 00:06:24 +00006356TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6357 bool WrittenAsLValue,
6358 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006359 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006360 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006361}
6362
6363template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006364QualType
John McCall85737a72009-10-30 00:06:24 +00006365TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6366 QualType ClassType,
6367 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006368 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006369 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006370}
6371
6372template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006373QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006374TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6375 ArrayType::ArraySizeModifier SizeMod,
6376 const llvm::APInt *Size,
6377 Expr *SizeExpr,
6378 unsigned IndexTypeQuals,
6379 SourceRange BracketsRange) {
6380 if (SizeExpr || !Size)
6381 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6382 IndexTypeQuals, BracketsRange,
6383 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006384
6385 QualType Types[] = {
6386 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6387 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6388 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006389 };
6390 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6391 QualType SizeType;
6392 for (unsigned I = 0; I != NumTypes; ++I)
6393 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6394 SizeType = Types[I];
6395 break;
6396 }
Mike Stump1eb44332009-09-09 15:08:12 +00006397
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006398 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6399 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006400 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006401 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006402 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006403}
Mike Stump1eb44332009-09-09 15:08:12 +00006404
Douglas Gregor577f75a2009-08-04 16:50:30 +00006405template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006406QualType
6407TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006408 ArrayType::ArraySizeModifier SizeMod,
6409 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006410 unsigned IndexTypeQuals,
6411 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006412 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006413 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006414}
6415
6416template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006417QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006418TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006419 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006420 unsigned IndexTypeQuals,
6421 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006422 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006423 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006424}
Mike Stump1eb44332009-09-09 15:08:12 +00006425
Douglas Gregor577f75a2009-08-04 16:50:30 +00006426template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006427QualType
6428TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006429 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006430 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006431 unsigned IndexTypeQuals,
6432 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006433 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006434 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006435 IndexTypeQuals, BracketsRange);
6436}
6437
6438template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006439QualType
6440TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006441 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006442 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006443 unsigned IndexTypeQuals,
6444 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006445 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006446 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006447 IndexTypeQuals, BracketsRange);
6448}
6449
6450template<typename Derived>
6451QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner788b0fd2010-06-23 06:00:24 +00006452 unsigned NumElements,
6453 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006454 // FIXME: semantic checking!
Chris Lattner788b0fd2010-06-23 06:00:24 +00006455 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006456}
Mike Stump1eb44332009-09-09 15:08:12 +00006457
Douglas Gregor577f75a2009-08-04 16:50:30 +00006458template<typename Derived>
6459QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6460 unsigned NumElements,
6461 SourceLocation AttributeLoc) {
6462 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6463 NumElements, true);
6464 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006465 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6466 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00006467 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006468}
Mike Stump1eb44332009-09-09 15:08:12 +00006469
Douglas Gregor577f75a2009-08-04 16:50:30 +00006470template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006471QualType
6472TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00006473 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006474 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00006475 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006476}
Mike Stump1eb44332009-09-09 15:08:12 +00006477
Douglas Gregor577f75a2009-08-04 16:50:30 +00006478template<typename Derived>
6479QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006480 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006481 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006482 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00006483 unsigned Quals,
6484 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00006485 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006486 Quals,
6487 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006488 getDerived().getBaseEntity(),
6489 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006490}
Mike Stump1eb44332009-09-09 15:08:12 +00006491
Douglas Gregor577f75a2009-08-04 16:50:30 +00006492template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006493QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6494 return SemaRef.Context.getFunctionNoProtoType(T);
6495}
6496
6497template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006498QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6499 assert(D && "no decl found");
6500 if (D->isInvalidDecl()) return QualType();
6501
Douglas Gregor92e986e2010-04-22 16:44:27 +00006502 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006503 TypeDecl *Ty;
6504 if (isa<UsingDecl>(D)) {
6505 UsingDecl *Using = cast<UsingDecl>(D);
6506 assert(Using->isTypeName() &&
6507 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6508
6509 // A valid resolved using typename decl points to exactly one type decl.
6510 assert(++Using->shadow_begin() == Using->shadow_end());
6511 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006512
John McCalled976492009-12-04 22:46:56 +00006513 } else {
6514 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6515 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6516 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6517 }
6518
6519 return SemaRef.Context.getTypeDeclType(Ty);
6520}
6521
6522template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00006523QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6524 SourceLocation Loc) {
6525 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006526}
6527
6528template<typename Derived>
6529QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6530 return SemaRef.Context.getTypeOfType(Underlying);
6531}
6532
6533template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00006534QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6535 SourceLocation Loc) {
6536 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006537}
6538
6539template<typename Derived>
6540QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006541 TemplateName Template,
6542 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006543 const TemplateArgumentListInfo &TemplateArgs) {
6544 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006545}
Mike Stump1eb44332009-09-09 15:08:12 +00006546
Douglas Gregordcee1a12009-08-06 05:28:30 +00006547template<typename Derived>
6548NestedNameSpecifier *
6549TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6550 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006551 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006552 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006553 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006554 CXXScopeSpec SS;
6555 // FIXME: The source location information is all wrong.
6556 SS.setRange(Range);
6557 SS.setScopeRep(Prefix);
6558 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006559 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006560 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006561 ObjectType,
6562 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006563 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006564}
6565
6566template<typename Derived>
6567NestedNameSpecifier *
6568TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6569 SourceRange Range,
6570 NamespaceDecl *NS) {
6571 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6572}
6573
6574template<typename Derived>
6575NestedNameSpecifier *
6576TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6577 SourceRange Range,
6578 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006579 QualType T) {
6580 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006581 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006582 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006583 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6584 T.getTypePtr());
6585 }
Mike Stump1eb44332009-09-09 15:08:12 +00006586
Douglas Gregordcee1a12009-08-06 05:28:30 +00006587 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6588 return 0;
6589}
Mike Stump1eb44332009-09-09 15:08:12 +00006590
Douglas Gregord1067e52009-08-06 06:41:21 +00006591template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006592TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006593TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6594 bool TemplateKW,
6595 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006596 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006597 Template);
6598}
6599
6600template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006601TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006602TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006603 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006604 const IdentifierInfo &II,
6605 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006606 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006607 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00006608 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006609 UnqualifiedId Name;
6610 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00006611 Sema::TemplateTy Template;
6612 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6613 /*FIXME:*/getDerived().getBaseLocation(),
6614 SS,
6615 Name,
John McCallb3d87482010-08-24 05:47:05 +00006616 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006617 /*EnteringContext=*/false,
6618 Template);
6619 return Template.template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00006620}
Mike Stump1eb44332009-09-09 15:08:12 +00006621
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006623TemplateName
6624TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6625 OverloadedOperatorKind Operator,
6626 QualType ObjectType) {
6627 CXXScopeSpec SS;
6628 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6629 SS.setScopeRep(Qualifier);
6630 UnqualifiedId Name;
6631 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6632 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6633 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00006634 Sema::TemplateTy Template;
6635 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006636 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006637 SS,
6638 Name,
John McCallb3d87482010-08-24 05:47:05 +00006639 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006640 /*EnteringContext=*/false,
6641 Template);
6642 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006643}
Sean Huntc3021132010-05-05 15:23:54 +00006644
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006645template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006646ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6648 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006649 Expr *OrigCallee,
6650 Expr *First,
6651 Expr *Second) {
6652 Expr *Callee = OrigCallee->IgnoreParenCasts();
6653 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006654
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006656 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00006657 if (!First->getType()->isOverloadableType() &&
6658 !Second->getType()->isOverloadableType())
6659 return getSema().CreateBuiltinArraySubscriptExpr(First,
6660 Callee->getLocStart(),
6661 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006662 } else if (Op == OO_Arrow) {
6663 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00006664 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6665 } else if (Second == 0 || isPostIncDec) {
6666 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667 // The argument is not of overloadable type, so try to create a
6668 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00006669 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006671
John McCall9ae2f072010-08-23 23:25:46 +00006672 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006673 }
6674 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006675 if (!First->getType()->isOverloadableType() &&
6676 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677 // Neither of the arguments is an overloadable type, so try to
6678 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00006679 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006680 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00006681 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006682 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006683 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006684
Douglas Gregorb98b1992009-08-11 05:31:07 +00006685 return move(Result);
6686 }
6687 }
Mike Stump1eb44332009-09-09 15:08:12 +00006688
6689 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006691 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006692
John McCall9ae2f072010-08-23 23:25:46 +00006693 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00006694 assert(ULE->requiresADL());
6695
6696 // FIXME: Do we have to check
6697 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006698 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006699 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006700 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006701 }
Mike Stump1eb44332009-09-09 15:08:12 +00006702
Douglas Gregorb98b1992009-08-11 05:31:07 +00006703 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00006704 Expr *Args[2] = { First, Second };
6705 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006706
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 // Create the overloaded operator invocation for unary operators.
6708 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00006709 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00006711 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 }
Mike Stump1eb44332009-09-09 15:08:12 +00006713
Sebastian Redlf322ed62009-10-29 20:17:01 +00006714 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00006715 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00006716 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006717 First,
6718 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006719
Douglas Gregorb98b1992009-08-11 05:31:07 +00006720 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00006721 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006722 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6724 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006725 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006726
Mike Stump1eb44332009-09-09 15:08:12 +00006727 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728}
Mike Stump1eb44332009-09-09 15:08:12 +00006729
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006730template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006731ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00006732TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006733 SourceLocation OperatorLoc,
6734 bool isArrow,
6735 NestedNameSpecifier *Qualifier,
6736 SourceRange QualifierRange,
6737 TypeSourceInfo *ScopeType,
6738 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006739 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006740 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006741 CXXScopeSpec SS;
6742 if (Qualifier) {
6743 SS.setRange(QualifierRange);
6744 SS.setScopeRep(Qualifier);
6745 }
6746
John McCall9ae2f072010-08-23 23:25:46 +00006747 QualType BaseType = Base->getType();
6748 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006749 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006750 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006751 !BaseType->getAs<PointerType>()->getPointeeType()
6752 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006753 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00006754 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006755 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006756 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006757 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006758 /*FIXME?*/true);
6759 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006760
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006761 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00006762 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6763 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6764 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6765 NameInfo.setNamedTypeInfo(DestroyedType);
6766
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006767 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00006768
John McCall9ae2f072010-08-23 23:25:46 +00006769 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006770 OperatorLoc, isArrow,
6771 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00006772 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006773 /*TemplateArgs*/ 0);
6774}
6775
Douglas Gregor577f75a2009-08-04 16:50:30 +00006776} // end namespace clang
6777
6778#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H