blob: bae703daa30111d7b38a9333012e4d004d9ad25c [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.
John McCall43fed0d2010-11-12 08:19:04 +0000192 QualType TransformType(QualType T);
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.
John McCall43fed0d2010-11-12 08:19:04 +0000202 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000203
204 /// \brief Transform the given type-with-location into a new
205 /// type, collecting location information in the given builder
206 /// as necessary.
207 ///
John McCall43fed0d2010-11-12 08:19:04 +0000208 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000209
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000210 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000211 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000212 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000213 /// appropriate TransformXXXStmt function to transform a specific kind of
214 /// statement or the TransformExpr() function to transform an expression.
215 /// Subclasses may override this function to transform statements using some
216 /// other mechanism.
217 ///
218 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000219 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000220
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000221 /// \brief Transform the given expression.
222 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000223 /// By default, this routine transforms an expression by delegating to the
224 /// appropriate TransformXXXExpr function to build a new expression.
225 /// Subclasses may override this function to transform expressions using some
226 /// other mechanism.
227 ///
228 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000229 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000230
Douglas Gregor577f75a2009-08-04 16:50:30 +0000231 /// \brief Transform the given declaration, which is referenced from a type
232 /// or expression.
233 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000234 /// By default, acts as the identity function on declarations. Subclasses
235 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000236 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000237
238 /// \brief Transform the definition of the given declaration.
239 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000240 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000241 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000242 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
243 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000244 }
Mike Stump1eb44332009-09-09 15:08:12 +0000245
Douglas Gregor6cd21982009-10-20 05:58:46 +0000246 /// \brief Transform the given declaration, which was the first part of a
247 /// nested-name-specifier in a member access expression.
248 ///
Sean Huntc3021132010-05-05 15:23:54 +0000249 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000250 /// identifier in a nested-name-specifier of a member access expression, e.g.,
251 /// the \c T in \c x->T::member
252 ///
253 /// By default, invokes TransformDecl() to transform the declaration.
254 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000255 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
256 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000257 }
Sean Huntc3021132010-05-05 15:23:54 +0000258
Douglas Gregor577f75a2009-08-04 16:50:30 +0000259 /// \brief Transform the given nested-name-specifier.
260 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000261 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000262 /// nested-name-specifier. Subclasses may override this function to provide
263 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000264 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000265 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000266 QualType ObjectType = QualType(),
267 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000268
Douglas Gregor81499bb2009-09-03 22:13:48 +0000269 /// \brief Transform the given declaration name.
270 ///
271 /// By default, transforms the types of conversion function, constructor,
272 /// and destructor names and then (if needed) rebuilds the declaration name.
273 /// Identifiers and selectors are returned unmodified. Sublcasses may
274 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000275 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000276 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000277
Douglas Gregor577f75a2009-08-04 16:50:30 +0000278 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000279 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000280 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000281 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000282 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000283 TemplateName TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +0000284 QualType ObjectType = QualType(),
285 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000286
Douglas Gregor577f75a2009-08-04 16:50:30 +0000287 /// \brief Transform the given template argument.
288 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000289 /// By default, this operation transforms the type, expression, or
290 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000291 /// new template argument from the transformed result. Subclasses may
292 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000293 ///
294 /// Returns true if there was an error.
295 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
296 TemplateArgumentLoc &Output);
297
298 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
299 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
300 TemplateArgumentLoc &ArgLoc);
301
John McCalla93c9342009-12-07 02:54:59 +0000302 /// \brief Fakes up a TypeSourceInfo for a type.
303 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
304 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000305 getDerived().getBaseLocation());
306 }
Mike Stump1eb44332009-09-09 15:08:12 +0000307
John McCalla2becad2009-10-21 00:40:46 +0000308#define ABSTRACT_TYPELOC(CLASS, PARENT)
309#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000310 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000311#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000312
John McCall43fed0d2010-11-12 08:19:04 +0000313 QualType
314 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
315 TemplateSpecializationTypeLoc TL,
316 TemplateName Template);
317
318 QualType
319 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
320 DependentTemplateSpecializationTypeLoc TL,
321 NestedNameSpecifier *Prefix);
322
John McCall21ef0fa2010-03-11 09:03:00 +0000323 /// \brief Transforms the parameters of a function type into the
324 /// given vectors.
325 ///
326 /// The result vectors should be kept in sync; null entries in the
327 /// variables vector are acceptable.
328 ///
329 /// Return true on error.
330 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
331 llvm::SmallVectorImpl<QualType> &PTypes,
332 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
333
334 /// \brief Transforms a single function-type parameter. Return null
335 /// on error.
336 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
337
John McCall43fed0d2010-11-12 08:19:04 +0000338 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000339
John McCall60d7b3a2010-08-24 06:29:42 +0000340 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
341 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000342
Douglas Gregor43959a92009-08-20 07:17:43 +0000343#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000344 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000345#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000346 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000347#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000348#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000349
Douglas Gregor577f75a2009-08-04 16:50:30 +0000350 /// \brief Build a new pointer type given its pointee type.
351 ///
352 /// By default, performs semantic analysis when building the pointer type.
353 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000354 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000355
356 /// \brief Build a new block pointer type given its pointee type.
357 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000358 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000359 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000360 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000361
John McCall85737a72009-10-30 00:06:24 +0000362 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000363 ///
John McCall85737a72009-10-30 00:06:24 +0000364 /// By default, performs semantic analysis when building the
365 /// reference type. Subclasses may override this routine to provide
366 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000367 ///
John McCall85737a72009-10-30 00:06:24 +0000368 /// \param LValue whether the type was written with an lvalue sigil
369 /// or an rvalue sigil.
370 QualType RebuildReferenceType(QualType ReferentType,
371 bool LValue,
372 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000373
Douglas Gregor577f75a2009-08-04 16:50:30 +0000374 /// \brief Build a new member pointer type given the pointee type and the
375 /// class type it refers into.
376 ///
377 /// By default, performs semantic analysis when building the member pointer
378 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000379 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
380 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000381
Douglas Gregor577f75a2009-08-04 16:50:30 +0000382 /// \brief Build a new array type given the element type, size
383 /// modifier, size of the array (if known), size expression, and index type
384 /// qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000388 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000389 QualType RebuildArrayType(QualType ElementType,
390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt *Size,
392 Expr *SizeExpr,
393 unsigned IndexTypeQuals,
394 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000395
Douglas Gregor577f75a2009-08-04 16:50:30 +0000396 /// \brief Build a new constant array type given the element type, size
397 /// modifier, (known) size of the array, and index type qualifiers.
398 ///
399 /// By default, performs semantic analysis when building the array type.
400 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000401 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
403 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000404 unsigned IndexTypeQuals,
405 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000406
Douglas Gregor577f75a2009-08-04 16:50:30 +0000407 /// \brief Build a new incomplete array type given the element type, size
408 /// modifier, and index type qualifiers.
409 ///
410 /// By default, performs semantic analysis when building the array type.
411 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000412 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000413 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000416
Mike Stump1eb44332009-09-09 15:08:12 +0000417 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000418 /// size modifier, size expression, and index type qualifiers.
419 ///
420 /// By default, performs semantic analysis when building the array type.
421 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000422 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000424 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
Mike Stump1eb44332009-09-09 15:08:12 +0000428 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000429 /// size modifier, size expression, and index type qualifiers.
430 ///
431 /// By default, performs semantic analysis when building the array type.
432 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000433 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000434 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000435 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000436 unsigned IndexTypeQuals,
437 SourceRange BracketsRange);
438
439 /// \brief Build a new vector type given the element type and
440 /// number of elements.
441 ///
442 /// By default, performs semantic analysis when building the vector type.
443 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000444 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000445 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000446
Douglas Gregor577f75a2009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000461 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000463
Douglas Gregor577f75a2009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000471 bool Variadic, unsigned Quals,
472 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000473
John McCalla2becad2009-10-21 00:40:46 +0000474 /// \brief Build a new unprototyped function type.
475 QualType RebuildFunctionNoProtoType(QualType ResultType);
476
John McCalled976492009-12-04 22:46:56 +0000477 /// \brief Rebuild an unresolved typename type, given the decl that
478 /// the UnresolvedUsingTypenameDecl was transformed to.
479 QualType RebuildUnresolvedUsingType(Decl *D);
480
Douglas Gregor577f75a2009-08-04 16:50:30 +0000481 /// \brief Build a new typedef type.
482 QualType RebuildTypedefType(TypedefDecl *Typedef) {
483 return SemaRef.Context.getTypeDeclType(Typedef);
484 }
485
486 /// \brief Build a new class/struct/union type.
487 QualType RebuildRecordType(RecordDecl *Record) {
488 return SemaRef.Context.getTypeDeclType(Record);
489 }
490
491 /// \brief Build a new Enum type.
492 QualType RebuildEnumType(EnumDecl *Enum) {
493 return SemaRef.Context.getTypeDeclType(Enum);
494 }
John McCall7da24312009-09-05 00:15:47 +0000495
Mike Stump1eb44332009-09-09 15:08:12 +0000496 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000497 ///
498 /// By default, performs semantic analysis when building the typeof type.
499 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000500 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000501
Mike Stump1eb44332009-09-09 15:08:12 +0000502 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000503 ///
504 /// By default, builds a new TypeOfType with the given underlying type.
505 QualType RebuildTypeOfType(QualType Underlying);
506
Mike Stump1eb44332009-09-09 15:08:12 +0000507 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000508 ///
509 /// By default, performs semantic analysis when building the decltype type.
510 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000511 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000512
Douglas Gregor577f75a2009-08-04 16:50:30 +0000513 /// \brief Build a new template specialization type.
514 ///
515 /// By default, performs semantic analysis when building the template
516 /// specialization type. Subclasses may override this routine to provide
517 /// different behavior.
518 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000519 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000520 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000521
Douglas Gregor577f75a2009-08-04 16:50:30 +0000522 /// \brief Build a new qualified name type.
523 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000524 /// By default, builds a new ElaboratedType type from the keyword,
525 /// the nested-name-specifier and the named type.
526 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000527 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
528 ElaboratedTypeKeyword Keyword,
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000529 NestedNameSpecifier *NNS, QualType Named) {
530 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000531 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000532
533 /// \brief Build a new typename type that refers to a template-id.
534 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000535 /// By default, builds a new DependentNameType type from the
536 /// nested-name-specifier and the given type. Subclasses may override
537 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000538 QualType RebuildDependentTemplateSpecializationType(
539 ElaboratedTypeKeyword Keyword,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000540 NestedNameSpecifier *Qualifier,
541 SourceRange QualifierRange,
John McCall33500952010-06-11 00:33:02 +0000542 const IdentifierInfo *Name,
543 SourceLocation NameLoc,
544 const TemplateArgumentListInfo &Args) {
545 // Rebuild the template name.
546 // TODO: avoid TemplateName abstraction
547 TemplateName InstName =
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000548 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall43fed0d2010-11-12 08:19:04 +0000549 QualType(), 0);
John McCall33500952010-06-11 00:33:02 +0000550
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000551 if (InstName.isNull())
552 return QualType();
553
John McCall33500952010-06-11 00:33:02 +0000554 // If it's still dependent, make a dependent specialization.
555 if (InstName.getAsDependentTemplateName())
556 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000557 Keyword, Qualifier, Name, Args);
John McCall33500952010-06-11 00:33:02 +0000558
559 // Otherwise, make an elaborated type wrapping a non-dependent
560 // specialization.
561 QualType T =
562 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
563 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000564
Abramo Bagnara22f638a2010-08-10 13:46:45 +0000565 // NOTE: NNS is already recorded in template specialization type T.
566 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000567 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000568
569 /// \brief Build a new typename type that refers to an identifier.
570 ///
571 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000572 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000573 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000574 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000575 NestedNameSpecifier *NNS,
576 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000577 SourceLocation KeywordLoc,
578 SourceRange NNSRange,
579 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000580 CXXScopeSpec SS;
581 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000582 SS.setRange(NNSRange);
583
Douglas Gregor40336422010-03-31 22:19:08 +0000584 if (NNS->isDependent()) {
585 // If the name is still dependent, just build a new dependent name type.
586 if (!SemaRef.computeDeclContext(SS))
587 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
588 }
589
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000590 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000591 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
592 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000593
594 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
595
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000596 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000597 // into a non-dependent elaborated-type-specifier. Find the tag we're
598 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000599 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000600 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
601 if (!DC)
602 return QualType();
603
John McCall56138762010-05-27 06:40:31 +0000604 if (SemaRef.RequireCompleteDeclContext(SS, DC))
605 return QualType();
606
Douglas Gregor40336422010-03-31 22:19:08 +0000607 TagDecl *Tag = 0;
608 SemaRef.LookupQualifiedName(Result, DC);
609 switch (Result.getResultKind()) {
610 case LookupResult::NotFound:
611 case LookupResult::NotFoundInCurrentInstantiation:
612 break;
Sean Huntc3021132010-05-05 15:23:54 +0000613
Douglas Gregor40336422010-03-31 22:19:08 +0000614 case LookupResult::Found:
615 Tag = Result.getAsSingle<TagDecl>();
616 break;
Sean Huntc3021132010-05-05 15:23:54 +0000617
Douglas Gregor40336422010-03-31 22:19:08 +0000618 case LookupResult::FoundOverloaded:
619 case LookupResult::FoundUnresolvedValue:
620 llvm_unreachable("Tag lookup cannot find non-tags");
621 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000622
Douglas Gregor40336422010-03-31 22:19:08 +0000623 case LookupResult::Ambiguous:
624 // Let the LookupResult structure handle ambiguities.
625 return QualType();
626 }
627
628 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000629 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000630 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000631 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000632 return QualType();
633 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000634
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000635 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
636 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000637 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
638 return QualType();
639 }
640
641 // Build the elaborated-type-specifier type.
642 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000643 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000644 }
Mike Stump1eb44332009-09-09 15:08:12 +0000645
Douglas Gregordcee1a12009-08-06 05:28:30 +0000646 /// \brief Build a new nested-name-specifier given the prefix and an
647 /// identifier that names the next step in the nested-name-specifier.
648 ///
649 /// By default, performs semantic analysis when building the new
650 /// nested-name-specifier. Subclasses may override this routine to provide
651 /// different behavior.
652 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
653 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000654 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000655 QualType ObjectType,
656 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000657
658 /// \brief Build a new nested-name-specifier given the prefix and the
659 /// namespace named in the next step in the nested-name-specifier.
660 ///
661 /// By default, performs semantic analysis when building the new
662 /// nested-name-specifier. Subclasses may override this routine to provide
663 /// different behavior.
664 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
665 SourceRange Range,
666 NamespaceDecl *NS);
667
668 /// \brief Build a new nested-name-specifier given the prefix and the
669 /// type named in the next step in the nested-name-specifier.
670 ///
671 /// By default, performs semantic analysis when building the new
672 /// nested-name-specifier. Subclasses may override this routine to provide
673 /// different behavior.
674 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
675 SourceRange Range,
676 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000677 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000678
679 /// \brief Build a new template name given a nested name specifier, a flag
680 /// indicating whether the "template" keyword was provided, and the template
681 /// that the template name refers to.
682 ///
683 /// By default, builds the new template name directly. Subclasses may override
684 /// this routine to provide different behavior.
685 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
686 bool TemplateKW,
687 TemplateDecl *Template);
688
Douglas Gregord1067e52009-08-06 06:41:21 +0000689 /// \brief Build a new template name given a nested name specifier and the
690 /// name that is referred to as a template.
691 ///
692 /// By default, performs semantic analysis to determine whether the name can
693 /// be resolved to a specific template, then builds the appropriate kind of
694 /// template name. Subclasses may override this routine to provide different
695 /// behavior.
696 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000697 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000698 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +0000699 QualType ObjectType,
700 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000701
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000702 /// \brief Build a new template name given a nested name specifier and the
703 /// overloaded operator name that is referred to as a template.
704 ///
705 /// By default, performs semantic analysis to determine whether the name can
706 /// be resolved to a specific template, then builds the appropriate kind of
707 /// template name. Subclasses may override this routine to provide different
708 /// behavior.
709 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
710 OverloadedOperatorKind Operator,
711 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000712
Douglas Gregor43959a92009-08-20 07:17:43 +0000713 /// \brief Build a new compound statement.
714 ///
715 /// By default, performs semantic analysis to build the new statement.
716 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000717 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000718 MultiStmtArg Statements,
719 SourceLocation RBraceLoc,
720 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000721 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000722 IsStmtExpr);
723 }
724
725 /// \brief Build a new case statement.
726 ///
727 /// By default, performs semantic analysis to build the new statement.
728 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000729 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000730 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000731 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000732 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000733 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000734 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000735 ColonLoc);
736 }
Mike Stump1eb44332009-09-09 15:08:12 +0000737
Douglas Gregor43959a92009-08-20 07:17:43 +0000738 /// \brief Attach the body to a new case statement.
739 ///
740 /// By default, performs semantic analysis to build the new statement.
741 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000742 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000743 getSema().ActOnCaseStmtBody(S, Body);
744 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000745 }
Mike Stump1eb44332009-09-09 15:08:12 +0000746
Douglas Gregor43959a92009-08-20 07:17:43 +0000747 /// \brief Build a new default statement.
748 ///
749 /// By default, performs semantic analysis to build the new statement.
750 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000751 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000752 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000753 Stmt *SubStmt) {
754 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000755 /*CurScope=*/0);
756 }
Mike Stump1eb44332009-09-09 15:08:12 +0000757
Douglas Gregor43959a92009-08-20 07:17:43 +0000758 /// \brief Build a new label statement.
759 ///
760 /// By default, performs semantic analysis to build the new statement.
761 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000762 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000763 IdentifierInfo *Id,
764 SourceLocation ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +0000765 Stmt *SubStmt, bool HasUnusedAttr) {
766 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
767 HasUnusedAttr);
Douglas Gregor43959a92009-08-20 07:17:43 +0000768 }
Mike Stump1eb44332009-09-09 15:08:12 +0000769
Douglas Gregor43959a92009-08-20 07:17:43 +0000770 /// \brief Build a new "if" statement.
771 ///
772 /// By default, performs semantic analysis to build the new statement.
773 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000774 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCall9ae2f072010-08-23 23:25:46 +0000775 VarDecl *CondVar, Stmt *Then,
776 SourceLocation ElseLoc, Stmt *Else) {
777 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000778 }
Mike Stump1eb44332009-09-09 15:08:12 +0000779
Douglas Gregor43959a92009-08-20 07:17:43 +0000780 /// \brief Start building a new switch statement.
781 ///
782 /// By default, performs semantic analysis to build the new statement.
783 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000784 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000785 Expr *Cond, VarDecl *CondVar) {
786 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +0000787 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +0000788 }
Mike Stump1eb44332009-09-09 15:08:12 +0000789
Douglas Gregor43959a92009-08-20 07:17:43 +0000790 /// \brief Attach the body to the switch statement.
791 ///
792 /// By default, performs semantic analysis to build the new statement.
793 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000794 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000795 Stmt *Switch, Stmt *Body) {
796 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000797 }
798
799 /// \brief Build a new while statement.
800 ///
801 /// By default, performs semantic analysis to build the new statement.
802 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000803 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000804 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000805 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000806 Stmt *Body) {
807 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000808 }
Mike Stump1eb44332009-09-09 15:08:12 +0000809
Douglas Gregor43959a92009-08-20 07:17:43 +0000810 /// \brief Build a new do-while statement.
811 ///
812 /// By default, performs semantic analysis to build the new statement.
813 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000814 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregor43959a92009-08-20 07:17:43 +0000815 SourceLocation WhileLoc,
816 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000817 Expr *Cond,
Douglas Gregor43959a92009-08-20 07:17:43 +0000818 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000819 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
820 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +0000821 }
822
823 /// \brief Build a new for statement.
824 ///
825 /// By default, performs semantic analysis to build the new statement.
826 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000827 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000828 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000829 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000830 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCall9ae2f072010-08-23 23:25:46 +0000831 SourceLocation RParenLoc, Stmt *Body) {
832 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCalld226f652010-08-21 09:40:31 +0000833 CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000834 Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000835 }
Mike Stump1eb44332009-09-09 15:08:12 +0000836
Douglas Gregor43959a92009-08-20 07:17:43 +0000837 /// \brief Build a new goto statement.
838 ///
839 /// By default, performs semantic analysis to build the new statement.
840 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000841 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000842 SourceLocation LabelLoc,
843 LabelStmt *Label) {
844 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
845 }
846
847 /// \brief Build a new indirect goto statement.
848 ///
849 /// By default, performs semantic analysis to build the new statement.
850 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000851 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000852 SourceLocation StarLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000853 Expr *Target) {
854 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +0000855 }
Mike Stump1eb44332009-09-09 15:08:12 +0000856
Douglas Gregor43959a92009-08-20 07:17:43 +0000857 /// \brief Build a new return statement.
858 ///
859 /// By default, performs semantic analysis to build the new statement.
860 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000861 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000862 Expr *Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000863
John McCall9ae2f072010-08-23 23:25:46 +0000864 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +0000865 }
Mike Stump1eb44332009-09-09 15:08:12 +0000866
Douglas Gregor43959a92009-08-20 07:17:43 +0000867 /// \brief Build a new declaration statement.
868 ///
869 /// By default, performs semantic analysis to build the new statement.
870 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000871 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000872 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000873 SourceLocation EndLoc) {
874 return getSema().Owned(
875 new (getSema().Context) DeclStmt(
876 DeclGroupRef::Create(getSema().Context,
877 Decls, NumDecls),
878 StartLoc, EndLoc));
879 }
Mike Stump1eb44332009-09-09 15:08:12 +0000880
Anders Carlsson703e3942010-01-24 05:50:09 +0000881 /// \brief Build a new inline asm statement.
882 ///
883 /// By default, performs semantic analysis to build the new statement.
884 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000885 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +0000886 bool IsSimple,
887 bool IsVolatile,
888 unsigned NumOutputs,
889 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000890 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000891 MultiExprArg Constraints,
892 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +0000893 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +0000894 MultiExprArg Clobbers,
895 SourceLocation RParenLoc,
896 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000897 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000898 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +0000899 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +0000900 RParenLoc, MSAsm);
901 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000902
903 /// \brief Build a new Objective-C @try statement.
904 ///
905 /// By default, performs semantic analysis to build the new statement.
906 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000907 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000908 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000909 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +0000910 Stmt *Finally) {
911 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
912 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000913 }
914
Douglas Gregorbe270a02010-04-26 17:57:08 +0000915 /// \brief Rebuild an Objective-C exception declaration.
916 ///
917 /// By default, performs semantic analysis to build the new declaration.
918 /// Subclasses may override this routine to provide different behavior.
919 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
920 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +0000921 return getSema().BuildObjCExceptionDecl(TInfo, T,
922 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +0000923 ExceptionDecl->getLocation());
924 }
Sean Huntc3021132010-05-05 15:23:54 +0000925
Douglas Gregorbe270a02010-04-26 17:57:08 +0000926 /// \brief Build a new Objective-C @catch statement.
927 ///
928 /// By default, performs semantic analysis to build the new statement.
929 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000930 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +0000931 SourceLocation RParenLoc,
932 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +0000933 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +0000934 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000935 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +0000936 }
Sean Huntc3021132010-05-05 15:23:54 +0000937
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000938 /// \brief Build a new Objective-C @finally statement.
939 ///
940 /// By default, performs semantic analysis to build the new statement.
941 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000942 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000943 Stmt *Body) {
944 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000945 }
Sean Huntc3021132010-05-05 15:23:54 +0000946
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000947 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +0000948 ///
949 /// By default, performs semantic analysis to build the new statement.
950 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000951 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000952 Expr *Operand) {
953 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +0000954 }
Sean Huntc3021132010-05-05 15:23:54 +0000955
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000956 /// \brief Build a new Objective-C @synchronized statement.
957 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000958 /// By default, performs semantic analysis to build the new statement.
959 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000960 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000961 Expr *Object,
962 Stmt *Body) {
963 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
964 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000965 }
Douglas Gregorc3203e72010-04-22 23:10:45 +0000966
967 /// \brief Build a new Objective-C fast enumeration statement.
968 ///
969 /// By default, performs semantic analysis to build the new statement.
970 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000971 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +0000972 SourceLocation LParenLoc,
973 Stmt *Element,
974 Expr *Collection,
975 SourceLocation RParenLoc,
976 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +0000977 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000978 Element,
979 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +0000980 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000981 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +0000982 }
Sean Huntc3021132010-05-05 15:23:54 +0000983
Douglas Gregor43959a92009-08-20 07:17:43 +0000984 /// \brief Build a new C++ exception declaration.
985 ///
986 /// By default, performs semantic analysis to build the new decaration.
987 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor83cb9422010-09-09 17:09:21 +0000988 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +0000989 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000990 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +0000991 SourceLocation Loc) {
992 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-08-20 07:17:43 +0000993 }
994
995 /// \brief Build a new C++ catch statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000999 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001000 VarDecl *ExceptionDecl,
1001 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001002 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1003 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001004 }
Mike Stump1eb44332009-09-09 15:08:12 +00001005
Douglas Gregor43959a92009-08-20 07:17:43 +00001006 /// \brief Build a new C++ try statement.
1007 ///
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001010 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001011 Stmt *TryBlock,
1012 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001013 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001014 }
Mike Stump1eb44332009-09-09 15:08:12 +00001015
Douglas Gregorb98b1992009-08-11 05:31:07 +00001016 /// \brief Build a new expression that references a declaration.
1017 ///
1018 /// By default, performs semantic analysis to build the new expression.
1019 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001020 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001021 LookupResult &R,
1022 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001023 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1024 }
1025
1026
1027 /// \brief Build a new expression that references a declaration.
1028 ///
1029 /// By default, performs semantic analysis to build the new expression.
1030 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001031 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001032 SourceRange QualifierRange,
1033 ValueDecl *VD,
1034 const DeclarationNameInfo &NameInfo,
1035 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001036 CXXScopeSpec SS;
1037 SS.setScopeRep(Qualifier);
1038 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001039
1040 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001041
1042 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001043 }
Mike Stump1eb44332009-09-09 15:08:12 +00001044
Douglas Gregorb98b1992009-08-11 05:31:07 +00001045 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001046 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001047 /// By default, performs semantic analysis to build the new expression.
1048 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001049 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001050 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001051 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001052 }
1053
Douglas Gregora71d8192009-09-04 17:36:40 +00001054 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001055 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001056 /// By default, performs semantic analysis to build the new expression.
1057 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001058 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001059 SourceLocation OperatorLoc,
1060 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001061 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001062 SourceRange QualifierRange,
1063 TypeSourceInfo *ScopeType,
1064 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001065 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001066 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001067
Douglas Gregorb98b1992009-08-11 05:31:07 +00001068 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001069 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001070 /// By default, performs semantic analysis to build the new expression.
1071 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001072 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001073 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001074 Expr *SubExpr) {
1075 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001076 }
Mike Stump1eb44332009-09-09 15:08:12 +00001077
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001078 /// \brief Build a new builtin offsetof expression.
1079 ///
1080 /// By default, performs semantic analysis to build the new expression.
1081 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001082 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001083 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001084 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001085 unsigned NumComponents,
1086 SourceLocation RParenLoc) {
1087 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1088 NumComponents, RParenLoc);
1089 }
Sean Huntc3021132010-05-05 15:23:54 +00001090
Douglas Gregorb98b1992009-08-11 05:31:07 +00001091 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001092 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001093 /// By default, performs semantic analysis to build the new expression.
1094 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001095 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001096 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001097 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001098 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001099 }
1100
Mike Stump1eb44332009-09-09 15:08:12 +00001101 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001102 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001103 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001104 /// By default, performs semantic analysis to build the new expression.
1105 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001106 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001107 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001108 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001109 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001110 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001111 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001112
Douglas Gregorb98b1992009-08-11 05:31:07 +00001113 return move(Result);
1114 }
Mike Stump1eb44332009-09-09 15:08:12 +00001115
Douglas Gregorb98b1992009-08-11 05:31:07 +00001116 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001117 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001118 /// By default, performs semantic analysis to build the new expression.
1119 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001120 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001121 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001122 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001123 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001124 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1125 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001126 RBracketLoc);
1127 }
1128
1129 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001130 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001131 /// By default, performs semantic analysis to build the new expression.
1132 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001133 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001134 MultiExprArg Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001135 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001136 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora1a04782010-09-09 16:33:13 +00001137 move(Args), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001138 }
1139
1140 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001141 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001142 /// By default, performs semantic analysis to build the new expression.
1143 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001144 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001145 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001146 NestedNameSpecifier *Qualifier,
1147 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001148 const DeclarationNameInfo &MemberNameInfo,
Eli Friedmanf595cc42009-12-04 06:40:45 +00001149 ValueDecl *Member,
John McCall6bb80172010-03-30 21:47:33 +00001150 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001151 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +00001152 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001153 if (!Member->getDeclName()) {
1154 // We have a reference to an unnamed field.
1155 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +00001156
John McCall9ae2f072010-08-23 23:25:46 +00001157 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001158 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001159 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001160
Mike Stump1eb44332009-09-09 15:08:12 +00001161 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001162 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001163 Member, MemberNameInfo,
Anders Carlssond8b285f2009-09-01 04:26:58 +00001164 cast<FieldDecl>(Member)->getType());
1165 return getSema().Owned(ME);
1166 }
Mike Stump1eb44332009-09-09 15:08:12 +00001167
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001168 CXXScopeSpec SS;
1169 if (Qualifier) {
1170 SS.setRange(QualifierRange);
1171 SS.setScopeRep(Qualifier);
1172 }
1173
John McCall9ae2f072010-08-23 23:25:46 +00001174 getSema().DefaultFunctionArrayConversion(Base);
1175 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001176
John McCall6bb80172010-03-30 21:47:33 +00001177 // FIXME: this involves duplicating earlier analysis in a lot of
1178 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001179 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001180 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001181 R.resolveKind();
1182
John McCall9ae2f072010-08-23 23:25:46 +00001183 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001184 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001185 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001186 }
Mike Stump1eb44332009-09-09 15:08:12 +00001187
Douglas Gregorb98b1992009-08-11 05:31:07 +00001188 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001189 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001190 /// By default, performs semantic analysis to build the new expression.
1191 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001192 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001193 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001194 Expr *LHS, Expr *RHS) {
1195 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001196 }
1197
1198 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001199 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001200 /// By default, performs semantic analysis to build the new expression.
1201 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001202 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001203 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001204 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001205 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001206 Expr *RHS) {
1207 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1208 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001209 }
1210
Douglas Gregorb98b1992009-08-11 05:31:07 +00001211 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001212 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001213 /// By default, performs semantic analysis to build the new expression.
1214 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001215 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001216 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001217 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001218 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001219 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001220 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001221 }
Mike Stump1eb44332009-09-09 15:08:12 +00001222
Douglas Gregorb98b1992009-08-11 05:31:07 +00001223 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001224 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001225 /// By default, performs semantic analysis to build the new expression.
1226 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001227 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001228 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001229 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001230 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001231 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001232 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001233 }
Mike Stump1eb44332009-09-09 15:08:12 +00001234
Douglas Gregorb98b1992009-08-11 05:31:07 +00001235 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001236 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001237 /// By default, performs semantic analysis to build the new expression.
1238 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001239 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001240 SourceLocation OpLoc,
1241 SourceLocation AccessorLoc,
1242 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001243
John McCall129e2df2009-11-30 22:42:35 +00001244 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001245 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001246 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001247 OpLoc, /*IsArrow*/ false,
1248 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001249 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001250 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001251 }
Mike Stump1eb44332009-09-09 15:08:12 +00001252
Douglas Gregorb98b1992009-08-11 05:31:07 +00001253 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001254 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001255 /// By default, performs semantic analysis to build the new expression.
1256 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001257 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001258 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001259 SourceLocation RBraceLoc,
1260 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001261 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001262 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1263 if (Result.isInvalid() || ResultTy->isDependentType())
1264 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001265
Douglas Gregore48319a2009-11-09 17:16:50 +00001266 // Patch in the result type we were given, which may have been computed
1267 // when the initial InitListExpr was built.
1268 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1269 ILE->setType(ResultTy);
1270 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001271 }
Mike Stump1eb44332009-09-09 15:08:12 +00001272
Douglas Gregorb98b1992009-08-11 05:31:07 +00001273 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001274 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001275 /// By default, performs semantic analysis to build the new expression.
1276 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001277 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001278 MultiExprArg ArrayExprs,
1279 SourceLocation EqualOrColonLoc,
1280 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001281 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001282 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001283 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001284 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001285 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001286 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001287
Douglas Gregorb98b1992009-08-11 05:31:07 +00001288 ArrayExprs.release();
1289 return move(Result);
1290 }
Mike Stump1eb44332009-09-09 15:08:12 +00001291
Douglas Gregorb98b1992009-08-11 05:31:07 +00001292 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001293 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001294 /// By default, builds the implicit value initialization without performing
1295 /// any semantic analysis. Subclasses may override this routine to provide
1296 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001297 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001298 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1299 }
Mike Stump1eb44332009-09-09 15:08:12 +00001300
Douglas Gregorb98b1992009-08-11 05:31:07 +00001301 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001302 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001303 /// By default, performs semantic analysis to build the new expression.
1304 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001305 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001306 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001307 SourceLocation RParenLoc) {
1308 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001309 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001310 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001311 }
1312
1313 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001314 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001315 /// By default, performs semantic analysis to build the new expression.
1316 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001317 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001318 MultiExprArg SubExprs,
1319 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001320 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001321 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001322 }
Mike Stump1eb44332009-09-09 15:08:12 +00001323
Douglas Gregorb98b1992009-08-11 05:31:07 +00001324 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001325 ///
1326 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001327 /// rather than attempting to map the label statement itself.
1328 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001329 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001330 SourceLocation LabelLoc,
1331 LabelStmt *Label) {
1332 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1333 }
Mike Stump1eb44332009-09-09 15:08:12 +00001334
Douglas Gregorb98b1992009-08-11 05:31:07 +00001335 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001336 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001337 /// By default, performs semantic analysis to build the new expression.
1338 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001339 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001340 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001341 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001342 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001343 }
Mike Stump1eb44332009-09-09 15:08:12 +00001344
Douglas Gregorb98b1992009-08-11 05:31:07 +00001345 /// \brief Build a new __builtin_types_compatible_p expression.
1346 ///
1347 /// By default, performs semantic analysis to build the new expression.
1348 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001349 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001350 TypeSourceInfo *TInfo1,
1351 TypeSourceInfo *TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001352 SourceLocation RParenLoc) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001353 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1354 TInfo1, TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001355 RParenLoc);
1356 }
Mike Stump1eb44332009-09-09 15:08:12 +00001357
Douglas Gregorb98b1992009-08-11 05:31:07 +00001358 /// \brief Build a new __builtin_choose_expr expression.
1359 ///
1360 /// By default, performs semantic analysis to build the new expression.
1361 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001362 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001363 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001364 SourceLocation RParenLoc) {
1365 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001366 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001367 RParenLoc);
1368 }
Mike Stump1eb44332009-09-09 15:08:12 +00001369
Douglas Gregorb98b1992009-08-11 05:31:07 +00001370 /// \brief Build a new overloaded operator call expression.
1371 ///
1372 /// By default, performs semantic analysis to build the new expression.
1373 /// The semantic analysis provides the behavior of template instantiation,
1374 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001375 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001376 /// argument-dependent lookup, etc. Subclasses may override this routine to
1377 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001378 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001379 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001380 Expr *Callee,
1381 Expr *First,
1382 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001383
1384 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001385 /// reinterpret_cast.
1386 ///
1387 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001388 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001389 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001390 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001391 Stmt::StmtClass Class,
1392 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001393 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001394 SourceLocation RAngleLoc,
1395 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001396 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001397 SourceLocation RParenLoc) {
1398 switch (Class) {
1399 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001400 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001401 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001402 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001403
1404 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001405 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001406 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001407 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001408
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001410 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001411 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001412 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001413 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001414
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001416 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001417 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001418 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001419
Douglas Gregorb98b1992009-08-11 05:31:07 +00001420 default:
1421 assert(false && "Invalid C++ named cast");
1422 break;
1423 }
Mike Stump1eb44332009-09-09 15:08:12 +00001424
John McCallf312b1e2010-08-26 23:41:50 +00001425 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001426 }
Mike Stump1eb44332009-09-09 15:08:12 +00001427
Douglas Gregorb98b1992009-08-11 05:31:07 +00001428 /// \brief Build a new C++ static_cast expression.
1429 ///
1430 /// By default, performs semantic analysis to build the new expression.
1431 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001432 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001433 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001434 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001435 SourceLocation RAngleLoc,
1436 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001437 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001438 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001439 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001440 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001441 SourceRange(LAngleLoc, RAngleLoc),
1442 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001443 }
1444
1445 /// \brief Build a new C++ dynamic_cast expression.
1446 ///
1447 /// By default, performs semantic analysis to build the new expression.
1448 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001449 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001451 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001452 SourceLocation RAngleLoc,
1453 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001454 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001455 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001456 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001457 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001458 SourceRange(LAngleLoc, RAngleLoc),
1459 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001460 }
1461
1462 /// \brief Build a new C++ reinterpret_cast expression.
1463 ///
1464 /// By default, performs semantic analysis to build the new expression.
1465 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001466 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001468 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001469 SourceLocation RAngleLoc,
1470 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001471 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001472 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001473 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001474 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001475 SourceRange(LAngleLoc, RAngleLoc),
1476 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 }
1478
1479 /// \brief Build a new C++ const_cast expression.
1480 ///
1481 /// By default, performs semantic analysis to build the new expression.
1482 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001483 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001485 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001486 SourceLocation RAngleLoc,
1487 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001488 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001490 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001491 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001492 SourceRange(LAngleLoc, RAngleLoc),
1493 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 }
Mike Stump1eb44332009-09-09 15:08:12 +00001495
Douglas Gregorb98b1992009-08-11 05:31:07 +00001496 /// \brief Build a new C++ functional-style cast expression.
1497 ///
1498 /// By default, performs semantic analysis to build the new expression.
1499 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001500 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1501 SourceLocation LParenLoc,
1502 Expr *Sub,
1503 SourceLocation RParenLoc) {
1504 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001505 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 RParenLoc);
1507 }
Mike Stump1eb44332009-09-09 15:08:12 +00001508
Douglas Gregorb98b1992009-08-11 05:31:07 +00001509 /// \brief Build a new C++ typeid(type) expression.
1510 ///
1511 /// By default, performs semantic analysis to build the new expression.
1512 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001513 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001514 SourceLocation TypeidLoc,
1515 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001517 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001518 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001519 }
Mike Stump1eb44332009-09-09 15:08:12 +00001520
Francois Pichet01b7c302010-09-08 12:20:18 +00001521
Douglas Gregorb98b1992009-08-11 05:31:07 +00001522 /// \brief Build a new C++ typeid(expr) expression.
1523 ///
1524 /// By default, performs semantic analysis to build the new expression.
1525 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001526 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001527 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001528 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001529 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001530 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001531 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001532 }
1533
Francois Pichet01b7c302010-09-08 12:20:18 +00001534 /// \brief Build a new C++ __uuidof(type) expression.
1535 ///
1536 /// By default, performs semantic analysis to build the new expression.
1537 /// Subclasses may override this routine to provide different behavior.
1538 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1539 SourceLocation TypeidLoc,
1540 TypeSourceInfo *Operand,
1541 SourceLocation RParenLoc) {
1542 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1543 RParenLoc);
1544 }
1545
1546 /// \brief Build a new C++ __uuidof(expr) expression.
1547 ///
1548 /// By default, performs semantic analysis to build the new expression.
1549 /// Subclasses may override this routine to provide different behavior.
1550 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1551 SourceLocation TypeidLoc,
1552 Expr *Operand,
1553 SourceLocation RParenLoc) {
1554 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1555 RParenLoc);
1556 }
1557
Douglas Gregorb98b1992009-08-11 05:31:07 +00001558 /// \brief Build a new C++ "this" expression.
1559 ///
1560 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001561 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001562 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001563 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001564 QualType ThisType,
1565 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001566 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001567 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1568 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 }
1570
1571 /// \brief Build a new C++ throw expression.
1572 ///
1573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001575 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001576 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 }
1578
1579 /// \brief Build a new C++ default-argument expression.
1580 ///
1581 /// By default, builds a new default-argument expression, which does not
1582 /// require any semantic analysis. Subclasses may override this routine to
1583 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001584 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001585 ParmVarDecl *Param) {
1586 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1587 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001588 }
1589
1590 /// \brief Build a new C++ zero-initialization expression.
1591 ///
1592 /// By default, performs semantic analysis to build the new expression.
1593 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001594 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1595 SourceLocation LParenLoc,
1596 SourceLocation RParenLoc) {
1597 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001598 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001599 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 }
Mike Stump1eb44332009-09-09 15:08:12 +00001601
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 /// \brief Build a new C++ "new" expression.
1603 ///
1604 /// By default, performs semantic analysis to build the new expression.
1605 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001606 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001607 bool UseGlobal,
1608 SourceLocation PlacementLParen,
1609 MultiExprArg PlacementArgs,
1610 SourceLocation PlacementRParen,
1611 SourceRange TypeIdParens,
1612 QualType AllocatedType,
1613 TypeSourceInfo *AllocatedTypeInfo,
1614 Expr *ArraySize,
1615 SourceLocation ConstructorLParen,
1616 MultiExprArg ConstructorArgs,
1617 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001618 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001619 PlacementLParen,
1620 move(PlacementArgs),
1621 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001622 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001623 AllocatedType,
1624 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001625 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001626 ConstructorLParen,
1627 move(ConstructorArgs),
1628 ConstructorRParen);
1629 }
Mike Stump1eb44332009-09-09 15:08:12 +00001630
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 /// \brief Build a new C++ "delete" expression.
1632 ///
1633 /// By default, performs semantic analysis to build the new expression.
1634 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001635 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 bool IsGlobalDelete,
1637 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001638 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001640 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 }
Mike Stump1eb44332009-09-09 15:08:12 +00001642
Douglas Gregorb98b1992009-08-11 05:31:07 +00001643 /// \brief Build a new unary type trait expression.
1644 ///
1645 /// By default, performs semantic analysis to build the new expression.
1646 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001647 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001648 SourceLocation StartLoc,
1649 TypeSourceInfo *T,
1650 SourceLocation RParenLoc) {
1651 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 }
1653
Mike Stump1eb44332009-09-09 15:08:12 +00001654 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 /// expression.
1656 ///
1657 /// By default, performs semantic analysis to build the new expression.
1658 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001659 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001661 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001662 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 CXXScopeSpec SS;
1664 SS.setRange(QualifierRange);
1665 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001666
1667 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001668 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001669 *TemplateArgs);
1670
Abramo Bagnara25777432010-08-11 22:01:17 +00001671 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 }
1673
1674 /// \brief Build a new template-id expression.
1675 ///
1676 /// By default, performs semantic analysis to build the new expression.
1677 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001678 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001679 LookupResult &R,
1680 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001681 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001682 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 }
1684
1685 /// \brief Build a new object-construction expression.
1686 ///
1687 /// By default, performs semantic analysis to build the new expression.
1688 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001689 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001690 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 CXXConstructorDecl *Constructor,
1692 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001693 MultiExprArg Args,
1694 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00001695 CXXConstructExpr::ConstructionKind ConstructKind,
1696 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00001697 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001698 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001699 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001700 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001701
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001702 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001703 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00001704 RequiresZeroInit, ConstructKind,
1705 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 }
1707
1708 /// \brief Build a new object-construction expression.
1709 ///
1710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001712 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1713 SourceLocation LParenLoc,
1714 MultiExprArg Args,
1715 SourceLocation RParenLoc) {
1716 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 LParenLoc,
1718 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719 RParenLoc);
1720 }
1721
1722 /// \brief Build a new object-construction expression.
1723 ///
1724 /// By default, performs semantic analysis to build the new expression.
1725 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001726 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1727 SourceLocation LParenLoc,
1728 MultiExprArg Args,
1729 SourceLocation RParenLoc) {
1730 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001731 LParenLoc,
1732 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001733 RParenLoc);
1734 }
Mike Stump1eb44332009-09-09 15:08:12 +00001735
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 /// \brief Build a new member reference expression.
1737 ///
1738 /// By default, performs semantic analysis to build the new expression.
1739 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001740 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001741 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 bool IsArrow,
1743 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001744 NestedNameSpecifier *Qualifier,
1745 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001746 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001747 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001748 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001750 SS.setRange(QualifierRange);
1751 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001752
John McCall9ae2f072010-08-23 23:25:46 +00001753 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001754 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001755 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001756 MemberNameInfo,
1757 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001758 }
1759
John McCall129e2df2009-11-30 22:42:35 +00001760 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001761 ///
1762 /// By default, performs semantic analysis to build the new expression.
1763 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001764 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001765 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001766 SourceLocation OperatorLoc,
1767 bool IsArrow,
1768 NestedNameSpecifier *Qualifier,
1769 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001770 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001771 LookupResult &R,
1772 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001773 CXXScopeSpec SS;
1774 SS.setRange(QualifierRange);
1775 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001776
John McCall9ae2f072010-08-23 23:25:46 +00001777 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001778 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001779 SS, FirstQualifierInScope,
1780 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001781 }
Mike Stump1eb44332009-09-09 15:08:12 +00001782
Sebastian Redl2e156222010-09-10 20:55:43 +00001783 /// \brief Build a new noexcept expression.
1784 ///
1785 /// By default, performs semantic analysis to build the new expression.
1786 /// Subclasses may override this routine to provide different behavior.
1787 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1788 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1789 }
1790
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 /// \brief Build a new Objective-C @encode expression.
1792 ///
1793 /// By default, performs semantic analysis to build the new expression.
1794 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001795 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001796 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001798 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001800 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801
Douglas Gregor92e986e2010-04-22 16:44:27 +00001802 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00001803 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001804 Selector Sel,
1805 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001806 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001807 MultiExprArg Args,
1808 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001809 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1810 ReceiverTypeInfo->getType(),
1811 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001812 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001813 move(Args));
1814 }
1815
1816 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00001817 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001818 Selector Sel,
1819 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001820 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001821 MultiExprArg Args,
1822 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001823 return SemaRef.BuildInstanceMessage(Receiver,
1824 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00001825 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001826 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001827 move(Args));
1828 }
1829
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001830 /// \brief Build a new Objective-C ivar reference expression.
1831 ///
1832 /// By default, performs semantic analysis to build the new expression.
1833 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001834 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001835 SourceLocation IvarLoc,
1836 bool IsArrow, bool IsFreeIvar) {
1837 // FIXME: We lose track of the IsFreeIvar bit.
1838 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001839 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001840 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1841 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001842 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001843 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00001844 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00001845 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001846 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001847 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001848
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001849 if (Result.get())
1850 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001851
John McCall9ae2f072010-08-23 23:25:46 +00001852 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001853 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001854 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001855 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001856 /*TemplateArgs=*/0);
1857 }
Douglas Gregore3303542010-04-26 20:47:02 +00001858
1859 /// \brief Build a new Objective-C property reference expression.
1860 ///
1861 /// By default, performs semantic analysis to build the new expression.
1862 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001863 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001864 ObjCPropertyDecl *Property,
1865 SourceLocation PropertyLoc) {
1866 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001867 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00001868 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1869 Sema::LookupMemberName);
1870 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00001871 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00001872 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00001873 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00001874 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001875 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001876
Douglas Gregore3303542010-04-26 20:47:02 +00001877 if (Result.get())
1878 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001879
John McCall9ae2f072010-08-23 23:25:46 +00001880 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001881 /*FIXME:*/PropertyLoc, IsArrow,
1882 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001883 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001884 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001885 /*TemplateArgs=*/0);
1886 }
Sean Huntc3021132010-05-05 15:23:54 +00001887
1888 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001889 /// expression.
1890 ///
1891 /// By default, performs semantic analysis to build the new expression.
Sean Huntc3021132010-05-05 15:23:54 +00001892 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001893 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001894 ObjCMethodDecl *Getter,
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001895 QualType T,
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001896 ObjCMethodDecl *Setter,
1897 SourceLocation NameLoc,
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001898 Expr *Base,
1899 SourceLocation SuperLoc,
1900 QualType SuperTy,
1901 bool Super) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001902 // Since these expressions can only be value-dependent, we do not need to
1903 // perform semantic analysis again.
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00001904 if (Super)
1905 return Owned(
1906 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1907 Setter,
1908 NameLoc,
1909 SuperLoc,
1910 SuperTy));
1911 else
1912 return Owned(
1913 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(
1914 Getter, T,
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001915 Setter,
1916 NameLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001917 Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001918 }
1919
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001920 /// \brief Build a new Objective-C "isa" expression.
1921 ///
1922 /// By default, performs semantic analysis to build the new expression.
1923 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001924 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001925 bool IsArrow) {
1926 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001927 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001928 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1929 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001930 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001931 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00001932 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001933 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001934 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001935
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001936 if (Result.get())
1937 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001938
John McCall9ae2f072010-08-23 23:25:46 +00001939 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001940 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001941 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001942 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001943 /*TemplateArgs=*/0);
1944 }
Sean Huntc3021132010-05-05 15:23:54 +00001945
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946 /// \brief Build a new shuffle vector expression.
1947 ///
1948 /// By default, performs semantic analysis to build the new expression.
1949 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001950 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001951 MultiExprArg SubExprs,
1952 SourceLocation RParenLoc) {
1953 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001954 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001955 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1956 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1957 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1958 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001959
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 // Build a reference to the __builtin_shufflevector builtin
1961 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001962 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001964 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001965 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001966
1967 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001968 unsigned NumSubExprs = SubExprs.size();
1969 Expr **Subs = (Expr **)SubExprs.release();
1970 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1971 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00001972 Builtin->getCallResultType(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00001974 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001975
Douglas Gregorb98b1992009-08-11 05:31:07 +00001976 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00001977 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001978 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001979 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001980
Douglas Gregorb98b1992009-08-11 05:31:07 +00001981 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001982 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001983 }
John McCall43fed0d2010-11-12 08:19:04 +00001984
1985private:
1986 QualType TransformTypeInObjectScope(QualType T,
1987 QualType ObjectType,
1988 NamedDecl *FirstQualifierInScope,
1989 NestedNameSpecifier *Prefix);
1990
1991 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
1992 QualType ObjectType,
1993 NamedDecl *FirstQualifierInScope,
1994 NestedNameSpecifier *Prefix);
Douglas Gregor577f75a2009-08-04 16:50:30 +00001995};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001996
Douglas Gregor43959a92009-08-20 07:17:43 +00001997template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00001998StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00001999 if (!S)
2000 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002001
Douglas Gregor43959a92009-08-20 07:17:43 +00002002 switch (S->getStmtClass()) {
2003 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002004
Douglas Gregor43959a92009-08-20 07:17:43 +00002005 // Transform individual statement nodes
2006#define STMT(Node, Parent) \
2007 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2008#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002009#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002010
Douglas Gregor43959a92009-08-20 07:17:43 +00002011 // Transform expressions by calling TransformExpr.
2012#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002013#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002014#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002015#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002016 {
John McCall60d7b3a2010-08-24 06:29:42 +00002017 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002018 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002019 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002020
John McCall9ae2f072010-08-23 23:25:46 +00002021 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002022 }
Mike Stump1eb44332009-09-09 15:08:12 +00002023 }
2024
John McCall3fa5cae2010-10-26 07:05:15 +00002025 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002026}
Mike Stump1eb44332009-09-09 15:08:12 +00002027
2028
Douglas Gregor670444e2009-08-04 22:27:00 +00002029template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002030ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002031 if (!E)
2032 return SemaRef.Owned(E);
2033
2034 switch (E->getStmtClass()) {
2035 case Stmt::NoStmtClass: break;
2036#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002037#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002038#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002039 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002040#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002041 }
2042
John McCall3fa5cae2010-10-26 07:05:15 +00002043 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002044}
2045
2046template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002047NestedNameSpecifier *
2048TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002049 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002050 QualType ObjectType,
2051 NamedDecl *FirstQualifierInScope) {
John McCall43fed0d2010-11-12 08:19:04 +00002052 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump1eb44332009-09-09 15:08:12 +00002053
Douglas Gregor43959a92009-08-20 07:17:43 +00002054 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002055 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002056 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002057 ObjectType,
2058 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002059 if (!Prefix)
2060 return 0;
2061 }
Mike Stump1eb44332009-09-09 15:08:12 +00002062
Douglas Gregordcee1a12009-08-06 05:28:30 +00002063 switch (NNS->getKind()) {
2064 case NestedNameSpecifier::Identifier:
John McCall43fed0d2010-11-12 08:19:04 +00002065 if (Prefix) {
2066 // The object type and qualifier-in-scope really apply to the
2067 // leftmost entity.
2068 ObjectType = QualType();
2069 FirstQualifierInScope = 0;
2070 }
2071
Mike Stump1eb44332009-09-09 15:08:12 +00002072 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002073 "Identifier nested-name-specifier with no prefix or object type");
2074 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2075 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002076 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002077
2078 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002079 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002080 ObjectType,
2081 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002082
Douglas Gregordcee1a12009-08-06 05:28:30 +00002083 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002084 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002085 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002086 getDerived().TransformDecl(Range.getBegin(),
2087 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002088 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002089 Prefix == NNS->getPrefix() &&
2090 NS == NNS->getAsNamespace())
2091 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002092
Douglas Gregordcee1a12009-08-06 05:28:30 +00002093 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2094 }
Mike Stump1eb44332009-09-09 15:08:12 +00002095
Douglas Gregordcee1a12009-08-06 05:28:30 +00002096 case NestedNameSpecifier::Global:
2097 // There is no meaningful transformation that one could perform on the
2098 // global scope.
2099 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002100
Douglas Gregordcee1a12009-08-06 05:28:30 +00002101 case NestedNameSpecifier::TypeSpecWithTemplate:
2102 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002103 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall43fed0d2010-11-12 08:19:04 +00002104 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2105 ObjectType,
2106 FirstQualifierInScope,
2107 Prefix);
Douglas Gregord1067e52009-08-06 06:41:21 +00002108 if (T.isNull())
2109 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002110
Douglas Gregordcee1a12009-08-06 05:28:30 +00002111 if (!getDerived().AlwaysRebuild() &&
2112 Prefix == NNS->getPrefix() &&
2113 T == QualType(NNS->getAsType(), 0))
2114 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002115
2116 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2117 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002118 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002119 }
2120 }
Mike Stump1eb44332009-09-09 15:08:12 +00002121
Douglas Gregordcee1a12009-08-06 05:28:30 +00002122 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002123 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002124}
2125
2126template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002127DeclarationNameInfo
2128TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002129::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002130 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002131 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002132 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002133
2134 switch (Name.getNameKind()) {
2135 case DeclarationName::Identifier:
2136 case DeclarationName::ObjCZeroArgSelector:
2137 case DeclarationName::ObjCOneArgSelector:
2138 case DeclarationName::ObjCMultiArgSelector:
2139 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002140 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002141 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002142 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002143
Douglas Gregor81499bb2009-09-03 22:13:48 +00002144 case DeclarationName::CXXConstructorName:
2145 case DeclarationName::CXXDestructorName:
2146 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002147 TypeSourceInfo *NewTInfo;
2148 CanQualType NewCanTy;
2149 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002150 NewTInfo = getDerived().TransformType(OldTInfo);
2151 if (!NewTInfo)
2152 return DeclarationNameInfo();
2153 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002154 }
2155 else {
2156 NewTInfo = 0;
2157 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002158 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002159 if (NewT.isNull())
2160 return DeclarationNameInfo();
2161 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2162 }
Mike Stump1eb44332009-09-09 15:08:12 +00002163
Abramo Bagnara25777432010-08-11 22:01:17 +00002164 DeclarationName NewName
2165 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2166 NewCanTy);
2167 DeclarationNameInfo NewNameInfo(NameInfo);
2168 NewNameInfo.setName(NewName);
2169 NewNameInfo.setNamedTypeInfo(NewTInfo);
2170 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002171 }
Mike Stump1eb44332009-09-09 15:08:12 +00002172 }
2173
Abramo Bagnara25777432010-08-11 22:01:17 +00002174 assert(0 && "Unknown name kind.");
2175 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002176}
2177
2178template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002179TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002180TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +00002181 QualType ObjectType,
2182 NamedDecl *FirstQualifierInScope) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002183 SourceLocation Loc = getDerived().getBaseLocation();
2184
Douglas Gregord1067e52009-08-06 06:41:21 +00002185 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002186 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002187 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002188 /*FIXME*/ SourceRange(Loc),
2189 ObjectType,
2190 FirstQualifierInScope);
Douglas Gregord1067e52009-08-06 06:41:21 +00002191 if (!NNS)
2192 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002193
Douglas Gregord1067e52009-08-06 06:41:21 +00002194 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002195 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002196 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002197 if (!TransTemplate)
2198 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002199
Douglas Gregord1067e52009-08-06 06:41:21 +00002200 if (!getDerived().AlwaysRebuild() &&
2201 NNS == QTN->getQualifier() &&
2202 TransTemplate == Template)
2203 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002204
Douglas Gregord1067e52009-08-06 06:41:21 +00002205 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2206 TransTemplate);
2207 }
Mike Stump1eb44332009-09-09 15:08:12 +00002208
John McCallf7a1a742009-11-24 19:00:30 +00002209 // These should be getting filtered out before they make it into the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002210 llvm_unreachable("overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002211 }
Mike Stump1eb44332009-09-09 15:08:12 +00002212
Douglas Gregord1067e52009-08-06 06:41:21 +00002213 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall43fed0d2010-11-12 08:19:04 +00002214 NestedNameSpecifier *NNS = DTN->getQualifier();
2215 if (NNS) {
2216 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2217 /*FIXME:*/SourceRange(Loc),
2218 ObjectType,
2219 FirstQualifierInScope);
2220 if (!NNS) return TemplateName();
2221
2222 // These apply to the scope specifier, not the template.
2223 ObjectType = QualType();
2224 FirstQualifierInScope = 0;
2225 }
Mike Stump1eb44332009-09-09 15:08:12 +00002226
Douglas Gregord1067e52009-08-06 06:41:21 +00002227 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002228 NNS == DTN->getQualifier() &&
2229 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002230 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002231
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002232 if (DTN->isIdentifier()) {
2233 // FIXME: Bad range
2234 SourceRange QualifierRange(getDerived().getBaseLocation());
2235 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2236 *DTN->getIdentifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002237 ObjectType,
2238 FirstQualifierInScope);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002239 }
Sean Huntc3021132010-05-05 15:23:54 +00002240
2241 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002242 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002243 }
Mike Stump1eb44332009-09-09 15:08:12 +00002244
Douglas Gregord1067e52009-08-06 06:41:21 +00002245 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002246 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002247 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002248 if (!TransTemplate)
2249 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002250
Douglas Gregord1067e52009-08-06 06:41:21 +00002251 if (!getDerived().AlwaysRebuild() &&
2252 TransTemplate == Template)
2253 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002254
Douglas Gregord1067e52009-08-06 06:41:21 +00002255 return TemplateName(TransTemplate);
2256 }
Mike Stump1eb44332009-09-09 15:08:12 +00002257
John McCallf7a1a742009-11-24 19:00:30 +00002258 // These should be getting filtered out before they reach the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002259 llvm_unreachable("overloaded function decl survived to here");
John McCallf7a1a742009-11-24 19:00:30 +00002260 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002261}
2262
2263template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002264void TreeTransform<Derived>::InventTemplateArgumentLoc(
2265 const TemplateArgument &Arg,
2266 TemplateArgumentLoc &Output) {
2267 SourceLocation Loc = getDerived().getBaseLocation();
2268 switch (Arg.getKind()) {
2269 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002270 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002271 break;
2272
2273 case TemplateArgument::Type:
2274 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002275 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002276
John McCall833ca992009-10-29 08:12:44 +00002277 break;
2278
Douglas Gregor788cd062009-11-11 01:00:40 +00002279 case TemplateArgument::Template:
2280 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2281 break;
Sean Huntc3021132010-05-05 15:23:54 +00002282
John McCall833ca992009-10-29 08:12:44 +00002283 case TemplateArgument::Expression:
2284 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2285 break;
2286
2287 case TemplateArgument::Declaration:
2288 case TemplateArgument::Integral:
2289 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002290 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002291 break;
2292 }
2293}
2294
2295template<typename Derived>
2296bool TreeTransform<Derived>::TransformTemplateArgument(
2297 const TemplateArgumentLoc &Input,
2298 TemplateArgumentLoc &Output) {
2299 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002300 switch (Arg.getKind()) {
2301 case TemplateArgument::Null:
2302 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002303 Output = Input;
2304 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002305
Douglas Gregor670444e2009-08-04 22:27:00 +00002306 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002307 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002308 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002309 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002310
2311 DI = getDerived().TransformType(DI);
2312 if (!DI) return true;
2313
2314 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2315 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002316 }
Mike Stump1eb44332009-09-09 15:08:12 +00002317
Douglas Gregor670444e2009-08-04 22:27:00 +00002318 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002319 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002320 DeclarationName Name;
2321 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2322 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002323 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002324 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002325 if (!D) return true;
2326
John McCall828bff22009-10-29 18:45:58 +00002327 Expr *SourceExpr = Input.getSourceDeclExpression();
2328 if (SourceExpr) {
2329 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002330 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002331 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002332 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002333 }
2334
2335 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002336 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002337 }
Mike Stump1eb44332009-09-09 15:08:12 +00002338
Douglas Gregor788cd062009-11-11 01:00:40 +00002339 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002340 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002341 TemplateName Template
2342 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2343 if (Template.isNull())
2344 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002345
Douglas Gregor788cd062009-11-11 01:00:40 +00002346 Output = TemplateArgumentLoc(TemplateArgument(Template),
2347 Input.getTemplateQualifierRange(),
2348 Input.getTemplateNameLoc());
2349 return false;
2350 }
Sean Huntc3021132010-05-05 15:23:54 +00002351
Douglas Gregor670444e2009-08-04 22:27:00 +00002352 case TemplateArgument::Expression: {
2353 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002354 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002355 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002356
John McCall833ca992009-10-29 08:12:44 +00002357 Expr *InputExpr = Input.getSourceExpression();
2358 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2359
John McCall60d7b3a2010-08-24 06:29:42 +00002360 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002361 = getDerived().TransformExpr(InputExpr);
2362 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002363 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002364 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002365 }
Mike Stump1eb44332009-09-09 15:08:12 +00002366
Douglas Gregor670444e2009-08-04 22:27:00 +00002367 case TemplateArgument::Pack: {
2368 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2369 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002370 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002371 AEnd = Arg.pack_end();
2372 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002373
John McCall833ca992009-10-29 08:12:44 +00002374 // FIXME: preserve source information here when we start
2375 // caring about parameter packs.
2376
John McCall828bff22009-10-29 18:45:58 +00002377 TemplateArgumentLoc InputArg;
2378 TemplateArgumentLoc OutputArg;
2379 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2380 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002381 return true;
2382
John McCall828bff22009-10-29 18:45:58 +00002383 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002384 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002385
2386 TemplateArgument *TransformedArgsPtr
2387 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2388 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2389 TransformedArgsPtr);
2390 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2391 TransformedArgs.size()),
2392 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002393 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002394 }
2395 }
Mike Stump1eb44332009-09-09 15:08:12 +00002396
Douglas Gregor670444e2009-08-04 22:27:00 +00002397 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002398 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002399}
2400
Douglas Gregor577f75a2009-08-04 16:50:30 +00002401//===----------------------------------------------------------------------===//
2402// Type transformation
2403//===----------------------------------------------------------------------===//
2404
2405template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002406QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002407 if (getDerived().AlreadyTransformed(T))
2408 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002409
John McCalla2becad2009-10-21 00:40:46 +00002410 // Temporary workaround. All of these transformations should
2411 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002412 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002413 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002414
John McCall43fed0d2010-11-12 08:19:04 +00002415 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002416
John McCalla2becad2009-10-21 00:40:46 +00002417 if (!NewDI)
2418 return QualType();
2419
2420 return NewDI->getType();
2421}
2422
2423template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002424TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002425 if (getDerived().AlreadyTransformed(DI->getType()))
2426 return DI;
2427
2428 TypeLocBuilder TLB;
2429
2430 TypeLoc TL = DI->getTypeLoc();
2431 TLB.reserve(TL.getFullDataSize());
2432
John McCall43fed0d2010-11-12 08:19:04 +00002433 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00002434 if (Result.isNull())
2435 return 0;
2436
John McCalla93c9342009-12-07 02:54:59 +00002437 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002438}
2439
2440template<typename Derived>
2441QualType
John McCall43fed0d2010-11-12 08:19:04 +00002442TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00002443 switch (T.getTypeLocClass()) {
2444#define ABSTRACT_TYPELOC(CLASS, PARENT)
2445#define TYPELOC(CLASS, PARENT) \
2446 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00002447 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00002448#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002449 }
Mike Stump1eb44332009-09-09 15:08:12 +00002450
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002451 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002452 return QualType();
2453}
2454
2455/// FIXME: By default, this routine adds type qualifiers only to types
2456/// that can have qualifiers, and silently suppresses those qualifiers
2457/// that are not permitted (e.g., qualifiers on reference or function
2458/// types). This is the right thing for template instantiation, but
2459/// probably not for other clients.
2460template<typename Derived>
2461QualType
2462TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002463 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002464 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002465
John McCall43fed0d2010-11-12 08:19:04 +00002466 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00002467 if (Result.isNull())
2468 return QualType();
2469
2470 // Silently suppress qualifiers if the result type can't be qualified.
2471 // FIXME: this is the right thing for template instantiation, but
2472 // probably not for other clients.
2473 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002474 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002475
John McCall28654742010-06-05 06:41:15 +00002476 if (!Quals.empty()) {
2477 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2478 TLB.push<QualifiedTypeLoc>(Result);
2479 // No location information to preserve.
2480 }
John McCalla2becad2009-10-21 00:40:46 +00002481
2482 return Result;
2483}
2484
John McCall43fed0d2010-11-12 08:19:04 +00002485/// \brief Transforms a type that was written in a scope specifier,
2486/// given an object type, the results of unqualified lookup, and
2487/// an already-instantiated prefix.
2488///
2489/// The object type is provided iff the scope specifier qualifies the
2490/// member of a dependent member-access expression. The prefix is
2491/// provided iff the the scope specifier in which this appears has a
2492/// prefix.
2493///
2494/// This is private to TreeTransform.
2495template<typename Derived>
2496QualType
2497TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2498 QualType ObjectType,
2499 NamedDecl *UnqualLookup,
2500 NestedNameSpecifier *Prefix) {
2501 if (getDerived().AlreadyTransformed(T))
2502 return T;
2503
2504 TypeSourceInfo *TSI =
2505 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2506
2507 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2508 UnqualLookup, Prefix);
2509 if (!TSI) return QualType();
2510 return TSI->getType();
2511}
2512
2513template<typename Derived>
2514TypeSourceInfo *
2515TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2516 QualType ObjectType,
2517 NamedDecl *UnqualLookup,
2518 NestedNameSpecifier *Prefix) {
2519 // TODO: in some cases, we might be some verification to do here.
2520 if (ObjectType.isNull())
2521 return getDerived().TransformType(TSI);
2522
2523 QualType T = TSI->getType();
2524 if (getDerived().AlreadyTransformed(T))
2525 return TSI;
2526
2527 TypeLocBuilder TLB;
2528 QualType Result;
2529
2530 if (isa<TemplateSpecializationType>(T)) {
2531 TemplateSpecializationTypeLoc TL
2532 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2533
2534 TemplateName Template =
2535 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2536 ObjectType, UnqualLookup);
2537 if (Template.isNull()) return 0;
2538
2539 Result = getDerived()
2540 .TransformTemplateSpecializationType(TLB, TL, Template);
2541 } else if (isa<DependentTemplateSpecializationType>(T)) {
2542 DependentTemplateSpecializationTypeLoc TL
2543 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2544
2545 Result = getDerived()
2546 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2547 } else {
2548 // Nothing special needs to be done for these.
2549 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2550 }
2551
2552 if (Result.isNull()) return 0;
2553 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2554}
2555
John McCalla2becad2009-10-21 00:40:46 +00002556template <class TyLoc> static inline
2557QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2558 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2559 NewT.setNameLoc(T.getNameLoc());
2560 return T.getType();
2561}
2562
John McCalla2becad2009-10-21 00:40:46 +00002563template<typename Derived>
2564QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002565 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002566 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2567 NewT.setBuiltinLoc(T.getBuiltinLoc());
2568 if (T.needsExtraLocalData())
2569 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2570 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002571}
Mike Stump1eb44332009-09-09 15:08:12 +00002572
Douglas Gregor577f75a2009-08-04 16:50:30 +00002573template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002574QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002575 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00002576 // FIXME: recurse?
2577 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002578}
Mike Stump1eb44332009-09-09 15:08:12 +00002579
Douglas Gregor577f75a2009-08-04 16:50:30 +00002580template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002581QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002582 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00002583 QualType PointeeType
2584 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002585 if (PointeeType.isNull())
2586 return QualType();
2587
2588 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002589 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002590 // A dependent pointer type 'T *' has is being transformed such
2591 // that an Objective-C class type is being replaced for 'T'. The
2592 // resulting pointer type is an ObjCObjectPointerType, not a
2593 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002594 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002595
John McCallc12c5bb2010-05-15 11:32:37 +00002596 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2597 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002598 return Result;
2599 }
John McCall43fed0d2010-11-12 08:19:04 +00002600
Douglas Gregor92e986e2010-04-22 16:44:27 +00002601 if (getDerived().AlwaysRebuild() ||
2602 PointeeType != TL.getPointeeLoc().getType()) {
2603 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2604 if (Result.isNull())
2605 return QualType();
2606 }
Sean Huntc3021132010-05-05 15:23:54 +00002607
Douglas Gregor92e986e2010-04-22 16:44:27 +00002608 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2609 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002610 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002611}
Mike Stump1eb44332009-09-09 15:08:12 +00002612
2613template<typename Derived>
2614QualType
John McCalla2becad2009-10-21 00:40:46 +00002615TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002616 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002617 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002618 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2619 if (PointeeType.isNull())
2620 return QualType();
2621
2622 QualType Result = TL.getType();
2623 if (getDerived().AlwaysRebuild() ||
2624 PointeeType != TL.getPointeeLoc().getType()) {
2625 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002626 TL.getSigilLoc());
2627 if (Result.isNull())
2628 return QualType();
2629 }
2630
Douglas Gregor39968ad2010-04-22 16:50:51 +00002631 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002632 NewT.setSigilLoc(TL.getSigilLoc());
2633 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002634}
2635
John McCall85737a72009-10-30 00:06:24 +00002636/// Transforms a reference type. Note that somewhat paradoxically we
2637/// don't care whether the type itself is an l-value type or an r-value
2638/// type; we only care if the type was *written* as an l-value type
2639/// or an r-value type.
2640template<typename Derived>
2641QualType
2642TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002643 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00002644 const ReferenceType *T = TL.getTypePtr();
2645
2646 // Note that this works with the pointee-as-written.
2647 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2648 if (PointeeType.isNull())
2649 return QualType();
2650
2651 QualType Result = TL.getType();
2652 if (getDerived().AlwaysRebuild() ||
2653 PointeeType != T->getPointeeTypeAsWritten()) {
2654 Result = getDerived().RebuildReferenceType(PointeeType,
2655 T->isSpelledAsLValue(),
2656 TL.getSigilLoc());
2657 if (Result.isNull())
2658 return QualType();
2659 }
2660
2661 // r-value references can be rebuilt as l-value references.
2662 ReferenceTypeLoc NewTL;
2663 if (isa<LValueReferenceType>(Result))
2664 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2665 else
2666 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2667 NewTL.setSigilLoc(TL.getSigilLoc());
2668
2669 return Result;
2670}
2671
Mike Stump1eb44332009-09-09 15:08:12 +00002672template<typename Derived>
2673QualType
John McCalla2becad2009-10-21 00:40:46 +00002674TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002675 LValueReferenceTypeLoc TL) {
2676 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002677}
2678
Mike Stump1eb44332009-09-09 15:08:12 +00002679template<typename Derived>
2680QualType
John McCalla2becad2009-10-21 00:40:46 +00002681TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002682 RValueReferenceTypeLoc TL) {
2683 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002684}
Mike Stump1eb44332009-09-09 15:08:12 +00002685
Douglas Gregor577f75a2009-08-04 16:50:30 +00002686template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002687QualType
John McCalla2becad2009-10-21 00:40:46 +00002688TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002689 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002690 MemberPointerType *T = TL.getTypePtr();
2691
2692 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002693 if (PointeeType.isNull())
2694 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002695
John McCalla2becad2009-10-21 00:40:46 +00002696 // TODO: preserve source information for this.
2697 QualType ClassType
2698 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002699 if (ClassType.isNull())
2700 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002701
John McCalla2becad2009-10-21 00:40:46 +00002702 QualType Result = TL.getType();
2703 if (getDerived().AlwaysRebuild() ||
2704 PointeeType != T->getPointeeType() ||
2705 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002706 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2707 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002708 if (Result.isNull())
2709 return QualType();
2710 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002711
John McCalla2becad2009-10-21 00:40:46 +00002712 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2713 NewTL.setSigilLoc(TL.getSigilLoc());
2714
2715 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002716}
2717
Mike Stump1eb44332009-09-09 15:08:12 +00002718template<typename Derived>
2719QualType
John McCalla2becad2009-10-21 00:40:46 +00002720TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002721 ConstantArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002722 ConstantArrayType *T = TL.getTypePtr();
2723 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002724 if (ElementType.isNull())
2725 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002726
John McCalla2becad2009-10-21 00:40:46 +00002727 QualType Result = TL.getType();
2728 if (getDerived().AlwaysRebuild() ||
2729 ElementType != T->getElementType()) {
2730 Result = getDerived().RebuildConstantArrayType(ElementType,
2731 T->getSizeModifier(),
2732 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002733 T->getIndexTypeCVRQualifiers(),
2734 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002735 if (Result.isNull())
2736 return QualType();
2737 }
Sean Huntc3021132010-05-05 15:23:54 +00002738
John McCalla2becad2009-10-21 00:40:46 +00002739 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2740 NewTL.setLBracketLoc(TL.getLBracketLoc());
2741 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002742
John McCalla2becad2009-10-21 00:40:46 +00002743 Expr *Size = TL.getSizeExpr();
2744 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00002745 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002746 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2747 }
2748 NewTL.setSizeExpr(Size);
2749
2750 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002751}
Mike Stump1eb44332009-09-09 15:08:12 +00002752
Douglas Gregor577f75a2009-08-04 16:50:30 +00002753template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002754QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002755 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002756 IncompleteArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002757 IncompleteArrayType *T = TL.getTypePtr();
2758 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002759 if (ElementType.isNull())
2760 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002761
John McCalla2becad2009-10-21 00:40:46 +00002762 QualType Result = TL.getType();
2763 if (getDerived().AlwaysRebuild() ||
2764 ElementType != T->getElementType()) {
2765 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002766 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002767 T->getIndexTypeCVRQualifiers(),
2768 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002769 if (Result.isNull())
2770 return QualType();
2771 }
Sean Huntc3021132010-05-05 15:23:54 +00002772
John McCalla2becad2009-10-21 00:40:46 +00002773 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2774 NewTL.setLBracketLoc(TL.getLBracketLoc());
2775 NewTL.setRBracketLoc(TL.getRBracketLoc());
2776 NewTL.setSizeExpr(0);
2777
2778 return Result;
2779}
2780
2781template<typename Derived>
2782QualType
2783TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002784 VariableArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002785 VariableArrayType *T = TL.getTypePtr();
2786 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2787 if (ElementType.isNull())
2788 return QualType();
2789
2790 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002791 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002792
John McCall60d7b3a2010-08-24 06:29:42 +00002793 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002794 = getDerived().TransformExpr(T->getSizeExpr());
2795 if (SizeResult.isInvalid())
2796 return QualType();
2797
John McCall9ae2f072010-08-23 23:25:46 +00002798 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00002799
2800 QualType Result = TL.getType();
2801 if (getDerived().AlwaysRebuild() ||
2802 ElementType != T->getElementType() ||
2803 Size != T->getSizeExpr()) {
2804 Result = getDerived().RebuildVariableArrayType(ElementType,
2805 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002806 Size,
John McCalla2becad2009-10-21 00:40:46 +00002807 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002808 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002809 if (Result.isNull())
2810 return QualType();
2811 }
Sean Huntc3021132010-05-05 15:23:54 +00002812
John McCalla2becad2009-10-21 00:40:46 +00002813 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2814 NewTL.setLBracketLoc(TL.getLBracketLoc());
2815 NewTL.setRBracketLoc(TL.getRBracketLoc());
2816 NewTL.setSizeExpr(Size);
2817
2818 return Result;
2819}
2820
2821template<typename Derived>
2822QualType
2823TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002824 DependentSizedArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002825 DependentSizedArrayType *T = TL.getTypePtr();
2826 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2827 if (ElementType.isNull())
2828 return QualType();
2829
2830 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002831 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00002832
John McCall60d7b3a2010-08-24 06:29:42 +00002833 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00002834 = getDerived().TransformExpr(T->getSizeExpr());
2835 if (SizeResult.isInvalid())
2836 return QualType();
2837
2838 Expr *Size = static_cast<Expr*>(SizeResult.get());
2839
2840 QualType Result = TL.getType();
2841 if (getDerived().AlwaysRebuild() ||
2842 ElementType != T->getElementType() ||
2843 Size != T->getSizeExpr()) {
2844 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2845 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00002846 Size,
John McCalla2becad2009-10-21 00:40:46 +00002847 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002848 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002849 if (Result.isNull())
2850 return QualType();
2851 }
2852 else SizeResult.take();
2853
2854 // We might have any sort of array type now, but fortunately they
2855 // all have the same location layout.
2856 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2857 NewTL.setLBracketLoc(TL.getLBracketLoc());
2858 NewTL.setRBracketLoc(TL.getRBracketLoc());
2859 NewTL.setSizeExpr(Size);
2860
2861 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002862}
Mike Stump1eb44332009-09-09 15:08:12 +00002863
2864template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002865QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002866 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002867 DependentSizedExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002868 DependentSizedExtVectorType *T = TL.getTypePtr();
2869
2870 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002871 QualType ElementType = getDerived().TransformType(T->getElementType());
2872 if (ElementType.isNull())
2873 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002874
Douglas Gregor670444e2009-08-04 22:27:00 +00002875 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00002876 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00002877
John McCall60d7b3a2010-08-24 06:29:42 +00002878 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002879 if (Size.isInvalid())
2880 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002881
John McCalla2becad2009-10-21 00:40:46 +00002882 QualType Result = TL.getType();
2883 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002884 ElementType != T->getElementType() ||
2885 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002886 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00002887 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00002888 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002889 if (Result.isNull())
2890 return QualType();
2891 }
John McCalla2becad2009-10-21 00:40:46 +00002892
2893 // Result might be dependent or not.
2894 if (isa<DependentSizedExtVectorType>(Result)) {
2895 DependentSizedExtVectorTypeLoc NewTL
2896 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2897 NewTL.setNameLoc(TL.getNameLoc());
2898 } else {
2899 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2900 NewTL.setNameLoc(TL.getNameLoc());
2901 }
2902
2903 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002904}
Mike Stump1eb44332009-09-09 15:08:12 +00002905
2906template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002907QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002908 VectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002909 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002910 QualType ElementType = getDerived().TransformType(T->getElementType());
2911 if (ElementType.isNull())
2912 return QualType();
2913
John McCalla2becad2009-10-21 00:40:46 +00002914 QualType Result = TL.getType();
2915 if (getDerived().AlwaysRebuild() ||
2916 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002917 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00002918 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00002919 if (Result.isNull())
2920 return QualType();
2921 }
Sean Huntc3021132010-05-05 15:23:54 +00002922
John McCalla2becad2009-10-21 00:40:46 +00002923 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2924 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002925
John McCalla2becad2009-10-21 00:40:46 +00002926 return Result;
2927}
2928
2929template<typename Derived>
2930QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002931 ExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002932 VectorType *T = TL.getTypePtr();
2933 QualType ElementType = getDerived().TransformType(T->getElementType());
2934 if (ElementType.isNull())
2935 return QualType();
2936
2937 QualType Result = TL.getType();
2938 if (getDerived().AlwaysRebuild() ||
2939 ElementType != T->getElementType()) {
2940 Result = getDerived().RebuildExtVectorType(ElementType,
2941 T->getNumElements(),
2942 /*FIXME*/ SourceLocation());
2943 if (Result.isNull())
2944 return QualType();
2945 }
Sean Huntc3021132010-05-05 15:23:54 +00002946
John McCalla2becad2009-10-21 00:40:46 +00002947 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2948 NewTL.setNameLoc(TL.getNameLoc());
2949
2950 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002951}
Mike Stump1eb44332009-09-09 15:08:12 +00002952
2953template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002954ParmVarDecl *
2955TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2956 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2957 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2958 if (!NewDI)
2959 return 0;
2960
2961 if (NewDI == OldDI)
2962 return OldParm;
2963 else
2964 return ParmVarDecl::Create(SemaRef.Context,
2965 OldParm->getDeclContext(),
2966 OldParm->getLocation(),
2967 OldParm->getIdentifier(),
2968 NewDI->getType(),
2969 NewDI,
2970 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002971 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002972 /* DefArg */ NULL);
2973}
2974
2975template<typename Derived>
2976bool TreeTransform<Derived>::
2977 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2978 llvm::SmallVectorImpl<QualType> &PTypes,
2979 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2980 FunctionProtoType *T = TL.getTypePtr();
2981
2982 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2983 ParmVarDecl *OldParm = TL.getArg(i);
2984
2985 QualType NewType;
2986 ParmVarDecl *NewParm;
2987
2988 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002989 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2990 if (!NewParm)
2991 return true;
2992 NewType = NewParm->getType();
2993
2994 // Deal with the possibility that we don't have a parameter
2995 // declaration for this parameter.
2996 } else {
2997 NewParm = 0;
2998
2999 QualType OldType = T->getArgType(i);
3000 NewType = getDerived().TransformType(OldType);
3001 if (NewType.isNull())
3002 return true;
3003 }
3004
3005 PTypes.push_back(NewType);
3006 PVars.push_back(NewParm);
3007 }
3008
3009 return false;
3010}
3011
3012template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003013QualType
John McCalla2becad2009-10-21 00:40:46 +00003014TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003015 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003016 // Transform the parameters and return type.
3017 //
3018 // We instantiate in source order, with the return type first followed by
3019 // the parameters, because users tend to expect this (even if they shouldn't
3020 // rely on it!).
3021 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003022 // When the function has a trailing return type, we instantiate the
3023 // parameters before the return type, since the return type can then refer
3024 // to the parameters themselves (via decltype, sizeof, etc.).
3025 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003026 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003027 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor895162d2010-04-30 18:55:50 +00003028 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003029
Douglas Gregordab60ad2010-10-01 18:44:50 +00003030 QualType ResultType;
3031
3032 if (TL.getTrailingReturn()) {
3033 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3034 return QualType();
3035
3036 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3037 if (ResultType.isNull())
3038 return QualType();
3039 }
3040 else {
3041 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3042 if (ResultType.isNull())
3043 return QualType();
3044
3045 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3046 return QualType();
3047 }
3048
John McCalla2becad2009-10-21 00:40:46 +00003049 QualType Result = TL.getType();
3050 if (getDerived().AlwaysRebuild() ||
3051 ResultType != T->getResultType() ||
3052 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3053 Result = getDerived().RebuildFunctionProtoType(ResultType,
3054 ParamTypes.data(),
3055 ParamTypes.size(),
3056 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003057 T->getTypeQuals(),
3058 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00003059 if (Result.isNull())
3060 return QualType();
3061 }
Mike Stump1eb44332009-09-09 15:08:12 +00003062
John McCalla2becad2009-10-21 00:40:46 +00003063 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3064 NewTL.setLParenLoc(TL.getLParenLoc());
3065 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003066 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00003067 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3068 NewTL.setArg(i, ParamDecls[i]);
3069
3070 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003071}
Mike Stump1eb44332009-09-09 15:08:12 +00003072
Douglas Gregor577f75a2009-08-04 16:50:30 +00003073template<typename Derived>
3074QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00003075 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003076 FunctionNoProtoTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003077 FunctionNoProtoType *T = TL.getTypePtr();
3078 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3079 if (ResultType.isNull())
3080 return QualType();
3081
3082 QualType Result = TL.getType();
3083 if (getDerived().AlwaysRebuild() ||
3084 ResultType != T->getResultType())
3085 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3086
3087 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3088 NewTL.setLParenLoc(TL.getLParenLoc());
3089 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003090 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003091
3092 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003093}
Mike Stump1eb44332009-09-09 15:08:12 +00003094
John McCalled976492009-12-04 22:46:56 +00003095template<typename Derived> QualType
3096TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003097 UnresolvedUsingTypeLoc TL) {
John McCalled976492009-12-04 22:46:56 +00003098 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003099 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00003100 if (!D)
3101 return QualType();
3102
3103 QualType Result = TL.getType();
3104 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3105 Result = getDerived().RebuildUnresolvedUsingType(D);
3106 if (Result.isNull())
3107 return QualType();
3108 }
3109
3110 // We might get an arbitrary type spec type back. We should at
3111 // least always get a type spec type, though.
3112 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3113 NewTL.setNameLoc(TL.getNameLoc());
3114
3115 return Result;
3116}
3117
Douglas Gregor577f75a2009-08-04 16:50:30 +00003118template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003119QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003120 TypedefTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003121 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003122 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003123 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3124 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003125 if (!Typedef)
3126 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003127
John McCalla2becad2009-10-21 00:40:46 +00003128 QualType Result = TL.getType();
3129 if (getDerived().AlwaysRebuild() ||
3130 Typedef != T->getDecl()) {
3131 Result = getDerived().RebuildTypedefType(Typedef);
3132 if (Result.isNull())
3133 return QualType();
3134 }
Mike Stump1eb44332009-09-09 15:08:12 +00003135
John McCalla2becad2009-10-21 00:40:46 +00003136 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3137 NewTL.setNameLoc(TL.getNameLoc());
3138
3139 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003140}
Mike Stump1eb44332009-09-09 15:08:12 +00003141
Douglas Gregor577f75a2009-08-04 16:50:30 +00003142template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003143QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003144 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003145 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003146 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003147
John McCall60d7b3a2010-08-24 06:29:42 +00003148 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003149 if (E.isInvalid())
3150 return QualType();
3151
John McCalla2becad2009-10-21 00:40:46 +00003152 QualType Result = TL.getType();
3153 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003154 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003155 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00003156 if (Result.isNull())
3157 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003158 }
John McCalla2becad2009-10-21 00:40:46 +00003159 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003160
John McCalla2becad2009-10-21 00:40:46 +00003161 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003162 NewTL.setTypeofLoc(TL.getTypeofLoc());
3163 NewTL.setLParenLoc(TL.getLParenLoc());
3164 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003165
3166 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003167}
Mike Stump1eb44332009-09-09 15:08:12 +00003168
3169template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003170QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003171 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00003172 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3173 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3174 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003175 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003176
John McCalla2becad2009-10-21 00:40:46 +00003177 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003178 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3179 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003180 if (Result.isNull())
3181 return QualType();
3182 }
Mike Stump1eb44332009-09-09 15:08:12 +00003183
John McCalla2becad2009-10-21 00:40:46 +00003184 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003185 NewTL.setTypeofLoc(TL.getTypeofLoc());
3186 NewTL.setLParenLoc(TL.getLParenLoc());
3187 NewTL.setRParenLoc(TL.getRParenLoc());
3188 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003189
3190 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003191}
Mike Stump1eb44332009-09-09 15:08:12 +00003192
3193template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003194QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003195 DecltypeTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003196 DecltypeType *T = TL.getTypePtr();
3197
Douglas Gregor670444e2009-08-04 22:27:00 +00003198 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003199 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003200
John McCall60d7b3a2010-08-24 06:29:42 +00003201 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003202 if (E.isInvalid())
3203 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003204
John McCalla2becad2009-10-21 00:40:46 +00003205 QualType Result = TL.getType();
3206 if (getDerived().AlwaysRebuild() ||
3207 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003208 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003209 if (Result.isNull())
3210 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003211 }
John McCalla2becad2009-10-21 00:40:46 +00003212 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003213
John McCalla2becad2009-10-21 00:40:46 +00003214 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3215 NewTL.setNameLoc(TL.getNameLoc());
3216
3217 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003218}
3219
3220template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003221QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003222 RecordTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003223 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003224 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003225 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3226 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003227 if (!Record)
3228 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003229
John McCalla2becad2009-10-21 00:40:46 +00003230 QualType Result = TL.getType();
3231 if (getDerived().AlwaysRebuild() ||
3232 Record != T->getDecl()) {
3233 Result = getDerived().RebuildRecordType(Record);
3234 if (Result.isNull())
3235 return QualType();
3236 }
Mike Stump1eb44332009-09-09 15:08:12 +00003237
John McCalla2becad2009-10-21 00:40:46 +00003238 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3239 NewTL.setNameLoc(TL.getNameLoc());
3240
3241 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003242}
Mike Stump1eb44332009-09-09 15:08:12 +00003243
3244template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003245QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003246 EnumTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003247 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003248 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003249 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3250 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003251 if (!Enum)
3252 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003253
John McCalla2becad2009-10-21 00:40:46 +00003254 QualType Result = TL.getType();
3255 if (getDerived().AlwaysRebuild() ||
3256 Enum != T->getDecl()) {
3257 Result = getDerived().RebuildEnumType(Enum);
3258 if (Result.isNull())
3259 return QualType();
3260 }
Mike Stump1eb44332009-09-09 15:08:12 +00003261
John McCalla2becad2009-10-21 00:40:46 +00003262 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3263 NewTL.setNameLoc(TL.getNameLoc());
3264
3265 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003266}
John McCall7da24312009-09-05 00:15:47 +00003267
John McCall3cb0ebd2010-03-10 03:28:59 +00003268template<typename Derived>
3269QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3270 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003271 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00003272 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3273 TL.getTypePtr()->getDecl());
3274 if (!D) return QualType();
3275
3276 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3277 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3278 return T;
3279}
3280
Mike Stump1eb44332009-09-09 15:08:12 +00003281
Douglas Gregor577f75a2009-08-04 16:50:30 +00003282template<typename Derived>
3283QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003284 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003285 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003286 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003287}
3288
Mike Stump1eb44332009-09-09 15:08:12 +00003289template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003290QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003291 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003292 SubstTemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003293 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003294}
3295
3296template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003297QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003298 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003299 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00003300 const TemplateSpecializationType *T = TL.getTypePtr();
3301
Mike Stump1eb44332009-09-09 15:08:12 +00003302 TemplateName Template
John McCall43fed0d2010-11-12 08:19:04 +00003303 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003304 if (Template.isNull())
3305 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003306
John McCall43fed0d2010-11-12 08:19:04 +00003307 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3308}
3309
3310template <typename Derived>
3311QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3312 TypeLocBuilder &TLB,
3313 TemplateSpecializationTypeLoc TL,
3314 TemplateName Template) {
3315 const TemplateSpecializationType *T = TL.getTypePtr();
3316
John McCalld5532b62009-11-23 01:53:49 +00003317 TemplateArgumentListInfo NewTemplateArgs;
3318 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3319 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3320
3321 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3322 TemplateArgumentLoc Loc;
3323 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003324 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003325 NewTemplateArgs.addArgument(Loc);
3326 }
Mike Stump1eb44332009-09-09 15:08:12 +00003327
John McCall833ca992009-10-29 08:12:44 +00003328 // FIXME: maybe don't rebuild if all the template arguments are the same.
3329
3330 QualType Result =
3331 getDerived().RebuildTemplateSpecializationType(Template,
3332 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003333 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003334
3335 if (!Result.isNull()) {
3336 TemplateSpecializationTypeLoc NewTL
3337 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3338 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3339 NewTL.setLAngleLoc(TL.getLAngleLoc());
3340 NewTL.setRAngleLoc(TL.getRAngleLoc());
3341 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3342 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003343 }
Mike Stump1eb44332009-09-09 15:08:12 +00003344
John McCall833ca992009-10-29 08:12:44 +00003345 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003346}
Mike Stump1eb44332009-09-09 15:08:12 +00003347
3348template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003349QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003350TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003351 ElaboratedTypeLoc TL) {
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003352 ElaboratedType *T = TL.getTypePtr();
3353
3354 NestedNameSpecifier *NNS = 0;
3355 // NOTE: the qualifier in an ElaboratedType is optional.
3356 if (T->getQualifier() != 0) {
3357 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003358 TL.getQualifierRange());
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003359 if (!NNS)
3360 return QualType();
3361 }
Mike Stump1eb44332009-09-09 15:08:12 +00003362
John McCall43fed0d2010-11-12 08:19:04 +00003363 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3364 if (NamedT.isNull())
3365 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00003366
John McCalla2becad2009-10-21 00:40:46 +00003367 QualType Result = TL.getType();
3368 if (getDerived().AlwaysRebuild() ||
3369 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003370 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00003371 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3372 T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003373 if (Result.isNull())
3374 return QualType();
3375 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003376
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003377 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003378 NewTL.setKeywordLoc(TL.getKeywordLoc());
3379 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003380
3381 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003382}
Mike Stump1eb44332009-09-09 15:08:12 +00003383
3384template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003385QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003386 DependentNameTypeLoc TL) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003387 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003388
Douglas Gregor577f75a2009-08-04 16:50:30 +00003389 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003390 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003391 TL.getQualifierRange());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003392 if (!NNS)
3393 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003394
John McCall33500952010-06-11 00:33:02 +00003395 QualType Result
3396 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3397 T->getIdentifier(),
3398 TL.getKeywordLoc(),
3399 TL.getQualifierRange(),
3400 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003401 if (Result.isNull())
3402 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003403
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003404 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3405 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003406 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3407
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003408 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3409 NewTL.setKeywordLoc(TL.getKeywordLoc());
3410 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003411 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003412 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3413 NewTL.setKeywordLoc(TL.getKeywordLoc());
3414 NewTL.setQualifierRange(TL.getQualifierRange());
3415 NewTL.setNameLoc(TL.getNameLoc());
3416 }
John McCalla2becad2009-10-21 00:40:46 +00003417 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003418}
Mike Stump1eb44332009-09-09 15:08:12 +00003419
Douglas Gregor577f75a2009-08-04 16:50:30 +00003420template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003421QualType TreeTransform<Derived>::
3422 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003423 DependentTemplateSpecializationTypeLoc TL) {
John McCall33500952010-06-11 00:33:02 +00003424 DependentTemplateSpecializationType *T = TL.getTypePtr();
3425
3426 NestedNameSpecifier *NNS
3427 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003428 TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003429 if (!NNS)
3430 return QualType();
3431
John McCall43fed0d2010-11-12 08:19:04 +00003432 return getDerived()
3433 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3434}
3435
3436template<typename Derived>
3437QualType TreeTransform<Derived>::
3438 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3439 DependentTemplateSpecializationTypeLoc TL,
3440 NestedNameSpecifier *NNS) {
3441 DependentTemplateSpecializationType *T = TL.getTypePtr();
3442
John McCall33500952010-06-11 00:33:02 +00003443 TemplateArgumentListInfo NewTemplateArgs;
3444 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3445 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3446
3447 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3448 TemplateArgumentLoc Loc;
3449 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3450 return QualType();
3451 NewTemplateArgs.addArgument(Loc);
3452 }
3453
Douglas Gregor1efb6c72010-09-08 23:56:00 +00003454 QualType Result
3455 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3456 NNS,
3457 TL.getQualifierRange(),
3458 T->getIdentifier(),
3459 TL.getNameLoc(),
3460 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00003461 if (Result.isNull())
3462 return QualType();
3463
3464 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3465 QualType NamedT = ElabT->getNamedType();
3466
3467 // Copy information relevant to the template specialization.
3468 TemplateSpecializationTypeLoc NamedTL
3469 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3470 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3471 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3472 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3473 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3474
3475 // Copy information relevant to the elaborated type.
3476 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3477 NewTL.setKeywordLoc(TL.getKeywordLoc());
3478 NewTL.setQualifierRange(TL.getQualifierRange());
3479 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003480 TypeLoc NewTL(Result, TL.getOpaqueData());
3481 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003482 }
3483 return Result;
3484}
3485
3486template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003487QualType
3488TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003489 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003490 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003491 TLB.pushFullCopy(TL);
3492 return TL.getType();
3493}
3494
3495template<typename Derived>
3496QualType
3497TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003498 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00003499 // ObjCObjectType is never dependent.
3500 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003501 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003502}
Mike Stump1eb44332009-09-09 15:08:12 +00003503
3504template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003505QualType
3506TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003507 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003508 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003509 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003510 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003511}
3512
Douglas Gregor577f75a2009-08-04 16:50:30 +00003513//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003514// Statement transformation
3515//===----------------------------------------------------------------------===//
3516template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003517StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003518TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00003519 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003520}
3521
3522template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003523StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003524TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3525 return getDerived().TransformCompoundStmt(S, false);
3526}
3527
3528template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003529StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003530TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003531 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00003532 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00003533 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003534 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00003535 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3536 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00003537 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00003538 if (Result.isInvalid()) {
3539 // Immediately fail if this was a DeclStmt, since it's very
3540 // likely that this will cause problems for future statements.
3541 if (isa<DeclStmt>(*B))
3542 return StmtError();
3543
3544 // Otherwise, just keep processing substatements and fail later.
3545 SubStmtInvalid = true;
3546 continue;
3547 }
Mike Stump1eb44332009-09-09 15:08:12 +00003548
Douglas Gregor43959a92009-08-20 07:17:43 +00003549 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3550 Statements.push_back(Result.takeAs<Stmt>());
3551 }
Mike Stump1eb44332009-09-09 15:08:12 +00003552
John McCall7114cba2010-08-27 19:56:05 +00003553 if (SubStmtInvalid)
3554 return StmtError();
3555
Douglas Gregor43959a92009-08-20 07:17:43 +00003556 if (!getDerived().AlwaysRebuild() &&
3557 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00003558 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003559
3560 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3561 move_arg(Statements),
3562 S->getRBracLoc(),
3563 IsStmtExpr);
3564}
Mike Stump1eb44332009-09-09 15:08:12 +00003565
Douglas Gregor43959a92009-08-20 07:17:43 +00003566template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003567StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003568TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003569 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00003570 {
3571 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00003572 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003573
Eli Friedman264c1f82009-11-19 03:14:00 +00003574 // Transform the left-hand case value.
3575 LHS = getDerived().TransformExpr(S->getLHS());
3576 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003577 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003578
Eli Friedman264c1f82009-11-19 03:14:00 +00003579 // Transform the right-hand case value (for the GNU case-range extension).
3580 RHS = getDerived().TransformExpr(S->getRHS());
3581 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003582 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00003583 }
Mike Stump1eb44332009-09-09 15:08:12 +00003584
Douglas Gregor43959a92009-08-20 07:17:43 +00003585 // Build the case statement.
3586 // Case statements are always rebuilt so that they will attached to their
3587 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003588 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003589 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003590 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003591 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003592 S->getColonLoc());
3593 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003594 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003595
Douglas Gregor43959a92009-08-20 07:17:43 +00003596 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00003597 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003598 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003599 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003600
Douglas Gregor43959a92009-08-20 07:17:43 +00003601 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00003602 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003603}
3604
3605template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003606StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003607TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003608 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00003609 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003610 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003611 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003612
Douglas Gregor43959a92009-08-20 07:17:43 +00003613 // Default statements are always rebuilt
3614 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003615 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003616}
Mike Stump1eb44332009-09-09 15:08:12 +00003617
Douglas Gregor43959a92009-08-20 07:17:43 +00003618template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003619StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003620TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003621 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003622 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003623 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003624
Douglas Gregor43959a92009-08-20 07:17:43 +00003625 // FIXME: Pass the real colon location in.
3626 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3627 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +00003628 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00003629}
Mike Stump1eb44332009-09-09 15:08:12 +00003630
Douglas Gregor43959a92009-08-20 07:17:43 +00003631template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003632StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003633TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003634 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003635 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003636 VarDecl *ConditionVar = 0;
3637 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003638 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003639 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003640 getDerived().TransformDefinition(
3641 S->getConditionVariable()->getLocation(),
3642 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003643 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003644 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003645 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003646 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003647
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003648 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003649 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003650
3651 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003652 if (S->getCond()) {
John McCall60d7b3a2010-08-24 06:29:42 +00003653 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003654 S->getIfLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003655 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003656 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003657 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003658
John McCall9ae2f072010-08-23 23:25:46 +00003659 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003660 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003661 }
Sean Huntc3021132010-05-05 15:23:54 +00003662
John McCall9ae2f072010-08-23 23:25:46 +00003663 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3664 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003665 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003666
Douglas Gregor43959a92009-08-20 07:17:43 +00003667 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003668 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00003669 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003670 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003671
Douglas Gregor43959a92009-08-20 07:17:43 +00003672 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003673 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00003674 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003675 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003676
Douglas Gregor43959a92009-08-20 07:17:43 +00003677 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003678 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003679 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003680 Then.get() == S->getThen() &&
3681 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00003682 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003683
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003684 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCall9ae2f072010-08-23 23:25:46 +00003685 Then.get(),
3686 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003687}
3688
3689template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003690StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003691TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003692 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00003693 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00003694 VarDecl *ConditionVar = 0;
3695 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003696 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003697 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003698 getDerived().TransformDefinition(
3699 S->getConditionVariable()->getLocation(),
3700 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003701 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003702 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003703 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003704 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003705
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003706 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003707 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003708 }
Mike Stump1eb44332009-09-09 15:08:12 +00003709
Douglas Gregor43959a92009-08-20 07:17:43 +00003710 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003711 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00003712 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00003713 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003714 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003715 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003716
Douglas Gregor43959a92009-08-20 07:17:43 +00003717 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003718 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003719 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003720 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003721
Douglas Gregor43959a92009-08-20 07:17:43 +00003722 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00003723 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3724 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003725}
Mike Stump1eb44332009-09-09 15:08:12 +00003726
Douglas Gregor43959a92009-08-20 07:17:43 +00003727template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003728StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003729TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003730 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003731 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00003732 VarDecl *ConditionVar = 0;
3733 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003734 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003735 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003736 getDerived().TransformDefinition(
3737 S->getConditionVariable()->getLocation(),
3738 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003739 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003740 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003741 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003742 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003743
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003744 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003745 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003746
3747 if (S->getCond()) {
3748 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003749 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003750 S->getWhileLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003751 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003752 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003753 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00003754 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003755 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003756 }
Mike Stump1eb44332009-09-09 15:08:12 +00003757
John McCall9ae2f072010-08-23 23:25:46 +00003758 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3759 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003760 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003761
Douglas Gregor43959a92009-08-20 07:17:43 +00003762 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003763 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003764 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003765 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003766
Douglas Gregor43959a92009-08-20 07:17:43 +00003767 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003768 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003769 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003770 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00003771 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003772
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003773 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00003774 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003775}
Mike Stump1eb44332009-09-09 15:08:12 +00003776
Douglas Gregor43959a92009-08-20 07:17:43 +00003777template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003778StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003779TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003780 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003781 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003782 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003783 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003784
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003785 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003786 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003787 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003788 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003789
Douglas Gregor43959a92009-08-20 07:17:43 +00003790 if (!getDerived().AlwaysRebuild() &&
3791 Cond.get() == S->getCond() &&
3792 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00003793 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003794
John McCall9ae2f072010-08-23 23:25:46 +00003795 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3796 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003797 S->getRParenLoc());
3798}
Mike Stump1eb44332009-09-09 15:08:12 +00003799
Douglas Gregor43959a92009-08-20 07:17:43 +00003800template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003801StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003802TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003803 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00003804 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00003805 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003806 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003807
Douglas Gregor43959a92009-08-20 07:17:43 +00003808 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003809 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003810 VarDecl *ConditionVar = 0;
3811 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003812 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003813 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003814 getDerived().TransformDefinition(
3815 S->getConditionVariable()->getLocation(),
3816 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003817 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003818 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003819 } else {
3820 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003821
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003822 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003823 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003824
3825 if (S->getCond()) {
3826 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003827 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003828 S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003829 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003830 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003831 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003832
John McCall9ae2f072010-08-23 23:25:46 +00003833 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003834 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003835 }
Mike Stump1eb44332009-09-09 15:08:12 +00003836
John McCall9ae2f072010-08-23 23:25:46 +00003837 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3838 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003839 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003840
Douglas Gregor43959a92009-08-20 07:17:43 +00003841 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00003842 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00003843 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003844 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003845
John McCall9ae2f072010-08-23 23:25:46 +00003846 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3847 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00003848 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003849
Douglas Gregor43959a92009-08-20 07:17:43 +00003850 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003851 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003852 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003853 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003854
Douglas Gregor43959a92009-08-20 07:17:43 +00003855 if (!getDerived().AlwaysRebuild() &&
3856 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00003857 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003858 Inc.get() == S->getInc() &&
3859 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00003860 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003861
Douglas Gregor43959a92009-08-20 07:17:43 +00003862 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003863 Init.get(), FullCond, ConditionVar,
3864 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003865}
3866
3867template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003868StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003869TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003870 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003871 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003872 S->getLabel());
3873}
3874
3875template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003876StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003877TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003878 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00003879 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003880 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003881
Douglas Gregor43959a92009-08-20 07:17:43 +00003882 if (!getDerived().AlwaysRebuild() &&
3883 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00003884 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003885
3886 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003887 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003888}
3889
3890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003891StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003892TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00003893 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003894}
Mike Stump1eb44332009-09-09 15:08:12 +00003895
Douglas Gregor43959a92009-08-20 07:17:43 +00003896template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003897StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003898TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00003899 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003900}
Mike Stump1eb44332009-09-09 15:08:12 +00003901
Douglas Gregor43959a92009-08-20 07:17:43 +00003902template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003903StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003904TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003905 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00003906 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003907 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00003908
Mike Stump1eb44332009-09-09 15:08:12 +00003909 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003910 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00003911 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003912}
Mike Stump1eb44332009-09-09 15:08:12 +00003913
Douglas Gregor43959a92009-08-20 07:17:43 +00003914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003915StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003916TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003917 bool DeclChanged = false;
3918 llvm::SmallVector<Decl *, 4> Decls;
3919 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3920 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003921 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3922 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003923 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00003924 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003925
Douglas Gregor43959a92009-08-20 07:17:43 +00003926 if (Transformed != *D)
3927 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003928
Douglas Gregor43959a92009-08-20 07:17:43 +00003929 Decls.push_back(Transformed);
3930 }
Mike Stump1eb44332009-09-09 15:08:12 +00003931
Douglas Gregor43959a92009-08-20 07:17:43 +00003932 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00003933 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003934
3935 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003936 S->getStartLoc(), S->getEndLoc());
3937}
Mike Stump1eb44332009-09-09 15:08:12 +00003938
Douglas Gregor43959a92009-08-20 07:17:43 +00003939template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003940StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003941TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003942 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCall3fa5cae2010-10-26 07:05:15 +00003943 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003944}
3945
3946template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003947StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003948TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003949
John McCallca0408f2010-08-23 06:44:23 +00003950 ASTOwningVector<Expr*> Constraints(getSema());
3951 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003952 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003953
John McCall60d7b3a2010-08-24 06:29:42 +00003954 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00003955 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00003956
3957 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003958
Anders Carlsson703e3942010-01-24 05:50:09 +00003959 // Go through the outputs.
3960 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003961 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003962
Anders Carlsson703e3942010-01-24 05:50:09 +00003963 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00003964 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00003965
Anders Carlsson703e3942010-01-24 05:50:09 +00003966 // Transform the output expr.
3967 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003968 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003969 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003970 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003971
Anders Carlsson703e3942010-01-24 05:50:09 +00003972 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003973
John McCall9ae2f072010-08-23 23:25:46 +00003974 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003975 }
Sean Huntc3021132010-05-05 15:23:54 +00003976
Anders Carlsson703e3942010-01-24 05:50:09 +00003977 // Go through the inputs.
3978 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003979 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003980
Anders Carlsson703e3942010-01-24 05:50:09 +00003981 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00003982 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00003983
Anders Carlsson703e3942010-01-24 05:50:09 +00003984 // Transform the input expr.
3985 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003986 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00003987 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003988 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003989
Anders Carlsson703e3942010-01-24 05:50:09 +00003990 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003991
John McCall9ae2f072010-08-23 23:25:46 +00003992 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00003993 }
Sean Huntc3021132010-05-05 15:23:54 +00003994
Anders Carlsson703e3942010-01-24 05:50:09 +00003995 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00003996 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00003997
3998 // Go through the clobbers.
3999 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00004000 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00004001
4002 // No need to transform the asm string literal.
4003 AsmString = SemaRef.Owned(S->getAsmString());
4004
4005 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4006 S->isSimple(),
4007 S->isVolatile(),
4008 S->getNumOutputs(),
4009 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00004010 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004011 move_arg(Constraints),
4012 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00004013 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004014 move_arg(Clobbers),
4015 S->getRParenLoc(),
4016 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00004017}
4018
4019
4020template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004021StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004022TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004023 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00004024 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004025 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004026 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004027
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004028 // Transform the @catch statements (if present).
4029 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004030 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004031 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004032 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004033 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004034 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004035 if (Catch.get() != S->getCatchStmt(I))
4036 AnyCatchChanged = true;
4037 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004038 }
Sean Huntc3021132010-05-05 15:23:54 +00004039
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004040 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00004041 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004042 if (S->getFinallyStmt()) {
4043 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4044 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004045 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004046 }
4047
4048 // If nothing changed, just retain this statement.
4049 if (!getDerived().AlwaysRebuild() &&
4050 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004051 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004052 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004053 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004054
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004055 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00004056 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4057 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004058}
Mike Stump1eb44332009-09-09 15:08:12 +00004059
Douglas Gregor43959a92009-08-20 07:17:43 +00004060template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004061StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004062TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004063 // Transform the @catch parameter, if there is one.
4064 VarDecl *Var = 0;
4065 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4066 TypeSourceInfo *TSInfo = 0;
4067 if (FromVar->getTypeSourceInfo()) {
4068 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4069 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004070 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004071 }
Sean Huntc3021132010-05-05 15:23:54 +00004072
Douglas Gregorbe270a02010-04-26 17:57:08 +00004073 QualType T;
4074 if (TSInfo)
4075 T = TSInfo->getType();
4076 else {
4077 T = getDerived().TransformType(FromVar->getType());
4078 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004079 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004080 }
Sean Huntc3021132010-05-05 15:23:54 +00004081
Douglas Gregorbe270a02010-04-26 17:57:08 +00004082 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4083 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004084 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004085 }
Sean Huntc3021132010-05-05 15:23:54 +00004086
John McCall60d7b3a2010-08-24 06:29:42 +00004087 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004088 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004089 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004090
4091 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004092 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004093 Var, Body.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
Mike Stump1eb44332009-09-09 15:08:12 +00004098TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004099 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004100 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004101 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004102 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004103
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004104 // If nothing changed, just retain this statement.
4105 if (!getDerived().AlwaysRebuild() &&
4106 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004107 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004108
4109 // Build a new statement.
4110 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004111 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004112}
Mike Stump1eb44332009-09-09 15:08:12 +00004113
Douglas Gregor43959a92009-08-20 07:17:43 +00004114template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004115StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004116TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004117 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004118 if (S->getThrowExpr()) {
4119 Operand = getDerived().TransformExpr(S->getThrowExpr());
4120 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004121 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004122 }
Sean Huntc3021132010-05-05 15:23:54 +00004123
Douglas Gregord1377b22010-04-22 21:44:01 +00004124 if (!getDerived().AlwaysRebuild() &&
4125 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004126 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004127
John McCall9ae2f072010-08-23 23:25:46 +00004128 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004129}
Mike Stump1eb44332009-09-09 15:08:12 +00004130
Douglas Gregor43959a92009-08-20 07:17:43 +00004131template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004132StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004133TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004134 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004135 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004136 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004137 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004138 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004139
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004140 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004141 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004142 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004143 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004144
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004145 // If nothing change, just retain the current statement.
4146 if (!getDerived().AlwaysRebuild() &&
4147 Object.get() == S->getSynchExpr() &&
4148 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004149 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004150
4151 // Build a new statement.
4152 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004153 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004154}
4155
4156template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004157StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004158TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004159 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004160 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004161 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004162 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004163 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004164
Douglas Gregorc3203e72010-04-22 23:10:45 +00004165 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00004166 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004167 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004168 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004169
Douglas Gregorc3203e72010-04-22 23:10:45 +00004170 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004171 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004172 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004173 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004174
Douglas Gregorc3203e72010-04-22 23:10:45 +00004175 // If nothing changed, just retain this statement.
4176 if (!getDerived().AlwaysRebuild() &&
4177 Element.get() == S->getElement() &&
4178 Collection.get() == S->getCollection() &&
4179 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004180 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004181
Douglas Gregorc3203e72010-04-22 23:10:45 +00004182 // Build a new statement.
4183 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4184 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004185 Element.get(),
4186 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00004187 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004188 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004189}
4190
4191
4192template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004193StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004194TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4195 // Transform the exception declaration, if any.
4196 VarDecl *Var = 0;
4197 if (S->getExceptionDecl()) {
4198 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00004199 TypeSourceInfo *T = getDerived().TransformType(
4200 ExceptionDecl->getTypeSourceInfo());
4201 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00004202 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004203
Douglas Gregor83cb9422010-09-09 17:09:21 +00004204 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00004205 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00004206 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00004207 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00004208 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004209 }
Mike Stump1eb44332009-09-09 15:08:12 +00004210
Douglas Gregor43959a92009-08-20 07:17:43 +00004211 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00004212 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004213 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004214 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004215
Douglas Gregor43959a92009-08-20 07:17:43 +00004216 if (!getDerived().AlwaysRebuild() &&
4217 !Var &&
4218 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00004219 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004220
4221 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4222 Var,
John McCall9ae2f072010-08-23 23:25:46 +00004223 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004224}
Mike Stump1eb44332009-09-09 15:08:12 +00004225
Douglas Gregor43959a92009-08-20 07:17:43 +00004226template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004227StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004228TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4229 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004230 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004231 = getDerived().TransformCompoundStmt(S->getTryBlock());
4232 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004233 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004234
Douglas Gregor43959a92009-08-20 07:17:43 +00004235 // Transform the handlers.
4236 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004237 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00004238 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004239 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004240 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4241 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004242 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004243
Douglas Gregor43959a92009-08-20 07:17:43 +00004244 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4245 Handlers.push_back(Handler.takeAs<Stmt>());
4246 }
Mike Stump1eb44332009-09-09 15:08:12 +00004247
Douglas Gregor43959a92009-08-20 07:17:43 +00004248 if (!getDerived().AlwaysRebuild() &&
4249 TryBlock.get() == S->getTryBlock() &&
4250 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004251 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004252
John McCall9ae2f072010-08-23 23:25:46 +00004253 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00004254 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004255}
Mike Stump1eb44332009-09-09 15:08:12 +00004256
Douglas Gregor43959a92009-08-20 07:17:43 +00004257//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004258// Expression transformation
4259//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004260template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004261ExprResult
John McCall454feb92009-12-08 09:21:05 +00004262TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004263 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004264}
Mike Stump1eb44332009-09-09 15:08:12 +00004265
4266template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004267ExprResult
John McCall454feb92009-12-08 09:21:05 +00004268TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004269 NestedNameSpecifier *Qualifier = 0;
4270 if (E->getQualifier()) {
4271 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004272 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004273 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00004274 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00004275 }
John McCalldbd872f2009-12-08 09:08:17 +00004276
4277 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004278 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4279 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004280 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00004281 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004282
John McCallec8045d2010-08-17 21:27:17 +00004283 DeclarationNameInfo NameInfo = E->getNameInfo();
4284 if (NameInfo.getName()) {
4285 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4286 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00004287 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00004288 }
Abramo Bagnara25777432010-08-11 22:01:17 +00004289
4290 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004291 Qualifier == E->getQualifier() &&
4292 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00004293 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00004294 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004295
4296 // Mark it referenced in the new context regardless.
4297 // FIXME: this is a bit instantiation-specific.
4298 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4299
John McCall3fa5cae2010-10-26 07:05:15 +00004300 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00004301 }
John McCalldbd872f2009-12-08 09:08:17 +00004302
4303 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00004304 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004305 TemplateArgs = &TransArgs;
4306 TransArgs.setLAngleLoc(E->getLAngleLoc());
4307 TransArgs.setRAngleLoc(E->getRAngleLoc());
4308 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4309 TemplateArgumentLoc Loc;
4310 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004311 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00004312 TransArgs.addArgument(Loc);
4313 }
4314 }
4315
Douglas Gregora2813ce2009-10-23 18:54:35 +00004316 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004317 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004318}
Mike Stump1eb44332009-09-09 15:08:12 +00004319
Douglas Gregorb98b1992009-08-11 05:31:07 +00004320template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004321ExprResult
John McCall454feb92009-12-08 09:21:05 +00004322TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004323 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004324}
Mike Stump1eb44332009-09-09 15:08:12 +00004325
Douglas Gregorb98b1992009-08-11 05:31:07 +00004326template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004327ExprResult
John McCall454feb92009-12-08 09:21:05 +00004328TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004329 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004330}
Mike Stump1eb44332009-09-09 15:08:12 +00004331
Douglas Gregorb98b1992009-08-11 05:31:07 +00004332template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004333ExprResult
John McCall454feb92009-12-08 09:21:05 +00004334TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004335 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004336}
Mike Stump1eb44332009-09-09 15:08:12 +00004337
Douglas Gregorb98b1992009-08-11 05:31:07 +00004338template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004339ExprResult
John McCall454feb92009-12-08 09:21:05 +00004340TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004341 return SemaRef.Owned(E);
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
John McCall454feb92009-12-08 09:21:05 +00004346TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004347 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004348}
4349
4350template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004351ExprResult
John McCall454feb92009-12-08 09:21:05 +00004352TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004353 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004354 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004355 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004356
Douglas Gregorb98b1992009-08-11 05:31:07 +00004357 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004358 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004359
John McCall9ae2f072010-08-23 23:25:46 +00004360 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004361 E->getRParen());
4362}
4363
Mike Stump1eb44332009-09-09 15:08:12 +00004364template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004365ExprResult
John McCall454feb92009-12-08 09:21:05 +00004366TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004367 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004368 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004369 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004370
Douglas Gregorb98b1992009-08-11 05:31:07 +00004371 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004372 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004373
Douglas Gregorb98b1992009-08-11 05:31:07 +00004374 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4375 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004376 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004377}
Mike Stump1eb44332009-09-09 15:08:12 +00004378
Douglas Gregorb98b1992009-08-11 05:31:07 +00004379template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004380ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004381TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4382 // Transform the type.
4383 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4384 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00004385 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004386
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004387 // Transform all of the components into components similar to what the
4388 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004389 // FIXME: It would be slightly more efficient in the non-dependent case to
4390 // just map FieldDecls, rather than requiring the rebuilder to look for
4391 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004392 // template code that we don't care.
4393 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00004394 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004395 typedef OffsetOfExpr::OffsetOfNode Node;
4396 llvm::SmallVector<Component, 4> Components;
4397 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4398 const Node &ON = E->getComponent(I);
4399 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004400 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004401 Comp.LocStart = ON.getRange().getBegin();
4402 Comp.LocEnd = ON.getRange().getEnd();
4403 switch (ON.getKind()) {
4404 case Node::Array: {
4405 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00004406 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004407 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004408 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004409
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004410 ExprChanged = ExprChanged || Index.get() != FromIndex;
4411 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00004412 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004413 break;
4414 }
Sean Huntc3021132010-05-05 15:23:54 +00004415
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004416 case Node::Field:
4417 case Node::Identifier:
4418 Comp.isBrackets = false;
4419 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004420 if (!Comp.U.IdentInfo)
4421 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004422
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004423 break;
Sean Huntc3021132010-05-05 15:23:54 +00004424
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004425 case Node::Base:
4426 // Will be recomputed during the rebuild.
4427 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004428 }
Sean Huntc3021132010-05-05 15:23:54 +00004429
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004430 Components.push_back(Comp);
4431 }
Sean Huntc3021132010-05-05 15:23:54 +00004432
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004433 // If nothing changed, retain the existing expression.
4434 if (!getDerived().AlwaysRebuild() &&
4435 Type == E->getTypeSourceInfo() &&
4436 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004437 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00004438
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004439 // Build a new offsetof expression.
4440 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4441 Components.data(), Components.size(),
4442 E->getRParenLoc());
4443}
4444
4445template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004446ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00004447TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
4448 assert(getDerived().AlreadyTransformed(E->getType()) &&
4449 "opaque value expression requires transformation");
4450 return SemaRef.Owned(E);
4451}
4452
4453template<typename Derived>
4454ExprResult
John McCall454feb92009-12-08 09:21:05 +00004455TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004456 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004457 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004458
John McCalla93c9342009-12-07 02:54:59 +00004459 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004460 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004461 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004462
John McCall5ab75172009-11-04 07:28:41 +00004463 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00004464 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004465
John McCall5ab75172009-11-04 07:28:41 +00004466 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004467 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004468 E->getSourceRange());
4469 }
Mike Stump1eb44332009-09-09 15:08:12 +00004470
John McCall60d7b3a2010-08-24 06:29:42 +00004471 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00004472 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004473 // C++0x [expr.sizeof]p1:
4474 // The operand is either an expression, which is an unevaluated operand
4475 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00004476 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004477
Douglas Gregorb98b1992009-08-11 05:31:07 +00004478 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4479 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004480 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004481
Douglas Gregorb98b1992009-08-11 05:31:07 +00004482 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004483 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004484 }
Mike Stump1eb44332009-09-09 15:08:12 +00004485
John McCall9ae2f072010-08-23 23:25:46 +00004486 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004487 E->isSizeOf(),
4488 E->getSourceRange());
4489}
Mike Stump1eb44332009-09-09 15:08:12 +00004490
Douglas Gregorb98b1992009-08-11 05:31:07 +00004491template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004492ExprResult
John McCall454feb92009-12-08 09:21:05 +00004493TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004494 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004495 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004496 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004497
John McCall60d7b3a2010-08-24 06:29:42 +00004498 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004499 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004500 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004501
4502
Douglas Gregorb98b1992009-08-11 05:31:07 +00004503 if (!getDerived().AlwaysRebuild() &&
4504 LHS.get() == E->getLHS() &&
4505 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004506 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004507
John McCall9ae2f072010-08-23 23:25:46 +00004508 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004509 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00004510 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004511 E->getRBracketLoc());
4512}
Mike Stump1eb44332009-09-09 15:08:12 +00004513
4514template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004515ExprResult
John McCall454feb92009-12-08 09:21:05 +00004516TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004517 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00004518 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004519 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004520 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004521
4522 // Transform arguments.
4523 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004524 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004525 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004526 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004527 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004528 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004529
Mike Stump1eb44332009-09-09 15:08:12 +00004530 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00004531 Args.push_back(Arg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004532 }
Mike Stump1eb44332009-09-09 15:08:12 +00004533
Douglas Gregorb98b1992009-08-11 05:31:07 +00004534 if (!getDerived().AlwaysRebuild() &&
4535 Callee.get() == E->getCallee() &&
4536 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004537 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004538
Douglas Gregorb98b1992009-08-11 05:31:07 +00004539 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004540 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004541 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00004542 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004543 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004544 E->getRParenLoc());
4545}
Mike Stump1eb44332009-09-09 15:08:12 +00004546
4547template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004548ExprResult
John McCall454feb92009-12-08 09:21:05 +00004549TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004550 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004551 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004552 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004553
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004554 NestedNameSpecifier *Qualifier = 0;
4555 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004556 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004557 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004558 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004559 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00004560 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004561 }
Mike Stump1eb44332009-09-09 15:08:12 +00004562
Eli Friedmanf595cc42009-12-04 06:40:45 +00004563 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004564 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4565 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004566 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00004567 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004568
John McCall6bb80172010-03-30 21:47:33 +00004569 NamedDecl *FoundDecl = E->getFoundDecl();
4570 if (FoundDecl == E->getMemberDecl()) {
4571 FoundDecl = Member;
4572 } else {
4573 FoundDecl = cast_or_null<NamedDecl>(
4574 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4575 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00004576 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00004577 }
4578
Douglas Gregorb98b1992009-08-11 05:31:07 +00004579 if (!getDerived().AlwaysRebuild() &&
4580 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004581 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004582 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004583 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00004584 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00004585
Anders Carlsson1f240322009-12-22 05:24:09 +00004586 // Mark it referenced in the new context regardless.
4587 // FIXME: this is a bit instantiation-specific.
4588 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00004589 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00004590 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004591
John McCalld5532b62009-11-23 01:53:49 +00004592 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00004593 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00004594 TransArgs.setLAngleLoc(E->getLAngleLoc());
4595 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004596 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004597 TemplateArgumentLoc Loc;
4598 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004599 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004600 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004601 }
4602 }
Sean Huntc3021132010-05-05 15:23:54 +00004603
Douglas Gregorb98b1992009-08-11 05:31:07 +00004604 // FIXME: Bogus source location for the operator
4605 SourceLocation FakeOperatorLoc
4606 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4607
John McCallc2233c52010-01-15 08:34:02 +00004608 // FIXME: to do this check properly, we will need to preserve the
4609 // first-qualifier-in-scope here, just in case we had a dependent
4610 // base (and therefore couldn't do the check) and a
4611 // nested-name-qualifier (and therefore could do the lookup).
4612 NamedDecl *FirstQualifierInScope = 0;
4613
John McCall9ae2f072010-08-23 23:25:46 +00004614 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004615 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004616 Qualifier,
4617 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004618 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004619 Member,
John McCall6bb80172010-03-30 21:47:33 +00004620 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00004621 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00004622 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004623 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004624}
Mike Stump1eb44332009-09-09 15:08:12 +00004625
Douglas Gregorb98b1992009-08-11 05:31:07 +00004626template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004627ExprResult
John McCall454feb92009-12-08 09:21:05 +00004628TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004629 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004630 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004631 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004632
John McCall60d7b3a2010-08-24 06:29:42 +00004633 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004634 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004635 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004636
Douglas Gregorb98b1992009-08-11 05:31:07 +00004637 if (!getDerived().AlwaysRebuild() &&
4638 LHS.get() == E->getLHS() &&
4639 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004640 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004641
Douglas Gregorb98b1992009-08-11 05:31:07 +00004642 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004643 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004644}
4645
Mike Stump1eb44332009-09-09 15:08:12 +00004646template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004647ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004648TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004649 CompoundAssignOperator *E) {
4650 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004651}
Mike Stump1eb44332009-09-09 15:08:12 +00004652
Douglas Gregorb98b1992009-08-11 05:31:07 +00004653template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004654ExprResult
John McCall454feb92009-12-08 09:21:05 +00004655TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004656 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004657 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004658 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004659
John McCall60d7b3a2010-08-24 06:29:42 +00004660 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004661 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004662 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004663
John McCall60d7b3a2010-08-24 06:29:42 +00004664 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004665 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004666 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004667
Douglas Gregorb98b1992009-08-11 05:31:07 +00004668 if (!getDerived().AlwaysRebuild() &&
4669 Cond.get() == E->getCond() &&
4670 LHS.get() == E->getLHS() &&
4671 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004672 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004673
John McCall9ae2f072010-08-23 23:25:46 +00004674 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004675 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004676 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004677 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004678 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004679}
Mike Stump1eb44332009-09-09 15:08:12 +00004680
4681template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004682ExprResult
John McCall454feb92009-12-08 09:21:05 +00004683TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004684 // Implicit casts are eliminated during transformation, since they
4685 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004686 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004687}
Mike Stump1eb44332009-09-09 15:08:12 +00004688
Douglas Gregorb98b1992009-08-11 05:31:07 +00004689template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004690ExprResult
John McCall454feb92009-12-08 09:21:05 +00004691TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004692 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4693 if (!Type)
4694 return ExprError();
4695
John McCall60d7b3a2010-08-24 06:29:42 +00004696 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004697 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004698 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004699 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004700
Douglas Gregorb98b1992009-08-11 05:31:07 +00004701 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004702 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004703 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004704 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004705
John McCall9d125032010-01-15 18:39:57 +00004706 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004707 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004708 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004709 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004710}
Mike Stump1eb44332009-09-09 15:08:12 +00004711
Douglas Gregorb98b1992009-08-11 05:31:07 +00004712template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004713ExprResult
John McCall454feb92009-12-08 09:21:05 +00004714TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004715 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4716 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4717 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004718 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004719
John McCall60d7b3a2010-08-24 06:29:42 +00004720 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004721 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004722 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004723
Douglas Gregorb98b1992009-08-11 05:31:07 +00004724 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004725 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004726 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00004727 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004728
John McCall1d7d8d62010-01-19 22:33:45 +00004729 // Note: the expression type doesn't necessarily match the
4730 // type-as-written, but that's okay, because it should always be
4731 // derivable from the initializer.
4732
John McCall42f56b52010-01-18 19:35:47 +00004733 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004734 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00004735 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004736}
Mike Stump1eb44332009-09-09 15:08:12 +00004737
Douglas Gregorb98b1992009-08-11 05:31:07 +00004738template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004739ExprResult
John McCall454feb92009-12-08 09:21:05 +00004740TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004741 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004742 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004743 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004744
Douglas Gregorb98b1992009-08-11 05:31:07 +00004745 if (!getDerived().AlwaysRebuild() &&
4746 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00004747 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004748
Douglas Gregorb98b1992009-08-11 05:31:07 +00004749 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004750 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004751 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00004752 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004753 E->getAccessorLoc(),
4754 E->getAccessor());
4755}
Mike Stump1eb44332009-09-09 15:08:12 +00004756
Douglas Gregorb98b1992009-08-11 05:31:07 +00004757template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004758ExprResult
John McCall454feb92009-12-08 09:21:05 +00004759TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004760 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004761
John McCallca0408f2010-08-23 06:44:23 +00004762 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004763 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004764 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004765 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004766 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004767
Douglas Gregorb98b1992009-08-11 05:31:07 +00004768 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCall9ae2f072010-08-23 23:25:46 +00004769 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004770 }
Mike Stump1eb44332009-09-09 15:08:12 +00004771
Douglas Gregorb98b1992009-08-11 05:31:07 +00004772 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004773 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004774
Douglas Gregorb98b1992009-08-11 05:31:07 +00004775 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004776 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004777}
Mike Stump1eb44332009-09-09 15:08:12 +00004778
Douglas Gregorb98b1992009-08-11 05:31:07 +00004779template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004780ExprResult
John McCall454feb92009-12-08 09:21:05 +00004781TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004782 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004783
Douglas Gregor43959a92009-08-20 07:17:43 +00004784 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00004785 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004786 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004787 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004788
Douglas Gregor43959a92009-08-20 07:17:43 +00004789 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00004790 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004791 bool ExprChanged = false;
4792 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4793 DEnd = E->designators_end();
4794 D != DEnd; ++D) {
4795 if (D->isFieldDesignator()) {
4796 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4797 D->getDotLoc(),
4798 D->getFieldLoc()));
4799 continue;
4800 }
Mike Stump1eb44332009-09-09 15:08:12 +00004801
Douglas Gregorb98b1992009-08-11 05:31:07 +00004802 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00004803 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004804 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004805 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004806
4807 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004808 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004809
Douglas Gregorb98b1992009-08-11 05:31:07 +00004810 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4811 ArrayExprs.push_back(Index.release());
4812 continue;
4813 }
Mike Stump1eb44332009-09-09 15:08:12 +00004814
Douglas Gregorb98b1992009-08-11 05:31:07 +00004815 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00004816 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004817 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4818 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004819 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004820
John McCall60d7b3a2010-08-24 06:29:42 +00004821 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004822 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004823 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004824
4825 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004826 End.get(),
4827 D->getLBracketLoc(),
4828 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004829
Douglas Gregorb98b1992009-08-11 05:31:07 +00004830 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4831 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004832
Douglas Gregorb98b1992009-08-11 05:31:07 +00004833 ArrayExprs.push_back(Start.release());
4834 ArrayExprs.push_back(End.release());
4835 }
Mike Stump1eb44332009-09-09 15:08:12 +00004836
Douglas Gregorb98b1992009-08-11 05:31:07 +00004837 if (!getDerived().AlwaysRebuild() &&
4838 Init.get() == E->getInit() &&
4839 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004840 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004841
Douglas Gregorb98b1992009-08-11 05:31:07 +00004842 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4843 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004844 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004845}
Mike Stump1eb44332009-09-09 15:08:12 +00004846
Douglas Gregorb98b1992009-08-11 05:31:07 +00004847template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004848ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004849TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004850 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004851 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004852
Douglas Gregor5557b252009-10-28 00:29:27 +00004853 // FIXME: Will we ever have proper type location here? Will we actually
4854 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004855 QualType T = getDerived().TransformType(E->getType());
4856 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004857 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004858
Douglas Gregorb98b1992009-08-11 05:31:07 +00004859 if (!getDerived().AlwaysRebuild() &&
4860 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00004861 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004862
Douglas Gregorb98b1992009-08-11 05:31:07 +00004863 return getDerived().RebuildImplicitValueInitExpr(T);
4864}
Mike Stump1eb44332009-09-09 15:08:12 +00004865
Douglas Gregorb98b1992009-08-11 05:31:07 +00004866template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004867ExprResult
John McCall454feb92009-12-08 09:21:05 +00004868TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004869 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4870 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004871 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004872
John McCall60d7b3a2010-08-24 06:29:42 +00004873 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004874 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004875 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004876
Douglas Gregorb98b1992009-08-11 05:31:07 +00004877 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004878 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004879 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004880 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004881
John McCall9ae2f072010-08-23 23:25:46 +00004882 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004883 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004884}
4885
4886template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004887ExprResult
John McCall454feb92009-12-08 09:21:05 +00004888TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004889 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004890 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004891 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004892 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004893 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004894 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004895
Douglas Gregorb98b1992009-08-11 05:31:07 +00004896 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00004897 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004898 }
Mike Stump1eb44332009-09-09 15:08:12 +00004899
Douglas Gregorb98b1992009-08-11 05:31:07 +00004900 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4901 move_arg(Inits),
4902 E->getRParenLoc());
4903}
Mike Stump1eb44332009-09-09 15:08:12 +00004904
Douglas Gregorb98b1992009-08-11 05:31:07 +00004905/// \brief Transform an address-of-label expression.
4906///
4907/// By default, the transformation of an address-of-label expression always
4908/// rebuilds the expression, so that the label identifier can be resolved to
4909/// the corresponding label statement by semantic analysis.
4910template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004911ExprResult
John McCall454feb92009-12-08 09:21:05 +00004912TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004913 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4914 E->getLabel());
4915}
Mike Stump1eb44332009-09-09 15:08:12 +00004916
4917template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004918ExprResult
John McCall454feb92009-12-08 09:21:05 +00004919TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004920 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004921 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4922 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004923 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004924
Douglas Gregorb98b1992009-08-11 05:31:07 +00004925 if (!getDerived().AlwaysRebuild() &&
4926 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004927 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004928
4929 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004930 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004931 E->getRParenLoc());
4932}
Mike Stump1eb44332009-09-09 15:08:12 +00004933
Douglas Gregorb98b1992009-08-11 05:31:07 +00004934template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004935ExprResult
John McCall454feb92009-12-08 09:21:05 +00004936TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004937 TypeSourceInfo *TInfo1;
4938 TypeSourceInfo *TInfo2;
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004939
4940 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4941 if (!TInfo1)
John McCallf312b1e2010-08-26 23:41:50 +00004942 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004943
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004944 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4945 if (!TInfo2)
John McCallf312b1e2010-08-26 23:41:50 +00004946 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004947
4948 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004949 TInfo1 == E->getArgTInfo1() &&
4950 TInfo2 == E->getArgTInfo2())
John McCall3fa5cae2010-10-26 07:05:15 +00004951 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004952
Douglas Gregorb98b1992009-08-11 05:31:07 +00004953 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004954 TInfo1, TInfo2,
4955 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004956}
Mike Stump1eb44332009-09-09 15:08:12 +00004957
Douglas Gregorb98b1992009-08-11 05:31:07 +00004958template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004959ExprResult
John McCall454feb92009-12-08 09:21:05 +00004960TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004961 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004962 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004963 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004964
John McCall60d7b3a2010-08-24 06:29:42 +00004965 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004966 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004967 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004968
John McCall60d7b3a2010-08-24 06:29:42 +00004969 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004970 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004971 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004972
Douglas Gregorb98b1992009-08-11 05:31:07 +00004973 if (!getDerived().AlwaysRebuild() &&
4974 Cond.get() == E->getCond() &&
4975 LHS.get() == E->getLHS() &&
4976 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004977 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004978
Douglas Gregorb98b1992009-08-11 05:31:07 +00004979 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004980 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004981 E->getRParenLoc());
4982}
Mike Stump1eb44332009-09-09 15:08:12 +00004983
Douglas Gregorb98b1992009-08-11 05:31:07 +00004984template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004985ExprResult
John McCall454feb92009-12-08 09:21:05 +00004986TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004987 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004988}
4989
4990template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004991ExprResult
John McCall454feb92009-12-08 09:21:05 +00004992TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004993 switch (E->getOperator()) {
4994 case OO_New:
4995 case OO_Delete:
4996 case OO_Array_New:
4997 case OO_Array_Delete:
4998 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00004999 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005000
Douglas Gregor668d6d92009-12-13 20:44:55 +00005001 case OO_Call: {
5002 // This is a call to an object's operator().
5003 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5004
5005 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005006 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005007 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005008 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005009
5010 // FIXME: Poor location information
5011 SourceLocation FakeLParenLoc
5012 = SemaRef.PP.getLocForEndOfToken(
5013 static_cast<Expr *>(Object.get())->getLocEnd());
5014
5015 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00005016 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor668d6d92009-12-13 20:44:55 +00005017 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005018 if (getDerived().DropCallArgument(E->getArg(I)))
5019 break;
Sean Huntc3021132010-05-05 15:23:54 +00005020
John McCall60d7b3a2010-08-24 06:29:42 +00005021 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005022 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005023 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005024
Douglas Gregor668d6d92009-12-13 20:44:55 +00005025 Args.push_back(Arg.release());
5026 }
5027
John McCall9ae2f072010-08-23 23:25:46 +00005028 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00005029 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00005030 E->getLocEnd());
5031 }
5032
5033#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5034 case OO_##Name:
5035#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5036#include "clang/Basic/OperatorKinds.def"
5037 case OO_Subscript:
5038 // Handled below.
5039 break;
5040
5041 case OO_Conditional:
5042 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00005043 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005044
5045 case OO_None:
5046 case NUM_OVERLOADED_OPERATORS:
5047 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00005048 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005049 }
5050
John McCall60d7b3a2010-08-24 06:29:42 +00005051 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005052 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005053 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005054
John McCall60d7b3a2010-08-24 06:29:42 +00005055 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005056 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005057 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005058
John McCall60d7b3a2010-08-24 06:29:42 +00005059 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005060 if (E->getNumArgs() == 2) {
5061 Second = getDerived().TransformExpr(E->getArg(1));
5062 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005063 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005064 }
Mike Stump1eb44332009-09-09 15:08:12 +00005065
Douglas Gregorb98b1992009-08-11 05:31:07 +00005066 if (!getDerived().AlwaysRebuild() &&
5067 Callee.get() == E->getCallee() &&
5068 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005069 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00005070 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005071
Douglas Gregorb98b1992009-08-11 05:31:07 +00005072 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5073 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005074 Callee.get(),
5075 First.get(),
5076 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005077}
Mike Stump1eb44332009-09-09 15:08:12 +00005078
Douglas Gregorb98b1992009-08-11 05:31:07 +00005079template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005080ExprResult
John McCall454feb92009-12-08 09:21:05 +00005081TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5082 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005083}
Mike Stump1eb44332009-09-09 15:08:12 +00005084
Douglas Gregorb98b1992009-08-11 05:31:07 +00005085template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005086ExprResult
John McCall454feb92009-12-08 09:21:05 +00005087TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005088 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5089 if (!Type)
5090 return ExprError();
5091
John McCall60d7b3a2010-08-24 06:29:42 +00005092 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005093 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005094 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005095 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005096
Douglas Gregorb98b1992009-08-11 05:31:07 +00005097 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005098 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005099 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005100 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005101
Douglas Gregorb98b1992009-08-11 05:31:07 +00005102 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005103 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005104 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5105 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5106 SourceLocation FakeRParenLoc
5107 = SemaRef.PP.getLocForEndOfToken(
5108 E->getSubExpr()->getSourceRange().getEnd());
5109 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005110 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005111 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005112 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005113 FakeRAngleLoc,
5114 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005115 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005116 FakeRParenLoc);
5117}
Mike Stump1eb44332009-09-09 15:08:12 +00005118
Douglas Gregorb98b1992009-08-11 05:31:07 +00005119template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005120ExprResult
John McCall454feb92009-12-08 09:21:05 +00005121TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5122 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005123}
Mike Stump1eb44332009-09-09 15:08:12 +00005124
5125template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005126ExprResult
John McCall454feb92009-12-08 09:21:05 +00005127TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5128 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005129}
5130
Douglas Gregorb98b1992009-08-11 05:31:07 +00005131template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005132ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005133TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005134 CXXReinterpretCastExpr *E) {
5135 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005136}
Mike Stump1eb44332009-09-09 15:08:12 +00005137
Douglas Gregorb98b1992009-08-11 05:31:07 +00005138template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005139ExprResult
John McCall454feb92009-12-08 09:21:05 +00005140TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5141 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005142}
Mike Stump1eb44332009-09-09 15:08:12 +00005143
Douglas Gregorb98b1992009-08-11 05:31:07 +00005144template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005145ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005146TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005147 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005148 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5149 if (!Type)
5150 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005151
John McCall60d7b3a2010-08-24 06:29:42 +00005152 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005153 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005154 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005155 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005156
Douglas Gregorb98b1992009-08-11 05:31:07 +00005157 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005158 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005159 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005160 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005161
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005162 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005163 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005164 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005165 E->getRParenLoc());
5166}
Mike Stump1eb44332009-09-09 15:08:12 +00005167
Douglas Gregorb98b1992009-08-11 05:31:07 +00005168template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005169ExprResult
John McCall454feb92009-12-08 09:21:05 +00005170TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005171 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005172 TypeSourceInfo *TInfo
5173 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5174 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005175 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005176
Douglas Gregorb98b1992009-08-11 05:31:07 +00005177 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005178 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005179 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005180
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005181 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5182 E->getLocStart(),
5183 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005184 E->getLocEnd());
5185 }
Mike Stump1eb44332009-09-09 15:08:12 +00005186
Douglas Gregorb98b1992009-08-11 05:31:07 +00005187 // We don't know whether the expression is potentially evaluated until
5188 // after we perform semantic analysis, so the expression is potentially
5189 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005190 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00005191 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005192
John McCall60d7b3a2010-08-24 06:29:42 +00005193 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005194 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005195 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005196
Douglas Gregorb98b1992009-08-11 05:31:07 +00005197 if (!getDerived().AlwaysRebuild() &&
5198 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005199 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005200
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005201 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5202 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005203 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005204 E->getLocEnd());
5205}
5206
5207template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005208ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00005209TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5210 if (E->isTypeOperand()) {
5211 TypeSourceInfo *TInfo
5212 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5213 if (!TInfo)
5214 return ExprError();
5215
5216 if (!getDerived().AlwaysRebuild() &&
5217 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005218 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005219
5220 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5221 E->getLocStart(),
5222 TInfo,
5223 E->getLocEnd());
5224 }
5225
5226 // We don't know whether the expression is potentially evaluated until
5227 // after we perform semantic analysis, so the expression is potentially
5228 // potentially evaluated.
5229 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5230
5231 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5232 if (SubExpr.isInvalid())
5233 return ExprError();
5234
5235 if (!getDerived().AlwaysRebuild() &&
5236 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005237 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005238
5239 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5240 E->getLocStart(),
5241 SubExpr.get(),
5242 E->getLocEnd());
5243}
5244
5245template<typename Derived>
5246ExprResult
John McCall454feb92009-12-08 09:21:05 +00005247TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005248 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005249}
Mike Stump1eb44332009-09-09 15:08:12 +00005250
Douglas Gregorb98b1992009-08-11 05:31:07 +00005251template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005252ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005253TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005254 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005255 return SemaRef.Owned(E);
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
John McCall454feb92009-12-08 09:21:05 +00005260TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005261 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5262 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5263 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00005264
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005265 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005266 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005267
Douglas Gregor828a1972010-01-07 23:12:05 +00005268 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005269}
Mike Stump1eb44332009-09-09 15:08:12 +00005270
Douglas Gregorb98b1992009-08-11 05:31:07 +00005271template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005272ExprResult
John McCall454feb92009-12-08 09:21:05 +00005273TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005274 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005275 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005276 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005277
Douglas Gregorb98b1992009-08-11 05:31:07 +00005278 if (!getDerived().AlwaysRebuild() &&
5279 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005280 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005281
John McCall9ae2f072010-08-23 23:25:46 +00005282 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005283}
Mike Stump1eb44332009-09-09 15:08:12 +00005284
Douglas Gregorb98b1992009-08-11 05:31:07 +00005285template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005286ExprResult
John McCall454feb92009-12-08 09:21:05 +00005287TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005288 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005289 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5290 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005291 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00005292 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005293
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005294 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005295 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00005296 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005297
Douglas Gregor036aed12009-12-23 23:03:06 +00005298 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005299}
Mike Stump1eb44332009-09-09 15:08:12 +00005300
Douglas Gregorb98b1992009-08-11 05:31:07 +00005301template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005302ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00005303TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5304 CXXScalarValueInitExpr *E) {
5305 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5306 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005307 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00005308
Douglas Gregorb98b1992009-08-11 05:31:07 +00005309 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005310 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005311 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005312
Douglas Gregorab6677e2010-09-08 00:15:04 +00005313 return getDerived().RebuildCXXScalarValueInitExpr(T,
5314 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00005315 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005316}
Mike Stump1eb44332009-09-09 15:08:12 +00005317
Douglas Gregorb98b1992009-08-11 05:31:07 +00005318template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005319ExprResult
John McCall454feb92009-12-08 09:21:05 +00005320TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005321 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005322 TypeSourceInfo *AllocTypeInfo
5323 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5324 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005325 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005326
Douglas Gregorb98b1992009-08-11 05:31:07 +00005327 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00005328 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005329 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005330 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005331
Douglas Gregorb98b1992009-08-11 05:31:07 +00005332 // Transform the placement arguments (if any).
5333 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005334 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005335 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall63d5fb32010-10-05 22:36:42 +00005336 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5337 ArgumentChanged = true;
5338 break;
5339 }
5340
John McCall60d7b3a2010-08-24 06:29:42 +00005341 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005342 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005343 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005344
Douglas Gregorb98b1992009-08-11 05:31:07 +00005345 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5346 PlacementArgs.push_back(Arg.take());
5347 }
Mike Stump1eb44332009-09-09 15:08:12 +00005348
Douglas Gregor43959a92009-08-20 07:17:43 +00005349 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00005350 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005351 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall63d5fb32010-10-05 22:36:42 +00005352 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5353 ArgumentChanged = true;
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005354 break;
John McCall63d5fb32010-10-05 22:36:42 +00005355 }
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005356
John McCall60d7b3a2010-08-24 06:29:42 +00005357 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005358 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005359 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005360
Douglas Gregorb98b1992009-08-11 05:31:07 +00005361 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5362 ConstructorArgs.push_back(Arg.take());
5363 }
Mike Stump1eb44332009-09-09 15:08:12 +00005364
Douglas Gregor1af74512010-02-26 00:38:10 +00005365 // Transform constructor, new operator, and delete operator.
5366 CXXConstructorDecl *Constructor = 0;
5367 if (E->getConstructor()) {
5368 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005369 getDerived().TransformDecl(E->getLocStart(),
5370 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005371 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005372 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005373 }
5374
5375 FunctionDecl *OperatorNew = 0;
5376 if (E->getOperatorNew()) {
5377 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005378 getDerived().TransformDecl(E->getLocStart(),
5379 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005380 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00005381 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005382 }
5383
5384 FunctionDecl *OperatorDelete = 0;
5385 if (E->getOperatorDelete()) {
5386 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005387 getDerived().TransformDecl(E->getLocStart(),
5388 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005389 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005390 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005391 }
Sean Huntc3021132010-05-05 15:23:54 +00005392
Douglas Gregorb98b1992009-08-11 05:31:07 +00005393 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005394 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005395 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005396 Constructor == E->getConstructor() &&
5397 OperatorNew == E->getOperatorNew() &&
5398 OperatorDelete == E->getOperatorDelete() &&
5399 !ArgumentChanged) {
5400 // Mark any declarations we need as referenced.
5401 // FIXME: instantiation-specific.
5402 if (Constructor)
5403 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5404 if (OperatorNew)
5405 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5406 if (OperatorDelete)
5407 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00005408 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00005409 }
Mike Stump1eb44332009-09-09 15:08:12 +00005410
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005411 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005412 if (!ArraySize.get()) {
5413 // If no array size was specified, but the new expression was
5414 // instantiated with an array type (e.g., "new T" where T is
5415 // instantiated with "int[4]"), extract the outer bound from the
5416 // array type as our array size. We do this with constant and
5417 // dependently-sized array types.
5418 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5419 if (!ArrayT) {
5420 // Do nothing
5421 } else if (const ConstantArrayType *ConsArrayT
5422 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005423 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00005424 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5425 ConsArrayT->getSize(),
5426 SemaRef.Context.getSizeType(),
5427 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005428 AllocType = ConsArrayT->getElementType();
5429 } else if (const DependentSizedArrayType *DepArrayT
5430 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5431 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00005432 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005433 AllocType = DepArrayT->getElementType();
5434 }
5435 }
5436 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005437
Douglas Gregorb98b1992009-08-11 05:31:07 +00005438 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5439 E->isGlobalNew(),
5440 /*FIXME:*/E->getLocStart(),
5441 move_arg(PlacementArgs),
5442 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00005443 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005444 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005445 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00005446 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005447 /*FIXME:*/E->getLocStart(),
5448 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005449 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005450}
Mike Stump1eb44332009-09-09 15:08:12 +00005451
Douglas Gregorb98b1992009-08-11 05:31:07 +00005452template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005453ExprResult
John McCall454feb92009-12-08 09:21:05 +00005454TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005455 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005456 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005457 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005458
Douglas Gregor1af74512010-02-26 00:38:10 +00005459 // Transform the delete operator, if known.
5460 FunctionDecl *OperatorDelete = 0;
5461 if (E->getOperatorDelete()) {
5462 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005463 getDerived().TransformDecl(E->getLocStart(),
5464 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005465 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005466 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005467 }
Sean Huntc3021132010-05-05 15:23:54 +00005468
Douglas Gregorb98b1992009-08-11 05:31:07 +00005469 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005470 Operand.get() == E->getArgument() &&
5471 OperatorDelete == E->getOperatorDelete()) {
5472 // Mark any declarations we need as referenced.
5473 // FIXME: instantiation-specific.
5474 if (OperatorDelete)
5475 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00005476
5477 if (!E->getArgument()->isTypeDependent()) {
5478 QualType Destroyed = SemaRef.Context.getBaseElementType(
5479 E->getDestroyedType());
5480 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5481 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5482 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5483 SemaRef.LookupDestructor(Record));
5484 }
5485 }
5486
John McCall3fa5cae2010-10-26 07:05:15 +00005487 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00005488 }
Mike Stump1eb44332009-09-09 15:08:12 +00005489
Douglas Gregorb98b1992009-08-11 05:31:07 +00005490 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5491 E->isGlobalDelete(),
5492 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00005493 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005494}
Mike Stump1eb44332009-09-09 15:08:12 +00005495
Douglas Gregorb98b1992009-08-11 05:31:07 +00005496template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005497ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005498TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005499 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005500 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00005501 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005502 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005503
John McCallb3d87482010-08-24 05:47:05 +00005504 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005505 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005506 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005507 E->getOperatorLoc(),
5508 E->isArrow()? tok::arrow : tok::period,
5509 ObjectTypePtr,
5510 MayBePseudoDestructor);
5511 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005512 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005513
John McCallb3d87482010-08-24 05:47:05 +00005514 QualType ObjectType = ObjectTypePtr.get();
John McCall43fed0d2010-11-12 08:19:04 +00005515 NestedNameSpecifier *Qualifier = E->getQualifier();
5516 if (Qualifier) {
5517 Qualifier
5518 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5519 E->getQualifierRange(),
5520 ObjectType);
5521 if (!Qualifier)
5522 return ExprError();
5523 }
Mike Stump1eb44332009-09-09 15:08:12 +00005524
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005525 PseudoDestructorTypeStorage Destroyed;
5526 if (E->getDestroyedTypeInfo()) {
5527 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00005528 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5529 ObjectType, 0, Qualifier);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005530 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005531 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005532 Destroyed = DestroyedTypeInfo;
5533 } else if (ObjectType->isDependentType()) {
5534 // We aren't likely to be able to resolve the identifier down to a type
5535 // now anyway, so just retain the identifier.
5536 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5537 E->getDestroyedTypeLoc());
5538 } else {
5539 // Look for a destructor known with the given name.
5540 CXXScopeSpec SS;
5541 if (Qualifier) {
5542 SS.setScopeRep(Qualifier);
5543 SS.setRange(E->getQualifierRange());
5544 }
Sean Huntc3021132010-05-05 15:23:54 +00005545
John McCallb3d87482010-08-24 05:47:05 +00005546 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005547 *E->getDestroyedTypeIdentifier(),
5548 E->getDestroyedTypeLoc(),
5549 /*Scope=*/0,
5550 SS, ObjectTypePtr,
5551 false);
5552 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005553 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005554
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005555 Destroyed
5556 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5557 E->getDestroyedTypeLoc());
5558 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005559
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005560 TypeSourceInfo *ScopeTypeInfo = 0;
5561 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00005562 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005563 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005564 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00005565 }
Sean Huntc3021132010-05-05 15:23:54 +00005566
John McCall9ae2f072010-08-23 23:25:46 +00005567 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005568 E->getOperatorLoc(),
5569 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005570 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005571 E->getQualifierRange(),
5572 ScopeTypeInfo,
5573 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005574 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005575 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005576}
Mike Stump1eb44332009-09-09 15:08:12 +00005577
Douglas Gregora71d8192009-09-04 17:36:40 +00005578template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005579ExprResult
John McCallba135432009-11-21 08:51:07 +00005580TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005581 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005582 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5583
5584 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5585 Sema::LookupOrdinaryName);
5586
5587 // Transform all the decls.
5588 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5589 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005590 NamedDecl *InstD = static_cast<NamedDecl*>(
5591 getDerived().TransformDecl(Old->getNameLoc(),
5592 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005593 if (!InstD) {
5594 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5595 // This can happen because of dependent hiding.
5596 if (isa<UsingShadowDecl>(*I))
5597 continue;
5598 else
John McCallf312b1e2010-08-26 23:41:50 +00005599 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005600 }
John McCallf7a1a742009-11-24 19:00:30 +00005601
5602 // Expand using declarations.
5603 if (isa<UsingDecl>(InstD)) {
5604 UsingDecl *UD = cast<UsingDecl>(InstD);
5605 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5606 E = UD->shadow_end(); I != E; ++I)
5607 R.addDecl(*I);
5608 continue;
5609 }
5610
5611 R.addDecl(InstD);
5612 }
5613
5614 // Resolve a kind, but don't do any further analysis. If it's
5615 // ambiguous, the callee needs to deal with it.
5616 R.resolveKind();
5617
5618 // Rebuild the nested-name qualifier, if present.
5619 CXXScopeSpec SS;
5620 NestedNameSpecifier *Qualifier = 0;
5621 if (Old->getQualifier()) {
5622 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005623 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005624 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005625 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005626
John McCallf7a1a742009-11-24 19:00:30 +00005627 SS.setScopeRep(Qualifier);
5628 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005629 }
5630
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005631 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005632 CXXRecordDecl *NamingClass
5633 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5634 Old->getNameLoc(),
5635 Old->getNamingClass()));
5636 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00005637 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005638
Douglas Gregor66c45152010-04-27 16:10:10 +00005639 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005640 }
5641
5642 // If we have no template arguments, it's a normal declaration name.
5643 if (!Old->hasExplicitTemplateArgs())
5644 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5645
5646 // If we have template arguments, rebuild them, then rebuild the
5647 // templateid expression.
5648 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5649 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5650 TemplateArgumentLoc Loc;
5651 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005652 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00005653 TransArgs.addArgument(Loc);
5654 }
5655
5656 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5657 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005658}
Mike Stump1eb44332009-09-09 15:08:12 +00005659
Douglas Gregorb98b1992009-08-11 05:31:07 +00005660template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005661ExprResult
John McCall454feb92009-12-08 09:21:05 +00005662TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005663 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5664 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005665 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005666
Douglas Gregorb98b1992009-08-11 05:31:07 +00005667 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005668 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005669 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005670
Mike Stump1eb44332009-09-09 15:08:12 +00005671 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005672 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005673 T,
5674 E->getLocEnd());
5675}
Mike Stump1eb44332009-09-09 15:08:12 +00005676
Douglas Gregorb98b1992009-08-11 05:31:07 +00005677template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005678ExprResult
John McCall865d4472009-11-19 22:55:06 +00005679TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005680 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005681 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005682 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005683 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005684 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00005685 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005686
John McCall43fed0d2010-11-12 08:19:04 +00005687 // TODO: If this is a conversion-function-id, verify that the
5688 // destination type name (if present) resolves the same way after
5689 // instantiation as it did in the local scope.
5690
Abramo Bagnara25777432010-08-11 22:01:17 +00005691 DeclarationNameInfo NameInfo
5692 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5693 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005694 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005695
John McCallf7a1a742009-11-24 19:00:30 +00005696 if (!E->hasExplicitTemplateArgs()) {
5697 if (!getDerived().AlwaysRebuild() &&
5698 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005699 // Note: it is sufficient to compare the Name component of NameInfo:
5700 // if name has not changed, DNLoc has not changed either.
5701 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00005702 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005703
John McCallf7a1a742009-11-24 19:00:30 +00005704 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5705 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005706 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005707 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005708 }
John McCalld5532b62009-11-23 01:53:49 +00005709
5710 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005711 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005712 TemplateArgumentLoc Loc;
5713 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005714 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005715 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005716 }
5717
John McCallf7a1a742009-11-24 19:00:30 +00005718 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5719 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005720 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005721 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005722}
5723
5724template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005725ExprResult
John McCall454feb92009-12-08 09:21:05 +00005726TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005727 // CXXConstructExprs are always implicit, so when we have a
5728 // 1-argument construction we just transform that argument.
5729 if (E->getNumArgs() == 1 ||
5730 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5731 return getDerived().TransformExpr(E->getArg(0));
5732
Douglas Gregorb98b1992009-08-11 05:31:07 +00005733 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5734
5735 QualType T = getDerived().TransformType(E->getType());
5736 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005737 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005738
5739 CXXConstructorDecl *Constructor
5740 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005741 getDerived().TransformDecl(E->getLocStart(),
5742 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005743 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005744 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005745
Douglas Gregorb98b1992009-08-11 05:31:07 +00005746 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005747 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005748 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005749 ArgEnd = E->arg_end();
5750 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005751 if (getDerived().DropCallArgument(*Arg)) {
5752 ArgumentChanged = true;
5753 break;
5754 }
5755
John McCall60d7b3a2010-08-24 06:29:42 +00005756 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005757 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005758 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005759
Douglas Gregorb98b1992009-08-11 05:31:07 +00005760 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005761 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005762 }
5763
5764 if (!getDerived().AlwaysRebuild() &&
5765 T == E->getType() &&
5766 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005767 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005768 // Mark the constructor as referenced.
5769 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005770 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00005771 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00005772 }
Mike Stump1eb44332009-09-09 15:08:12 +00005773
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005774 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5775 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00005776 move_arg(Args),
5777 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00005778 E->getConstructionKind(),
5779 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005780}
Mike Stump1eb44332009-09-09 15:08:12 +00005781
Douglas Gregorb98b1992009-08-11 05:31:07 +00005782/// \brief Transform a C++ temporary-binding expression.
5783///
Douglas Gregor51326552009-12-24 18:51:59 +00005784/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5785/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005786template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005787ExprResult
John McCall454feb92009-12-08 09:21:05 +00005788TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005789 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005790}
Mike Stump1eb44332009-09-09 15:08:12 +00005791
5792/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005793/// be destroyed after the expression is evaluated.
5794///
Douglas Gregor51326552009-12-24 18:51:59 +00005795/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5796/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005797template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005798ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005799TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005800 CXXExprWithTemporaries *E) {
5801 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005802}
Mike Stump1eb44332009-09-09 15:08:12 +00005803
Douglas Gregorb98b1992009-08-11 05:31:07 +00005804template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005805ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005806TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00005807 CXXTemporaryObjectExpr *E) {
5808 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5809 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005810 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005811
Douglas Gregorb98b1992009-08-11 05:31:07 +00005812 CXXConstructorDecl *Constructor
5813 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005814 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005815 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005816 if (!Constructor)
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 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005820 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005821 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005822 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005823 ArgEnd = E->arg_end();
5824 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005825 if (getDerived().DropCallArgument(*Arg)) {
5826 ArgumentChanged = true;
5827 break;
5828 }
5829
John McCall60d7b3a2010-08-24 06:29:42 +00005830 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005831 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005832 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005833
Douglas Gregorb98b1992009-08-11 05:31:07 +00005834 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5835 Args.push_back((Expr *)TransArg.release());
5836 }
Mike Stump1eb44332009-09-09 15:08:12 +00005837
Douglas Gregorb98b1992009-08-11 05:31:07 +00005838 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005839 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005840 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005841 !ArgumentChanged) {
5842 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00005843 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00005844 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00005845 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00005846
5847 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5848 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005849 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005850 E->getLocEnd());
5851}
Mike Stump1eb44332009-09-09 15:08:12 +00005852
Douglas Gregorb98b1992009-08-11 05:31:07 +00005853template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005854ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005855TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005856 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00005857 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5858 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005859 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005860
Douglas Gregorb98b1992009-08-11 05:31:07 +00005861 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005862 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005863 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5864 ArgEnd = E->arg_end();
5865 Arg != ArgEnd; ++Arg) {
John McCall60d7b3a2010-08-24 06:29:42 +00005866 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005867 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005868 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005869
Douglas Gregorb98b1992009-08-11 05:31:07 +00005870 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005871 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005872 }
Mike Stump1eb44332009-09-09 15:08:12 +00005873
Douglas Gregorb98b1992009-08-11 05:31:07 +00005874 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005875 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005876 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005877 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005878
Douglas Gregorb98b1992009-08-11 05:31:07 +00005879 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00005880 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005881 E->getLParenLoc(),
5882 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005883 E->getRParenLoc());
5884}
Mike Stump1eb44332009-09-09 15:08:12 +00005885
Douglas Gregorb98b1992009-08-11 05:31:07 +00005886template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005887ExprResult
John McCall865d4472009-11-19 22:55:06 +00005888TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005889 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005890 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005891 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005892 Expr *OldBase;
5893 QualType BaseType;
5894 QualType ObjectType;
5895 if (!E->isImplicitAccess()) {
5896 OldBase = E->getBase();
5897 Base = getDerived().TransformExpr(OldBase);
5898 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005899 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005900
John McCallaa81e162009-12-01 22:10:20 +00005901 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00005902 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00005903 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005904 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005905 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005906 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005907 ObjectTy,
5908 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005909 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005910 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005911
John McCallb3d87482010-08-24 05:47:05 +00005912 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00005913 BaseType = ((Expr*) Base.get())->getType();
5914 } else {
5915 OldBase = 0;
5916 BaseType = getDerived().TransformType(E->getBaseType());
5917 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5918 }
Mike Stump1eb44332009-09-09 15:08:12 +00005919
Douglas Gregor6cd21982009-10-20 05:58:46 +00005920 // Transform the first part of the nested-name-specifier that qualifies
5921 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005922 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005923 = getDerived().TransformFirstQualifierInScope(
5924 E->getFirstQualifierFoundInScope(),
5925 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005926
Douglas Gregora38c6872009-09-03 16:14:30 +00005927 NestedNameSpecifier *Qualifier = 0;
5928 if (E->getQualifier()) {
5929 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5930 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005931 ObjectType,
5932 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005933 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005934 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00005935 }
Mike Stump1eb44332009-09-09 15:08:12 +00005936
John McCall43fed0d2010-11-12 08:19:04 +00005937 // TODO: If this is a conversion-function-id, verify that the
5938 // destination type name (if present) resolves the same way after
5939 // instantiation as it did in the local scope.
5940
Abramo Bagnara25777432010-08-11 22:01:17 +00005941 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00005942 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00005943 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005944 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005945
John McCallaa81e162009-12-01 22:10:20 +00005946 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005947 // This is a reference to a member without an explicitly-specified
5948 // template argument list. Optimize for this common case.
5949 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005950 Base.get() == OldBase &&
5951 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005952 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005953 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005954 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00005955 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005956
John McCall9ae2f072010-08-23 23:25:46 +00005957 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005958 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005959 E->isArrow(),
5960 E->getOperatorLoc(),
5961 Qualifier,
5962 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005963 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005964 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005965 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005966 }
5967
John McCalld5532b62009-11-23 01:53:49 +00005968 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005969 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005970 TemplateArgumentLoc Loc;
5971 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005972 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005973 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005974 }
Mike Stump1eb44332009-09-09 15:08:12 +00005975
John McCall9ae2f072010-08-23 23:25:46 +00005976 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005977 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005978 E->isArrow(),
5979 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005980 Qualifier,
5981 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005982 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005983 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005984 &TransArgs);
5985}
5986
5987template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005988ExprResult
John McCall454feb92009-12-08 09:21:05 +00005989TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005990 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005991 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005992 QualType BaseType;
5993 if (!Old->isImplicitAccess()) {
5994 Base = getDerived().TransformExpr(Old->getBase());
5995 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005996 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005997 BaseType = ((Expr*) Base.get())->getType();
5998 } else {
5999 BaseType = getDerived().TransformType(Old->getBaseType());
6000 }
John McCall129e2df2009-11-30 22:42:35 +00006001
6002 NestedNameSpecifier *Qualifier = 0;
6003 if (Old->getQualifier()) {
6004 Qualifier
6005 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006006 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00006007 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00006008 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006009 }
6010
Abramo Bagnara25777432010-08-11 22:01:17 +00006011 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00006012 Sema::LookupOrdinaryName);
6013
6014 // Transform all the decls.
6015 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6016 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006017 NamedDecl *InstD = static_cast<NamedDecl*>(
6018 getDerived().TransformDecl(Old->getMemberLoc(),
6019 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006020 if (!InstD) {
6021 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6022 // This can happen because of dependent hiding.
6023 if (isa<UsingShadowDecl>(*I))
6024 continue;
6025 else
John McCallf312b1e2010-08-26 23:41:50 +00006026 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006027 }
John McCall129e2df2009-11-30 22:42:35 +00006028
6029 // Expand using declarations.
6030 if (isa<UsingDecl>(InstD)) {
6031 UsingDecl *UD = cast<UsingDecl>(InstD);
6032 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6033 E = UD->shadow_end(); I != E; ++I)
6034 R.addDecl(*I);
6035 continue;
6036 }
6037
6038 R.addDecl(InstD);
6039 }
6040
6041 R.resolveKind();
6042
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006043 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00006044 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00006045 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006046 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00006047 Old->getMemberLoc(),
6048 Old->getNamingClass()));
6049 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006050 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006051
Douglas Gregor66c45152010-04-27 16:10:10 +00006052 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006053 }
Sean Huntc3021132010-05-05 15:23:54 +00006054
John McCall129e2df2009-11-30 22:42:35 +00006055 TemplateArgumentListInfo TransArgs;
6056 if (Old->hasExplicitTemplateArgs()) {
6057 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6058 TransArgs.setRAngleLoc(Old->getRAngleLoc());
6059 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6060 TemplateArgumentLoc Loc;
6061 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6062 Loc))
John McCallf312b1e2010-08-26 23:41:50 +00006063 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006064 TransArgs.addArgument(Loc);
6065 }
6066 }
John McCallc2233c52010-01-15 08:34:02 +00006067
6068 // FIXME: to do this check properly, we will need to preserve the
6069 // first-qualifier-in-scope here, just in case we had a dependent
6070 // base (and therefore couldn't do the check) and a
6071 // nested-name-qualifier (and therefore could do the lookup).
6072 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006073
John McCall9ae2f072010-08-23 23:25:46 +00006074 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006075 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006076 Old->getOperatorLoc(),
6077 Old->isArrow(),
6078 Qualifier,
6079 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006080 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006081 R,
6082 (Old->hasExplicitTemplateArgs()
6083 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006084}
6085
6086template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006087ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006088TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6089 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6090 if (SubExpr.isInvalid())
6091 return ExprError();
6092
6093 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006094 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00006095
6096 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6097}
6098
6099template<typename Derived>
6100ExprResult
John McCall454feb92009-12-08 09:21:05 +00006101TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006102 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006103}
6104
Mike Stump1eb44332009-09-09 15:08:12 +00006105template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006106ExprResult
John McCall454feb92009-12-08 09:21:05 +00006107TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006108 TypeSourceInfo *EncodedTypeInfo
6109 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6110 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006111 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006112
Douglas Gregorb98b1992009-08-11 05:31:07 +00006113 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006114 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006115 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006116
6117 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006118 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006119 E->getRParenLoc());
6120}
Mike Stump1eb44332009-09-09 15:08:12 +00006121
Douglas Gregorb98b1992009-08-11 05:31:07 +00006122template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006123ExprResult
John McCall454feb92009-12-08 09:21:05 +00006124TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006125 // Transform arguments.
6126 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006127 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006128 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006129 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor92e986e2010-04-22 16:44:27 +00006130 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006131 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006132
Douglas Gregor92e986e2010-04-22 16:44:27 +00006133 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00006134 Args.push_back(Arg.get());
Douglas Gregor92e986e2010-04-22 16:44:27 +00006135 }
6136
6137 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6138 // Class message: transform the receiver type.
6139 TypeSourceInfo *ReceiverTypeInfo
6140 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6141 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006142 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006143
Douglas Gregor92e986e2010-04-22 16:44:27 +00006144 // If nothing changed, just retain the existing message send.
6145 if (!getDerived().AlwaysRebuild() &&
6146 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006147 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006148
6149 // Build a new class message send.
6150 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6151 E->getSelector(),
6152 E->getMethodDecl(),
6153 E->getLeftLoc(),
6154 move_arg(Args),
6155 E->getRightLoc());
6156 }
6157
6158 // Instance message: transform the receiver
6159 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6160 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006161 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006162 = getDerived().TransformExpr(E->getInstanceReceiver());
6163 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006164 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006165
6166 // If nothing changed, just retain the existing message send.
6167 if (!getDerived().AlwaysRebuild() &&
6168 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006169 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006170
Douglas Gregor92e986e2010-04-22 16:44:27 +00006171 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006172 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006173 E->getSelector(),
6174 E->getMethodDecl(),
6175 E->getLeftLoc(),
6176 move_arg(Args),
6177 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006178}
6179
Mike Stump1eb44332009-09-09 15:08:12 +00006180template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006181ExprResult
John McCall454feb92009-12-08 09:21:05 +00006182TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006183 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006184}
6185
Mike Stump1eb44332009-09-09 15:08:12 +00006186template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006187ExprResult
John McCall454feb92009-12-08 09:21:05 +00006188TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006189 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006190}
6191
Mike Stump1eb44332009-09-09 15:08:12 +00006192template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006193ExprResult
John McCall454feb92009-12-08 09:21:05 +00006194TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006195 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006196 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006197 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006198 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006199
6200 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006201
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006202 // If nothing changed, just retain the existing expression.
6203 if (!getDerived().AlwaysRebuild() &&
6204 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006205 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006206
John McCall9ae2f072010-08-23 23:25:46 +00006207 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006208 E->getLocation(),
6209 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006210}
6211
Mike Stump1eb44332009-09-09 15:08:12 +00006212template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006213ExprResult
John McCall454feb92009-12-08 09:21:05 +00006214TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006215 // 'super' never changes. Property never changes. Just retain the existing
6216 // expression.
6217 if (E->isSuperReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00006218 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006219
Douglas Gregore3303542010-04-26 20:47:02 +00006220 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006221 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00006222 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006223 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006224
Douglas Gregore3303542010-04-26 20:47:02 +00006225 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006226
Douglas Gregore3303542010-04-26 20:47:02 +00006227 // If nothing changed, just retain the existing expression.
6228 if (!getDerived().AlwaysRebuild() &&
6229 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006230 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006231
John McCall9ae2f072010-08-23 23:25:46 +00006232 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregore3303542010-04-26 20:47:02 +00006233 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006234}
6235
Mike Stump1eb44332009-09-09 15:08:12 +00006236template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006237ExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00006238TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00006239 ObjCImplicitSetterGetterRefExpr *E) {
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006240 // If this implicit setter/getter refers to super, it cannot have any
6241 // dependent parts. Just retain the existing declaration.
6242 if (E->isSuperReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00006243 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006244
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006245 // If this implicit setter/getter refers to class methods, it cannot have any
6246 // dependent parts. Just retain the existing declaration.
6247 if (E->getInterfaceDecl())
John McCall3fa5cae2010-10-26 07:05:15 +00006248 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006249
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006250 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006251 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006252 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006253 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006254
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006255 // We don't need to transform the getters/setters; they will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006256
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006257 // If nothing changed, just retain the existing expression.
6258 if (!getDerived().AlwaysRebuild() &&
6259 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006260 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006261
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006262 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6263 E->getGetterMethod(),
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006264 E->getType(),
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006265 E->getSetterMethod(),
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006266 E->getLocation(),
6267 Base.get(),
6268 E->getSuperLocation(),
6269 E->getSuperType(),
6270 E->isSuperReceiver());
Sean Huntc3021132010-05-05 15:23:54 +00006271
Douglas Gregorb98b1992009-08-11 05:31:07 +00006272}
6273
Mike Stump1eb44332009-09-09 15:08:12 +00006274template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006275ExprResult
John McCall454feb92009-12-08 09:21:05 +00006276TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006277 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006278 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006279 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006280 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006281
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006282 // If nothing changed, just retain the existing expression.
6283 if (!getDerived().AlwaysRebuild() &&
6284 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006285 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006286
John McCall9ae2f072010-08-23 23:25:46 +00006287 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006288 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006289}
6290
Mike Stump1eb44332009-09-09 15:08:12 +00006291template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006292ExprResult
John McCall454feb92009-12-08 09:21:05 +00006293TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006294 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006295 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006296 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006297 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006298 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006299 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006300
Douglas Gregorb98b1992009-08-11 05:31:07 +00006301 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00006302 SubExprs.push_back(SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006303 }
Mike Stump1eb44332009-09-09 15:08:12 +00006304
Douglas Gregorb98b1992009-08-11 05:31:07 +00006305 if (!getDerived().AlwaysRebuild() &&
6306 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006307 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006308
Douglas Gregorb98b1992009-08-11 05:31:07 +00006309 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6310 move_arg(SubExprs),
6311 E->getRParenLoc());
6312}
6313
Mike Stump1eb44332009-09-09 15:08:12 +00006314template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006315ExprResult
John McCall454feb92009-12-08 09:21:05 +00006316TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006317 SourceLocation CaretLoc(E->getExprLoc());
6318
6319 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6320 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6321 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6322 llvm::SmallVector<ParmVarDecl*, 4> Params;
6323 llvm::SmallVector<QualType, 4> ParamTypes;
6324
6325 // Parameter substitution.
6326 const BlockDecl *BD = E->getBlockDecl();
6327 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6328 EN = BD->param_end(); P != EN; ++P) {
6329 ParmVarDecl *OldParm = (*P);
6330 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6331 QualType NewType = NewParm->getType();
6332 Params.push_back(NewParm);
6333 ParamTypes.push_back(NewParm->getType());
6334 }
6335
6336 const FunctionType *BExprFunctionType = E->getFunctionType();
6337 QualType BExprResultType = BExprFunctionType->getResultType();
6338 if (!BExprResultType.isNull()) {
6339 if (!BExprResultType->isDependentType())
6340 CurBlock->ReturnType = BExprResultType;
6341 else if (BExprResultType != SemaRef.Context.DependentTy)
6342 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6343 }
6344
6345 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00006346 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006347 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006348 return ExprError();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006349 // Set the parameters on the block decl.
6350 if (!Params.empty())
6351 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6352
6353 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6354 CurBlock->ReturnType,
6355 ParamTypes.data(),
6356 ParamTypes.size(),
6357 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006358 0,
6359 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006360
6361 CurBlock->FunctionType = FunctionType;
John McCall9ae2f072010-08-23 23:25:46 +00006362 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006363}
6364
Mike Stump1eb44332009-09-09 15:08:12 +00006365template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006366ExprResult
John McCall454feb92009-12-08 09:21:05 +00006367TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006368 NestedNameSpecifier *Qualifier = 0;
6369
6370 ValueDecl *ND
6371 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6372 E->getDecl()));
6373 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006374 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00006375
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006376 if (!getDerived().AlwaysRebuild() &&
6377 ND == E->getDecl()) {
6378 // Mark it referenced in the new context regardless.
6379 // FIXME: this is a bit instantiation-specific.
6380 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6381
John McCall3fa5cae2010-10-26 07:05:15 +00006382 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006383 }
6384
Abramo Bagnara25777432010-08-11 22:01:17 +00006385 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006386 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006387 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006388}
Mike Stump1eb44332009-09-09 15:08:12 +00006389
Douglas Gregorb98b1992009-08-11 05:31:07 +00006390//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006391// Type reconstruction
6392//===----------------------------------------------------------------------===//
6393
Mike Stump1eb44332009-09-09 15:08:12 +00006394template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006395QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6396 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006397 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006398 getDerived().getBaseEntity());
6399}
6400
Mike Stump1eb44332009-09-09 15:08:12 +00006401template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006402QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6403 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006404 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006405 getDerived().getBaseEntity());
6406}
6407
Mike Stump1eb44332009-09-09 15:08:12 +00006408template<typename Derived>
6409QualType
John McCall85737a72009-10-30 00:06:24 +00006410TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6411 bool WrittenAsLValue,
6412 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006413 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006414 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006415}
6416
6417template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006418QualType
John McCall85737a72009-10-30 00:06:24 +00006419TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6420 QualType ClassType,
6421 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006422 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006423 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006424}
6425
6426template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006427QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006428TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6429 ArrayType::ArraySizeModifier SizeMod,
6430 const llvm::APInt *Size,
6431 Expr *SizeExpr,
6432 unsigned IndexTypeQuals,
6433 SourceRange BracketsRange) {
6434 if (SizeExpr || !Size)
6435 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6436 IndexTypeQuals, BracketsRange,
6437 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006438
6439 QualType Types[] = {
6440 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6441 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6442 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006443 };
6444 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6445 QualType SizeType;
6446 for (unsigned I = 0; I != NumTypes; ++I)
6447 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6448 SizeType = Types[I];
6449 break;
6450 }
Mike Stump1eb44332009-09-09 15:08:12 +00006451
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006452 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6453 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006454 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006455 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006456 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006457}
Mike Stump1eb44332009-09-09 15:08:12 +00006458
Douglas Gregor577f75a2009-08-04 16:50:30 +00006459template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006460QualType
6461TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006462 ArrayType::ArraySizeModifier SizeMod,
6463 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006464 unsigned IndexTypeQuals,
6465 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006466 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006467 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006468}
6469
6470template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006471QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006472TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006473 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006474 unsigned IndexTypeQuals,
6475 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006476 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006477 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006478}
Mike Stump1eb44332009-09-09 15:08:12 +00006479
Douglas Gregor577f75a2009-08-04 16:50:30 +00006480template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006481QualType
6482TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006483 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006484 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006485 unsigned IndexTypeQuals,
6486 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006487 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006488 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006489 IndexTypeQuals, BracketsRange);
6490}
6491
6492template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006493QualType
6494TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006495 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006496 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006497 unsigned IndexTypeQuals,
6498 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006499 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006500 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006501 IndexTypeQuals, BracketsRange);
6502}
6503
6504template<typename Derived>
6505QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00006506 unsigned NumElements,
6507 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006508 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00006509 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006510}
Mike Stump1eb44332009-09-09 15:08:12 +00006511
Douglas Gregor577f75a2009-08-04 16:50:30 +00006512template<typename Derived>
6513QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6514 unsigned NumElements,
6515 SourceLocation AttributeLoc) {
6516 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6517 NumElements, true);
6518 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006519 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6520 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00006521 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006522}
Mike Stump1eb44332009-09-09 15:08:12 +00006523
Douglas Gregor577f75a2009-08-04 16:50:30 +00006524template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006525QualType
6526TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00006527 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006528 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00006529 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006530}
Mike Stump1eb44332009-09-09 15:08:12 +00006531
Douglas Gregor577f75a2009-08-04 16:50:30 +00006532template<typename Derived>
6533QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006534 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006535 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006536 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00006537 unsigned Quals,
6538 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00006539 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006540 Quals,
6541 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006542 getDerived().getBaseEntity(),
6543 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006544}
Mike Stump1eb44332009-09-09 15:08:12 +00006545
Douglas Gregor577f75a2009-08-04 16:50:30 +00006546template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006547QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6548 return SemaRef.Context.getFunctionNoProtoType(T);
6549}
6550
6551template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006552QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6553 assert(D && "no decl found");
6554 if (D->isInvalidDecl()) return QualType();
6555
Douglas Gregor92e986e2010-04-22 16:44:27 +00006556 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006557 TypeDecl *Ty;
6558 if (isa<UsingDecl>(D)) {
6559 UsingDecl *Using = cast<UsingDecl>(D);
6560 assert(Using->isTypeName() &&
6561 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6562
6563 // A valid resolved using typename decl points to exactly one type decl.
6564 assert(++Using->shadow_begin() == Using->shadow_end());
6565 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006566
John McCalled976492009-12-04 22:46:56 +00006567 } else {
6568 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6569 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6570 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6571 }
6572
6573 return SemaRef.Context.getTypeDeclType(Ty);
6574}
6575
6576template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00006577QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6578 SourceLocation Loc) {
6579 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006580}
6581
6582template<typename Derived>
6583QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6584 return SemaRef.Context.getTypeOfType(Underlying);
6585}
6586
6587template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00006588QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6589 SourceLocation Loc) {
6590 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006591}
6592
6593template<typename Derived>
6594QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006595 TemplateName Template,
6596 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006597 const TemplateArgumentListInfo &TemplateArgs) {
6598 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006599}
Mike Stump1eb44332009-09-09 15:08:12 +00006600
Douglas Gregordcee1a12009-08-06 05:28:30 +00006601template<typename Derived>
6602NestedNameSpecifier *
6603TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6604 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006605 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006606 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006607 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006608 CXXScopeSpec SS;
6609 // FIXME: The source location information is all wrong.
6610 SS.setRange(Range);
6611 SS.setScopeRep(Prefix);
6612 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006613 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006614 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006615 ObjectType,
6616 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006617 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006618}
6619
6620template<typename Derived>
6621NestedNameSpecifier *
6622TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6623 SourceRange Range,
6624 NamespaceDecl *NS) {
6625 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6626}
6627
6628template<typename Derived>
6629NestedNameSpecifier *
6630TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6631 SourceRange Range,
6632 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006633 QualType T) {
6634 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006635 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006636 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006637 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6638 T.getTypePtr());
6639 }
Mike Stump1eb44332009-09-09 15:08:12 +00006640
Douglas Gregordcee1a12009-08-06 05:28:30 +00006641 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6642 return 0;
6643}
Mike Stump1eb44332009-09-09 15:08:12 +00006644
Douglas Gregord1067e52009-08-06 06:41:21 +00006645template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006646TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006647TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6648 bool TemplateKW,
6649 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006650 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006651 Template);
6652}
6653
6654template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006655TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006656TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006657 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006658 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +00006659 QualType ObjectType,
6660 NamedDecl *FirstQualifierInScope) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006661 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006662 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00006663 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006664 UnqualifiedId Name;
6665 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00006666 Sema::TemplateTy Template;
6667 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6668 /*FIXME:*/getDerived().getBaseLocation(),
6669 SS,
6670 Name,
John McCallb3d87482010-08-24 05:47:05 +00006671 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006672 /*EnteringContext=*/false,
6673 Template);
John McCall43fed0d2010-11-12 08:19:04 +00006674 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00006675}
Mike Stump1eb44332009-09-09 15:08:12 +00006676
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006678TemplateName
6679TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6680 OverloadedOperatorKind Operator,
6681 QualType ObjectType) {
6682 CXXScopeSpec SS;
6683 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6684 SS.setScopeRep(Qualifier);
6685 UnqualifiedId Name;
6686 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6687 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6688 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00006689 Sema::TemplateTy Template;
6690 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006691 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006692 SS,
6693 Name,
John McCallb3d87482010-08-24 05:47:05 +00006694 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006695 /*EnteringContext=*/false,
6696 Template);
6697 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006698}
Sean Huntc3021132010-05-05 15:23:54 +00006699
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006700template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006701ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006702TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6703 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006704 Expr *OrigCallee,
6705 Expr *First,
6706 Expr *Second) {
6707 Expr *Callee = OrigCallee->IgnoreParenCasts();
6708 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006709
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006711 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00006712 if (!First->getType()->isOverloadableType() &&
6713 !Second->getType()->isOverloadableType())
6714 return getSema().CreateBuiltinArraySubscriptExpr(First,
6715 Callee->getLocStart(),
6716 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006717 } else if (Op == OO_Arrow) {
6718 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00006719 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6720 } else if (Second == 0 || isPostIncDec) {
6721 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722 // The argument is not of overloadable type, so try to create a
6723 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00006724 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006726
John McCall9ae2f072010-08-23 23:25:46 +00006727 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728 }
6729 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006730 if (!First->getType()->isOverloadableType() &&
6731 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006732 // Neither of the arguments is an overloadable type, so try to
6733 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00006734 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006735 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00006736 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006738 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006739
Douglas Gregorb98b1992009-08-11 05:31:07 +00006740 return move(Result);
6741 }
6742 }
Mike Stump1eb44332009-09-09 15:08:12 +00006743
6744 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006746 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006747
John McCall9ae2f072010-08-23 23:25:46 +00006748 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00006749 assert(ULE->requiresADL());
6750
6751 // FIXME: Do we have to check
6752 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006753 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006754 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006755 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006756 }
Mike Stump1eb44332009-09-09 15:08:12 +00006757
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00006759 Expr *Args[2] = { First, Second };
6760 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006761
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762 // Create the overloaded operator invocation for unary operators.
6763 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00006764 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006765 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00006766 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767 }
Mike Stump1eb44332009-09-09 15:08:12 +00006768
Sebastian Redlf322ed62009-10-29 20:17:01 +00006769 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00006770 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00006771 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006772 First,
6773 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006774
Douglas Gregorb98b1992009-08-11 05:31:07 +00006775 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00006776 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006777 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006778 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6779 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006780 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006781
Mike Stump1eb44332009-09-09 15:08:12 +00006782 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783}
Mike Stump1eb44332009-09-09 15:08:12 +00006784
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006785template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006786ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00006787TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006788 SourceLocation OperatorLoc,
6789 bool isArrow,
6790 NestedNameSpecifier *Qualifier,
6791 SourceRange QualifierRange,
6792 TypeSourceInfo *ScopeType,
6793 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006794 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006795 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006796 CXXScopeSpec SS;
6797 if (Qualifier) {
6798 SS.setRange(QualifierRange);
6799 SS.setScopeRep(Qualifier);
6800 }
6801
John McCall9ae2f072010-08-23 23:25:46 +00006802 QualType BaseType = Base->getType();
6803 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006804 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006805 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006806 !BaseType->getAs<PointerType>()->getPointeeType()
6807 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006808 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00006809 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006810 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006811 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006812 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006813 /*FIXME?*/true);
6814 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006815
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006816 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00006817 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6818 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6819 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6820 NameInfo.setNamedTypeInfo(DestroyedType);
6821
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006822 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00006823
John McCall9ae2f072010-08-23 23:25:46 +00006824 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006825 OperatorLoc, isArrow,
6826 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00006827 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006828 /*TemplateArgs*/ 0);
6829}
6830
Douglas Gregor577f75a2009-08-04 16:50:30 +00006831} // end namespace clang
6832
6833#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H