blob: a90ea393251ab420db688dab6ae84ef78aa7eef1 [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 McCall19510852010-08-20 18:27:03 +000028#include "clang/Sema/Ownership.h"
29#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000030#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000031#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000032#include "TypeLocBuilder.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
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000522 /// \brief Build a new parenthesized type.
523 ///
524 /// By default, builds a new ParenType type from the inner type.
525 /// Subclasses may override this routine to provide different behavior.
526 QualType RebuildParenType(QualType InnerType) {
527 return SemaRef.Context.getParenType(InnerType);
528 }
529
Douglas Gregor577f75a2009-08-04 16:50:30 +0000530 /// \brief Build a new qualified name type.
531 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000532 /// By default, builds a new ElaboratedType type from the keyword,
533 /// the nested-name-specifier and the named type.
534 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000535 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
536 ElaboratedTypeKeyword Keyword,
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000537 NestedNameSpecifier *NNS, QualType Named) {
538 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000539 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000540
541 /// \brief Build a new typename type that refers to a template-id.
542 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000543 /// By default, builds a new DependentNameType type from the
544 /// nested-name-specifier and the given type. Subclasses may override
545 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000546 QualType RebuildDependentTemplateSpecializationType(
547 ElaboratedTypeKeyword Keyword,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000548 NestedNameSpecifier *Qualifier,
549 SourceRange QualifierRange,
John McCall33500952010-06-11 00:33:02 +0000550 const IdentifierInfo *Name,
551 SourceLocation NameLoc,
552 const TemplateArgumentListInfo &Args) {
553 // Rebuild the template name.
554 // TODO: avoid TemplateName abstraction
555 TemplateName InstName =
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000556 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall43fed0d2010-11-12 08:19:04 +0000557 QualType(), 0);
John McCall33500952010-06-11 00:33:02 +0000558
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000559 if (InstName.isNull())
560 return QualType();
561
John McCall33500952010-06-11 00:33:02 +0000562 // If it's still dependent, make a dependent specialization.
563 if (InstName.getAsDependentTemplateName())
564 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000565 Keyword, Qualifier, Name, Args);
John McCall33500952010-06-11 00:33:02 +0000566
567 // Otherwise, make an elaborated type wrapping a non-dependent
568 // specialization.
569 QualType T =
570 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
571 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000572
Abramo Bagnara22f638a2010-08-10 13:46:45 +0000573 // NOTE: NNS is already recorded in template specialization type T.
574 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000575 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000576
577 /// \brief Build a new typename type that refers to an identifier.
578 ///
579 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000580 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000581 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000582 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000583 NestedNameSpecifier *NNS,
584 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000585 SourceLocation KeywordLoc,
586 SourceRange NNSRange,
587 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000588 CXXScopeSpec SS;
589 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000590 SS.setRange(NNSRange);
591
Douglas Gregor40336422010-03-31 22:19:08 +0000592 if (NNS->isDependent()) {
593 // If the name is still dependent, just build a new dependent name type.
594 if (!SemaRef.computeDeclContext(SS))
595 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
596 }
597
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000598 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000599 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
600 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000601
602 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
603
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000604 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000605 // into a non-dependent elaborated-type-specifier. Find the tag we're
606 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000607 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000608 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
609 if (!DC)
610 return QualType();
611
John McCall56138762010-05-27 06:40:31 +0000612 if (SemaRef.RequireCompleteDeclContext(SS, DC))
613 return QualType();
614
Douglas Gregor40336422010-03-31 22:19:08 +0000615 TagDecl *Tag = 0;
616 SemaRef.LookupQualifiedName(Result, DC);
617 switch (Result.getResultKind()) {
618 case LookupResult::NotFound:
619 case LookupResult::NotFoundInCurrentInstantiation:
620 break;
Sean Huntc3021132010-05-05 15:23:54 +0000621
Douglas Gregor40336422010-03-31 22:19:08 +0000622 case LookupResult::Found:
623 Tag = Result.getAsSingle<TagDecl>();
624 break;
Sean Huntc3021132010-05-05 15:23:54 +0000625
Douglas Gregor40336422010-03-31 22:19:08 +0000626 case LookupResult::FoundOverloaded:
627 case LookupResult::FoundUnresolvedValue:
628 llvm_unreachable("Tag lookup cannot find non-tags");
629 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000630
Douglas Gregor40336422010-03-31 22:19:08 +0000631 case LookupResult::Ambiguous:
632 // Let the LookupResult structure handle ambiguities.
633 return QualType();
634 }
635
636 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000637 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000638 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000639 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000640 return QualType();
641 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000642
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000643 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
644 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000645 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
646 return QualType();
647 }
648
649 // Build the elaborated-type-specifier type.
650 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000651 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000652 }
Mike Stump1eb44332009-09-09 15:08:12 +0000653
Douglas Gregordcee1a12009-08-06 05:28:30 +0000654 /// \brief Build a new nested-name-specifier given the prefix and an
655 /// identifier that names the next step in the nested-name-specifier.
656 ///
657 /// By default, performs semantic analysis when building the new
658 /// nested-name-specifier. Subclasses may override this routine to provide
659 /// different behavior.
660 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
661 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000662 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000663 QualType ObjectType,
664 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000665
666 /// \brief Build a new nested-name-specifier given the prefix and the
667 /// namespace named in the next step in the nested-name-specifier.
668 ///
669 /// By default, performs semantic analysis when building the new
670 /// nested-name-specifier. Subclasses may override this routine to provide
671 /// different behavior.
672 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
673 SourceRange Range,
674 NamespaceDecl *NS);
675
676 /// \brief Build a new nested-name-specifier given the prefix and the
677 /// type named in the next step in the nested-name-specifier.
678 ///
679 /// By default, performs semantic analysis when building the new
680 /// nested-name-specifier. Subclasses may override this routine to provide
681 /// different behavior.
682 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
683 SourceRange Range,
684 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000685 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000686
687 /// \brief Build a new template name given a nested name specifier, a flag
688 /// indicating whether the "template" keyword was provided, and the template
689 /// that the template name refers to.
690 ///
691 /// By default, builds the new template name directly. Subclasses may override
692 /// this routine to provide different behavior.
693 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
694 bool TemplateKW,
695 TemplateDecl *Template);
696
Douglas Gregord1067e52009-08-06 06:41:21 +0000697 /// \brief Build a new template name given a nested name specifier and the
698 /// name that is referred to as a template.
699 ///
700 /// By default, performs semantic analysis to determine whether the name can
701 /// be resolved to a specific template, then builds the appropriate kind of
702 /// template name. Subclasses may override this routine to provide different
703 /// behavior.
704 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000705 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000706 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +0000707 QualType ObjectType,
708 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000709
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000710 /// \brief Build a new template name given a nested name specifier and the
711 /// overloaded operator name that is referred to as a template.
712 ///
713 /// By default, performs semantic analysis to determine whether the name can
714 /// be resolved to a specific template, then builds the appropriate kind of
715 /// template name. Subclasses may override this routine to provide different
716 /// behavior.
717 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
718 OverloadedOperatorKind Operator,
719 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000720
Douglas Gregor43959a92009-08-20 07:17:43 +0000721 /// \brief Build a new compound statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000725 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000726 MultiStmtArg Statements,
727 SourceLocation RBraceLoc,
728 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000729 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000730 IsStmtExpr);
731 }
732
733 /// \brief Build a new case statement.
734 ///
735 /// By default, performs semantic analysis to build the new statement.
736 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000737 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000738 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000739 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000740 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000741 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000742 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000743 ColonLoc);
744 }
Mike Stump1eb44332009-09-09 15:08:12 +0000745
Douglas Gregor43959a92009-08-20 07:17:43 +0000746 /// \brief Attach the body to a new case statement.
747 ///
748 /// By default, performs semantic analysis to build the new statement.
749 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000750 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000751 getSema().ActOnCaseStmtBody(S, Body);
752 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000753 }
Mike Stump1eb44332009-09-09 15:08:12 +0000754
Douglas Gregor43959a92009-08-20 07:17:43 +0000755 /// \brief Build a new default statement.
756 ///
757 /// By default, performs semantic analysis to build the new statement.
758 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000759 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000760 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000761 Stmt *SubStmt) {
762 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000763 /*CurScope=*/0);
764 }
Mike Stump1eb44332009-09-09 15:08:12 +0000765
Douglas Gregor43959a92009-08-20 07:17:43 +0000766 /// \brief Build a new label statement.
767 ///
768 /// By default, performs semantic analysis to build the new statement.
769 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000770 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000771 IdentifierInfo *Id,
772 SourceLocation ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +0000773 Stmt *SubStmt, bool HasUnusedAttr) {
774 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
775 HasUnusedAttr);
Douglas Gregor43959a92009-08-20 07:17:43 +0000776 }
Mike Stump1eb44332009-09-09 15:08:12 +0000777
Douglas Gregor43959a92009-08-20 07:17:43 +0000778 /// \brief Build a new "if" statement.
779 ///
780 /// By default, performs semantic analysis to build the new statement.
781 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000782 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000783 VarDecl *CondVar, Stmt *Then,
John McCall9ae2f072010-08-23 23:25:46 +0000784 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000785 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000786 }
Mike Stump1eb44332009-09-09 15:08:12 +0000787
Douglas Gregor43959a92009-08-20 07:17:43 +0000788 /// \brief Start building a new switch statement.
789 ///
790 /// By default, performs semantic analysis to build the new statement.
791 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000792 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000793 Expr *Cond, VarDecl *CondVar) {
794 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +0000795 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +0000796 }
Mike Stump1eb44332009-09-09 15:08:12 +0000797
Douglas Gregor43959a92009-08-20 07:17:43 +0000798 /// \brief Attach the body to the switch statement.
799 ///
800 /// By default, performs semantic analysis to build the new statement.
801 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000802 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000803 Stmt *Switch, Stmt *Body) {
804 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000805 }
806
807 /// \brief Build a new while statement.
808 ///
809 /// By default, performs semantic analysis to build the new statement.
810 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000811 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000812 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000813 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000814 Stmt *Body) {
815 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000816 }
Mike Stump1eb44332009-09-09 15:08:12 +0000817
Douglas Gregor43959a92009-08-20 07:17:43 +0000818 /// \brief Build a new do-while statement.
819 ///
820 /// By default, performs semantic analysis to build the new statement.
821 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000822 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregor43959a92009-08-20 07:17:43 +0000823 SourceLocation WhileLoc,
824 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000825 Expr *Cond,
Douglas Gregor43959a92009-08-20 07:17:43 +0000826 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000827 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
828 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +0000829 }
830
831 /// \brief Build a new for statement.
832 ///
833 /// By default, performs semantic analysis to build the new statement.
834 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000835 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000836 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000837 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000838 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCall9ae2f072010-08-23 23:25:46 +0000839 SourceLocation RParenLoc, Stmt *Body) {
840 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCalld226f652010-08-21 09:40:31 +0000841 CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000842 Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000843 }
Mike Stump1eb44332009-09-09 15:08:12 +0000844
Douglas Gregor43959a92009-08-20 07:17:43 +0000845 /// \brief Build a new goto statement.
846 ///
847 /// By default, performs semantic analysis to build the new statement.
848 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000849 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000850 SourceLocation LabelLoc,
851 LabelStmt *Label) {
852 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
853 }
854
855 /// \brief Build a new indirect goto statement.
856 ///
857 /// By default, performs semantic analysis to build the new statement.
858 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000859 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000860 SourceLocation StarLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000861 Expr *Target) {
862 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +0000863 }
Mike Stump1eb44332009-09-09 15:08:12 +0000864
Douglas Gregor43959a92009-08-20 07:17:43 +0000865 /// \brief Build a new return statement.
866 ///
867 /// By default, performs semantic analysis to build the new statement.
868 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000869 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000870 Expr *Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000871
John McCall9ae2f072010-08-23 23:25:46 +0000872 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +0000873 }
Mike Stump1eb44332009-09-09 15:08:12 +0000874
Douglas Gregor43959a92009-08-20 07:17:43 +0000875 /// \brief Build a new declaration statement.
876 ///
877 /// By default, performs semantic analysis to build the new statement.
878 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000879 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000880 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000881 SourceLocation EndLoc) {
882 return getSema().Owned(
883 new (getSema().Context) DeclStmt(
884 DeclGroupRef::Create(getSema().Context,
885 Decls, NumDecls),
886 StartLoc, EndLoc));
887 }
Mike Stump1eb44332009-09-09 15:08:12 +0000888
Anders Carlsson703e3942010-01-24 05:50:09 +0000889 /// \brief Build a new inline asm statement.
890 ///
891 /// By default, performs semantic analysis to build the new statement.
892 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000893 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +0000894 bool IsSimple,
895 bool IsVolatile,
896 unsigned NumOutputs,
897 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000898 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000899 MultiExprArg Constraints,
900 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +0000901 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +0000902 MultiExprArg Clobbers,
903 SourceLocation RParenLoc,
904 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000905 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000906 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +0000907 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +0000908 RParenLoc, MSAsm);
909 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000910
911 /// \brief Build a new Objective-C @try statement.
912 ///
913 /// By default, performs semantic analysis to build the new statement.
914 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000915 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000916 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000917 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +0000918 Stmt *Finally) {
919 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
920 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000921 }
922
Douglas Gregorbe270a02010-04-26 17:57:08 +0000923 /// \brief Rebuild an Objective-C exception declaration.
924 ///
925 /// By default, performs semantic analysis to build the new declaration.
926 /// Subclasses may override this routine to provide different behavior.
927 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
928 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +0000929 return getSema().BuildObjCExceptionDecl(TInfo, T,
930 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +0000931 ExceptionDecl->getLocation());
932 }
Sean Huntc3021132010-05-05 15:23:54 +0000933
Douglas Gregorbe270a02010-04-26 17:57:08 +0000934 /// \brief Build a new Objective-C @catch statement.
935 ///
936 /// By default, performs semantic analysis to build the new statement.
937 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000938 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +0000939 SourceLocation RParenLoc,
940 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +0000941 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +0000942 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000943 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +0000944 }
Sean Huntc3021132010-05-05 15:23:54 +0000945
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000946 /// \brief Build a new Objective-C @finally statement.
947 ///
948 /// By default, performs semantic analysis to build the new statement.
949 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000950 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000951 Stmt *Body) {
952 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000953 }
Sean Huntc3021132010-05-05 15:23:54 +0000954
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000955 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +0000956 ///
957 /// By default, performs semantic analysis to build the new statement.
958 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000959 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000960 Expr *Operand) {
961 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +0000962 }
Sean Huntc3021132010-05-05 15:23:54 +0000963
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000964 /// \brief Build a new Objective-C @synchronized statement.
965 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000968 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000969 Expr *Object,
970 Stmt *Body) {
971 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
972 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000973 }
Douglas Gregorc3203e72010-04-22 23:10:45 +0000974
975 /// \brief Build a new Objective-C fast enumeration statement.
976 ///
977 /// By default, performs semantic analysis to build the new statement.
978 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000979 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +0000980 SourceLocation LParenLoc,
981 Stmt *Element,
982 Expr *Collection,
983 SourceLocation RParenLoc,
984 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +0000985 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000986 Element,
987 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +0000988 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000989 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +0000990 }
Sean Huntc3021132010-05-05 15:23:54 +0000991
Douglas Gregor43959a92009-08-20 07:17:43 +0000992 /// \brief Build a new C++ exception declaration.
993 ///
994 /// By default, performs semantic analysis to build the new decaration.
995 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor83cb9422010-09-09 17:09:21 +0000996 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +0000997 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000998 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +0000999 SourceLocation Loc) {
1000 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001001 }
1002
1003 /// \brief Build a new C++ catch statement.
1004 ///
1005 /// By default, performs semantic analysis to build the new statement.
1006 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001007 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001008 VarDecl *ExceptionDecl,
1009 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001010 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1011 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001012 }
Mike Stump1eb44332009-09-09 15:08:12 +00001013
Douglas Gregor43959a92009-08-20 07:17:43 +00001014 /// \brief Build a new C++ try statement.
1015 ///
1016 /// By default, performs semantic analysis to build the new statement.
1017 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001018 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001019 Stmt *TryBlock,
1020 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001021 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001022 }
Mike Stump1eb44332009-09-09 15:08:12 +00001023
Douglas Gregorb98b1992009-08-11 05:31:07 +00001024 /// \brief Build a new expression that references a declaration.
1025 ///
1026 /// By default, performs semantic analysis to build the new expression.
1027 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001028 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001029 LookupResult &R,
1030 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001031 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1032 }
1033
1034
1035 /// \brief Build a new expression that references a declaration.
1036 ///
1037 /// By default, performs semantic analysis to build the new expression.
1038 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001039 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001040 SourceRange QualifierRange,
1041 ValueDecl *VD,
1042 const DeclarationNameInfo &NameInfo,
1043 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001044 CXXScopeSpec SS;
1045 SS.setScopeRep(Qualifier);
1046 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001047
1048 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001049
1050 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001051 }
Mike Stump1eb44332009-09-09 15:08:12 +00001052
Douglas Gregorb98b1992009-08-11 05:31:07 +00001053 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001054 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001055 /// By default, performs semantic analysis to build the new expression.
1056 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001057 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001058 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001059 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001060 }
1061
Douglas Gregora71d8192009-09-04 17:36:40 +00001062 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001063 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001064 /// By default, performs semantic analysis to build the new expression.
1065 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001066 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001067 SourceLocation OperatorLoc,
1068 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001069 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001070 SourceRange QualifierRange,
1071 TypeSourceInfo *ScopeType,
1072 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001073 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001074 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001075
Douglas Gregorb98b1992009-08-11 05:31:07 +00001076 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001077 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001078 /// By default, performs semantic analysis to build the new expression.
1079 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001080 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001081 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001082 Expr *SubExpr) {
1083 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001084 }
Mike Stump1eb44332009-09-09 15:08:12 +00001085
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001086 /// \brief Build a new builtin offsetof expression.
1087 ///
1088 /// By default, performs semantic analysis to build the new expression.
1089 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001090 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001091 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001092 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001093 unsigned NumComponents,
1094 SourceLocation RParenLoc) {
1095 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1096 NumComponents, RParenLoc);
1097 }
Sean Huntc3021132010-05-05 15:23:54 +00001098
Douglas Gregorb98b1992009-08-11 05:31:07 +00001099 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001100 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001101 /// By default, performs semantic analysis to build the new expression.
1102 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001103 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001104 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001105 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001106 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001107 }
1108
Mike Stump1eb44332009-09-09 15:08:12 +00001109 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001110 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001111 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001112 /// By default, performs semantic analysis to build the new expression.
1113 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001114 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001115 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001116 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001117 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001118 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001119 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001120
Douglas Gregorb98b1992009-08-11 05:31:07 +00001121 return move(Result);
1122 }
Mike Stump1eb44332009-09-09 15:08:12 +00001123
Douglas Gregorb98b1992009-08-11 05:31:07 +00001124 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001125 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001126 /// By default, performs semantic analysis to build the new expression.
1127 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001128 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001129 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001130 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001131 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001132 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1133 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001134 RBracketLoc);
1135 }
1136
1137 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001138 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001139 /// By default, performs semantic analysis to build the new expression.
1140 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001141 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001142 MultiExprArg Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001143 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001144 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora1a04782010-09-09 16:33:13 +00001145 move(Args), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001146 }
1147
1148 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001149 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001150 /// By default, performs semantic analysis to build the new expression.
1151 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001152 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001153 bool isArrow,
1154 NestedNameSpecifier *Qualifier,
1155 SourceRange QualifierRange,
1156 const DeclarationNameInfo &MemberNameInfo,
1157 ValueDecl *Member,
1158 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001159 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001160 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001161 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001162 // We have a reference to an unnamed field. This is always the
1163 // base of an anonymous struct/union member access, i.e. the
1164 // field is always of record type.
Anders Carlssond8b285f2009-09-01 04:26:58 +00001165 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001166 assert(Member->getType()->isRecordType() &&
1167 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001168
John McCall9ae2f072010-08-23 23:25:46 +00001169 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001170 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001171 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001172
John McCallf89e55a2010-11-18 06:31:45 +00001173 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001174 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001175 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001176 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001177 cast<FieldDecl>(Member)->getType(),
1178 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001179 return getSema().Owned(ME);
1180 }
Mike Stump1eb44332009-09-09 15:08:12 +00001181
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001182 CXXScopeSpec SS;
1183 if (Qualifier) {
1184 SS.setRange(QualifierRange);
1185 SS.setScopeRep(Qualifier);
1186 }
1187
John McCall9ae2f072010-08-23 23:25:46 +00001188 getSema().DefaultFunctionArrayConversion(Base);
1189 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001190
John McCall6bb80172010-03-30 21:47:33 +00001191 // FIXME: this involves duplicating earlier analysis in a lot of
1192 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001193 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001194 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001195 R.resolveKind();
1196
John McCall9ae2f072010-08-23 23:25:46 +00001197 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001198 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001199 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001200 }
Mike Stump1eb44332009-09-09 15:08:12 +00001201
Douglas Gregorb98b1992009-08-11 05:31:07 +00001202 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001203 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001204 /// By default, performs semantic analysis to build the new expression.
1205 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001206 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001207 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001208 Expr *LHS, Expr *RHS) {
1209 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001210 }
1211
1212 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001213 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001214 /// By default, performs semantic analysis to build the new expression.
1215 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001216 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001217 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001218 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001219 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001220 Expr *RHS) {
1221 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1222 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001223 }
1224
Douglas Gregorb98b1992009-08-11 05:31:07 +00001225 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001226 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001227 /// By default, performs semantic analysis to build the new expression.
1228 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001229 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001230 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001231 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001232 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001233 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001234 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001235 }
Mike Stump1eb44332009-09-09 15:08:12 +00001236
Douglas Gregorb98b1992009-08-11 05:31:07 +00001237 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001238 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001239 /// By default, performs semantic analysis to build the new expression.
1240 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001241 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001242 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001243 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001244 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001245 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001246 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001247 }
Mike Stump1eb44332009-09-09 15:08:12 +00001248
Douglas Gregorb98b1992009-08-11 05:31:07 +00001249 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001250 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001251 /// By default, performs semantic analysis to build the new expression.
1252 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001253 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001254 SourceLocation OpLoc,
1255 SourceLocation AccessorLoc,
1256 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001257
John McCall129e2df2009-11-30 22:42:35 +00001258 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001259 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001260 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001261 OpLoc, /*IsArrow*/ false,
1262 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001263 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001264 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001265 }
Mike Stump1eb44332009-09-09 15:08:12 +00001266
Douglas Gregorb98b1992009-08-11 05:31:07 +00001267 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001268 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001269 /// By default, performs semantic analysis to build the new expression.
1270 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001271 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001272 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001273 SourceLocation RBraceLoc,
1274 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001275 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001276 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1277 if (Result.isInvalid() || ResultTy->isDependentType())
1278 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001279
Douglas Gregore48319a2009-11-09 17:16:50 +00001280 // Patch in the result type we were given, which may have been computed
1281 // when the initial InitListExpr was built.
1282 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1283 ILE->setType(ResultTy);
1284 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001285 }
Mike Stump1eb44332009-09-09 15:08:12 +00001286
Douglas Gregorb98b1992009-08-11 05:31:07 +00001287 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001288 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001289 /// By default, performs semantic analysis to build the new expression.
1290 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001291 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001292 MultiExprArg ArrayExprs,
1293 SourceLocation EqualOrColonLoc,
1294 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001295 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001296 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001297 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001298 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001299 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001300 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001301
Douglas Gregorb98b1992009-08-11 05:31:07 +00001302 ArrayExprs.release();
1303 return move(Result);
1304 }
Mike Stump1eb44332009-09-09 15:08:12 +00001305
Douglas Gregorb98b1992009-08-11 05:31:07 +00001306 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001307 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001308 /// By default, builds the implicit value initialization without performing
1309 /// any semantic analysis. Subclasses may override this routine to provide
1310 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001311 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001312 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1313 }
Mike Stump1eb44332009-09-09 15:08:12 +00001314
Douglas Gregorb98b1992009-08-11 05:31:07 +00001315 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001316 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001317 /// By default, performs semantic analysis to build the new expression.
1318 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001319 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001320 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001321 SourceLocation RParenLoc) {
1322 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001323 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001324 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001325 }
1326
1327 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001328 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001329 /// By default, performs semantic analysis to build the new expression.
1330 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001331 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001332 MultiExprArg SubExprs,
1333 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001334 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001335 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001336 }
Mike Stump1eb44332009-09-09 15:08:12 +00001337
Douglas Gregorb98b1992009-08-11 05:31:07 +00001338 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001339 ///
1340 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001341 /// rather than attempting to map the label statement itself.
1342 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001343 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001344 SourceLocation LabelLoc,
1345 LabelStmt *Label) {
1346 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1347 }
Mike Stump1eb44332009-09-09 15:08:12 +00001348
Douglas Gregorb98b1992009-08-11 05:31:07 +00001349 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001350 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001351 /// By default, performs semantic analysis to build the new expression.
1352 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001353 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001354 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001355 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001356 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001357 }
Mike Stump1eb44332009-09-09 15:08:12 +00001358
Douglas Gregorb98b1992009-08-11 05:31:07 +00001359 /// \brief Build a new __builtin_choose_expr expression.
1360 ///
1361 /// By default, performs semantic analysis to build the new expression.
1362 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001363 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001364 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001365 SourceLocation RParenLoc) {
1366 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001367 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001368 RParenLoc);
1369 }
Mike Stump1eb44332009-09-09 15:08:12 +00001370
Douglas Gregorb98b1992009-08-11 05:31:07 +00001371 /// \brief Build a new overloaded operator call expression.
1372 ///
1373 /// By default, performs semantic analysis to build the new expression.
1374 /// The semantic analysis provides the behavior of template instantiation,
1375 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001376 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001377 /// argument-dependent lookup, etc. Subclasses may override this routine to
1378 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001379 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001380 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001381 Expr *Callee,
1382 Expr *First,
1383 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001384
1385 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001386 /// reinterpret_cast.
1387 ///
1388 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001389 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001390 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001391 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001392 Stmt::StmtClass Class,
1393 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001394 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001395 SourceLocation RAngleLoc,
1396 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001397 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001398 SourceLocation RParenLoc) {
1399 switch (Class) {
1400 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001401 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001402 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001403 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001404
1405 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001406 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001407 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001408 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001409
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001411 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001412 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001413 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001415
Douglas Gregorb98b1992009-08-11 05:31:07 +00001416 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001417 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001418 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001419 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001420
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 default:
1422 assert(false && "Invalid C++ named cast");
1423 break;
1424 }
Mike Stump1eb44332009-09-09 15:08:12 +00001425
John McCallf312b1e2010-08-26 23:41:50 +00001426 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001427 }
Mike Stump1eb44332009-09-09 15:08:12 +00001428
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 /// \brief Build a new C++ static_cast expression.
1430 ///
1431 /// By default, performs semantic analysis to build the new expression.
1432 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001433 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001435 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 SourceLocation RAngleLoc,
1437 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001438 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001440 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001441 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001442 SourceRange(LAngleLoc, RAngleLoc),
1443 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001444 }
1445
1446 /// \brief Build a new C++ dynamic_cast expression.
1447 ///
1448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001450 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001451 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001452 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001453 SourceLocation RAngleLoc,
1454 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001455 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001457 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001458 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001459 SourceRange(LAngleLoc, RAngleLoc),
1460 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001461 }
1462
1463 /// \brief Build a new C++ reinterpret_cast expression.
1464 ///
1465 /// By default, performs semantic analysis to build the new expression.
1466 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001467 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001468 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001469 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 SourceLocation RAngleLoc,
1471 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001472 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001474 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001475 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001476 SourceRange(LAngleLoc, RAngleLoc),
1477 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001478 }
1479
1480 /// \brief Build a new C++ const_cast expression.
1481 ///
1482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001484 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001486 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 SourceLocation RAngleLoc,
1488 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001489 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001491 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001492 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001493 SourceRange(LAngleLoc, RAngleLoc),
1494 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 }
Mike Stump1eb44332009-09-09 15:08:12 +00001496
Douglas Gregorb98b1992009-08-11 05:31:07 +00001497 /// \brief Build a new C++ functional-style cast expression.
1498 ///
1499 /// By default, performs semantic analysis to build the new expression.
1500 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001501 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1502 SourceLocation LParenLoc,
1503 Expr *Sub,
1504 SourceLocation RParenLoc) {
1505 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001506 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 RParenLoc);
1508 }
Mike Stump1eb44332009-09-09 15:08:12 +00001509
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 /// \brief Build a new C++ typeid(type) expression.
1511 ///
1512 /// By default, performs semantic analysis to build the new expression.
1513 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001514 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001515 SourceLocation TypeidLoc,
1516 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001518 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001519 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001520 }
Mike Stump1eb44332009-09-09 15:08:12 +00001521
Francois Pichet01b7c302010-09-08 12:20:18 +00001522
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 /// \brief Build a new C++ typeid(expr) expression.
1524 ///
1525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001527 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001528 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001529 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001530 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001531 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001532 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001533 }
1534
Francois Pichet01b7c302010-09-08 12:20:18 +00001535 /// \brief Build a new C++ __uuidof(type) expression.
1536 ///
1537 /// By default, performs semantic analysis to build the new expression.
1538 /// Subclasses may override this routine to provide different behavior.
1539 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1540 SourceLocation TypeidLoc,
1541 TypeSourceInfo *Operand,
1542 SourceLocation RParenLoc) {
1543 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1544 RParenLoc);
1545 }
1546
1547 /// \brief Build a new C++ __uuidof(expr) expression.
1548 ///
1549 /// By default, performs semantic analysis to build the new expression.
1550 /// Subclasses may override this routine to provide different behavior.
1551 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1552 SourceLocation TypeidLoc,
1553 Expr *Operand,
1554 SourceLocation RParenLoc) {
1555 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1556 RParenLoc);
1557 }
1558
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 /// \brief Build a new C++ "this" expression.
1560 ///
1561 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001562 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001564 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001565 QualType ThisType,
1566 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001568 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1569 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 }
1571
1572 /// \brief Build a new C++ throw expression.
1573 ///
1574 /// By default, performs semantic analysis to build the new expression.
1575 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001576 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001577 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 }
1579
1580 /// \brief Build a new C++ default-argument expression.
1581 ///
1582 /// By default, builds a new default-argument expression, which does not
1583 /// require any semantic analysis. Subclasses may override this routine to
1584 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001585 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001586 ParmVarDecl *Param) {
1587 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1588 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 }
1590
1591 /// \brief Build a new C++ zero-initialization expression.
1592 ///
1593 /// By default, performs semantic analysis to build the new expression.
1594 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001595 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1596 SourceLocation LParenLoc,
1597 SourceLocation RParenLoc) {
1598 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001599 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001600 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001601 }
Mike Stump1eb44332009-09-09 15:08:12 +00001602
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 /// \brief Build a new C++ "new" expression.
1604 ///
1605 /// By default, performs semantic analysis to build the new expression.
1606 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001607 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001608 bool UseGlobal,
1609 SourceLocation PlacementLParen,
1610 MultiExprArg PlacementArgs,
1611 SourceLocation PlacementRParen,
1612 SourceRange TypeIdParens,
1613 QualType AllocatedType,
1614 TypeSourceInfo *AllocatedTypeInfo,
1615 Expr *ArraySize,
1616 SourceLocation ConstructorLParen,
1617 MultiExprArg ConstructorArgs,
1618 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001619 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 PlacementLParen,
1621 move(PlacementArgs),
1622 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001623 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001624 AllocatedType,
1625 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001626 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001627 ConstructorLParen,
1628 move(ConstructorArgs),
1629 ConstructorRParen);
1630 }
Mike Stump1eb44332009-09-09 15:08:12 +00001631
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 /// \brief Build a new C++ "delete" expression.
1633 ///
1634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001636 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 bool IsGlobalDelete,
1638 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001639 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001640 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001641 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 }
Mike Stump1eb44332009-09-09 15:08:12 +00001643
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 /// \brief Build a new unary type trait expression.
1645 ///
1646 /// By default, performs semantic analysis to build the new expression.
1647 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001648 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001649 SourceLocation StartLoc,
1650 TypeSourceInfo *T,
1651 SourceLocation RParenLoc) {
1652 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 }
1654
Francois Pichet6ad6f282010-12-07 00:08:36 +00001655 /// \brief Build a new binary type trait expression.
1656 ///
1657 /// By default, performs semantic analysis to build the new expression.
1658 /// Subclasses may override this routine to provide different behavior.
1659 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1660 SourceLocation StartLoc,
1661 TypeSourceInfo *LhsT,
1662 TypeSourceInfo *RhsT,
1663 SourceLocation RParenLoc) {
1664 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1665 }
1666
Mike Stump1eb44332009-09-09 15:08:12 +00001667 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 /// expression.
1669 ///
1670 /// By default, performs semantic analysis to build the new expression.
1671 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001672 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001674 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001675 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 CXXScopeSpec SS;
1677 SS.setRange(QualifierRange);
1678 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001679
1680 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001681 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001682 *TemplateArgs);
1683
Abramo Bagnara25777432010-08-11 22:01:17 +00001684 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 }
1686
1687 /// \brief Build a new template-id expression.
1688 ///
1689 /// By default, performs semantic analysis to build the new expression.
1690 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001691 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001692 LookupResult &R,
1693 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001694 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001695 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 }
1697
1698 /// \brief Build a new object-construction expression.
1699 ///
1700 /// By default, performs semantic analysis to build the new expression.
1701 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001702 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001703 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 CXXConstructorDecl *Constructor,
1705 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001706 MultiExprArg Args,
1707 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00001708 CXXConstructExpr::ConstructionKind ConstructKind,
1709 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00001710 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001711 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001712 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001713 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001714
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001715 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001716 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00001717 RequiresZeroInit, ConstructKind,
1718 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719 }
1720
1721 /// \brief Build a new object-construction expression.
1722 ///
1723 /// By default, performs semantic analysis to build the new expression.
1724 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001725 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1726 SourceLocation LParenLoc,
1727 MultiExprArg Args,
1728 SourceLocation RParenLoc) {
1729 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 LParenLoc,
1731 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 RParenLoc);
1733 }
1734
1735 /// \brief Build a new object-construction expression.
1736 ///
1737 /// By default, performs semantic analysis to build the new expression.
1738 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001739 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1740 SourceLocation LParenLoc,
1741 MultiExprArg Args,
1742 SourceLocation RParenLoc) {
1743 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001744 LParenLoc,
1745 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 RParenLoc);
1747 }
Mike Stump1eb44332009-09-09 15:08:12 +00001748
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 /// \brief Build a new member reference expression.
1750 ///
1751 /// By default, performs semantic analysis to build the new expression.
1752 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001753 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001754 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 bool IsArrow,
1756 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001757 NestedNameSpecifier *Qualifier,
1758 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001759 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001760 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001761 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001763 SS.setRange(QualifierRange);
1764 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001765
John McCall9ae2f072010-08-23 23:25:46 +00001766 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001767 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001768 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001769 MemberNameInfo,
1770 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 }
1772
John McCall129e2df2009-11-30 22:42:35 +00001773 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001774 ///
1775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001777 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001778 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001779 SourceLocation OperatorLoc,
1780 bool IsArrow,
1781 NestedNameSpecifier *Qualifier,
1782 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001783 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001784 LookupResult &R,
1785 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001786 CXXScopeSpec SS;
1787 SS.setRange(QualifierRange);
1788 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001789
John McCall9ae2f072010-08-23 23:25:46 +00001790 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001791 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001792 SS, FirstQualifierInScope,
1793 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001794 }
Mike Stump1eb44332009-09-09 15:08:12 +00001795
Sebastian Redl2e156222010-09-10 20:55:43 +00001796 /// \brief Build a new noexcept expression.
1797 ///
1798 /// By default, performs semantic analysis to build the new expression.
1799 /// Subclasses may override this routine to provide different behavior.
1800 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1801 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1802 }
1803
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 /// \brief Build a new Objective-C @encode expression.
1805 ///
1806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001808 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001809 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001811 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001812 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001813 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814
Douglas Gregor92e986e2010-04-22 16:44:27 +00001815 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00001816 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001817 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001818 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001819 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) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001823 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1824 ReceiverTypeInfo->getType(),
1825 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001826 Sel, Method, LBracLoc, SelectorLoc,
1827 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00001828 }
1829
1830 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00001831 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001832 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001833 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001834 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001835 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001836 MultiExprArg Args,
1837 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001838 return SemaRef.BuildInstanceMessage(Receiver,
1839 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00001840 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001841 Sel, Method, LBracLoc, SelectorLoc,
1842 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00001843 }
1844
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001845 /// \brief Build a new Objective-C ivar reference expression.
1846 ///
1847 /// By default, performs semantic analysis to build the new expression.
1848 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001849 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001850 SourceLocation IvarLoc,
1851 bool IsArrow, bool IsFreeIvar) {
1852 // FIXME: We lose track of the IsFreeIvar bit.
1853 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001854 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001855 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1856 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001857 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001858 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00001859 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00001860 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001861 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001862 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001863
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001864 if (Result.get())
1865 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001866
John McCall9ae2f072010-08-23 23:25:46 +00001867 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001868 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001869 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001870 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001871 /*TemplateArgs=*/0);
1872 }
Douglas Gregore3303542010-04-26 20:47:02 +00001873
1874 /// \brief Build a new Objective-C property reference expression.
1875 ///
1876 /// By default, performs semantic analysis to build the new expression.
1877 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001878 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001879 ObjCPropertyDecl *Property,
1880 SourceLocation PropertyLoc) {
1881 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001882 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00001883 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1884 Sema::LookupMemberName);
1885 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00001886 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00001887 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00001888 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00001889 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001890 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001891
Douglas Gregore3303542010-04-26 20:47:02 +00001892 if (Result.get())
1893 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001894
John McCall9ae2f072010-08-23 23:25:46 +00001895 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001896 /*FIXME:*/PropertyLoc, IsArrow,
1897 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001898 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001899 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001900 /*TemplateArgs=*/0);
1901 }
Sean Huntc3021132010-05-05 15:23:54 +00001902
John McCall12f78a62010-12-02 01:19:52 +00001903 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001904 ///
1905 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00001906 /// Subclasses may override this routine to provide different behavior.
1907 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
1908 ObjCMethodDecl *Getter,
1909 ObjCMethodDecl *Setter,
1910 SourceLocation PropertyLoc) {
1911 // Since these expressions can only be value-dependent, we do not
1912 // need to perform semantic analysis again.
1913 return Owned(
1914 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
1915 VK_LValue, OK_ObjCProperty,
1916 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001917 }
1918
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001919 /// \brief Build a new Objective-C "isa" expression.
1920 ///
1921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001923 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001924 bool IsArrow) {
1925 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001926 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001927 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1928 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001929 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001930 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00001931 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001932 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001933 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001934
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001935 if (Result.get())
1936 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001937
John McCall9ae2f072010-08-23 23:25:46 +00001938 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001939 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001940 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001941 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001942 /*TemplateArgs=*/0);
1943 }
Sean Huntc3021132010-05-05 15:23:54 +00001944
Douglas Gregorb98b1992009-08-11 05:31:07 +00001945 /// \brief Build a new shuffle vector expression.
1946 ///
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001949 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001950 MultiExprArg SubExprs,
1951 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001953 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001954 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1955 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1956 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1957 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001958
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 // Build a reference to the __builtin_shufflevector builtin
1960 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001961 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001962 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCallf89e55a2010-11-18 06:31:45 +00001963 VK_LValue, BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001964 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001965
1966 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001967 unsigned NumSubExprs = SubExprs.size();
1968 Expr **Subs = (Expr **)SubExprs.release();
1969 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1970 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00001971 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00001972 Expr::getValueKindForType(Builtin->getResultType()),
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>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00003385QualType
3386TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
3387 ParenTypeLoc TL) {
3388 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
3389 if (Inner.isNull())
3390 return QualType();
3391
3392 QualType Result = TL.getType();
3393 if (getDerived().AlwaysRebuild() ||
3394 Inner != TL.getInnerLoc().getType()) {
3395 Result = getDerived().RebuildParenType(Inner);
3396 if (Result.isNull())
3397 return QualType();
3398 }
3399
3400 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
3401 NewTL.setLParenLoc(TL.getLParenLoc());
3402 NewTL.setRParenLoc(TL.getRParenLoc());
3403 return Result;
3404}
3405
3406template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003407QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003408 DependentNameTypeLoc TL) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003409 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003410
Douglas Gregor577f75a2009-08-04 16:50:30 +00003411 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003412 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003413 TL.getQualifierRange());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003414 if (!NNS)
3415 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003416
John McCall33500952010-06-11 00:33:02 +00003417 QualType Result
3418 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3419 T->getIdentifier(),
3420 TL.getKeywordLoc(),
3421 TL.getQualifierRange(),
3422 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003423 if (Result.isNull())
3424 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003425
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003426 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3427 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003428 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3429
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003430 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3431 NewTL.setKeywordLoc(TL.getKeywordLoc());
3432 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003433 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003434 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3435 NewTL.setKeywordLoc(TL.getKeywordLoc());
3436 NewTL.setQualifierRange(TL.getQualifierRange());
3437 NewTL.setNameLoc(TL.getNameLoc());
3438 }
John McCalla2becad2009-10-21 00:40:46 +00003439 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003440}
Mike Stump1eb44332009-09-09 15:08:12 +00003441
Douglas Gregor577f75a2009-08-04 16:50:30 +00003442template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003443QualType TreeTransform<Derived>::
3444 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003445 DependentTemplateSpecializationTypeLoc TL) {
John McCall33500952010-06-11 00:33:02 +00003446 DependentTemplateSpecializationType *T = TL.getTypePtr();
3447
3448 NestedNameSpecifier *NNS
3449 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003450 TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003451 if (!NNS)
3452 return QualType();
3453
John McCall43fed0d2010-11-12 08:19:04 +00003454 return getDerived()
3455 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3456}
3457
3458template<typename Derived>
3459QualType TreeTransform<Derived>::
3460 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3461 DependentTemplateSpecializationTypeLoc TL,
3462 NestedNameSpecifier *NNS) {
3463 DependentTemplateSpecializationType *T = TL.getTypePtr();
3464
John McCall33500952010-06-11 00:33:02 +00003465 TemplateArgumentListInfo NewTemplateArgs;
3466 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3467 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3468
3469 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3470 TemplateArgumentLoc Loc;
3471 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3472 return QualType();
3473 NewTemplateArgs.addArgument(Loc);
3474 }
3475
Douglas Gregor1efb6c72010-09-08 23:56:00 +00003476 QualType Result
3477 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3478 NNS,
3479 TL.getQualifierRange(),
3480 T->getIdentifier(),
3481 TL.getNameLoc(),
3482 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00003483 if (Result.isNull())
3484 return QualType();
3485
3486 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3487 QualType NamedT = ElabT->getNamedType();
3488
3489 // Copy information relevant to the template specialization.
3490 TemplateSpecializationTypeLoc NamedTL
3491 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3492 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3493 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3494 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3495 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3496
3497 // Copy information relevant to the elaborated type.
3498 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3499 NewTL.setKeywordLoc(TL.getKeywordLoc());
3500 NewTL.setQualifierRange(TL.getQualifierRange());
3501 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003502 TypeLoc NewTL(Result, TL.getOpaqueData());
3503 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003504 }
3505 return Result;
3506}
3507
3508template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00003509QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
3510 PackExpansionTypeLoc TL) {
3511 // FIXME: Implement!
3512 getSema().Diag(TL.getEllipsisLoc(),
3513 diag::err_pack_expansion_instantiation_unsupported);
3514 return QualType();
3515}
3516
3517template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003518QualType
3519TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003520 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003521 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003522 TLB.pushFullCopy(TL);
3523 return TL.getType();
3524}
3525
3526template<typename Derived>
3527QualType
3528TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003529 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00003530 // ObjCObjectType is never dependent.
3531 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003532 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003533}
Mike Stump1eb44332009-09-09 15:08:12 +00003534
3535template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003536QualType
3537TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003538 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003539 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003540 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003541 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003542}
3543
Douglas Gregor577f75a2009-08-04 16:50:30 +00003544//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003545// Statement transformation
3546//===----------------------------------------------------------------------===//
3547template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003548StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003549TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00003550 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003551}
3552
3553template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003554StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003555TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3556 return getDerived().TransformCompoundStmt(S, false);
3557}
3558
3559template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003560StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003561TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003562 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00003563 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00003564 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003565 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00003566 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3567 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00003568 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00003569 if (Result.isInvalid()) {
3570 // Immediately fail if this was a DeclStmt, since it's very
3571 // likely that this will cause problems for future statements.
3572 if (isa<DeclStmt>(*B))
3573 return StmtError();
3574
3575 // Otherwise, just keep processing substatements and fail later.
3576 SubStmtInvalid = true;
3577 continue;
3578 }
Mike Stump1eb44332009-09-09 15:08:12 +00003579
Douglas Gregor43959a92009-08-20 07:17:43 +00003580 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3581 Statements.push_back(Result.takeAs<Stmt>());
3582 }
Mike Stump1eb44332009-09-09 15:08:12 +00003583
John McCall7114cba2010-08-27 19:56:05 +00003584 if (SubStmtInvalid)
3585 return StmtError();
3586
Douglas Gregor43959a92009-08-20 07:17:43 +00003587 if (!getDerived().AlwaysRebuild() &&
3588 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00003589 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003590
3591 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3592 move_arg(Statements),
3593 S->getRBracLoc(),
3594 IsStmtExpr);
3595}
Mike Stump1eb44332009-09-09 15:08:12 +00003596
Douglas Gregor43959a92009-08-20 07:17:43 +00003597template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003598StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003599TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003600 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00003601 {
3602 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00003603 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003604
Eli Friedman264c1f82009-11-19 03:14:00 +00003605 // Transform the left-hand case value.
3606 LHS = getDerived().TransformExpr(S->getLHS());
3607 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003608 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003609
Eli Friedman264c1f82009-11-19 03:14:00 +00003610 // Transform the right-hand case value (for the GNU case-range extension).
3611 RHS = getDerived().TransformExpr(S->getRHS());
3612 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003613 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00003614 }
Mike Stump1eb44332009-09-09 15:08:12 +00003615
Douglas Gregor43959a92009-08-20 07:17:43 +00003616 // Build the case statement.
3617 // Case statements are always rebuilt so that they will attached to their
3618 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003619 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003620 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003621 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003622 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003623 S->getColonLoc());
3624 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003625 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003626
Douglas Gregor43959a92009-08-20 07:17:43 +00003627 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00003628 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003629 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003630 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003631
Douglas Gregor43959a92009-08-20 07:17:43 +00003632 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00003633 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003634}
3635
3636template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003637StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003638TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003639 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00003640 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003641 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003642 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003643
Douglas Gregor43959a92009-08-20 07:17:43 +00003644 // Default statements are always rebuilt
3645 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003646 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003647}
Mike Stump1eb44332009-09-09 15:08:12 +00003648
Douglas Gregor43959a92009-08-20 07:17:43 +00003649template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003650StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003651TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003652 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003653 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003654 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003655
Douglas Gregor43959a92009-08-20 07:17:43 +00003656 // FIXME: Pass the real colon location in.
3657 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3658 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +00003659 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00003660}
Mike Stump1eb44332009-09-09 15:08:12 +00003661
Douglas Gregor43959a92009-08-20 07:17:43 +00003662template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003663StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003664TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003665 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003666 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003667 VarDecl *ConditionVar = 0;
3668 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003669 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003670 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003671 getDerived().TransformDefinition(
3672 S->getConditionVariable()->getLocation(),
3673 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003674 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003675 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003676 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003677 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003678
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003679 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003680 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003681
3682 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003683 if (S->getCond()) {
John McCall60d7b3a2010-08-24 06:29:42 +00003684 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003685 S->getIfLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003686 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003687 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003688 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003689
John McCall9ae2f072010-08-23 23:25:46 +00003690 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003691 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003692 }
Sean Huntc3021132010-05-05 15:23:54 +00003693
John McCall9ae2f072010-08-23 23:25:46 +00003694 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3695 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003696 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003697
Douglas Gregor43959a92009-08-20 07:17:43 +00003698 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003699 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00003700 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003701 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003702
Douglas Gregor43959a92009-08-20 07:17:43 +00003703 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00003704 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00003705 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003706 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003707
Douglas Gregor43959a92009-08-20 07:17:43 +00003708 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003709 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003710 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003711 Then.get() == S->getThen() &&
3712 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00003713 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003714
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003715 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00003716 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00003717 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003718}
3719
3720template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003721StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003722TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003723 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00003724 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00003725 VarDecl *ConditionVar = 0;
3726 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003727 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003728 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003729 getDerived().TransformDefinition(
3730 S->getConditionVariable()->getLocation(),
3731 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003732 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003733 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003734 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003735 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003736
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003737 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003738 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003739 }
Mike Stump1eb44332009-09-09 15:08:12 +00003740
Douglas Gregor43959a92009-08-20 07:17:43 +00003741 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003742 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00003743 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00003744 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003745 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003746 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003747
Douglas Gregor43959a92009-08-20 07:17:43 +00003748 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003749 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003750 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003751 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003752
Douglas Gregor43959a92009-08-20 07:17:43 +00003753 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00003754 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3755 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003756}
Mike Stump1eb44332009-09-09 15:08:12 +00003757
Douglas Gregor43959a92009-08-20 07:17:43 +00003758template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003759StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003760TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003761 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003762 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00003763 VarDecl *ConditionVar = 0;
3764 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003765 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003766 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003767 getDerived().TransformDefinition(
3768 S->getConditionVariable()->getLocation(),
3769 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003770 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003771 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003772 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003773 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003774
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003775 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003776 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003777
3778 if (S->getCond()) {
3779 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003780 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003781 S->getWhileLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003782 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003783 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003784 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00003785 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003786 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003787 }
Mike Stump1eb44332009-09-09 15:08:12 +00003788
John McCall9ae2f072010-08-23 23:25:46 +00003789 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3790 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003791 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003792
Douglas Gregor43959a92009-08-20 07:17:43 +00003793 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003794 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003795 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003796 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003797
Douglas Gregor43959a92009-08-20 07:17:43 +00003798 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00003799 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003800 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003801 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00003802 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003803
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003804 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00003805 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003806}
Mike Stump1eb44332009-09-09 15:08:12 +00003807
Douglas Gregor43959a92009-08-20 07:17:43 +00003808template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003809StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003810TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003811 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003812 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003813 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003814 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003815
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003816 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003817 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003818 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003819 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003820
Douglas Gregor43959a92009-08-20 07:17:43 +00003821 if (!getDerived().AlwaysRebuild() &&
3822 Cond.get() == S->getCond() &&
3823 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00003824 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003825
John McCall9ae2f072010-08-23 23:25:46 +00003826 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3827 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003828 S->getRParenLoc());
3829}
Mike Stump1eb44332009-09-09 15:08:12 +00003830
Douglas Gregor43959a92009-08-20 07:17:43 +00003831template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003832StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003833TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003834 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00003835 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00003836 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003837 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003838
Douglas Gregor43959a92009-08-20 07:17:43 +00003839 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003840 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003841 VarDecl *ConditionVar = 0;
3842 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003843 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003844 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003845 getDerived().TransformDefinition(
3846 S->getConditionVariable()->getLocation(),
3847 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003848 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00003849 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003850 } else {
3851 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003852
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003853 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003854 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003855
3856 if (S->getCond()) {
3857 // Convert the condition to a boolean value.
John McCall60d7b3a2010-08-24 06:29:42 +00003858 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003859 S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003860 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003861 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003862 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003863
John McCall9ae2f072010-08-23 23:25:46 +00003864 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003865 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003866 }
Mike Stump1eb44332009-09-09 15:08:12 +00003867
John McCall9ae2f072010-08-23 23:25:46 +00003868 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3869 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00003870 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003871
Douglas Gregor43959a92009-08-20 07:17:43 +00003872 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00003873 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00003874 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003875 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003876
John McCall9ae2f072010-08-23 23:25:46 +00003877 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3878 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00003879 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003880
Douglas Gregor43959a92009-08-20 07:17:43 +00003881 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00003882 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00003883 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003884 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003885
Douglas Gregor43959a92009-08-20 07:17:43 +00003886 if (!getDerived().AlwaysRebuild() &&
3887 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00003888 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003889 Inc.get() == S->getInc() &&
3890 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00003891 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003892
Douglas Gregor43959a92009-08-20 07:17:43 +00003893 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003894 Init.get(), FullCond, ConditionVar,
3895 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003896}
3897
3898template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003899StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003900TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003901 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003902 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003903 S->getLabel());
3904}
3905
3906template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003907StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003908TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003909 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00003910 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003911 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003912
Douglas Gregor43959a92009-08-20 07:17:43 +00003913 if (!getDerived().AlwaysRebuild() &&
3914 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00003915 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003916
3917 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003918 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003919}
3920
3921template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003922StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003923TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00003924 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003925}
Mike Stump1eb44332009-09-09 15:08:12 +00003926
Douglas Gregor43959a92009-08-20 07:17:43 +00003927template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003928StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003929TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00003930 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003931}
Mike Stump1eb44332009-09-09 15:08:12 +00003932
Douglas Gregor43959a92009-08-20 07:17:43 +00003933template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003934StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003935TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003936 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00003937 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003938 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00003939
Mike Stump1eb44332009-09-09 15:08:12 +00003940 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003941 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00003942 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003943}
Mike Stump1eb44332009-09-09 15:08:12 +00003944
Douglas Gregor43959a92009-08-20 07:17:43 +00003945template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003946StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003947TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003948 bool DeclChanged = false;
3949 llvm::SmallVector<Decl *, 4> Decls;
3950 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3951 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003952 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3953 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003954 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00003955 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003956
Douglas Gregor43959a92009-08-20 07:17:43 +00003957 if (Transformed != *D)
3958 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003959
Douglas Gregor43959a92009-08-20 07:17:43 +00003960 Decls.push_back(Transformed);
3961 }
Mike Stump1eb44332009-09-09 15:08:12 +00003962
Douglas Gregor43959a92009-08-20 07:17:43 +00003963 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00003964 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00003965
3966 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003967 S->getStartLoc(), S->getEndLoc());
3968}
Mike Stump1eb44332009-09-09 15:08:12 +00003969
Douglas Gregor43959a92009-08-20 07:17:43 +00003970template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003971StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003972TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003973 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCall3fa5cae2010-10-26 07:05:15 +00003974 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003975}
3976
3977template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003978StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003979TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003980
John McCallca0408f2010-08-23 06:44:23 +00003981 ASTOwningVector<Expr*> Constraints(getSema());
3982 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003983 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003984
John McCall60d7b3a2010-08-24 06:29:42 +00003985 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00003986 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00003987
3988 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003989
Anders Carlsson703e3942010-01-24 05:50:09 +00003990 // Go through the outputs.
3991 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003992 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003993
Anders Carlsson703e3942010-01-24 05:50:09 +00003994 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00003995 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00003996
Anders Carlsson703e3942010-01-24 05:50:09 +00003997 // Transform the output expr.
3998 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00003999 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004000 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004001 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004002
Anders Carlsson703e3942010-01-24 05:50:09 +00004003 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004004
John McCall9ae2f072010-08-23 23:25:46 +00004005 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004006 }
Sean Huntc3021132010-05-05 15:23:54 +00004007
Anders Carlsson703e3942010-01-24 05:50:09 +00004008 // Go through the inputs.
4009 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004010 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004011
Anders Carlsson703e3942010-01-24 05:50:09 +00004012 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004013 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004014
Anders Carlsson703e3942010-01-24 05:50:09 +00004015 // Transform the input expr.
4016 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004017 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004018 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004019 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004020
Anders Carlsson703e3942010-01-24 05:50:09 +00004021 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004022
John McCall9ae2f072010-08-23 23:25:46 +00004023 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004024 }
Sean Huntc3021132010-05-05 15:23:54 +00004025
Anders Carlsson703e3942010-01-24 05:50:09 +00004026 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004027 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00004028
4029 // Go through the clobbers.
4030 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00004031 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00004032
4033 // No need to transform the asm string literal.
4034 AsmString = SemaRef.Owned(S->getAsmString());
4035
4036 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4037 S->isSimple(),
4038 S->isVolatile(),
4039 S->getNumOutputs(),
4040 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00004041 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004042 move_arg(Constraints),
4043 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00004044 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004045 move_arg(Clobbers),
4046 S->getRParenLoc(),
4047 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00004048}
4049
4050
4051template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004052StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004053TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004054 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00004055 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004056 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004057 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004058
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004059 // Transform the @catch statements (if present).
4060 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004061 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004062 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004063 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004064 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004065 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004066 if (Catch.get() != S->getCatchStmt(I))
4067 AnyCatchChanged = true;
4068 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004069 }
Sean Huntc3021132010-05-05 15:23:54 +00004070
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004071 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00004072 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004073 if (S->getFinallyStmt()) {
4074 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4075 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004076 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004077 }
4078
4079 // If nothing changed, just retain this statement.
4080 if (!getDerived().AlwaysRebuild() &&
4081 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004082 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004083 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004084 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004085
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004086 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00004087 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4088 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004089}
Mike Stump1eb44332009-09-09 15:08:12 +00004090
Douglas Gregor43959a92009-08-20 07:17:43 +00004091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004092StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004093TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004094 // Transform the @catch parameter, if there is one.
4095 VarDecl *Var = 0;
4096 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4097 TypeSourceInfo *TSInfo = 0;
4098 if (FromVar->getTypeSourceInfo()) {
4099 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4100 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004101 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004102 }
Sean Huntc3021132010-05-05 15:23:54 +00004103
Douglas Gregorbe270a02010-04-26 17:57:08 +00004104 QualType T;
4105 if (TSInfo)
4106 T = TSInfo->getType();
4107 else {
4108 T = getDerived().TransformType(FromVar->getType());
4109 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004110 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004111 }
Sean Huntc3021132010-05-05 15:23:54 +00004112
Douglas Gregorbe270a02010-04-26 17:57:08 +00004113 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4114 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004115 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004116 }
Sean Huntc3021132010-05-05 15:23:54 +00004117
John McCall60d7b3a2010-08-24 06:29:42 +00004118 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004119 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004120 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004121
4122 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004123 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004124 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004125}
Mike Stump1eb44332009-09-09 15:08:12 +00004126
Douglas Gregor43959a92009-08-20 07:17:43 +00004127template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004128StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004129TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004130 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004131 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004132 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004133 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004134
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004135 // If nothing changed, just retain this statement.
4136 if (!getDerived().AlwaysRebuild() &&
4137 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004138 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004139
4140 // Build a new statement.
4141 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004142 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004143}
Mike Stump1eb44332009-09-09 15:08:12 +00004144
Douglas Gregor43959a92009-08-20 07:17:43 +00004145template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004146StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004147TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004148 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004149 if (S->getThrowExpr()) {
4150 Operand = getDerived().TransformExpr(S->getThrowExpr());
4151 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004152 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004153 }
Sean Huntc3021132010-05-05 15:23:54 +00004154
Douglas Gregord1377b22010-04-22 21:44:01 +00004155 if (!getDerived().AlwaysRebuild() &&
4156 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004157 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004158
John McCall9ae2f072010-08-23 23:25:46 +00004159 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004160}
Mike Stump1eb44332009-09-09 15:08:12 +00004161
Douglas Gregor43959a92009-08-20 07:17:43 +00004162template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004163StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004164TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004165 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004166 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004167 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004168 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004169 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004170
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004171 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004172 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004173 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004174 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004175
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004176 // If nothing change, just retain the current statement.
4177 if (!getDerived().AlwaysRebuild() &&
4178 Object.get() == S->getSynchExpr() &&
4179 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004180 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004181
4182 // Build a new statement.
4183 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004184 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004185}
4186
4187template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004188StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004189TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004190 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004191 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004192 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004193 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004194 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004195
Douglas Gregorc3203e72010-04-22 23:10:45 +00004196 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00004197 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004198 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004199 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004200
Douglas Gregorc3203e72010-04-22 23:10:45 +00004201 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004202 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004203 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004204 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004205
Douglas Gregorc3203e72010-04-22 23:10:45 +00004206 // If nothing changed, just retain this statement.
4207 if (!getDerived().AlwaysRebuild() &&
4208 Element.get() == S->getElement() &&
4209 Collection.get() == S->getCollection() &&
4210 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004211 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004212
Douglas Gregorc3203e72010-04-22 23:10:45 +00004213 // Build a new statement.
4214 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4215 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004216 Element.get(),
4217 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00004218 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004219 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004220}
4221
4222
4223template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004224StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004225TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4226 // Transform the exception declaration, if any.
4227 VarDecl *Var = 0;
4228 if (S->getExceptionDecl()) {
4229 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00004230 TypeSourceInfo *T = getDerived().TransformType(
4231 ExceptionDecl->getTypeSourceInfo());
4232 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00004233 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004234
Douglas Gregor83cb9422010-09-09 17:09:21 +00004235 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00004236 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00004237 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00004238 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00004239 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004240 }
Mike Stump1eb44332009-09-09 15:08:12 +00004241
Douglas Gregor43959a92009-08-20 07:17:43 +00004242 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00004243 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004244 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004245 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004246
Douglas Gregor43959a92009-08-20 07:17:43 +00004247 if (!getDerived().AlwaysRebuild() &&
4248 !Var &&
4249 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00004250 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004251
4252 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4253 Var,
John McCall9ae2f072010-08-23 23:25:46 +00004254 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004255}
Mike Stump1eb44332009-09-09 15:08:12 +00004256
Douglas Gregor43959a92009-08-20 07:17:43 +00004257template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004258StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004259TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4260 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004261 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004262 = getDerived().TransformCompoundStmt(S->getTryBlock());
4263 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004264 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004265
Douglas Gregor43959a92009-08-20 07:17:43 +00004266 // Transform the handlers.
4267 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004268 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00004269 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004270 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004271 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4272 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004273 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004274
Douglas Gregor43959a92009-08-20 07:17:43 +00004275 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4276 Handlers.push_back(Handler.takeAs<Stmt>());
4277 }
Mike Stump1eb44332009-09-09 15:08:12 +00004278
Douglas Gregor43959a92009-08-20 07:17:43 +00004279 if (!getDerived().AlwaysRebuild() &&
4280 TryBlock.get() == S->getTryBlock() &&
4281 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004282 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004283
John McCall9ae2f072010-08-23 23:25:46 +00004284 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00004285 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004286}
Mike Stump1eb44332009-09-09 15:08:12 +00004287
Douglas Gregor43959a92009-08-20 07:17:43 +00004288//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004289// Expression transformation
4290//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004291template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004292ExprResult
John McCall454feb92009-12-08 09:21:05 +00004293TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004294 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004295}
Mike Stump1eb44332009-09-09 15:08:12 +00004296
4297template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004298ExprResult
John McCall454feb92009-12-08 09:21:05 +00004299TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004300 NestedNameSpecifier *Qualifier = 0;
4301 if (E->getQualifier()) {
4302 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004303 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004304 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00004305 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00004306 }
John McCalldbd872f2009-12-08 09:08:17 +00004307
4308 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004309 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4310 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004311 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00004312 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004313
John McCallec8045d2010-08-17 21:27:17 +00004314 DeclarationNameInfo NameInfo = E->getNameInfo();
4315 if (NameInfo.getName()) {
4316 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4317 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00004318 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00004319 }
Abramo Bagnara25777432010-08-11 22:01:17 +00004320
4321 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004322 Qualifier == E->getQualifier() &&
4323 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00004324 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00004325 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004326
4327 // Mark it referenced in the new context regardless.
4328 // FIXME: this is a bit instantiation-specific.
4329 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4330
John McCall3fa5cae2010-10-26 07:05:15 +00004331 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00004332 }
John McCalldbd872f2009-12-08 09:08:17 +00004333
4334 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00004335 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004336 TemplateArgs = &TransArgs;
4337 TransArgs.setLAngleLoc(E->getLAngleLoc());
4338 TransArgs.setRAngleLoc(E->getRAngleLoc());
4339 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4340 TemplateArgumentLoc Loc;
4341 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004342 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00004343 TransArgs.addArgument(Loc);
4344 }
4345 }
4346
Douglas Gregora2813ce2009-10-23 18:54:35 +00004347 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004348 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004349}
Mike Stump1eb44332009-09-09 15:08:12 +00004350
Douglas Gregorb98b1992009-08-11 05:31:07 +00004351template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004352ExprResult
John McCall454feb92009-12-08 09:21:05 +00004353TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004354 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004355}
Mike Stump1eb44332009-09-09 15:08:12 +00004356
Douglas Gregorb98b1992009-08-11 05:31:07 +00004357template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004358ExprResult
John McCall454feb92009-12-08 09:21:05 +00004359TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004360 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004361}
Mike Stump1eb44332009-09-09 15:08:12 +00004362
Douglas Gregorb98b1992009-08-11 05:31:07 +00004363template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004364ExprResult
John McCall454feb92009-12-08 09:21:05 +00004365TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004366 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004367}
Mike Stump1eb44332009-09-09 15:08:12 +00004368
Douglas Gregorb98b1992009-08-11 05:31:07 +00004369template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004370ExprResult
John McCall454feb92009-12-08 09:21:05 +00004371TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004372 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004373}
Mike Stump1eb44332009-09-09 15:08:12 +00004374
Douglas Gregorb98b1992009-08-11 05:31:07 +00004375template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004376ExprResult
John McCall454feb92009-12-08 09:21:05 +00004377TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004378 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004379}
4380
4381template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004382ExprResult
John McCall454feb92009-12-08 09:21:05 +00004383TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004384 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004385 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004386 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004387
Douglas Gregorb98b1992009-08-11 05:31:07 +00004388 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004389 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004390
John McCall9ae2f072010-08-23 23:25:46 +00004391 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004392 E->getRParen());
4393}
4394
Mike Stump1eb44332009-09-09 15:08:12 +00004395template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004396ExprResult
John McCall454feb92009-12-08 09:21:05 +00004397TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004398 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004399 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004400 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004401
Douglas Gregorb98b1992009-08-11 05:31:07 +00004402 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004403 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004404
Douglas Gregorb98b1992009-08-11 05:31:07 +00004405 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4406 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004407 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004408}
Mike Stump1eb44332009-09-09 15:08:12 +00004409
Douglas Gregorb98b1992009-08-11 05:31:07 +00004410template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004411ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004412TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4413 // Transform the type.
4414 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4415 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00004416 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004417
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004418 // Transform all of the components into components similar to what the
4419 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004420 // FIXME: It would be slightly more efficient in the non-dependent case to
4421 // just map FieldDecls, rather than requiring the rebuilder to look for
4422 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004423 // template code that we don't care.
4424 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00004425 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004426 typedef OffsetOfExpr::OffsetOfNode Node;
4427 llvm::SmallVector<Component, 4> Components;
4428 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4429 const Node &ON = E->getComponent(I);
4430 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004431 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004432 Comp.LocStart = ON.getRange().getBegin();
4433 Comp.LocEnd = ON.getRange().getEnd();
4434 switch (ON.getKind()) {
4435 case Node::Array: {
4436 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00004437 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004438 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004439 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004440
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004441 ExprChanged = ExprChanged || Index.get() != FromIndex;
4442 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00004443 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004444 break;
4445 }
Sean Huntc3021132010-05-05 15:23:54 +00004446
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004447 case Node::Field:
4448 case Node::Identifier:
4449 Comp.isBrackets = false;
4450 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004451 if (!Comp.U.IdentInfo)
4452 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004453
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004454 break;
Sean Huntc3021132010-05-05 15:23:54 +00004455
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004456 case Node::Base:
4457 // Will be recomputed during the rebuild.
4458 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004459 }
Sean Huntc3021132010-05-05 15:23:54 +00004460
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004461 Components.push_back(Comp);
4462 }
Sean Huntc3021132010-05-05 15:23:54 +00004463
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004464 // If nothing changed, retain the existing expression.
4465 if (!getDerived().AlwaysRebuild() &&
4466 Type == E->getTypeSourceInfo() &&
4467 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004468 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00004469
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004470 // Build a new offsetof expression.
4471 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4472 Components.data(), Components.size(),
4473 E->getRParenLoc());
4474}
4475
4476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004477ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00004478TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
4479 assert(getDerived().AlreadyTransformed(E->getType()) &&
4480 "opaque value expression requires transformation");
4481 return SemaRef.Owned(E);
4482}
4483
4484template<typename Derived>
4485ExprResult
John McCall454feb92009-12-08 09:21:05 +00004486TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004487 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004488 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004489
John McCalla93c9342009-12-07 02:54:59 +00004490 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004491 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004492 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004493
John McCall5ab75172009-11-04 07:28:41 +00004494 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00004495 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004496
John McCall5ab75172009-11-04 07:28:41 +00004497 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004498 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004499 E->getSourceRange());
4500 }
Mike Stump1eb44332009-09-09 15:08:12 +00004501
John McCall60d7b3a2010-08-24 06:29:42 +00004502 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00004503 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004504 // C++0x [expr.sizeof]p1:
4505 // The operand is either an expression, which is an unevaluated operand
4506 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00004507 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004508
Douglas Gregorb98b1992009-08-11 05:31:07 +00004509 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4510 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004511 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004512
Douglas Gregorb98b1992009-08-11 05:31:07 +00004513 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004514 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004515 }
Mike Stump1eb44332009-09-09 15:08:12 +00004516
John McCall9ae2f072010-08-23 23:25:46 +00004517 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004518 E->isSizeOf(),
4519 E->getSourceRange());
4520}
Mike Stump1eb44332009-09-09 15:08:12 +00004521
Douglas Gregorb98b1992009-08-11 05:31:07 +00004522template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004523ExprResult
John McCall454feb92009-12-08 09:21:05 +00004524TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004525 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004526 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004527 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004528
John McCall60d7b3a2010-08-24 06:29:42 +00004529 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004530 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004531 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004532
4533
Douglas Gregorb98b1992009-08-11 05:31:07 +00004534 if (!getDerived().AlwaysRebuild() &&
4535 LHS.get() == E->getLHS() &&
4536 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004537 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004538
John McCall9ae2f072010-08-23 23:25:46 +00004539 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004540 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00004541 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004542 E->getRBracketLoc());
4543}
Mike Stump1eb44332009-09-09 15:08:12 +00004544
4545template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004546ExprResult
John McCall454feb92009-12-08 09:21:05 +00004547TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004548 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00004549 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004550 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004551 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004552
4553 // Transform arguments.
4554 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004555 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004556 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004557 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004558 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004559 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004560
Mike Stump1eb44332009-09-09 15:08:12 +00004561 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00004562 Args.push_back(Arg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004563 }
Mike Stump1eb44332009-09-09 15:08:12 +00004564
Douglas Gregorb98b1992009-08-11 05:31:07 +00004565 if (!getDerived().AlwaysRebuild() &&
4566 Callee.get() == E->getCallee() &&
4567 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004568 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004569
Douglas Gregorb98b1992009-08-11 05:31:07 +00004570 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004571 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004572 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00004573 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004574 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004575 E->getRParenLoc());
4576}
Mike Stump1eb44332009-09-09 15:08:12 +00004577
4578template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004579ExprResult
John McCall454feb92009-12-08 09:21:05 +00004580TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004581 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004582 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004583 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004584
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004585 NestedNameSpecifier *Qualifier = 0;
4586 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004587 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004588 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004589 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004590 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00004591 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004592 }
Mike Stump1eb44332009-09-09 15:08:12 +00004593
Eli Friedmanf595cc42009-12-04 06:40:45 +00004594 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004595 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4596 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004597 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00004598 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004599
John McCall6bb80172010-03-30 21:47:33 +00004600 NamedDecl *FoundDecl = E->getFoundDecl();
4601 if (FoundDecl == E->getMemberDecl()) {
4602 FoundDecl = Member;
4603 } else {
4604 FoundDecl = cast_or_null<NamedDecl>(
4605 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4606 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00004607 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00004608 }
4609
Douglas Gregorb98b1992009-08-11 05:31:07 +00004610 if (!getDerived().AlwaysRebuild() &&
4611 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004612 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004613 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004614 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00004615 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00004616
Anders Carlsson1f240322009-12-22 05:24:09 +00004617 // Mark it referenced in the new context regardless.
4618 // FIXME: this is a bit instantiation-specific.
4619 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00004620 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00004621 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004622
John McCalld5532b62009-11-23 01:53:49 +00004623 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00004624 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00004625 TransArgs.setLAngleLoc(E->getLAngleLoc());
4626 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004627 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004628 TemplateArgumentLoc Loc;
4629 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00004630 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004631 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004632 }
4633 }
Sean Huntc3021132010-05-05 15:23:54 +00004634
Douglas Gregorb98b1992009-08-11 05:31:07 +00004635 // FIXME: Bogus source location for the operator
4636 SourceLocation FakeOperatorLoc
4637 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4638
John McCallc2233c52010-01-15 08:34:02 +00004639 // FIXME: to do this check properly, we will need to preserve the
4640 // first-qualifier-in-scope here, just in case we had a dependent
4641 // base (and therefore couldn't do the check) and a
4642 // nested-name-qualifier (and therefore could do the lookup).
4643 NamedDecl *FirstQualifierInScope = 0;
4644
John McCall9ae2f072010-08-23 23:25:46 +00004645 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004646 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004647 Qualifier,
4648 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004649 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004650 Member,
John McCall6bb80172010-03-30 21:47:33 +00004651 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00004652 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00004653 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004654 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004655}
Mike Stump1eb44332009-09-09 15:08:12 +00004656
Douglas Gregorb98b1992009-08-11 05:31:07 +00004657template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004658ExprResult
John McCall454feb92009-12-08 09:21:05 +00004659TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
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 LHS.get() == E->getLHS() &&
4670 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004671 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004672
Douglas Gregorb98b1992009-08-11 05:31:07 +00004673 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004674 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004675}
4676
Mike Stump1eb44332009-09-09 15:08:12 +00004677template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004678ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004679TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004680 CompoundAssignOperator *E) {
4681 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004682}
Mike Stump1eb44332009-09-09 15:08:12 +00004683
Douglas Gregorb98b1992009-08-11 05:31:07 +00004684template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004685ExprResult
John McCall454feb92009-12-08 09:21:05 +00004686TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004687 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004688 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004689 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004690
John McCall60d7b3a2010-08-24 06:29:42 +00004691 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004692 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004693 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004694
John McCall60d7b3a2010-08-24 06:29:42 +00004695 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004696 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004697 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004698
Douglas Gregorb98b1992009-08-11 05:31:07 +00004699 if (!getDerived().AlwaysRebuild() &&
4700 Cond.get() == E->getCond() &&
4701 LHS.get() == E->getLHS() &&
4702 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004703 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004704
John McCall9ae2f072010-08-23 23:25:46 +00004705 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004706 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004707 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004708 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004709 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004710}
Mike Stump1eb44332009-09-09 15:08:12 +00004711
4712template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004713ExprResult
John McCall454feb92009-12-08 09:21:05 +00004714TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004715 // Implicit casts are eliminated during transformation, since they
4716 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004717 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004718}
Mike Stump1eb44332009-09-09 15:08:12 +00004719
Douglas Gregorb98b1992009-08-11 05:31:07 +00004720template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004721ExprResult
John McCall454feb92009-12-08 09:21:05 +00004722TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004723 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4724 if (!Type)
4725 return ExprError();
4726
John McCall60d7b3a2010-08-24 06:29:42 +00004727 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004728 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004729 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004730 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004731
Douglas Gregorb98b1992009-08-11 05:31:07 +00004732 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004733 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004734 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004735 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004736
John McCall9d125032010-01-15 18:39:57 +00004737 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00004738 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004739 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004740 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004741}
Mike Stump1eb44332009-09-09 15:08:12 +00004742
Douglas Gregorb98b1992009-08-11 05:31:07 +00004743template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004744ExprResult
John McCall454feb92009-12-08 09:21:05 +00004745TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004746 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4747 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4748 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004749 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004750
John McCall60d7b3a2010-08-24 06:29:42 +00004751 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004752 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004753 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004754
Douglas Gregorb98b1992009-08-11 05:31:07 +00004755 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004756 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004757 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00004758 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004759
John McCall1d7d8d62010-01-19 22:33:45 +00004760 // Note: the expression type doesn't necessarily match the
4761 // type-as-written, but that's okay, because it should always be
4762 // derivable from the initializer.
4763
John McCall42f56b52010-01-18 19:35:47 +00004764 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004765 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00004766 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004767}
Mike Stump1eb44332009-09-09 15:08:12 +00004768
Douglas Gregorb98b1992009-08-11 05:31:07 +00004769template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004770ExprResult
John McCall454feb92009-12-08 09:21:05 +00004771TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004772 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004773 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004774 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004775
Douglas Gregorb98b1992009-08-11 05:31:07 +00004776 if (!getDerived().AlwaysRebuild() &&
4777 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00004778 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004779
Douglas Gregorb98b1992009-08-11 05:31:07 +00004780 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004781 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004782 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00004783 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004784 E->getAccessorLoc(),
4785 E->getAccessor());
4786}
Mike Stump1eb44332009-09-09 15:08:12 +00004787
Douglas Gregorb98b1992009-08-11 05:31:07 +00004788template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004789ExprResult
John McCall454feb92009-12-08 09:21:05 +00004790TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004791 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004792
John McCallca0408f2010-08-23 06:44:23 +00004793 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004794 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004795 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004796 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004797 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004798
Douglas Gregorb98b1992009-08-11 05:31:07 +00004799 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCall9ae2f072010-08-23 23:25:46 +00004800 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004801 }
Mike Stump1eb44332009-09-09 15:08:12 +00004802
Douglas Gregorb98b1992009-08-11 05:31:07 +00004803 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004804 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004805
Douglas Gregorb98b1992009-08-11 05:31:07 +00004806 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004807 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004808}
Mike Stump1eb44332009-09-09 15:08:12 +00004809
Douglas Gregorb98b1992009-08-11 05:31:07 +00004810template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004811ExprResult
John McCall454feb92009-12-08 09:21:05 +00004812TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004813 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004814
Douglas Gregor43959a92009-08-20 07:17:43 +00004815 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00004816 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004817 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004818 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004819
Douglas Gregor43959a92009-08-20 07:17:43 +00004820 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00004821 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004822 bool ExprChanged = false;
4823 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4824 DEnd = E->designators_end();
4825 D != DEnd; ++D) {
4826 if (D->isFieldDesignator()) {
4827 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4828 D->getDotLoc(),
4829 D->getFieldLoc()));
4830 continue;
4831 }
Mike Stump1eb44332009-09-09 15:08:12 +00004832
Douglas Gregorb98b1992009-08-11 05:31:07 +00004833 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00004834 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004835 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004836 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004837
4838 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004839 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004840
Douglas Gregorb98b1992009-08-11 05:31:07 +00004841 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4842 ArrayExprs.push_back(Index.release());
4843 continue;
4844 }
Mike Stump1eb44332009-09-09 15:08:12 +00004845
Douglas Gregorb98b1992009-08-11 05:31:07 +00004846 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00004847 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004848 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4849 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004850 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004851
John McCall60d7b3a2010-08-24 06:29:42 +00004852 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004853 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004854 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004855
4856 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004857 End.get(),
4858 D->getLBracketLoc(),
4859 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004860
Douglas Gregorb98b1992009-08-11 05:31:07 +00004861 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4862 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004863
Douglas Gregorb98b1992009-08-11 05:31:07 +00004864 ArrayExprs.push_back(Start.release());
4865 ArrayExprs.push_back(End.release());
4866 }
Mike Stump1eb44332009-09-09 15:08:12 +00004867
Douglas Gregorb98b1992009-08-11 05:31:07 +00004868 if (!getDerived().AlwaysRebuild() &&
4869 Init.get() == E->getInit() &&
4870 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004871 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004872
Douglas Gregorb98b1992009-08-11 05:31:07 +00004873 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4874 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004875 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004876}
Mike Stump1eb44332009-09-09 15:08:12 +00004877
Douglas Gregorb98b1992009-08-11 05:31:07 +00004878template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004879ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004880TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004881 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004882 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004883
Douglas Gregor5557b252009-10-28 00:29:27 +00004884 // FIXME: Will we ever have proper type location here? Will we actually
4885 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004886 QualType T = getDerived().TransformType(E->getType());
4887 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004888 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004889
Douglas Gregorb98b1992009-08-11 05:31:07 +00004890 if (!getDerived().AlwaysRebuild() &&
4891 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00004892 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004893
Douglas Gregorb98b1992009-08-11 05:31:07 +00004894 return getDerived().RebuildImplicitValueInitExpr(T);
4895}
Mike Stump1eb44332009-09-09 15:08:12 +00004896
Douglas Gregorb98b1992009-08-11 05:31:07 +00004897template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004898ExprResult
John McCall454feb92009-12-08 09:21:05 +00004899TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004900 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4901 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004902 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004903
John McCall60d7b3a2010-08-24 06:29:42 +00004904 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004905 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004906 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004907
Douglas Gregorb98b1992009-08-11 05:31:07 +00004908 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004909 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004910 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004911 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004912
John McCall9ae2f072010-08-23 23:25:46 +00004913 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004914 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004915}
4916
4917template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004918ExprResult
John McCall454feb92009-12-08 09:21:05 +00004919TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004920 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004921 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004922 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004923 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004924 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004925 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004926
Douglas Gregorb98b1992009-08-11 05:31:07 +00004927 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00004928 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004929 }
Mike Stump1eb44332009-09-09 15:08:12 +00004930
Douglas Gregorb98b1992009-08-11 05:31:07 +00004931 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4932 move_arg(Inits),
4933 E->getRParenLoc());
4934}
Mike Stump1eb44332009-09-09 15:08:12 +00004935
Douglas Gregorb98b1992009-08-11 05:31:07 +00004936/// \brief Transform an address-of-label expression.
4937///
4938/// By default, the transformation of an address-of-label expression always
4939/// rebuilds the expression, so that the label identifier can be resolved to
4940/// the corresponding label statement by semantic analysis.
4941template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004942ExprResult
John McCall454feb92009-12-08 09:21:05 +00004943TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004944 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4945 E->getLabel());
4946}
Mike Stump1eb44332009-09-09 15:08:12 +00004947
4948template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004949ExprResult
John McCall454feb92009-12-08 09:21:05 +00004950TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004951 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004952 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4953 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004954 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004955
Douglas Gregorb98b1992009-08-11 05:31:07 +00004956 if (!getDerived().AlwaysRebuild() &&
4957 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004958 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004959
4960 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004961 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004962 E->getRParenLoc());
4963}
Mike Stump1eb44332009-09-09 15:08:12 +00004964
Douglas Gregorb98b1992009-08-11 05:31:07 +00004965template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004966ExprResult
John McCall454feb92009-12-08 09:21:05 +00004967TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004968 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004969 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004970 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004971
John McCall60d7b3a2010-08-24 06:29:42 +00004972 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004973 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004974 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004975
John McCall60d7b3a2010-08-24 06:29:42 +00004976 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004977 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004978 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004979
Douglas Gregorb98b1992009-08-11 05:31:07 +00004980 if (!getDerived().AlwaysRebuild() &&
4981 Cond.get() == E->getCond() &&
4982 LHS.get() == E->getLHS() &&
4983 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004984 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004985
Douglas Gregorb98b1992009-08-11 05:31:07 +00004986 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004987 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004988 E->getRParenLoc());
4989}
Mike Stump1eb44332009-09-09 15:08:12 +00004990
Douglas Gregorb98b1992009-08-11 05:31:07 +00004991template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004992ExprResult
John McCall454feb92009-12-08 09:21:05 +00004993TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004994 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004995}
4996
4997template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004998ExprResult
John McCall454feb92009-12-08 09:21:05 +00004999TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00005000 switch (E->getOperator()) {
5001 case OO_New:
5002 case OO_Delete:
5003 case OO_Array_New:
5004 case OO_Array_Delete:
5005 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00005006 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005007
Douglas Gregor668d6d92009-12-13 20:44:55 +00005008 case OO_Call: {
5009 // This is a call to an object's operator().
5010 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5011
5012 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005013 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005014 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005015 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005016
5017 // FIXME: Poor location information
5018 SourceLocation FakeLParenLoc
5019 = SemaRef.PP.getLocForEndOfToken(
5020 static_cast<Expr *>(Object.get())->getLocEnd());
5021
5022 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00005023 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor668d6d92009-12-13 20:44:55 +00005024 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005025 if (getDerived().DropCallArgument(E->getArg(I)))
5026 break;
Sean Huntc3021132010-05-05 15:23:54 +00005027
John McCall60d7b3a2010-08-24 06:29:42 +00005028 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005029 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005030 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005031
Douglas Gregor668d6d92009-12-13 20:44:55 +00005032 Args.push_back(Arg.release());
5033 }
5034
John McCall9ae2f072010-08-23 23:25:46 +00005035 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00005036 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00005037 E->getLocEnd());
5038 }
5039
5040#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5041 case OO_##Name:
5042#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5043#include "clang/Basic/OperatorKinds.def"
5044 case OO_Subscript:
5045 // Handled below.
5046 break;
5047
5048 case OO_Conditional:
5049 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00005050 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005051
5052 case OO_None:
5053 case NUM_OVERLOADED_OPERATORS:
5054 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00005055 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005056 }
5057
John McCall60d7b3a2010-08-24 06:29:42 +00005058 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005059 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005060 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005061
John McCall60d7b3a2010-08-24 06:29:42 +00005062 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005063 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005064 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005065
John McCall60d7b3a2010-08-24 06:29:42 +00005066 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005067 if (E->getNumArgs() == 2) {
5068 Second = getDerived().TransformExpr(E->getArg(1));
5069 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005070 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005071 }
Mike Stump1eb44332009-09-09 15:08:12 +00005072
Douglas Gregorb98b1992009-08-11 05:31:07 +00005073 if (!getDerived().AlwaysRebuild() &&
5074 Callee.get() == E->getCallee() &&
5075 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005076 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00005077 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005078
Douglas Gregorb98b1992009-08-11 05:31:07 +00005079 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5080 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005081 Callee.get(),
5082 First.get(),
5083 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005084}
Mike Stump1eb44332009-09-09 15:08:12 +00005085
Douglas Gregorb98b1992009-08-11 05:31:07 +00005086template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005087ExprResult
John McCall454feb92009-12-08 09:21:05 +00005088TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5089 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005090}
Mike Stump1eb44332009-09-09 15:08:12 +00005091
Douglas Gregorb98b1992009-08-11 05:31:07 +00005092template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005093ExprResult
John McCall454feb92009-12-08 09:21:05 +00005094TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005095 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5096 if (!Type)
5097 return ExprError();
5098
John McCall60d7b3a2010-08-24 06:29:42 +00005099 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005100 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005101 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005102 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005103
Douglas Gregorb98b1992009-08-11 05:31:07 +00005104 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005105 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005106 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005107 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005108
Douglas Gregorb98b1992009-08-11 05:31:07 +00005109 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005110 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005111 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5112 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5113 SourceLocation FakeRParenLoc
5114 = SemaRef.PP.getLocForEndOfToken(
5115 E->getSubExpr()->getSourceRange().getEnd());
5116 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005117 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005118 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005119 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005120 FakeRAngleLoc,
5121 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005122 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005123 FakeRParenLoc);
5124}
Mike Stump1eb44332009-09-09 15:08:12 +00005125
Douglas Gregorb98b1992009-08-11 05:31:07 +00005126template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005127ExprResult
John McCall454feb92009-12-08 09:21:05 +00005128TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5129 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005130}
Mike Stump1eb44332009-09-09 15:08:12 +00005131
5132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005133ExprResult
John McCall454feb92009-12-08 09:21:05 +00005134TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5135 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005136}
5137
Douglas Gregorb98b1992009-08-11 05:31:07 +00005138template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005139ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005140TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005141 CXXReinterpretCastExpr *E) {
5142 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005143}
Mike Stump1eb44332009-09-09 15:08:12 +00005144
Douglas Gregorb98b1992009-08-11 05:31:07 +00005145template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005146ExprResult
John McCall454feb92009-12-08 09:21:05 +00005147TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5148 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005149}
Mike Stump1eb44332009-09-09 15:08:12 +00005150
Douglas Gregorb98b1992009-08-11 05:31:07 +00005151template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005152ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005153TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005154 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005155 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5156 if (!Type)
5157 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005158
John McCall60d7b3a2010-08-24 06:29:42 +00005159 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005160 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005161 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005162 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005163
Douglas Gregorb98b1992009-08-11 05:31:07 +00005164 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005165 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005166 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005167 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005168
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005169 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005170 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005171 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005172 E->getRParenLoc());
5173}
Mike Stump1eb44332009-09-09 15:08:12 +00005174
Douglas Gregorb98b1992009-08-11 05:31:07 +00005175template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005176ExprResult
John McCall454feb92009-12-08 09:21:05 +00005177TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005178 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005179 TypeSourceInfo *TInfo
5180 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5181 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005182 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005183
Douglas Gregorb98b1992009-08-11 05:31:07 +00005184 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005185 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005186 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005187
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005188 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5189 E->getLocStart(),
5190 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005191 E->getLocEnd());
5192 }
Mike Stump1eb44332009-09-09 15:08:12 +00005193
Douglas Gregorb98b1992009-08-11 05:31:07 +00005194 // We don't know whether the expression is potentially evaluated until
5195 // after we perform semantic analysis, so the expression is potentially
5196 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005197 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00005198 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005199
John McCall60d7b3a2010-08-24 06:29:42 +00005200 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005201 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005202 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005203
Douglas Gregorb98b1992009-08-11 05:31:07 +00005204 if (!getDerived().AlwaysRebuild() &&
5205 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005206 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005207
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005208 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5209 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005210 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005211 E->getLocEnd());
5212}
5213
5214template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005215ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00005216TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5217 if (E->isTypeOperand()) {
5218 TypeSourceInfo *TInfo
5219 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5220 if (!TInfo)
5221 return ExprError();
5222
5223 if (!getDerived().AlwaysRebuild() &&
5224 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005225 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005226
5227 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5228 E->getLocStart(),
5229 TInfo,
5230 E->getLocEnd());
5231 }
5232
5233 // We don't know whether the expression is potentially evaluated until
5234 // after we perform semantic analysis, so the expression is potentially
5235 // potentially evaluated.
5236 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5237
5238 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5239 if (SubExpr.isInvalid())
5240 return ExprError();
5241
5242 if (!getDerived().AlwaysRebuild() &&
5243 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005244 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005245
5246 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5247 E->getLocStart(),
5248 SubExpr.get(),
5249 E->getLocEnd());
5250}
5251
5252template<typename Derived>
5253ExprResult
John McCall454feb92009-12-08 09:21:05 +00005254TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *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
Douglas Gregorb98b1992009-08-11 05:31:07 +00005260TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005261 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005262 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005263}
Mike Stump1eb44332009-09-09 15:08:12 +00005264
Douglas Gregorb98b1992009-08-11 05:31:07 +00005265template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005266ExprResult
John McCall454feb92009-12-08 09:21:05 +00005267TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005268 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5269 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5270 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00005271
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005272 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005273 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005274
Douglas Gregor828a1972010-01-07 23:12:05 +00005275 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005276}
Mike Stump1eb44332009-09-09 15:08:12 +00005277
Douglas Gregorb98b1992009-08-11 05:31:07 +00005278template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005279ExprResult
John McCall454feb92009-12-08 09:21:05 +00005280TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005281 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005282 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005283 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005284
Douglas Gregorb98b1992009-08-11 05:31:07 +00005285 if (!getDerived().AlwaysRebuild() &&
5286 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005287 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005288
John McCall9ae2f072010-08-23 23:25:46 +00005289 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005290}
Mike Stump1eb44332009-09-09 15:08:12 +00005291
Douglas Gregorb98b1992009-08-11 05:31:07 +00005292template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005293ExprResult
John McCall454feb92009-12-08 09:21:05 +00005294TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005295 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005296 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5297 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005298 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00005299 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005300
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005301 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005302 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00005303 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005304
Douglas Gregor036aed12009-12-23 23:03:06 +00005305 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005306}
Mike Stump1eb44332009-09-09 15:08:12 +00005307
Douglas Gregorb98b1992009-08-11 05:31:07 +00005308template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005309ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00005310TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5311 CXXScalarValueInitExpr *E) {
5312 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5313 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005314 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00005315
Douglas Gregorb98b1992009-08-11 05:31:07 +00005316 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005317 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005318 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005319
Douglas Gregorab6677e2010-09-08 00:15:04 +00005320 return getDerived().RebuildCXXScalarValueInitExpr(T,
5321 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00005322 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005323}
Mike Stump1eb44332009-09-09 15:08:12 +00005324
Douglas Gregorb98b1992009-08-11 05:31:07 +00005325template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005326ExprResult
John McCall454feb92009-12-08 09:21:05 +00005327TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005328 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005329 TypeSourceInfo *AllocTypeInfo
5330 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5331 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005332 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005333
Douglas Gregorb98b1992009-08-11 05:31:07 +00005334 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00005335 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005336 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005337 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005338
Douglas Gregorb98b1992009-08-11 05:31:07 +00005339 // Transform the placement arguments (if any).
5340 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005341 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005342 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall63d5fb32010-10-05 22:36:42 +00005343 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5344 ArgumentChanged = true;
5345 break;
5346 }
5347
John McCall60d7b3a2010-08-24 06:29:42 +00005348 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005349 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005350 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005351
Douglas Gregorb98b1992009-08-11 05:31:07 +00005352 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5353 PlacementArgs.push_back(Arg.take());
5354 }
Mike Stump1eb44332009-09-09 15:08:12 +00005355
Douglas Gregor43959a92009-08-20 07:17:43 +00005356 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00005357 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005358 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall63d5fb32010-10-05 22:36:42 +00005359 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5360 ArgumentChanged = true;
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005361 break;
John McCall63d5fb32010-10-05 22:36:42 +00005362 }
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005363
John McCall60d7b3a2010-08-24 06:29:42 +00005364 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005365 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005366 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005367
Douglas Gregorb98b1992009-08-11 05:31:07 +00005368 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5369 ConstructorArgs.push_back(Arg.take());
5370 }
Mike Stump1eb44332009-09-09 15:08:12 +00005371
Douglas Gregor1af74512010-02-26 00:38:10 +00005372 // Transform constructor, new operator, and delete operator.
5373 CXXConstructorDecl *Constructor = 0;
5374 if (E->getConstructor()) {
5375 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005376 getDerived().TransformDecl(E->getLocStart(),
5377 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005378 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005379 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005380 }
5381
5382 FunctionDecl *OperatorNew = 0;
5383 if (E->getOperatorNew()) {
5384 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005385 getDerived().TransformDecl(E->getLocStart(),
5386 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005387 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00005388 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005389 }
5390
5391 FunctionDecl *OperatorDelete = 0;
5392 if (E->getOperatorDelete()) {
5393 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005394 getDerived().TransformDecl(E->getLocStart(),
5395 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005396 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005397 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005398 }
Sean Huntc3021132010-05-05 15:23:54 +00005399
Douglas Gregorb98b1992009-08-11 05:31:07 +00005400 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005401 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005402 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005403 Constructor == E->getConstructor() &&
5404 OperatorNew == E->getOperatorNew() &&
5405 OperatorDelete == E->getOperatorDelete() &&
5406 !ArgumentChanged) {
5407 // Mark any declarations we need as referenced.
5408 // FIXME: instantiation-specific.
5409 if (Constructor)
5410 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5411 if (OperatorNew)
5412 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5413 if (OperatorDelete)
5414 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00005415 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00005416 }
Mike Stump1eb44332009-09-09 15:08:12 +00005417
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005418 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005419 if (!ArraySize.get()) {
5420 // If no array size was specified, but the new expression was
5421 // instantiated with an array type (e.g., "new T" where T is
5422 // instantiated with "int[4]"), extract the outer bound from the
5423 // array type as our array size. We do this with constant and
5424 // dependently-sized array types.
5425 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5426 if (!ArrayT) {
5427 // Do nothing
5428 } else if (const ConstantArrayType *ConsArrayT
5429 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005430 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00005431 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5432 ConsArrayT->getSize(),
5433 SemaRef.Context.getSizeType(),
5434 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005435 AllocType = ConsArrayT->getElementType();
5436 } else if (const DependentSizedArrayType *DepArrayT
5437 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5438 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00005439 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005440 AllocType = DepArrayT->getElementType();
5441 }
5442 }
5443 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005444
Douglas Gregorb98b1992009-08-11 05:31:07 +00005445 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5446 E->isGlobalNew(),
5447 /*FIXME:*/E->getLocStart(),
5448 move_arg(PlacementArgs),
5449 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00005450 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005451 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005452 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00005453 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005454 /*FIXME:*/E->getLocStart(),
5455 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005456 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005457}
Mike Stump1eb44332009-09-09 15:08:12 +00005458
Douglas Gregorb98b1992009-08-11 05:31:07 +00005459template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005460ExprResult
John McCall454feb92009-12-08 09:21:05 +00005461TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005462 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005463 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005464 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005465
Douglas Gregor1af74512010-02-26 00:38:10 +00005466 // Transform the delete operator, if known.
5467 FunctionDecl *OperatorDelete = 0;
5468 if (E->getOperatorDelete()) {
5469 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005470 getDerived().TransformDecl(E->getLocStart(),
5471 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005472 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005473 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005474 }
Sean Huntc3021132010-05-05 15:23:54 +00005475
Douglas Gregorb98b1992009-08-11 05:31:07 +00005476 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005477 Operand.get() == E->getArgument() &&
5478 OperatorDelete == E->getOperatorDelete()) {
5479 // Mark any declarations we need as referenced.
5480 // FIXME: instantiation-specific.
5481 if (OperatorDelete)
5482 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00005483
5484 if (!E->getArgument()->isTypeDependent()) {
5485 QualType Destroyed = SemaRef.Context.getBaseElementType(
5486 E->getDestroyedType());
5487 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5488 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5489 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5490 SemaRef.LookupDestructor(Record));
5491 }
5492 }
5493
John McCall3fa5cae2010-10-26 07:05:15 +00005494 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00005495 }
Mike Stump1eb44332009-09-09 15:08:12 +00005496
Douglas Gregorb98b1992009-08-11 05:31:07 +00005497 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5498 E->isGlobalDelete(),
5499 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00005500 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005501}
Mike Stump1eb44332009-09-09 15:08:12 +00005502
Douglas Gregorb98b1992009-08-11 05:31:07 +00005503template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005504ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005505TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005506 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005507 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00005508 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005509 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005510
John McCallb3d87482010-08-24 05:47:05 +00005511 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005512 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005513 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005514 E->getOperatorLoc(),
5515 E->isArrow()? tok::arrow : tok::period,
5516 ObjectTypePtr,
5517 MayBePseudoDestructor);
5518 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005519 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005520
John McCallb3d87482010-08-24 05:47:05 +00005521 QualType ObjectType = ObjectTypePtr.get();
John McCall43fed0d2010-11-12 08:19:04 +00005522 NestedNameSpecifier *Qualifier = E->getQualifier();
5523 if (Qualifier) {
5524 Qualifier
5525 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5526 E->getQualifierRange(),
5527 ObjectType);
5528 if (!Qualifier)
5529 return ExprError();
5530 }
Mike Stump1eb44332009-09-09 15:08:12 +00005531
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005532 PseudoDestructorTypeStorage Destroyed;
5533 if (E->getDestroyedTypeInfo()) {
5534 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00005535 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5536 ObjectType, 0, Qualifier);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005537 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005538 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005539 Destroyed = DestroyedTypeInfo;
5540 } else if (ObjectType->isDependentType()) {
5541 // We aren't likely to be able to resolve the identifier down to a type
5542 // now anyway, so just retain the identifier.
5543 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5544 E->getDestroyedTypeLoc());
5545 } else {
5546 // Look for a destructor known with the given name.
5547 CXXScopeSpec SS;
5548 if (Qualifier) {
5549 SS.setScopeRep(Qualifier);
5550 SS.setRange(E->getQualifierRange());
5551 }
Sean Huntc3021132010-05-05 15:23:54 +00005552
John McCallb3d87482010-08-24 05:47:05 +00005553 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005554 *E->getDestroyedTypeIdentifier(),
5555 E->getDestroyedTypeLoc(),
5556 /*Scope=*/0,
5557 SS, ObjectTypePtr,
5558 false);
5559 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005560 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005561
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005562 Destroyed
5563 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5564 E->getDestroyedTypeLoc());
5565 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005566
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005567 TypeSourceInfo *ScopeTypeInfo = 0;
5568 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00005569 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005570 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005571 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00005572 }
Sean Huntc3021132010-05-05 15:23:54 +00005573
John McCall9ae2f072010-08-23 23:25:46 +00005574 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005575 E->getOperatorLoc(),
5576 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005577 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005578 E->getQualifierRange(),
5579 ScopeTypeInfo,
5580 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005581 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005582 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005583}
Mike Stump1eb44332009-09-09 15:08:12 +00005584
Douglas Gregora71d8192009-09-04 17:36:40 +00005585template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005586ExprResult
John McCallba135432009-11-21 08:51:07 +00005587TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005588 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005589 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5590
5591 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5592 Sema::LookupOrdinaryName);
5593
5594 // Transform all the decls.
5595 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5596 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005597 NamedDecl *InstD = static_cast<NamedDecl*>(
5598 getDerived().TransformDecl(Old->getNameLoc(),
5599 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005600 if (!InstD) {
5601 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5602 // This can happen because of dependent hiding.
5603 if (isa<UsingShadowDecl>(*I))
5604 continue;
5605 else
John McCallf312b1e2010-08-26 23:41:50 +00005606 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005607 }
John McCallf7a1a742009-11-24 19:00:30 +00005608
5609 // Expand using declarations.
5610 if (isa<UsingDecl>(InstD)) {
5611 UsingDecl *UD = cast<UsingDecl>(InstD);
5612 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5613 E = UD->shadow_end(); I != E; ++I)
5614 R.addDecl(*I);
5615 continue;
5616 }
5617
5618 R.addDecl(InstD);
5619 }
5620
5621 // Resolve a kind, but don't do any further analysis. If it's
5622 // ambiguous, the callee needs to deal with it.
5623 R.resolveKind();
5624
5625 // Rebuild the nested-name qualifier, if present.
5626 CXXScopeSpec SS;
5627 NestedNameSpecifier *Qualifier = 0;
5628 if (Old->getQualifier()) {
5629 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005630 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005631 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005632 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005633
John McCallf7a1a742009-11-24 19:00:30 +00005634 SS.setScopeRep(Qualifier);
5635 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005636 }
5637
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005638 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005639 CXXRecordDecl *NamingClass
5640 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5641 Old->getNameLoc(),
5642 Old->getNamingClass()));
5643 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00005644 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005645
Douglas Gregor66c45152010-04-27 16:10:10 +00005646 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005647 }
5648
5649 // If we have no template arguments, it's a normal declaration name.
5650 if (!Old->hasExplicitTemplateArgs())
5651 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5652
5653 // If we have template arguments, rebuild them, then rebuild the
5654 // templateid expression.
5655 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5656 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5657 TemplateArgumentLoc Loc;
5658 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005659 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00005660 TransArgs.addArgument(Loc);
5661 }
5662
5663 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5664 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005665}
Mike Stump1eb44332009-09-09 15:08:12 +00005666
Douglas Gregorb98b1992009-08-11 05:31:07 +00005667template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005668ExprResult
John McCall454feb92009-12-08 09:21:05 +00005669TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005670 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5671 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005672 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005673
Douglas Gregorb98b1992009-08-11 05:31:07 +00005674 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005675 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005676 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005677
Mike Stump1eb44332009-09-09 15:08:12 +00005678 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005679 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005680 T,
5681 E->getLocEnd());
5682}
Mike Stump1eb44332009-09-09 15:08:12 +00005683
Douglas Gregorb98b1992009-08-11 05:31:07 +00005684template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005685ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00005686TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
5687 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
5688 if (!LhsT)
5689 return ExprError();
5690
5691 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
5692 if (!RhsT)
5693 return ExprError();
5694
5695 if (!getDerived().AlwaysRebuild() &&
5696 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
5697 return SemaRef.Owned(E);
5698
5699 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
5700 E->getLocStart(),
5701 LhsT, RhsT,
5702 E->getLocEnd());
5703}
5704
5705template<typename Derived>
5706ExprResult
John McCall865d4472009-11-19 22:55:06 +00005707TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005708 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005709 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005710 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005711 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005712 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00005713 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005714
John McCall43fed0d2010-11-12 08:19:04 +00005715 // TODO: If this is a conversion-function-id, verify that the
5716 // destination type name (if present) resolves the same way after
5717 // instantiation as it did in the local scope.
5718
Abramo Bagnara25777432010-08-11 22:01:17 +00005719 DeclarationNameInfo NameInfo
5720 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5721 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005722 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005723
John McCallf7a1a742009-11-24 19:00:30 +00005724 if (!E->hasExplicitTemplateArgs()) {
5725 if (!getDerived().AlwaysRebuild() &&
5726 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005727 // Note: it is sufficient to compare the Name component of NameInfo:
5728 // if name has not changed, DNLoc has not changed either.
5729 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00005730 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005731
John McCallf7a1a742009-11-24 19:00:30 +00005732 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5733 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005734 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005735 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005736 }
John McCalld5532b62009-11-23 01:53:49 +00005737
5738 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005739 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005740 TemplateArgumentLoc Loc;
5741 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005742 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005743 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005744 }
5745
John McCallf7a1a742009-11-24 19:00:30 +00005746 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5747 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005748 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005749 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005750}
5751
5752template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005753ExprResult
John McCall454feb92009-12-08 09:21:05 +00005754TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005755 // CXXConstructExprs are always implicit, so when we have a
5756 // 1-argument construction we just transform that argument.
5757 if (E->getNumArgs() == 1 ||
5758 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5759 return getDerived().TransformExpr(E->getArg(0));
5760
Douglas Gregorb98b1992009-08-11 05:31:07 +00005761 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5762
5763 QualType T = getDerived().TransformType(E->getType());
5764 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005765 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005766
5767 CXXConstructorDecl *Constructor
5768 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005769 getDerived().TransformDecl(E->getLocStart(),
5770 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005771 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005772 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005773
Douglas Gregorb98b1992009-08-11 05:31:07 +00005774 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005775 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005776 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005777 ArgEnd = E->arg_end();
5778 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005779 if (getDerived().DropCallArgument(*Arg)) {
5780 ArgumentChanged = true;
5781 break;
5782 }
5783
John McCall60d7b3a2010-08-24 06:29:42 +00005784 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005785 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005786 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005787
Douglas Gregorb98b1992009-08-11 05:31:07 +00005788 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005789 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005790 }
5791
5792 if (!getDerived().AlwaysRebuild() &&
5793 T == E->getType() &&
5794 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005795 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005796 // Mark the constructor as referenced.
5797 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005798 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00005799 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00005800 }
Mike Stump1eb44332009-09-09 15:08:12 +00005801
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005802 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5803 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00005804 move_arg(Args),
5805 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00005806 E->getConstructionKind(),
5807 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005808}
Mike Stump1eb44332009-09-09 15:08:12 +00005809
Douglas Gregorb98b1992009-08-11 05:31:07 +00005810/// \brief Transform a C++ temporary-binding expression.
5811///
Douglas Gregor51326552009-12-24 18:51:59 +00005812/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5813/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005814template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005815ExprResult
John McCall454feb92009-12-08 09:21:05 +00005816TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005817 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005818}
Mike Stump1eb44332009-09-09 15:08:12 +00005819
John McCall4765fa02010-12-06 08:20:24 +00005820/// \brief Transform a C++ expression that contains cleanups that should
5821/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005822///
John McCall4765fa02010-12-06 08:20:24 +00005823/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00005824/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005825template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005826ExprResult
John McCall4765fa02010-12-06 08:20:24 +00005827TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005828 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005829}
Mike Stump1eb44332009-09-09 15:08:12 +00005830
Douglas Gregorb98b1992009-08-11 05:31:07 +00005831template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005832ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005833TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00005834 CXXTemporaryObjectExpr *E) {
5835 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5836 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005837 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005838
Douglas Gregorb98b1992009-08-11 05:31:07 +00005839 CXXConstructorDecl *Constructor
5840 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005841 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005842 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005843 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005844 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005845
Douglas Gregorb98b1992009-08-11 05:31:07 +00005846 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005847 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005848 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005849 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005850 ArgEnd = E->arg_end();
5851 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005852 if (getDerived().DropCallArgument(*Arg)) {
5853 ArgumentChanged = true;
5854 break;
5855 }
5856
John McCall60d7b3a2010-08-24 06:29:42 +00005857 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005858 if (TransArg.isInvalid())
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 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5862 Args.push_back((Expr *)TransArg.release());
5863 }
Mike Stump1eb44332009-09-09 15:08:12 +00005864
Douglas Gregorb98b1992009-08-11 05:31:07 +00005865 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005866 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005867 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005868 !ArgumentChanged) {
5869 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00005870 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00005871 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00005872 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00005873
5874 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5875 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005876 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005877 E->getLocEnd());
5878}
Mike Stump1eb44332009-09-09 15:08:12 +00005879
Douglas Gregorb98b1992009-08-11 05:31:07 +00005880template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005881ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005882TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005883 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00005884 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5885 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005886 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005887
Douglas Gregorb98b1992009-08-11 05:31:07 +00005888 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005889 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005890 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5891 ArgEnd = E->arg_end();
5892 Arg != ArgEnd; ++Arg) {
John McCall60d7b3a2010-08-24 06:29:42 +00005893 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005894 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005895 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005896
Douglas Gregorb98b1992009-08-11 05:31:07 +00005897 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00005898 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005899 }
Mike Stump1eb44332009-09-09 15:08:12 +00005900
Douglas Gregorb98b1992009-08-11 05:31:07 +00005901 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005902 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005903 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005904 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005905
Douglas Gregorb98b1992009-08-11 05:31:07 +00005906 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00005907 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005908 E->getLParenLoc(),
5909 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005910 E->getRParenLoc());
5911}
Mike Stump1eb44332009-09-09 15:08:12 +00005912
Douglas Gregorb98b1992009-08-11 05:31:07 +00005913template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005914ExprResult
John McCall865d4472009-11-19 22:55:06 +00005915TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005916 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005917 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005918 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00005919 Expr *OldBase;
5920 QualType BaseType;
5921 QualType ObjectType;
5922 if (!E->isImplicitAccess()) {
5923 OldBase = E->getBase();
5924 Base = getDerived().TransformExpr(OldBase);
5925 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005926 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005927
John McCallaa81e162009-12-01 22:10:20 +00005928 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00005929 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00005930 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005931 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005932 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005933 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005934 ObjectTy,
5935 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005936 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005937 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00005938
John McCallb3d87482010-08-24 05:47:05 +00005939 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00005940 BaseType = ((Expr*) Base.get())->getType();
5941 } else {
5942 OldBase = 0;
5943 BaseType = getDerived().TransformType(E->getBaseType());
5944 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5945 }
Mike Stump1eb44332009-09-09 15:08:12 +00005946
Douglas Gregor6cd21982009-10-20 05:58:46 +00005947 // Transform the first part of the nested-name-specifier that qualifies
5948 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005949 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005950 = getDerived().TransformFirstQualifierInScope(
5951 E->getFirstQualifierFoundInScope(),
5952 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005953
Douglas Gregora38c6872009-09-03 16:14:30 +00005954 NestedNameSpecifier *Qualifier = 0;
5955 if (E->getQualifier()) {
5956 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5957 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005958 ObjectType,
5959 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005960 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005961 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00005962 }
Mike Stump1eb44332009-09-09 15:08:12 +00005963
John McCall43fed0d2010-11-12 08:19:04 +00005964 // TODO: If this is a conversion-function-id, verify that the
5965 // destination type name (if present) resolves the same way after
5966 // instantiation as it did in the local scope.
5967
Abramo Bagnara25777432010-08-11 22:01:17 +00005968 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00005969 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00005970 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005971 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005972
John McCallaa81e162009-12-01 22:10:20 +00005973 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005974 // This is a reference to a member without an explicitly-specified
5975 // template argument list. Optimize for this common case.
5976 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005977 Base.get() == OldBase &&
5978 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005979 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005980 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005981 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00005982 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005983
John McCall9ae2f072010-08-23 23:25:46 +00005984 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00005985 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005986 E->isArrow(),
5987 E->getOperatorLoc(),
5988 Qualifier,
5989 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005990 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005991 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005992 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005993 }
5994
John McCalld5532b62009-11-23 01:53:49 +00005995 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005996 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005997 TemplateArgumentLoc Loc;
5998 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallf312b1e2010-08-26 23:41:50 +00005999 return ExprError();
John McCalld5532b62009-11-23 01:53:49 +00006000 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006001 }
Mike Stump1eb44332009-09-09 15:08:12 +00006002
John McCall9ae2f072010-08-23 23:25:46 +00006003 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006004 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006005 E->isArrow(),
6006 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006007 Qualifier,
6008 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006009 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006010 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006011 &TransArgs);
6012}
6013
6014template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006015ExprResult
John McCall454feb92009-12-08 09:21:05 +00006016TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00006017 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006018 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006019 QualType BaseType;
6020 if (!Old->isImplicitAccess()) {
6021 Base = getDerived().TransformExpr(Old->getBase());
6022 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006023 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006024 BaseType = ((Expr*) Base.get())->getType();
6025 } else {
6026 BaseType = getDerived().TransformType(Old->getBaseType());
6027 }
John McCall129e2df2009-11-30 22:42:35 +00006028
6029 NestedNameSpecifier *Qualifier = 0;
6030 if (Old->getQualifier()) {
6031 Qualifier
6032 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006033 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00006034 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00006035 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006036 }
6037
Abramo Bagnara25777432010-08-11 22:01:17 +00006038 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00006039 Sema::LookupOrdinaryName);
6040
6041 // Transform all the decls.
6042 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6043 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006044 NamedDecl *InstD = static_cast<NamedDecl*>(
6045 getDerived().TransformDecl(Old->getMemberLoc(),
6046 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006047 if (!InstD) {
6048 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6049 // This can happen because of dependent hiding.
6050 if (isa<UsingShadowDecl>(*I))
6051 continue;
6052 else
John McCallf312b1e2010-08-26 23:41:50 +00006053 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006054 }
John McCall129e2df2009-11-30 22:42:35 +00006055
6056 // Expand using declarations.
6057 if (isa<UsingDecl>(InstD)) {
6058 UsingDecl *UD = cast<UsingDecl>(InstD);
6059 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6060 E = UD->shadow_end(); I != E; ++I)
6061 R.addDecl(*I);
6062 continue;
6063 }
6064
6065 R.addDecl(InstD);
6066 }
6067
6068 R.resolveKind();
6069
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006070 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00006071 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00006072 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006073 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00006074 Old->getMemberLoc(),
6075 Old->getNamingClass()));
6076 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006077 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006078
Douglas Gregor66c45152010-04-27 16:10:10 +00006079 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006080 }
Sean Huntc3021132010-05-05 15:23:54 +00006081
John McCall129e2df2009-11-30 22:42:35 +00006082 TemplateArgumentListInfo TransArgs;
6083 if (Old->hasExplicitTemplateArgs()) {
6084 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6085 TransArgs.setRAngleLoc(Old->getRAngleLoc());
6086 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6087 TemplateArgumentLoc Loc;
6088 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6089 Loc))
John McCallf312b1e2010-08-26 23:41:50 +00006090 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006091 TransArgs.addArgument(Loc);
6092 }
6093 }
John McCallc2233c52010-01-15 08:34:02 +00006094
6095 // FIXME: to do this check properly, we will need to preserve the
6096 // first-qualifier-in-scope here, just in case we had a dependent
6097 // base (and therefore couldn't do the check) and a
6098 // nested-name-qualifier (and therefore could do the lookup).
6099 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006100
John McCall9ae2f072010-08-23 23:25:46 +00006101 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006102 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006103 Old->getOperatorLoc(),
6104 Old->isArrow(),
6105 Qualifier,
6106 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006107 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006108 R,
6109 (Old->hasExplicitTemplateArgs()
6110 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006111}
6112
6113template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006114ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006115TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6116 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6117 if (SubExpr.isInvalid())
6118 return ExprError();
6119
6120 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006121 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00006122
6123 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6124}
6125
6126template<typename Derived>
6127ExprResult
John McCall454feb92009-12-08 09:21:05 +00006128TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006129 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006130}
6131
Mike Stump1eb44332009-09-09 15:08:12 +00006132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006133ExprResult
John McCall454feb92009-12-08 09:21:05 +00006134TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006135 TypeSourceInfo *EncodedTypeInfo
6136 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6137 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006138 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006139
Douglas Gregorb98b1992009-08-11 05:31:07 +00006140 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006141 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006142 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006143
6144 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006145 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006146 E->getRParenLoc());
6147}
Mike Stump1eb44332009-09-09 15:08:12 +00006148
Douglas Gregorb98b1992009-08-11 05:31:07 +00006149template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006150ExprResult
John McCall454feb92009-12-08 09:21:05 +00006151TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006152 // Transform arguments.
6153 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006154 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006155 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006156 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor92e986e2010-04-22 16:44:27 +00006157 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006158 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006159
Douglas Gregor92e986e2010-04-22 16:44:27 +00006160 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00006161 Args.push_back(Arg.get());
Douglas Gregor92e986e2010-04-22 16:44:27 +00006162 }
6163
6164 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6165 // Class message: transform the receiver type.
6166 TypeSourceInfo *ReceiverTypeInfo
6167 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6168 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006169 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006170
Douglas Gregor92e986e2010-04-22 16:44:27 +00006171 // If nothing changed, just retain the existing message send.
6172 if (!getDerived().AlwaysRebuild() &&
6173 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006174 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006175
6176 // Build a new class message send.
6177 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6178 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006179 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006180 E->getMethodDecl(),
6181 E->getLeftLoc(),
6182 move_arg(Args),
6183 E->getRightLoc());
6184 }
6185
6186 // Instance message: transform the receiver
6187 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6188 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006189 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006190 = getDerived().TransformExpr(E->getInstanceReceiver());
6191 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006192 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006193
6194 // If nothing changed, just retain the existing message send.
6195 if (!getDerived().AlwaysRebuild() &&
6196 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006197 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006198
Douglas Gregor92e986e2010-04-22 16:44:27 +00006199 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006200 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006201 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006202 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006203 E->getMethodDecl(),
6204 E->getLeftLoc(),
6205 move_arg(Args),
6206 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006207}
6208
Mike Stump1eb44332009-09-09 15:08:12 +00006209template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006210ExprResult
John McCall454feb92009-12-08 09:21:05 +00006211TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006212 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006213}
6214
Mike Stump1eb44332009-09-09 15:08:12 +00006215template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006216ExprResult
John McCall454feb92009-12-08 09:21:05 +00006217TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006218 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006219}
6220
Mike Stump1eb44332009-09-09 15:08:12 +00006221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006222ExprResult
John McCall454feb92009-12-08 09:21:05 +00006223TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006224 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006225 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006226 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006227 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006228
6229 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006230
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006231 // If nothing changed, just retain the existing expression.
6232 if (!getDerived().AlwaysRebuild() &&
6233 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006234 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006235
John McCall9ae2f072010-08-23 23:25:46 +00006236 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006237 E->getLocation(),
6238 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006239}
6240
Mike Stump1eb44332009-09-09 15:08:12 +00006241template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006242ExprResult
John McCall454feb92009-12-08 09:21:05 +00006243TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00006244 // 'super' and types never change. Property never changes. Just
6245 // retain the existing expression.
6246 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00006247 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006248
Douglas Gregore3303542010-04-26 20:47:02 +00006249 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006250 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00006251 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006252 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006253
Douglas Gregore3303542010-04-26 20:47:02 +00006254 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006255
Douglas Gregore3303542010-04-26 20:47:02 +00006256 // If nothing changed, just retain the existing expression.
6257 if (!getDerived().AlwaysRebuild() &&
6258 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006259 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006260
John McCall12f78a62010-12-02 01:19:52 +00006261 if (E->isExplicitProperty())
6262 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6263 E->getExplicitProperty(),
6264 E->getLocation());
6265
6266 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6267 E->getType(),
6268 E->getImplicitPropertyGetter(),
6269 E->getImplicitPropertySetter(),
6270 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006271}
6272
Mike Stump1eb44332009-09-09 15:08:12 +00006273template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006274ExprResult
John McCall454feb92009-12-08 09:21:05 +00006275TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006276 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006277 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006278 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006279 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006280
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006281 // If nothing changed, just retain the existing expression.
6282 if (!getDerived().AlwaysRebuild() &&
6283 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006284 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006285
John McCall9ae2f072010-08-23 23:25:46 +00006286 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006287 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006288}
6289
Mike Stump1eb44332009-09-09 15:08:12 +00006290template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006291ExprResult
John McCall454feb92009-12-08 09:21:05 +00006292TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006293 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006294 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006295 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006296 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006297 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006298 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006299
Douglas Gregorb98b1992009-08-11 05:31:07 +00006300 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00006301 SubExprs.push_back(SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006302 }
Mike Stump1eb44332009-09-09 15:08:12 +00006303
Douglas Gregorb98b1992009-08-11 05:31:07 +00006304 if (!getDerived().AlwaysRebuild() &&
6305 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006306 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006307
Douglas Gregorb98b1992009-08-11 05:31:07 +00006308 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6309 move_arg(SubExprs),
6310 E->getRParenLoc());
6311}
6312
Mike Stump1eb44332009-09-09 15:08:12 +00006313template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006314ExprResult
John McCall454feb92009-12-08 09:21:05 +00006315TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006316 SourceLocation CaretLoc(E->getExprLoc());
6317
6318 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6319 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6320 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6321 llvm::SmallVector<ParmVarDecl*, 4> Params;
6322 llvm::SmallVector<QualType, 4> ParamTypes;
6323
6324 // Parameter substitution.
6325 const BlockDecl *BD = E->getBlockDecl();
6326 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6327 EN = BD->param_end(); P != EN; ++P) {
6328 ParmVarDecl *OldParm = (*P);
6329 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6330 QualType NewType = NewParm->getType();
6331 Params.push_back(NewParm);
6332 ParamTypes.push_back(NewParm->getType());
6333 }
6334
6335 const FunctionType *BExprFunctionType = E->getFunctionType();
6336 QualType BExprResultType = BExprFunctionType->getResultType();
6337 if (!BExprResultType.isNull()) {
6338 if (!BExprResultType->isDependentType())
6339 CurBlock->ReturnType = BExprResultType;
6340 else if (BExprResultType != SemaRef.Context.DependentTy)
6341 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6342 }
6343
6344 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00006345 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006346 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006347 return ExprError();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006348 // Set the parameters on the block decl.
6349 if (!Params.empty())
6350 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6351
6352 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6353 CurBlock->ReturnType,
6354 ParamTypes.data(),
6355 ParamTypes.size(),
6356 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006357 0,
6358 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006359
6360 CurBlock->FunctionType = FunctionType;
John McCall9ae2f072010-08-23 23:25:46 +00006361 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006362}
6363
Mike Stump1eb44332009-09-09 15:08:12 +00006364template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006365ExprResult
John McCall454feb92009-12-08 09:21:05 +00006366TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006367 NestedNameSpecifier *Qualifier = 0;
6368
6369 ValueDecl *ND
6370 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6371 E->getDecl()));
6372 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006373 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00006374
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006375 if (!getDerived().AlwaysRebuild() &&
6376 ND == E->getDecl()) {
6377 // Mark it referenced in the new context regardless.
6378 // FIXME: this is a bit instantiation-specific.
6379 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6380
John McCall3fa5cae2010-10-26 07:05:15 +00006381 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006382 }
6383
Abramo Bagnara25777432010-08-11 22:01:17 +00006384 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006385 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006386 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006387}
Mike Stump1eb44332009-09-09 15:08:12 +00006388
Douglas Gregorb98b1992009-08-11 05:31:07 +00006389//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006390// Type reconstruction
6391//===----------------------------------------------------------------------===//
6392
Mike Stump1eb44332009-09-09 15:08:12 +00006393template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006394QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6395 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006396 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006397 getDerived().getBaseEntity());
6398}
6399
Mike Stump1eb44332009-09-09 15:08:12 +00006400template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006401QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6402 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006403 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006404 getDerived().getBaseEntity());
6405}
6406
Mike Stump1eb44332009-09-09 15:08:12 +00006407template<typename Derived>
6408QualType
John McCall85737a72009-10-30 00:06:24 +00006409TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6410 bool WrittenAsLValue,
6411 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006412 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006413 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006414}
6415
6416template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006417QualType
John McCall85737a72009-10-30 00:06:24 +00006418TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6419 QualType ClassType,
6420 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006421 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006422 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006423}
6424
6425template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006426QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006427TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6428 ArrayType::ArraySizeModifier SizeMod,
6429 const llvm::APInt *Size,
6430 Expr *SizeExpr,
6431 unsigned IndexTypeQuals,
6432 SourceRange BracketsRange) {
6433 if (SizeExpr || !Size)
6434 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6435 IndexTypeQuals, BracketsRange,
6436 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006437
6438 QualType Types[] = {
6439 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6440 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6441 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006442 };
6443 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6444 QualType SizeType;
6445 for (unsigned I = 0; I != NumTypes; ++I)
6446 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6447 SizeType = Types[I];
6448 break;
6449 }
Mike Stump1eb44332009-09-09 15:08:12 +00006450
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006451 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6452 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006453 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006454 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006455 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006456}
Mike Stump1eb44332009-09-09 15:08:12 +00006457
Douglas Gregor577f75a2009-08-04 16:50:30 +00006458template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006459QualType
6460TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006461 ArrayType::ArraySizeModifier SizeMod,
6462 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006463 unsigned IndexTypeQuals,
6464 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006465 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006466 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006467}
6468
6469template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006470QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006471TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006472 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006473 unsigned IndexTypeQuals,
6474 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006475 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006476 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006477}
Mike Stump1eb44332009-09-09 15:08:12 +00006478
Douglas Gregor577f75a2009-08-04 16:50:30 +00006479template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006480QualType
6481TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006482 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006483 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006484 unsigned IndexTypeQuals,
6485 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006486 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006487 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006488 IndexTypeQuals, BracketsRange);
6489}
6490
6491template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006492QualType
6493TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006494 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006495 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006496 unsigned IndexTypeQuals,
6497 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006498 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006499 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006500 IndexTypeQuals, BracketsRange);
6501}
6502
6503template<typename Derived>
6504QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00006505 unsigned NumElements,
6506 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006507 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00006508 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006509}
Mike Stump1eb44332009-09-09 15:08:12 +00006510
Douglas Gregor577f75a2009-08-04 16:50:30 +00006511template<typename Derived>
6512QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6513 unsigned NumElements,
6514 SourceLocation AttributeLoc) {
6515 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6516 NumElements, true);
6517 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006518 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6519 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00006520 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006521}
Mike Stump1eb44332009-09-09 15:08:12 +00006522
Douglas Gregor577f75a2009-08-04 16:50:30 +00006523template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006524QualType
6525TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00006526 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006527 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00006528 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006529}
Mike Stump1eb44332009-09-09 15:08:12 +00006530
Douglas Gregor577f75a2009-08-04 16:50:30 +00006531template<typename Derived>
6532QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006533 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006534 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006535 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00006536 unsigned Quals,
6537 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00006538 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006539 Quals,
6540 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006541 getDerived().getBaseEntity(),
6542 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006543}
Mike Stump1eb44332009-09-09 15:08:12 +00006544
Douglas Gregor577f75a2009-08-04 16:50:30 +00006545template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006546QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6547 return SemaRef.Context.getFunctionNoProtoType(T);
6548}
6549
6550template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006551QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6552 assert(D && "no decl found");
6553 if (D->isInvalidDecl()) return QualType();
6554
Douglas Gregor92e986e2010-04-22 16:44:27 +00006555 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006556 TypeDecl *Ty;
6557 if (isa<UsingDecl>(D)) {
6558 UsingDecl *Using = cast<UsingDecl>(D);
6559 assert(Using->isTypeName() &&
6560 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6561
6562 // A valid resolved using typename decl points to exactly one type decl.
6563 assert(++Using->shadow_begin() == Using->shadow_end());
6564 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006565
John McCalled976492009-12-04 22:46:56 +00006566 } else {
6567 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6568 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6569 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6570 }
6571
6572 return SemaRef.Context.getTypeDeclType(Ty);
6573}
6574
6575template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00006576QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6577 SourceLocation Loc) {
6578 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006579}
6580
6581template<typename Derived>
6582QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6583 return SemaRef.Context.getTypeOfType(Underlying);
6584}
6585
6586template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00006587QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6588 SourceLocation Loc) {
6589 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006590}
6591
6592template<typename Derived>
6593QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006594 TemplateName Template,
6595 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006596 const TemplateArgumentListInfo &TemplateArgs) {
6597 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006598}
Mike Stump1eb44332009-09-09 15:08:12 +00006599
Douglas Gregordcee1a12009-08-06 05:28:30 +00006600template<typename Derived>
6601NestedNameSpecifier *
6602TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6603 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006604 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006605 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006606 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006607 CXXScopeSpec SS;
6608 // FIXME: The source location information is all wrong.
6609 SS.setRange(Range);
6610 SS.setScopeRep(Prefix);
6611 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006612 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006613 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006614 ObjectType,
6615 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006616 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006617}
6618
6619template<typename Derived>
6620NestedNameSpecifier *
6621TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6622 SourceRange Range,
6623 NamespaceDecl *NS) {
6624 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6625}
6626
6627template<typename Derived>
6628NestedNameSpecifier *
6629TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6630 SourceRange Range,
6631 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006632 QualType T) {
6633 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006634 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006635 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006636 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6637 T.getTypePtr());
6638 }
Mike Stump1eb44332009-09-09 15:08:12 +00006639
Douglas Gregordcee1a12009-08-06 05:28:30 +00006640 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6641 return 0;
6642}
Mike Stump1eb44332009-09-09 15:08:12 +00006643
Douglas Gregord1067e52009-08-06 06:41:21 +00006644template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006645TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006646TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6647 bool TemplateKW,
6648 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006649 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006650 Template);
6651}
6652
6653template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006654TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006655TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006656 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006657 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +00006658 QualType ObjectType,
6659 NamedDecl *FirstQualifierInScope) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006660 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006661 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00006662 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006663 UnqualifiedId Name;
6664 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00006665 Sema::TemplateTy Template;
6666 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6667 /*FIXME:*/getDerived().getBaseLocation(),
6668 SS,
6669 Name,
John McCallb3d87482010-08-24 05:47:05 +00006670 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006671 /*EnteringContext=*/false,
6672 Template);
John McCall43fed0d2010-11-12 08:19:04 +00006673 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00006674}
Mike Stump1eb44332009-09-09 15:08:12 +00006675
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006677TemplateName
6678TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6679 OverloadedOperatorKind Operator,
6680 QualType ObjectType) {
6681 CXXScopeSpec SS;
6682 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6683 SS.setScopeRep(Qualifier);
6684 UnqualifiedId Name;
6685 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6686 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6687 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00006688 Sema::TemplateTy Template;
6689 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006690 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006691 SS,
6692 Name,
John McCallb3d87482010-08-24 05:47:05 +00006693 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006694 /*EnteringContext=*/false,
6695 Template);
6696 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006697}
Sean Huntc3021132010-05-05 15:23:54 +00006698
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006699template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006700ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6702 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006703 Expr *OrigCallee,
6704 Expr *First,
6705 Expr *Second) {
6706 Expr *Callee = OrigCallee->IgnoreParenCasts();
6707 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006708
Douglas Gregorb98b1992009-08-11 05:31:07 +00006709 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006710 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00006711 if (!First->getType()->isOverloadableType() &&
6712 !Second->getType()->isOverloadableType())
6713 return getSema().CreateBuiltinArraySubscriptExpr(First,
6714 Callee->getLocStart(),
6715 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006716 } else if (Op == OO_Arrow) {
6717 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00006718 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6719 } else if (Second == 0 || isPostIncDec) {
6720 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721 // The argument is not of overloadable type, so try to create a
6722 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00006723 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006724 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006725
John McCall9ae2f072010-08-23 23:25:46 +00006726 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006727 }
6728 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006729 if (!First->getType()->isOverloadableType() &&
6730 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006731 // Neither of the arguments is an overloadable type, so try to
6732 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00006733 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006734 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00006735 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006736 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006737 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006738
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 return move(Result);
6740 }
6741 }
Mike Stump1eb44332009-09-09 15:08:12 +00006742
6743 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006744 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006745 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006746
John McCall9ae2f072010-08-23 23:25:46 +00006747 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00006748 assert(ULE->requiresADL());
6749
6750 // FIXME: Do we have to check
6751 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006752 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006753 } else {
John McCall9ae2f072010-08-23 23:25:46 +00006754 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006755 }
Mike Stump1eb44332009-09-09 15:08:12 +00006756
Douglas Gregorb98b1992009-08-11 05:31:07 +00006757 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00006758 Expr *Args[2] = { First, Second };
6759 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006760
Douglas Gregorb98b1992009-08-11 05:31:07 +00006761 // Create the overloaded operator invocation for unary operators.
6762 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00006763 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006764 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00006765 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006766 }
Mike Stump1eb44332009-09-09 15:08:12 +00006767
Sebastian Redlf322ed62009-10-29 20:17:01 +00006768 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00006769 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00006770 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006771 First,
6772 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006773
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00006775 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00006776 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006777 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6778 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006779 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006780
Mike Stump1eb44332009-09-09 15:08:12 +00006781 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782}
Mike Stump1eb44332009-09-09 15:08:12 +00006783
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006785ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00006786TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006787 SourceLocation OperatorLoc,
6788 bool isArrow,
6789 NestedNameSpecifier *Qualifier,
6790 SourceRange QualifierRange,
6791 TypeSourceInfo *ScopeType,
6792 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006793 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006794 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006795 CXXScopeSpec SS;
6796 if (Qualifier) {
6797 SS.setRange(QualifierRange);
6798 SS.setScopeRep(Qualifier);
6799 }
6800
John McCall9ae2f072010-08-23 23:25:46 +00006801 QualType BaseType = Base->getType();
6802 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006803 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006804 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006805 !BaseType->getAs<PointerType>()->getPointeeType()
6806 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006807 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00006808 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006809 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006810 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006811 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006812 /*FIXME?*/true);
6813 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006814
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006815 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00006816 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6817 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6818 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6819 NameInfo.setNamedTypeInfo(DestroyedType);
6820
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006821 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00006822
John McCall9ae2f072010-08-23 23:25:46 +00006823 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006824 OperatorLoc, isArrow,
6825 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00006826 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006827 /*TemplateArgs*/ 0);
6828}
6829
Douglas Gregor577f75a2009-08-04 16:50:30 +00006830} // end namespace clang
6831
6832#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H