blob: 06017e7cbabd90b3b525a174f78d2a9e4ade5a63 [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +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.
Chris Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008//
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//
Chris Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall2d887082010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000034#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000035#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000036#include <algorithm>
37
38namespace clang {
John McCall781472f2010-08-25 08:40:02 +000039using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000040
Douglas Gregor577f75a2009-08-04 16:50:30 +000041/// \brief A semantic tree transformation that allows one to transform one
42/// abstract syntax tree into another.
43///
Mike Stump1eb44332009-09-09 15:08:12 +000044/// A new tree transformation is defined by creating a new subclass \c X of
45/// \c TreeTransform<X> and then overriding certain operations to provide
46/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000047/// instantiation is implemented as a tree transformation where the
48/// transformation of TemplateTypeParmType nodes involves substituting the
49/// template arguments for their corresponding template parameters; a similar
50/// transformation is performed for non-type template parameters and
51/// template template parameters.
52///
53/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000054/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000055/// override any of the transformation or rebuild operators by providing an
56/// operation with the same signature as the default implementation. The
57/// overridding function should not be virtual.
58///
59/// Semantic tree transformations are split into two stages, either of which
60/// can be replaced by a subclass. The "transform" step transforms an AST node
61/// or the parts of an AST node using the various transformation functions,
62/// then passes the pieces on to the "rebuild" step, which constructs a new AST
63/// node of the appropriate kind from the pieces. The default transformation
64/// routines recursively transform the operands to composite AST nodes (e.g.,
65/// the pointee type of a PointerType node) and, if any of those operand nodes
66/// were changed by the transformation, invokes the rebuild operation to create
67/// a new AST node.
68///
Mike Stump1eb44332009-09-09 15:08:12 +000069/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000070/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000071/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000072/// TransformTemplateName(), or TransformTemplateArgument() with entirely
73/// new implementations.
74///
75/// For more fine-grained transformations, subclasses can replace any of the
76/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000077/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000078/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000079/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000080/// parameters. Additionally, subclasses can override the \c RebuildXXX
81/// functions to control how AST nodes are rebuilt when their operands change.
82/// By default, \c TreeTransform will invoke semantic analysis to rebuild
83/// AST nodes. However, certain other tree transformations (e.g, cloning) may
84/// be able to use more efficient rebuild steps.
85///
86/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000087/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000088/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
89/// operands have not changed (\c AlwaysRebuild()), and customize the
90/// default locations and entity names used for type-checking
91/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000092template<typename Derived>
93class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000094 /// \brief Private RAII object that helps us forget and then re-remember
95 /// the template argument corresponding to a partially-substituted parameter
96 /// pack.
97 class ForgetPartiallySubstitutedPackRAII {
98 Derived &Self;
99 TemplateArgument Old;
100
101 public:
102 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
103 Old = Self.ForgetPartiallySubstitutedPack();
104 }
105
106 ~ForgetPartiallySubstitutedPackRAII() {
107 Self.RememberPartiallySubstitutedPack(Old);
108 }
109 };
110
Douglas Gregor577f75a2009-08-04 16:50:30 +0000111protected:
112 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000113
Mike Stump1eb44332009-09-09 15:08:12 +0000114public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000115 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000116 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000117
Douglas Gregor577f75a2009-08-04 16:50:30 +0000118 /// \brief Retrieves a reference to the derived class.
119 Derived &getDerived() { return static_cast<Derived&>(*this); }
120
121 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000122 const Derived &getDerived() const {
123 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 }
125
John McCall60d7b3a2010-08-24 06:29:42 +0000126 static inline ExprResult Owned(Expr *E) { return E; }
127 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000128
Douglas Gregor577f75a2009-08-04 16:50:30 +0000129 /// \brief Retrieves a reference to the semantic analysis object used for
130 /// this tree transform.
131 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000132
Douglas Gregor577f75a2009-08-04 16:50:30 +0000133 /// \brief Whether the transformation should always rebuild AST nodes, even
134 /// if none of the children have changed.
135 ///
136 /// Subclasses may override this function to specify when the transformation
137 /// should rebuild all AST nodes.
138 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000139
Douglas Gregor577f75a2009-08-04 16:50:30 +0000140 /// \brief Returns the location of the entity being transformed, if that
141 /// information was not available elsewhere in the AST.
142 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000143 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000144 /// provide an alternative implementation that provides better location
145 /// information.
146 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000147
Douglas Gregor577f75a2009-08-04 16:50:30 +0000148 /// \brief Returns the name of the entity being transformed, if that
149 /// information was not available elsewhere in the AST.
150 ///
151 /// By default, returns an empty name. Subclasses can provide an alternative
152 /// implementation with a more precise name.
153 DeclarationName getBaseEntity() { return DeclarationName(); }
154
Douglas Gregorb98b1992009-08-11 05:31:07 +0000155 /// \brief Sets the "base" location and entity when that
156 /// information is known based on another transformation.
157 ///
158 /// By default, the source location and entity are ignored. Subclasses can
159 /// override this function to provide a customized implementation.
160 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000161
Douglas Gregorb98b1992009-08-11 05:31:07 +0000162 /// \brief RAII object that temporarily sets the base location and entity
163 /// used for reporting diagnostics in types.
164 class TemporaryBase {
165 TreeTransform &Self;
166 SourceLocation OldLocation;
167 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000168
Douglas Gregorb98b1992009-08-11 05:31:07 +0000169 public:
170 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000171 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000172 OldLocation = Self.getDerived().getBaseLocation();
173 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregorae201f72011-01-25 17:51:48 +0000174
175 if (Location.isValid())
176 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000177 }
Mike Stump1eb44332009-09-09 15:08:12 +0000178
Douglas Gregorb98b1992009-08-11 05:31:07 +0000179 ~TemporaryBase() {
180 Self.getDerived().setBase(OldLocation, OldEntity);
181 }
182 };
Mike Stump1eb44332009-09-09 15:08:12 +0000183
184 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000185 /// transformed.
186 ///
187 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000188 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000189 /// not change. For example, template instantiation need not traverse
190 /// non-dependent types.
191 bool AlreadyTransformed(QualType T) {
192 return T.isNull();
193 }
194
Douglas Gregor6eef5192009-12-14 19:27:10 +0000195 /// \brief Determine whether the given call argument should be dropped, e.g.,
196 /// because it is a default argument.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine to
199 /// determine which kinds of call arguments get dropped. By default,
200 /// CXXDefaultArgument nodes are dropped (prior to transformation).
201 bool DropCallArgument(Expr *E) {
202 return E->isDefaultArgument();
203 }
Sean Huntc3021132010-05-05 15:23:54 +0000204
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000205 /// \brief Determine whether we should expand a pack expansion with the
206 /// given set of parameter packs into separate arguments by repeatedly
207 /// transforming the pattern.
208 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000209 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000210 /// Subclasses can override this routine to provide different behavior.
211 ///
212 /// \param EllipsisLoc The location of the ellipsis that identifies the
213 /// pack expansion.
214 ///
215 /// \param PatternRange The source range that covers the entire pattern of
216 /// the pack expansion.
217 ///
218 /// \param Unexpanded The set of unexpanded parameter packs within the
219 /// pattern.
220 ///
221 /// \param NumUnexpanded The number of unexpanded parameter packs in
222 /// \p Unexpanded.
223 ///
224 /// \param ShouldExpand Will be set to \c true if the transformer should
225 /// expand the corresponding pack expansions into separate arguments. When
226 /// set, \c NumExpansions must also be set.
227 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000228 /// \param RetainExpansion Whether the caller should add an unexpanded
229 /// pack expansion after all of the expanded arguments. This is used
230 /// when extending explicitly-specified template argument packs per
231 /// C++0x [temp.arg.explicit]p9.
232 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000233 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000234 /// the expanded form of the corresponding pack expansion. This is both an
235 /// input and an output parameter, which can be set by the caller if the
236 /// number of expansions is known a priori (e.g., due to a prior substitution)
237 /// and will be set by the callee when the number of expansions is known.
238 /// The callee must set this value when \c ShouldExpand is \c true; it may
239 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000240 ///
241 /// \returns true if an error occurred (e.g., because the parameter packs
242 /// are to be instantiated with arguments of different lengths), false
243 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
244 /// must be set.
245 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
246 SourceRange PatternRange,
247 const UnexpandedParameterPack *Unexpanded,
248 unsigned NumUnexpanded,
249 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000250 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000251 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000252 ShouldExpand = false;
253 return false;
254 }
255
Douglas Gregord3731192011-01-10 07:32:04 +0000256 /// \brief "Forget" about the partially-substituted pack template argument,
257 /// when performing an instantiation that must preserve the parameter pack
258 /// use.
259 ///
260 /// This routine is meant to be overridden by the template instantiator.
261 TemplateArgument ForgetPartiallySubstitutedPack() {
262 return TemplateArgument();
263 }
264
265 /// \brief "Remember" the partially-substituted pack template argument
266 /// after performing an instantiation that must preserve the parameter pack
267 /// use.
268 ///
269 /// This routine is meant to be overridden by the template instantiator.
270 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
271
Douglas Gregor12c9c002011-01-07 16:43:16 +0000272 /// \brief Note to the derived class when a function parameter pack is
273 /// being expanded.
274 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
275
Douglas Gregor577f75a2009-08-04 16:50:30 +0000276 /// \brief Transforms the given type into another type.
277 ///
John McCalla2becad2009-10-21 00:40:46 +0000278 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000279 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000280 /// function. This is expensive, but we don't mind, because
281 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000282 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000283 ///
284 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000285 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000286
John McCalla2becad2009-10-21 00:40:46 +0000287 /// \brief Transforms the given type-with-location into a new
288 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000289 ///
John McCalla2becad2009-10-21 00:40:46 +0000290 /// By default, this routine transforms a type by delegating to the
291 /// appropriate TransformXXXType to build a new type. Subclasses
292 /// may override this function (to take over all type
293 /// transformations) or some set of the TransformXXXType functions
294 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000295 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000296
297 /// \brief Transform the given type-with-location into a new
298 /// type, collecting location information in the given builder
299 /// as necessary.
300 ///
John McCall43fed0d2010-11-12 08:19:04 +0000301 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000302
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000303 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000304 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000305 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000306 /// appropriate TransformXXXStmt function to transform a specific kind of
307 /// statement or the TransformExpr() function to transform an expression.
308 /// Subclasses may override this function to transform statements using some
309 /// other mechanism.
310 ///
311 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000312 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000313
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000314 /// \brief Transform the given expression.
315 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000316 /// By default, this routine transforms an expression by delegating to the
317 /// appropriate TransformXXXExpr function to build a new expression.
318 /// Subclasses may override this function to transform expressions using some
319 /// other mechanism.
320 ///
321 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000322 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000323
Douglas Gregoraa165f82011-01-03 19:04:46 +0000324 /// \brief Transform the given list of expressions.
325 ///
326 /// This routine transforms a list of expressions by invoking
327 /// \c TransformExpr() for each subexpression. However, it also provides
328 /// support for variadic templates by expanding any pack expansions (if the
329 /// derived class permits such expansion) along the way. When pack expansions
330 /// are present, the number of outputs may not equal the number of inputs.
331 ///
332 /// \param Inputs The set of expressions to be transformed.
333 ///
334 /// \param NumInputs The number of expressions in \c Inputs.
335 ///
336 /// \param IsCall If \c true, then this transform is being performed on
337 /// function-call arguments, and any arguments that should be dropped, will
338 /// be.
339 ///
340 /// \param Outputs The transformed input expressions will be added to this
341 /// vector.
342 ///
343 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
344 /// due to transformation.
345 ///
346 /// \returns true if an error occurred, false otherwise.
347 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
348 llvm::SmallVectorImpl<Expr *> &Outputs,
349 bool *ArgChanged = 0);
350
Douglas Gregor577f75a2009-08-04 16:50:30 +0000351 /// \brief Transform the given declaration, which is referenced from a type
352 /// or expression.
353 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000354 /// By default, acts as the identity function on declarations. Subclasses
355 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000356 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000357
358 /// \brief Transform the definition of the given declaration.
359 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000360 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000361 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000362 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
363 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000364 }
Mike Stump1eb44332009-09-09 15:08:12 +0000365
Douglas Gregor6cd21982009-10-20 05:58:46 +0000366 /// \brief Transform the given declaration, which was the first part of a
367 /// nested-name-specifier in a member access expression.
368 ///
Sean Huntc3021132010-05-05 15:23:54 +0000369 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000370 /// identifier in a nested-name-specifier of a member access expression, e.g.,
371 /// the \c T in \c x->T::member
372 ///
373 /// By default, invokes TransformDecl() to transform the declaration.
374 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000375 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
376 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000377 }
Sean Huntc3021132010-05-05 15:23:54 +0000378
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000379 /// \brief Transform the given nested-name-specifier with source-location
380 /// information.
381 ///
382 /// By default, transforms all of the types and declarations within the
383 /// nested-name-specifier. Subclasses may override this function to provide
384 /// alternate behavior.
385 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
386 NestedNameSpecifierLoc NNS,
387 QualType ObjectType = QualType(),
388 NamedDecl *FirstQualifierInScope = 0);
389
Douglas Gregor81499bb2009-09-03 22:13:48 +0000390 /// \brief Transform the given declaration name.
391 ///
392 /// By default, transforms the types of conversion function, constructor,
393 /// and destructor names and then (if needed) rebuilds the declaration name.
394 /// Identifiers and selectors are returned unmodified. Sublcasses may
395 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000396 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000397 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000398
Douglas Gregor577f75a2009-08-04 16:50:30 +0000399 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000400 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000401 /// \param SS The nested-name-specifier that qualifies the template
402 /// name. This nested-name-specifier must already have been transformed.
403 ///
404 /// \param Name The template name to transform.
405 ///
406 /// \param NameLoc The source location of the template name.
407 ///
408 /// \param ObjectType If we're translating a template name within a member
409 /// access expression, this is the type of the object whose member template
410 /// is being referenced.
411 ///
412 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
413 /// also refers to a name within the current (lexical) scope, this is the
414 /// declaration it refers to.
415 ///
416 /// By default, transforms the template name by transforming the declarations
417 /// and nested-name-specifiers that occur within the template name.
418 /// Subclasses may override this function to provide alternate behavior.
419 TemplateName TransformTemplateName(CXXScopeSpec &SS,
420 TemplateName Name,
421 SourceLocation NameLoc,
422 QualType ObjectType = QualType(),
423 NamedDecl *FirstQualifierInScope = 0);
424
Douglas Gregor577f75a2009-08-04 16:50:30 +0000425 /// \brief Transform the given template argument.
426 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000427 /// By default, this operation transforms the type, expression, or
428 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000429 /// new template argument from the transformed result. Subclasses may
430 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000431 ///
432 /// Returns true if there was an error.
433 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
434 TemplateArgumentLoc &Output);
435
Douglas Gregorfcc12532010-12-20 17:31:10 +0000436 /// \brief Transform the given set of template arguments.
437 ///
438 /// By default, this operation transforms all of the template arguments
439 /// in the input set using \c TransformTemplateArgument(), and appends
440 /// the transformed arguments to the output list.
441 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000442 /// Note that this overload of \c TransformTemplateArguments() is merely
443 /// a convenience function. Subclasses that wish to override this behavior
444 /// should override the iterator-based member template version.
445 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000446 /// \param Inputs The set of template arguments to be transformed.
447 ///
448 /// \param NumInputs The number of template arguments in \p Inputs.
449 ///
450 /// \param Outputs The set of transformed template arguments output by this
451 /// routine.
452 ///
453 /// Returns true if an error occurred.
454 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
455 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000456 TemplateArgumentListInfo &Outputs) {
457 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
458 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000459
460 /// \brief Transform the given set of template arguments.
461 ///
462 /// By default, this operation transforms all of the template arguments
463 /// in the input set using \c TransformTemplateArgument(), and appends
464 /// the transformed arguments to the output list.
465 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000466 /// \param First An iterator to the first template argument.
467 ///
468 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000469 ///
470 /// \param Outputs The set of transformed template arguments output by this
471 /// routine.
472 ///
473 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000474 template<typename InputIterator>
475 bool TransformTemplateArguments(InputIterator First,
476 InputIterator Last,
477 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000478
John McCall833ca992009-10-29 08:12:44 +0000479 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
480 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
481 TemplateArgumentLoc &ArgLoc);
482
John McCalla93c9342009-12-07 02:54:59 +0000483 /// \brief Fakes up a TypeSourceInfo for a type.
484 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
485 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000486 getDerived().getBaseLocation());
487 }
Mike Stump1eb44332009-09-09 15:08:12 +0000488
John McCalla2becad2009-10-21 00:40:46 +0000489#define ABSTRACT_TYPELOC(CLASS, PARENT)
490#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000491 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000492#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000493
John Wiegley28bbe4b2011-04-28 01:08:34 +0000494 StmtResult
495 TransformSEHHandler(Stmt *Handler);
496
John McCall43fed0d2010-11-12 08:19:04 +0000497 QualType
498 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
499 TemplateSpecializationTypeLoc TL,
500 TemplateName Template);
501
502 QualType
503 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
504 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000505 TemplateName Template,
506 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000507
508 QualType
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000510 DependentTemplateSpecializationTypeLoc TL,
511 NestedNameSpecifierLoc QualifierLoc);
512
John McCall21ef0fa2010-03-11 09:03:00 +0000513 /// \brief Transforms the parameters of a function type into the
514 /// given vectors.
515 ///
516 /// The result vectors should be kept in sync; null entries in the
517 /// variables vector are acceptable.
518 ///
519 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000520 bool TransformFunctionTypeParams(SourceLocation Loc,
521 ParmVarDecl **Params, unsigned NumParams,
522 const QualType *ParamTypes,
John McCall21ef0fa2010-03-11 09:03:00 +0000523 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregora009b592011-01-07 00:20:55 +0000524 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000525
526 /// \brief Transforms a single function-type parameter. Return null
527 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000528 ///
529 /// \param indexAdjustment - A number to add to the parameter's
530 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000531 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000532 int indexAdjustment,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000533 llvm::Optional<unsigned> NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +0000534
John McCall43fed0d2010-11-12 08:19:04 +0000535 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000536
John McCall60d7b3a2010-08-24 06:29:42 +0000537 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
538 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000539
Douglas Gregor43959a92009-08-20 07:17:43 +0000540#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000541 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000542#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000543 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000544#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000545#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000546
Douglas Gregor577f75a2009-08-04 16:50:30 +0000547 /// \brief Build a new pointer type given its pointee type.
548 ///
549 /// By default, performs semantic analysis when building the pointer type.
550 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000551 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000552
553 /// \brief Build a new block pointer type given its pointee type.
554 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000555 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000556 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000557 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000558
John McCall85737a72009-10-30 00:06:24 +0000559 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000560 ///
John McCall85737a72009-10-30 00:06:24 +0000561 /// By default, performs semantic analysis when building the
562 /// reference type. Subclasses may override this routine to provide
563 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000564 ///
John McCall85737a72009-10-30 00:06:24 +0000565 /// \param LValue whether the type was written with an lvalue sigil
566 /// or an rvalue sigil.
567 QualType RebuildReferenceType(QualType ReferentType,
568 bool LValue,
569 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000570
Douglas Gregor577f75a2009-08-04 16:50:30 +0000571 /// \brief Build a new member pointer type given the pointee type and the
572 /// class type it refers into.
573 ///
574 /// By default, performs semantic analysis when building the member pointer
575 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000576 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
577 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000578
Douglas Gregor577f75a2009-08-04 16:50:30 +0000579 /// \brief Build a new array type given the element type, size
580 /// modifier, size of the array (if known), size expression, and index type
581 /// qualifiers.
582 ///
583 /// By default, performs semantic analysis when building the array type.
584 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000585 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000586 QualType RebuildArrayType(QualType ElementType,
587 ArrayType::ArraySizeModifier SizeMod,
588 const llvm::APInt *Size,
589 Expr *SizeExpr,
590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000592
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593 /// \brief Build a new constant array type given the element type, size
594 /// modifier, (known) size of the array, and index type qualifiers.
595 ///
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000598 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
600 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000603
Douglas Gregor577f75a2009-08-04 16:50:30 +0000604 /// \brief Build a new incomplete array type given the element type, size
605 /// modifier, and index type qualifiers.
606 ///
607 /// By default, performs semantic analysis when building the array type.
608 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000609 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000610 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000613
Mike Stump1eb44332009-09-09 15:08:12 +0000614 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000615 /// size modifier, size expression, and index type qualifiers.
616 ///
617 /// By default, performs semantic analysis when building the array type.
618 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000619 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000620 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000621 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
624
Mike Stump1eb44332009-09-09 15:08:12 +0000625 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000626 /// size modifier, size expression, and index type qualifiers.
627 ///
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000630 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000632 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
635
636 /// \brief Build a new vector type given the element type and
637 /// number of elements.
638 ///
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000641 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000642 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000643
Douglas Gregor577f75a2009-08-04 16:50:30 +0000644 /// \brief Build a new extended vector type given the element type and
645 /// number of elements.
646 ///
647 /// By default, performs semantic analysis when building the vector type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
650 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000651
652 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000653 /// given the element type and number of elements.
654 ///
655 /// By default, performs semantic analysis when building the vector type.
656 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000657 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000659 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000660
Douglas Gregor577f75a2009-08-04 16:50:30 +0000661 /// \brief Build a new function type.
662 ///
663 /// By default, performs semantic analysis when building the function type.
664 /// Subclasses may override this routine to provide different behavior.
665 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000666 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000667 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000668 bool Variadic, unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000669 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000670 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000671
John McCalla2becad2009-10-21 00:40:46 +0000672 /// \brief Build a new unprototyped function type.
673 QualType RebuildFunctionNoProtoType(QualType ResultType);
674
John McCalled976492009-12-04 22:46:56 +0000675 /// \brief Rebuild an unresolved typename type, given the decl that
676 /// the UnresolvedUsingTypenameDecl was transformed to.
677 QualType RebuildUnresolvedUsingType(Decl *D);
678
Douglas Gregor577f75a2009-08-04 16:50:30 +0000679 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000680 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 return SemaRef.Context.getTypeDeclType(Typedef);
682 }
683
684 /// \brief Build a new class/struct/union type.
685 QualType RebuildRecordType(RecordDecl *Record) {
686 return SemaRef.Context.getTypeDeclType(Record);
687 }
688
689 /// \brief Build a new Enum type.
690 QualType RebuildEnumType(EnumDecl *Enum) {
691 return SemaRef.Context.getTypeDeclType(Enum);
692 }
John McCall7da24312009-09-05 00:15:47 +0000693
Mike Stump1eb44332009-09-09 15:08:12 +0000694 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000695 ///
696 /// By default, performs semantic analysis when building the typeof type.
697 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000698 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000699
Mike Stump1eb44332009-09-09 15:08:12 +0000700 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000701 ///
702 /// By default, builds a new TypeOfType with the given underlying type.
703 QualType RebuildTypeOfType(QualType Underlying);
704
Sean Huntca63c202011-05-24 22:41:36 +0000705 /// \brief Build a new unary transform type.
706 QualType RebuildUnaryTransformType(QualType BaseType,
707 UnaryTransformType::UTTKind UKind,
708 SourceLocation Loc);
709
Mike Stump1eb44332009-09-09 15:08:12 +0000710 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000711 ///
712 /// By default, performs semantic analysis when building the decltype type.
713 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000714 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000715
Richard Smith34b41d92011-02-20 03:19:35 +0000716 /// \brief Build a new C++0x auto type.
717 ///
718 /// By default, builds a new AutoType with the given deduced type.
719 QualType RebuildAutoType(QualType Deduced) {
720 return SemaRef.Context.getAutoType(Deduced);
721 }
722
Douglas Gregor577f75a2009-08-04 16:50:30 +0000723 /// \brief Build a new template specialization type.
724 ///
725 /// By default, performs semantic analysis when building the template
726 /// specialization type. Subclasses may override this routine to provide
727 /// different behavior.
728 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000729 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000730 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000731
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000732 /// \brief Build a new parenthesized type.
733 ///
734 /// By default, builds a new ParenType type from the inner type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildParenType(QualType InnerType) {
737 return SemaRef.Context.getParenType(InnerType);
738 }
739
Douglas Gregor577f75a2009-08-04 16:50:30 +0000740 /// \brief Build a new qualified name type.
741 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000742 /// By default, builds a new ElaboratedType type from the keyword,
743 /// the nested-name-specifier and the named type.
744 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000745 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
746 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000747 NestedNameSpecifierLoc QualifierLoc,
748 QualType Named) {
749 return SemaRef.Context.getElaboratedType(Keyword,
750 QualifierLoc.getNestedNameSpecifier(),
751 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000752 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000753
754 /// \brief Build a new typename type that refers to a template-id.
755 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000756 /// By default, builds a new DependentNameType type from the
757 /// nested-name-specifier and the given type. Subclasses may override
758 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000759 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000760 ElaboratedTypeKeyword Keyword,
761 NestedNameSpecifierLoc QualifierLoc,
762 const IdentifierInfo *Name,
763 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000764 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000765 // Rebuild the template name.
766 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000767 CXXScopeSpec SS;
768 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000769 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000770 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000771
772 if (InstName.isNull())
773 return QualType();
774
775 // If it's still dependent, make a dependent specialization.
776 if (InstName.getAsDependentTemplateName())
777 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
778 QualifierLoc.getNestedNameSpecifier(),
779 Name,
780 Args);
781
782 // Otherwise, make an elaborated type wrapping a non-dependent
783 // specialization.
784 QualType T =
785 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
786 if (T.isNull()) return QualType();
787
788 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
789 return T;
790
791 return SemaRef.Context.getElaboratedType(Keyword,
792 QualifierLoc.getNestedNameSpecifier(),
793 T);
794 }
795
Douglas Gregor577f75a2009-08-04 16:50:30 +0000796 /// \brief Build a new typename type that refers to an identifier.
797 ///
798 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000799 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000800 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000801 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000802 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000803 NestedNameSpecifierLoc QualifierLoc,
804 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000805 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000806 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000807 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000808
Douglas Gregor2494dd02011-03-01 01:34:45 +0000809 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000810 // If the name is still dependent, just build a new dependent name type.
811 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000812 return SemaRef.Context.getDependentNameType(Keyword,
813 QualifierLoc.getNestedNameSpecifier(),
814 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000815 }
816
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000817 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000818 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000819 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000820
821 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
822
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000823 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000824 // into a non-dependent elaborated-type-specifier. Find the tag we're
825 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000826 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000827 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
828 if (!DC)
829 return QualType();
830
John McCall56138762010-05-27 06:40:31 +0000831 if (SemaRef.RequireCompleteDeclContext(SS, DC))
832 return QualType();
833
Douglas Gregor40336422010-03-31 22:19:08 +0000834 TagDecl *Tag = 0;
835 SemaRef.LookupQualifiedName(Result, DC);
836 switch (Result.getResultKind()) {
837 case LookupResult::NotFound:
838 case LookupResult::NotFoundInCurrentInstantiation:
839 break;
Sean Huntc3021132010-05-05 15:23:54 +0000840
Douglas Gregor40336422010-03-31 22:19:08 +0000841 case LookupResult::Found:
842 Tag = Result.getAsSingle<TagDecl>();
843 break;
Sean Huntc3021132010-05-05 15:23:54 +0000844
Douglas Gregor40336422010-03-31 22:19:08 +0000845 case LookupResult::FoundOverloaded:
846 case LookupResult::FoundUnresolvedValue:
847 llvm_unreachable("Tag lookup cannot find non-tags");
848 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000849
Douglas Gregor40336422010-03-31 22:19:08 +0000850 case LookupResult::Ambiguous:
851 // Let the LookupResult structure handle ambiguities.
852 return QualType();
853 }
854
855 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000856 // Check where the name exists but isn't a tag type and use that to emit
857 // better diagnostics.
858 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
859 SemaRef.LookupQualifiedName(Result, DC);
860 switch (Result.getResultKind()) {
861 case LookupResult::Found:
862 case LookupResult::FoundOverloaded:
863 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000864 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000865 unsigned Kind = 0;
866 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000867 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
868 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000869 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
870 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
871 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000872 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000873 default:
874 // FIXME: Would be nice to highlight just the source range.
875 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
876 << Kind << Id << DC;
877 break;
878 }
Douglas Gregor40336422010-03-31 22:19:08 +0000879 return QualType();
880 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000881
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000882 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
883 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000884 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
885 return QualType();
886 }
887
888 // Build the elaborated-type-specifier type.
889 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000890 return SemaRef.Context.getElaboratedType(Keyword,
891 QualifierLoc.getNestedNameSpecifier(),
892 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000893 }
Mike Stump1eb44332009-09-09 15:08:12 +0000894
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000895 /// \brief Build a new pack expansion type.
896 ///
897 /// By default, builds a new PackExpansionType type from the given pattern.
898 /// Subclasses may override this routine to provide different behavior.
899 QualType RebuildPackExpansionType(QualType Pattern,
900 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000901 SourceLocation EllipsisLoc,
902 llvm::Optional<unsigned> NumExpansions) {
903 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
904 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000905 }
906
Douglas Gregord1067e52009-08-06 06:41:21 +0000907 /// \brief Build a new template name given a nested name specifier, a flag
908 /// indicating whether the "template" keyword was provided, and the template
909 /// that the template name refers to.
910 ///
911 /// By default, builds the new template name directly. Subclasses may override
912 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000913 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000914 bool TemplateKW,
915 TemplateDecl *Template);
916
Douglas Gregord1067e52009-08-06 06:41:21 +0000917 /// \brief Build a new template name given a nested name specifier and the
918 /// name that is referred to as a template.
919 ///
920 /// By default, performs semantic analysis to determine whether the name can
921 /// be resolved to a specific template, then builds the appropriate kind of
922 /// template name. Subclasses may override this routine to provide different
923 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000924 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
925 const IdentifierInfo &Name,
926 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000927 QualType ObjectType,
928 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000929
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000930 /// \brief Build a new template name given a nested name specifier and the
931 /// overloaded operator name that is referred to as a template.
932 ///
933 /// By default, performs semantic analysis to determine whether the name can
934 /// be resolved to a specific template, then builds the appropriate kind of
935 /// template name. Subclasses may override this routine to provide different
936 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000937 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000938 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000939 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000940 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000941
942 /// \brief Build a new template name given a template template parameter pack
943 /// and the
944 ///
945 /// By default, performs semantic analysis to determine whether the name can
946 /// be resolved to a specific template, then builds the appropriate kind of
947 /// template name. Subclasses may override this routine to provide different
948 /// behavior.
949 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
950 const TemplateArgument &ArgPack) {
951 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
952 }
953
Douglas Gregor43959a92009-08-20 07:17:43 +0000954 /// \brief Build a new compound statement.
955 ///
956 /// By default, performs semantic analysis to build the new statement.
957 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000958 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000959 MultiStmtArg Statements,
960 SourceLocation RBraceLoc,
961 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000962 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000963 IsStmtExpr);
964 }
965
966 /// \brief Build a new case statement.
967 ///
968 /// By default, performs semantic analysis to build the new statement.
969 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000970 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000971 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000972 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000973 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000974 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000975 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000976 ColonLoc);
977 }
Mike Stump1eb44332009-09-09 15:08:12 +0000978
Douglas Gregor43959a92009-08-20 07:17:43 +0000979 /// \brief Attach the body to a new case statement.
980 ///
981 /// By default, performs semantic analysis to build the new statement.
982 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000983 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000984 getSema().ActOnCaseStmtBody(S, Body);
985 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000986 }
Mike Stump1eb44332009-09-09 15:08:12 +0000987
Douglas Gregor43959a92009-08-20 07:17:43 +0000988 /// \brief Build a new default statement.
989 ///
990 /// By default, performs semantic analysis to build the new statement.
991 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000992 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000993 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000994 Stmt *SubStmt) {
995 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000996 /*CurScope=*/0);
997 }
Mike Stump1eb44332009-09-09 15:08:12 +0000998
Douglas Gregor43959a92009-08-20 07:17:43 +0000999 /// \brief Build a new label statement.
1000 ///
1001 /// By default, performs semantic analysis to build the new statement.
1002 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001003 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1004 SourceLocation ColonLoc, Stmt *SubStmt) {
1005 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001006 }
Mike Stump1eb44332009-09-09 15:08:12 +00001007
Douglas Gregor43959a92009-08-20 07:17:43 +00001008 /// \brief Build a new "if" statement.
1009 ///
1010 /// By default, performs semantic analysis to build the new statement.
1011 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001012 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001013 VarDecl *CondVar, Stmt *Then,
1014 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001015 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001016 }
Mike Stump1eb44332009-09-09 15:08:12 +00001017
Douglas Gregor43959a92009-08-20 07:17:43 +00001018 /// \brief Start building a new switch statement.
1019 ///
1020 /// By default, performs semantic analysis to build the new statement.
1021 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001022 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001023 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001024 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001025 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001026 }
Mike Stump1eb44332009-09-09 15:08:12 +00001027
Douglas Gregor43959a92009-08-20 07:17:43 +00001028 /// \brief Attach the body to the switch statement.
1029 ///
1030 /// By default, performs semantic analysis to build the new statement.
1031 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001032 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001033 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001034 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 }
1036
1037 /// \brief Build a new while statement.
1038 ///
1039 /// By default, performs semantic analysis to build the new statement.
1040 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001041 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1042 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001043 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001044 }
Mike Stump1eb44332009-09-09 15:08:12 +00001045
Douglas Gregor43959a92009-08-20 07:17:43 +00001046 /// \brief Build a new do-while statement.
1047 ///
1048 /// By default, performs semantic analysis to build the new statement.
1049 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001050 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001051 SourceLocation WhileLoc, SourceLocation LParenLoc,
1052 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001053 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1054 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 }
1056
1057 /// \brief Build a new for statement.
1058 ///
1059 /// By default, performs semantic analysis to build the new statement.
1060 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001061 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1062 Stmt *Init, Sema::FullExprArg Cond,
1063 VarDecl *CondVar, Sema::FullExprArg Inc,
1064 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001065 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001066 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001067 }
Mike Stump1eb44332009-09-09 15:08:12 +00001068
Douglas Gregor43959a92009-08-20 07:17:43 +00001069 /// \brief Build a new goto statement.
1070 ///
1071 /// By default, performs semantic analysis to build the new statement.
1072 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001073 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1074 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001075 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001076 }
1077
1078 /// \brief Build a new indirect goto statement.
1079 ///
1080 /// By default, performs semantic analysis to build the new statement.
1081 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001082 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001083 SourceLocation StarLoc,
1084 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001085 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001086 }
Mike Stump1eb44332009-09-09 15:08:12 +00001087
Douglas Gregor43959a92009-08-20 07:17:43 +00001088 /// \brief Build a new return statement.
1089 ///
1090 /// By default, performs semantic analysis to build the new statement.
1091 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001092 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001093 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 }
Mike Stump1eb44332009-09-09 15:08:12 +00001095
Douglas Gregor43959a92009-08-20 07:17:43 +00001096 /// \brief Build a new declaration statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001100 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001101 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001102 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001103 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1104 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001105 }
Mike Stump1eb44332009-09-09 15:08:12 +00001106
Anders Carlsson703e3942010-01-24 05:50:09 +00001107 /// \brief Build a new inline asm statement.
1108 ///
1109 /// By default, performs semantic analysis to build the new statement.
1110 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001111 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001112 bool IsSimple,
1113 bool IsVolatile,
1114 unsigned NumOutputs,
1115 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001116 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001117 MultiExprArg Constraints,
1118 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001119 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001120 MultiExprArg Clobbers,
1121 SourceLocation RParenLoc,
1122 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001123 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001124 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001125 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001126 RParenLoc, MSAsm);
1127 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001128
1129 /// \brief Build a new Objective-C @try statement.
1130 ///
1131 /// By default, performs semantic analysis to build the new statement.
1132 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001133 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001134 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001135 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001136 Stmt *Finally) {
1137 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1138 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001139 }
1140
Douglas Gregorbe270a02010-04-26 17:57:08 +00001141 /// \brief Rebuild an Objective-C exception declaration.
1142 ///
1143 /// By default, performs semantic analysis to build the new declaration.
1144 /// Subclasses may override this routine to provide different behavior.
1145 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1146 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001147 return getSema().BuildObjCExceptionDecl(TInfo, T,
1148 ExceptionDecl->getInnerLocStart(),
1149 ExceptionDecl->getLocation(),
1150 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001151 }
Sean Huntc3021132010-05-05 15:23:54 +00001152
Douglas Gregorbe270a02010-04-26 17:57:08 +00001153 /// \brief Build a new Objective-C @catch statement.
1154 ///
1155 /// By default, performs semantic analysis to build the new statement.
1156 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001157 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001158 SourceLocation RParenLoc,
1159 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001160 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001161 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001162 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001163 }
Sean Huntc3021132010-05-05 15:23:54 +00001164
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001165 /// \brief Build a new Objective-C @finally statement.
1166 ///
1167 /// By default, performs semantic analysis to build the new statement.
1168 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001169 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001170 Stmt *Body) {
1171 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001172 }
Sean Huntc3021132010-05-05 15:23:54 +00001173
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001174 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001175 ///
1176 /// By default, performs semantic analysis to build the new statement.
1177 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001178 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001179 Expr *Operand) {
1180 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001181 }
Sean Huntc3021132010-05-05 15:23:54 +00001182
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001183 /// \brief Build a new Objective-C @synchronized statement.
1184 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001187 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001188 Expr *Object,
1189 Stmt *Body) {
1190 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1191 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001192 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001193
1194 /// \brief Build a new Objective-C fast enumeration statement.
1195 ///
1196 /// By default, performs semantic analysis to build the new statement.
1197 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001198 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001199 SourceLocation LParenLoc,
1200 Stmt *Element,
1201 Expr *Collection,
1202 SourceLocation RParenLoc,
1203 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001204 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001205 Element,
1206 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001207 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001208 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001209 }
Sean Huntc3021132010-05-05 15:23:54 +00001210
Douglas Gregor43959a92009-08-20 07:17:43 +00001211 /// \brief Build a new C++ exception declaration.
1212 ///
1213 /// By default, performs semantic analysis to build the new decaration.
1214 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001215 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001216 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001217 SourceLocation StartLoc,
1218 SourceLocation IdLoc,
1219 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001220 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1221 StartLoc, IdLoc, Id);
1222 if (Var)
1223 getSema().CurContext->addDecl(Var);
1224 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001225 }
1226
1227 /// \brief Build a new C++ catch statement.
1228 ///
1229 /// By default, performs semantic analysis to build the new statement.
1230 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001231 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001232 VarDecl *ExceptionDecl,
1233 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001234 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1235 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001236 }
Mike Stump1eb44332009-09-09 15:08:12 +00001237
Douglas Gregor43959a92009-08-20 07:17:43 +00001238 /// \brief Build a new C++ try statement.
1239 ///
1240 /// By default, performs semantic analysis to build the new statement.
1241 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001242 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001243 Stmt *TryBlock,
1244 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001245 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001246 }
Mike Stump1eb44332009-09-09 15:08:12 +00001247
Richard Smithad762fc2011-04-14 22:09:26 +00001248 /// \brief Build a new C++0x range-based for statement.
1249 ///
1250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
1252 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1253 SourceLocation ColonLoc,
1254 Stmt *Range, Stmt *BeginEnd,
1255 Expr *Cond, Expr *Inc,
1256 Stmt *LoopVar,
1257 SourceLocation RParenLoc) {
1258 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1259 Cond, Inc, LoopVar, RParenLoc);
1260 }
1261
1262 /// \brief Attach body to a C++0x range-based for statement.
1263 ///
1264 /// By default, performs semantic analysis to finish the new statement.
1265 /// Subclasses may override this routine to provide different behavior.
1266 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1267 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1268 }
1269
John Wiegley28bbe4b2011-04-28 01:08:34 +00001270 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1271 SourceLocation TryLoc,
1272 Stmt *TryBlock,
1273 Stmt *Handler) {
1274 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1275 }
1276
1277 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1278 Expr *FilterExpr,
1279 Stmt *Block) {
1280 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1281 }
1282
1283 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1284 Stmt *Block) {
1285 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1286 }
1287
Douglas Gregorb98b1992009-08-11 05:31:07 +00001288 /// \brief Build a new expression that references a declaration.
1289 ///
1290 /// By default, performs semantic analysis to build the new expression.
1291 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001292 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001293 LookupResult &R,
1294 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001295 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1296 }
1297
1298
1299 /// \brief Build a new expression that references a declaration.
1300 ///
1301 /// By default, performs semantic analysis to build the new expression.
1302 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001303 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001304 ValueDecl *VD,
1305 const DeclarationNameInfo &NameInfo,
1306 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001307 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001308 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001309
1310 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001311
1312 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001313 }
Mike Stump1eb44332009-09-09 15:08:12 +00001314
Douglas Gregorb98b1992009-08-11 05:31:07 +00001315 /// \brief Build a new expression in parentheses.
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 RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001320 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001321 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001322 }
1323
Douglas Gregora71d8192009-09-04 17:36:40 +00001324 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001325 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001326 /// By default, performs semantic analysis to build the new expression.
1327 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001328 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001329 SourceLocation OperatorLoc,
1330 bool isArrow,
1331 CXXScopeSpec &SS,
1332 TypeSourceInfo *ScopeType,
1333 SourceLocation CCLoc,
1334 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001335 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001336
Douglas Gregorb98b1992009-08-11 05:31:07 +00001337 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001338 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001339 /// By default, performs semantic analysis to build the new expression.
1340 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001341 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001342 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001343 Expr *SubExpr) {
1344 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001345 }
Mike Stump1eb44332009-09-09 15:08:12 +00001346
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001347 /// \brief Build a new builtin offsetof expression.
1348 ///
1349 /// By default, performs semantic analysis to build the new expression.
1350 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001351 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001352 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001353 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001354 unsigned NumComponents,
1355 SourceLocation RParenLoc) {
1356 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1357 NumComponents, RParenLoc);
1358 }
Sean Huntc3021132010-05-05 15:23:54 +00001359
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001360 /// \brief Build a new sizeof, alignof or vec_step expression with a
1361 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001362 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001363 /// By default, performs semantic analysis to build the new expression.
1364 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001365 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1366 SourceLocation OpLoc,
1367 UnaryExprOrTypeTrait ExprKind,
1368 SourceRange R) {
1369 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001370 }
1371
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001372 /// \brief Build a new sizeof, alignof or vec step expression with an
1373 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001374 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001375 /// By default, performs semantic analysis to build the new expression.
1376 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001377 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1378 UnaryExprOrTypeTrait ExprKind,
1379 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001380 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001381 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001382 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001383 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001384
Douglas Gregorb98b1992009-08-11 05:31:07 +00001385 return move(Result);
1386 }
Mike Stump1eb44332009-09-09 15:08:12 +00001387
Douglas Gregorb98b1992009-08-11 05:31:07 +00001388 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001389 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001390 /// By default, performs semantic analysis to build the new expression.
1391 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001392 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001393 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001394 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001395 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001396 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1397 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001398 RBracketLoc);
1399 }
1400
1401 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001402 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001403 /// By default, performs semantic analysis to build the new expression.
1404 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001405 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001406 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001407 SourceLocation RParenLoc,
1408 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001409 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001410 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001411 }
1412
1413 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001414 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 /// By default, performs semantic analysis to build the new expression.
1416 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001417 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001418 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001419 NestedNameSpecifierLoc QualifierLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001420 const DeclarationNameInfo &MemberNameInfo,
1421 ValueDecl *Member,
1422 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001423 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001424 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001425 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001426 // We have a reference to an unnamed field. This is always the
1427 // base of an anonymous struct/union member access, i.e. the
1428 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001429 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001430 assert(Member->getType()->isRecordType() &&
1431 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001432
John Wiegley429bb272011-04-08 18:41:53 +00001433 ExprResult BaseResult =
1434 getSema().PerformObjectMemberConversion(Base,
1435 QualifierLoc.getNestedNameSpecifier(),
1436 FoundDecl, Member);
1437 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001438 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001439 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001440 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001441 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001442 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001443 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001444 cast<FieldDecl>(Member)->getType(),
1445 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001446 return getSema().Owned(ME);
1447 }
Mike Stump1eb44332009-09-09 15:08:12 +00001448
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001449 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001450 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001451
John Wiegley429bb272011-04-08 18:41:53 +00001452 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1453 if (BaseResult.isInvalid())
1454 return ExprError();
1455 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001456 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001457
John McCall6bb80172010-03-30 21:47:33 +00001458 // FIXME: this involves duplicating earlier analysis in a lot of
1459 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001460 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001461 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001462 R.resolveKind();
1463
John McCall9ae2f072010-08-23 23:25:46 +00001464 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001465 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001466 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 }
Mike Stump1eb44332009-09-09 15:08:12 +00001468
Douglas Gregorb98b1992009-08-11 05:31:07 +00001469 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001470 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 /// By default, performs semantic analysis to build the new expression.
1472 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001473 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001474 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001475 Expr *LHS, Expr *RHS) {
1476 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 }
1478
1479 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001480 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 /// By default, performs semantic analysis to build the new expression.
1482 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001483 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001484 SourceLocation QuestionLoc,
1485 Expr *LHS,
1486 SourceLocation ColonLoc,
1487 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001488 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1489 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 }
1491
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001493 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 /// By default, performs semantic analysis to build the new expression.
1495 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001496 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001497 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001499 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001500 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001501 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 }
Mike Stump1eb44332009-09-09 15:08:12 +00001503
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001505 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 /// By default, performs semantic analysis to build the new expression.
1507 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001508 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001509 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001511 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001512 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001513 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 }
Mike Stump1eb44332009-09-09 15:08:12 +00001515
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001517 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 /// By default, performs semantic analysis to build the new expression.
1519 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001520 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001521 SourceLocation OpLoc,
1522 SourceLocation AccessorLoc,
1523 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001524
John McCall129e2df2009-11-30 22:42:35 +00001525 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001526 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001527 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001528 OpLoc, /*IsArrow*/ false,
1529 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001530 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001531 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001532 }
Mike Stump1eb44332009-09-09 15:08:12 +00001533
Douglas Gregorb98b1992009-08-11 05:31:07 +00001534 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001535 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001536 /// By default, performs semantic analysis to build the new expression.
1537 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001538 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001539 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001540 SourceLocation RBraceLoc,
1541 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001542 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001543 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1544 if (Result.isInvalid() || ResultTy->isDependentType())
1545 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001546
Douglas Gregore48319a2009-11-09 17:16:50 +00001547 // Patch in the result type we were given, which may have been computed
1548 // when the initial InitListExpr was built.
1549 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1550 ILE->setType(ResultTy);
1551 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001552 }
Mike Stump1eb44332009-09-09 15:08:12 +00001553
Douglas Gregorb98b1992009-08-11 05:31:07 +00001554 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001555 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001556 /// By default, performs semantic analysis to build the new expression.
1557 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001558 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 MultiExprArg ArrayExprs,
1560 SourceLocation EqualOrColonLoc,
1561 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001562 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001563 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001564 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001565 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001566 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001567 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001568
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 ArrayExprs.release();
1570 return move(Result);
1571 }
Mike Stump1eb44332009-09-09 15:08:12 +00001572
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001574 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001575 /// By default, builds the implicit value initialization without performing
1576 /// any semantic analysis. Subclasses may override this routine to provide
1577 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001578 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1580 }
Mike Stump1eb44332009-09-09 15:08:12 +00001581
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001583 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 /// By default, performs semantic analysis to build the new expression.
1585 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001586 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001587 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001588 SourceLocation RParenLoc) {
1589 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001590 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001591 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 }
1593
1594 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001595 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001598 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 MultiExprArg SubExprs,
1600 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001601 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001602 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 }
Mike Stump1eb44332009-09-09 15:08:12 +00001604
Douglas Gregorb98b1992009-08-11 05:31:07 +00001605 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001606 ///
1607 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 /// rather than attempting to map the label statement itself.
1609 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001610 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001611 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001612 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001613 }
Mike Stump1eb44332009-09-09 15:08:12 +00001614
Douglas Gregorb98b1992009-08-11 05:31:07 +00001615 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001616 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 /// By default, performs semantic analysis to build the new expression.
1618 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001619 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001620 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001621 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001622 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001623 }
Mike Stump1eb44332009-09-09 15:08:12 +00001624
Douglas Gregorb98b1992009-08-11 05:31:07 +00001625 /// \brief Build a new __builtin_choose_expr expression.
1626 ///
1627 /// By default, performs semantic analysis to build the new expression.
1628 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001629 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001630 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 SourceLocation RParenLoc) {
1632 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001633 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001634 RParenLoc);
1635 }
Mike Stump1eb44332009-09-09 15:08:12 +00001636
Peter Collingbournef111d932011-04-15 00:35:48 +00001637 /// \brief Build a new generic selection expression.
1638 ///
1639 /// By default, performs semantic analysis to build the new expression.
1640 /// Subclasses may override this routine to provide different behavior.
1641 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1642 SourceLocation DefaultLoc,
1643 SourceLocation RParenLoc,
1644 Expr *ControllingExpr,
1645 TypeSourceInfo **Types,
1646 Expr **Exprs,
1647 unsigned NumAssocs) {
1648 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1649 ControllingExpr, Types, Exprs,
1650 NumAssocs);
1651 }
1652
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 /// \brief Build a new overloaded operator call expression.
1654 ///
1655 /// By default, performs semantic analysis to build the new expression.
1656 /// The semantic analysis provides the behavior of template instantiation,
1657 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001658 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 /// argument-dependent lookup, etc. Subclasses may override this routine to
1660 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001661 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001663 Expr *Callee,
1664 Expr *First,
1665 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001666
1667 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 /// reinterpret_cast.
1669 ///
1670 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001671 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001673 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001674 Stmt::StmtClass Class,
1675 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001676 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001677 SourceLocation RAngleLoc,
1678 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001679 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 SourceLocation RParenLoc) {
1681 switch (Class) {
1682 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001683 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001684 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001685 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686
1687 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001688 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001689 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001690 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001691
Douglas Gregorb98b1992009-08-11 05:31:07 +00001692 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001693 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001694 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001695 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001697
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001699 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001700 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001701 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001702
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 default:
1704 assert(false && "Invalid C++ named cast");
1705 break;
1706 }
Mike Stump1eb44332009-09-09 15:08:12 +00001707
John McCallf312b1e2010-08-26 23:41:50 +00001708 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001709 }
Mike Stump1eb44332009-09-09 15:08:12 +00001710
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 /// \brief Build a new C++ static_cast expression.
1712 ///
1713 /// By default, performs semantic analysis to build the new expression.
1714 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001715 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001717 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 SourceLocation RAngleLoc,
1719 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001720 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001721 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001722 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001723 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001724 SourceRange(LAngleLoc, RAngleLoc),
1725 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001726 }
1727
1728 /// \brief Build a new C++ dynamic_cast expression.
1729 ///
1730 /// By default, performs semantic analysis to build the new expression.
1731 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001732 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001733 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001734 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001735 SourceLocation RAngleLoc,
1736 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001737 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001739 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001740 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001741 SourceRange(LAngleLoc, RAngleLoc),
1742 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001743 }
1744
1745 /// \brief Build a new C++ reinterpret_cast expression.
1746 ///
1747 /// By default, performs semantic analysis to build the new expression.
1748 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001749 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001751 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001752 SourceLocation RAngleLoc,
1753 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001754 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001756 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001757 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001758 SourceRange(LAngleLoc, RAngleLoc),
1759 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 }
1761
1762 /// \brief Build a new C++ const_cast expression.
1763 ///
1764 /// By default, performs semantic analysis to build the new expression.
1765 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001766 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001768 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001769 SourceLocation RAngleLoc,
1770 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001771 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001772 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001773 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001774 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001775 SourceRange(LAngleLoc, RAngleLoc),
1776 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 }
Mike Stump1eb44332009-09-09 15:08:12 +00001778
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779 /// \brief Build a new C++ functional-style cast expression.
1780 ///
1781 /// By default, performs semantic analysis to build the new expression.
1782 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001783 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1784 SourceLocation LParenLoc,
1785 Expr *Sub,
1786 SourceLocation RParenLoc) {
1787 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001788 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 RParenLoc);
1790 }
Mike Stump1eb44332009-09-09 15:08:12 +00001791
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 /// \brief Build a new C++ typeid(type) expression.
1793 ///
1794 /// By default, performs semantic analysis to build the new expression.
1795 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001796 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001797 SourceLocation TypeidLoc,
1798 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001800 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001801 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001802 }
Mike Stump1eb44332009-09-09 15:08:12 +00001803
Francois Pichet01b7c302010-09-08 12:20:18 +00001804
Douglas Gregorb98b1992009-08-11 05:31:07 +00001805 /// \brief Build a new C++ typeid(expr) expression.
1806 ///
1807 /// By default, performs semantic analysis to build the new expression.
1808 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001809 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001810 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001811 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001812 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001813 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001814 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001815 }
1816
Francois Pichet01b7c302010-09-08 12:20:18 +00001817 /// \brief Build a new C++ __uuidof(type) expression.
1818 ///
1819 /// By default, performs semantic analysis to build the new expression.
1820 /// Subclasses may override this routine to provide different behavior.
1821 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1822 SourceLocation TypeidLoc,
1823 TypeSourceInfo *Operand,
1824 SourceLocation RParenLoc) {
1825 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1826 RParenLoc);
1827 }
1828
1829 /// \brief Build a new C++ __uuidof(expr) expression.
1830 ///
1831 /// By default, performs semantic analysis to build the new expression.
1832 /// Subclasses may override this routine to provide different behavior.
1833 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1834 SourceLocation TypeidLoc,
1835 Expr *Operand,
1836 SourceLocation RParenLoc) {
1837 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1838 RParenLoc);
1839 }
1840
Douglas Gregorb98b1992009-08-11 05:31:07 +00001841 /// \brief Build a new C++ "this" expression.
1842 ///
1843 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001844 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001846 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001847 QualType ThisType,
1848 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001849 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001850 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1851 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001852 }
1853
1854 /// \brief Build a new C++ throw expression.
1855 ///
1856 /// By default, performs semantic analysis to build the new expression.
1857 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001858 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001859 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001860 }
1861
1862 /// \brief Build a new C++ default-argument expression.
1863 ///
1864 /// By default, builds a new default-argument expression, which does not
1865 /// require any semantic analysis. Subclasses may override this routine to
1866 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001867 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001868 ParmVarDecl *Param) {
1869 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1870 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001871 }
1872
1873 /// \brief Build a new C++ zero-initialization expression.
1874 ///
1875 /// By default, performs semantic analysis to build the new expression.
1876 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001877 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1878 SourceLocation LParenLoc,
1879 SourceLocation RParenLoc) {
1880 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001881 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001882 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001883 }
Mike Stump1eb44332009-09-09 15:08:12 +00001884
Douglas Gregorb98b1992009-08-11 05:31:07 +00001885 /// \brief Build a new C++ "new" expression.
1886 ///
1887 /// By default, performs semantic analysis to build the new expression.
1888 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001889 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001890 bool UseGlobal,
1891 SourceLocation PlacementLParen,
1892 MultiExprArg PlacementArgs,
1893 SourceLocation PlacementRParen,
1894 SourceRange TypeIdParens,
1895 QualType AllocatedType,
1896 TypeSourceInfo *AllocatedTypeInfo,
1897 Expr *ArraySize,
1898 SourceLocation ConstructorLParen,
1899 MultiExprArg ConstructorArgs,
1900 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001901 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001902 PlacementLParen,
1903 move(PlacementArgs),
1904 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001905 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001906 AllocatedType,
1907 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001908 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 ConstructorLParen,
1910 move(ConstructorArgs),
1911 ConstructorRParen);
1912 }
Mike Stump1eb44332009-09-09 15:08:12 +00001913
Douglas Gregorb98b1992009-08-11 05:31:07 +00001914 /// \brief Build a new C++ "delete" expression.
1915 ///
1916 /// By default, performs semantic analysis to build the new expression.
1917 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001918 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001919 bool IsGlobalDelete,
1920 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001921 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001922 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001923 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001924 }
Mike Stump1eb44332009-09-09 15:08:12 +00001925
Douglas Gregorb98b1992009-08-11 05:31:07 +00001926 /// \brief Build a new unary type trait expression.
1927 ///
1928 /// By default, performs semantic analysis to build the new expression.
1929 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001930 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001931 SourceLocation StartLoc,
1932 TypeSourceInfo *T,
1933 SourceLocation RParenLoc) {
1934 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 }
1936
Francois Pichet6ad6f282010-12-07 00:08:36 +00001937 /// \brief Build a new binary type trait expression.
1938 ///
1939 /// By default, performs semantic analysis to build the new expression.
1940 /// Subclasses may override this routine to provide different behavior.
1941 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1942 SourceLocation StartLoc,
1943 TypeSourceInfo *LhsT,
1944 TypeSourceInfo *RhsT,
1945 SourceLocation RParenLoc) {
1946 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1947 }
1948
John Wiegley21ff2e52011-04-28 00:16:57 +00001949 /// \brief Build a new array type trait expression.
1950 ///
1951 /// By default, performs semantic analysis to build the new expression.
1952 /// Subclasses may override this routine to provide different behavior.
1953 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1954 SourceLocation StartLoc,
1955 TypeSourceInfo *TSInfo,
1956 Expr *DimExpr,
1957 SourceLocation RParenLoc) {
1958 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1959 }
1960
John Wiegley55262202011-04-25 06:54:41 +00001961 /// \brief Build a new expression trait expression.
1962 ///
1963 /// By default, performs semantic analysis to build the new expression.
1964 /// Subclasses may override this routine to provide different behavior.
1965 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1966 SourceLocation StartLoc,
1967 Expr *Queried,
1968 SourceLocation RParenLoc) {
1969 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1970 }
1971
Mike Stump1eb44332009-09-09 15:08:12 +00001972 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 /// expression.
1974 ///
1975 /// By default, performs semantic analysis to build the new expression.
1976 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001977 ExprResult RebuildDependentScopeDeclRefExpr(
1978 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001979 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001980 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001981 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001982 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00001983
1984 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001985 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001986 *TemplateArgs);
1987
Abramo Bagnara25777432010-08-11 22:01:17 +00001988 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001989 }
1990
1991 /// \brief Build a new template-id expression.
1992 ///
1993 /// By default, performs semantic analysis to build the new expression.
1994 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001995 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001996 LookupResult &R,
1997 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001998 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001999 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002000 }
2001
2002 /// \brief Build a new object-construction expression.
2003 ///
2004 /// By default, performs semantic analysis to build the new expression.
2005 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002006 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002007 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002008 CXXConstructorDecl *Constructor,
2009 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002010 MultiExprArg Args,
2011 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002012 CXXConstructExpr::ConstructionKind ConstructKind,
2013 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002014 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002015 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002016 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002017 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002018
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002019 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002020 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00002021 RequiresZeroInit, ConstructKind,
2022 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002023 }
2024
2025 /// \brief Build a new object-construction expression.
2026 ///
2027 /// By default, performs semantic analysis to build the new expression.
2028 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002029 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2030 SourceLocation LParenLoc,
2031 MultiExprArg Args,
2032 SourceLocation RParenLoc) {
2033 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002034 LParenLoc,
2035 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002036 RParenLoc);
2037 }
2038
2039 /// \brief Build a new object-construction expression.
2040 ///
2041 /// By default, performs semantic analysis to build the new expression.
2042 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002043 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2044 SourceLocation LParenLoc,
2045 MultiExprArg Args,
2046 SourceLocation RParenLoc) {
2047 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002048 LParenLoc,
2049 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002050 RParenLoc);
2051 }
Mike Stump1eb44332009-09-09 15:08:12 +00002052
Douglas Gregorb98b1992009-08-11 05:31:07 +00002053 /// \brief Build a new member reference expression.
2054 ///
2055 /// By default, performs semantic analysis to build the new expression.
2056 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002057 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002058 QualType BaseType,
2059 bool IsArrow,
2060 SourceLocation OperatorLoc,
2061 NestedNameSpecifierLoc QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00002062 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002063 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002064 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002065 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002066 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002067
John McCall9ae2f072010-08-23 23:25:46 +00002068 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002069 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00002070 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002071 MemberNameInfo,
2072 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002073 }
2074
John McCall129e2df2009-11-30 22:42:35 +00002075 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002076 ///
2077 /// By default, performs semantic analysis to build the new expression.
2078 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002079 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00002080 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00002081 SourceLocation OperatorLoc,
2082 bool IsArrow,
Douglas Gregor4c9be892011-02-28 20:01:57 +00002083 NestedNameSpecifierLoc QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00002084 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00002085 LookupResult &R,
2086 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002087 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002088 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002089
John McCall9ae2f072010-08-23 23:25:46 +00002090 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002091 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00002092 SS, FirstQualifierInScope,
2093 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002094 }
Mike Stump1eb44332009-09-09 15:08:12 +00002095
Sebastian Redl2e156222010-09-10 20:55:43 +00002096 /// \brief Build a new noexcept expression.
2097 ///
2098 /// By default, performs semantic analysis to build the new expression.
2099 /// Subclasses may override this routine to provide different behavior.
2100 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2101 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2102 }
2103
Douglas Gregoree8aff02011-01-04 17:33:58 +00002104 /// \brief Build a new expression to compute the length of a parameter pack.
2105 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2106 SourceLocation PackLoc,
2107 SourceLocation RParenLoc,
2108 unsigned Length) {
2109 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2110 OperatorLoc, Pack, PackLoc,
2111 RParenLoc, Length);
2112 }
2113
Douglas Gregorb98b1992009-08-11 05:31:07 +00002114 /// \brief Build a new Objective-C @encode expression.
2115 ///
2116 /// By default, performs semantic analysis to build the new expression.
2117 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002118 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002119 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002120 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002121 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002122 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002123 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002124
Douglas Gregor92e986e2010-04-22 16:44:27 +00002125 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002126 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002127 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002128 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002129 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002130 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002131 MultiExprArg Args,
2132 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002133 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2134 ReceiverTypeInfo->getType(),
2135 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002136 Sel, Method, LBracLoc, SelectorLoc,
2137 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002138 }
2139
2140 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002141 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002142 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002143 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002144 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002145 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002146 MultiExprArg Args,
2147 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002148 return SemaRef.BuildInstanceMessage(Receiver,
2149 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002150 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002151 Sel, Method, LBracLoc, SelectorLoc,
2152 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002153 }
2154
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002155 /// \brief Build a new Objective-C ivar reference expression.
2156 ///
2157 /// By default, performs semantic analysis to build the new expression.
2158 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002159 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002160 SourceLocation IvarLoc,
2161 bool IsArrow, bool IsFreeIvar) {
2162 // FIXME: We lose track of the IsFreeIvar bit.
2163 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002164 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002165 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2166 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002167 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002168 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002169 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002170 false);
John Wiegley429bb272011-04-08 18:41:53 +00002171 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002172 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002173
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002174 if (Result.get())
2175 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002176
John Wiegley429bb272011-04-08 18:41:53 +00002177 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002178 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002179 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002180 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002181 /*TemplateArgs=*/0);
2182 }
Douglas Gregore3303542010-04-26 20:47:02 +00002183
2184 /// \brief Build a new Objective-C property reference expression.
2185 ///
2186 /// By default, performs semantic analysis to build the new expression.
2187 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002188 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002189 ObjCPropertyDecl *Property,
2190 SourceLocation PropertyLoc) {
2191 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002192 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002193 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2194 Sema::LookupMemberName);
2195 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002196 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002197 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002198 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002199 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002200 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002201
Douglas Gregore3303542010-04-26 20:47:02 +00002202 if (Result.get())
2203 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002204
John Wiegley429bb272011-04-08 18:41:53 +00002205 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002206 /*FIXME:*/PropertyLoc, IsArrow,
2207 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002208 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002209 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002210 /*TemplateArgs=*/0);
2211 }
Sean Huntc3021132010-05-05 15:23:54 +00002212
John McCall12f78a62010-12-02 01:19:52 +00002213 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002214 ///
2215 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002216 /// Subclasses may override this routine to provide different behavior.
2217 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2218 ObjCMethodDecl *Getter,
2219 ObjCMethodDecl *Setter,
2220 SourceLocation PropertyLoc) {
2221 // Since these expressions can only be value-dependent, we do not
2222 // need to perform semantic analysis again.
2223 return Owned(
2224 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2225 VK_LValue, OK_ObjCProperty,
2226 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002227 }
2228
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002229 /// \brief Build a new Objective-C "isa" expression.
2230 ///
2231 /// By default, performs semantic analysis to build the new expression.
2232 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002233 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002234 bool IsArrow) {
2235 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002236 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002237 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2238 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002239 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002240 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002241 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002242 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002243 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002244
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002245 if (Result.get())
2246 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002247
John Wiegley429bb272011-04-08 18:41:53 +00002248 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002249 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002250 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002251 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002252 /*TemplateArgs=*/0);
2253 }
Sean Huntc3021132010-05-05 15:23:54 +00002254
Douglas Gregorb98b1992009-08-11 05:31:07 +00002255 /// \brief Build a new shuffle vector expression.
2256 ///
2257 /// By default, performs semantic analysis to build the new expression.
2258 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002259 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002260 MultiExprArg SubExprs,
2261 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002262 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002263 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002264 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2265 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2266 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2267 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002268
Douglas Gregorb98b1992009-08-11 05:31:07 +00002269 // Build a reference to the __builtin_shufflevector builtin
2270 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002271 ExprResult Callee
2272 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2273 VK_LValue, BuiltinLoc));
2274 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2275 if (Callee.isInvalid())
2276 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002277
2278 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002279 unsigned NumSubExprs = SubExprs.size();
2280 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002281 ExprResult TheCall = SemaRef.Owned(
2282 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002283 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002284 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002285 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002286 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002287
Douglas Gregorb98b1992009-08-11 05:31:07 +00002288 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002289 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002290 }
John McCall43fed0d2010-11-12 08:19:04 +00002291
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002292 /// \brief Build a new template argument pack expansion.
2293 ///
2294 /// By default, performs semantic analysis to build a new pack expansion
2295 /// for a template argument. Subclasses may override this routine to provide
2296 /// different behavior.
2297 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002298 SourceLocation EllipsisLoc,
2299 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002300 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002301 case TemplateArgument::Expression: {
2302 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002303 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2304 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002305 if (Result.isInvalid())
2306 return TemplateArgumentLoc();
2307
2308 return TemplateArgumentLoc(Result.get(), Result.get());
2309 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002310
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002311 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002312 return TemplateArgumentLoc(TemplateArgument(
2313 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002314 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002315 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002316 Pattern.getTemplateNameLoc(),
2317 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002318
2319 case TemplateArgument::Null:
2320 case TemplateArgument::Integral:
2321 case TemplateArgument::Declaration:
2322 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002323 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002324 llvm_unreachable("Pack expansion pattern has no parameter packs");
2325
2326 case TemplateArgument::Type:
2327 if (TypeSourceInfo *Expansion
2328 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002329 EllipsisLoc,
2330 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002331 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2332 Expansion);
2333 break;
2334 }
2335
2336 return TemplateArgumentLoc();
2337 }
2338
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002339 /// \brief Build a new expression pack expansion.
2340 ///
2341 /// By default, performs semantic analysis to build a new pack expansion
2342 /// for an expression. Subclasses may override this routine to provide
2343 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002344 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2345 llvm::Optional<unsigned> NumExpansions) {
2346 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002347 }
2348
John McCall43fed0d2010-11-12 08:19:04 +00002349private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002350 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2351 QualType ObjectType,
2352 NamedDecl *FirstQualifierInScope,
2353 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002354
2355 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2356 QualType ObjectType,
2357 NamedDecl *FirstQualifierInScope,
2358 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002359};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002360
Douglas Gregor43959a92009-08-20 07:17:43 +00002361template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002362StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002363 if (!S)
2364 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002365
Douglas Gregor43959a92009-08-20 07:17:43 +00002366 switch (S->getStmtClass()) {
2367 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002368
Douglas Gregor43959a92009-08-20 07:17:43 +00002369 // Transform individual statement nodes
2370#define STMT(Node, Parent) \
2371 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002372#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002373#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002374#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002375
Douglas Gregor43959a92009-08-20 07:17:43 +00002376 // Transform expressions by calling TransformExpr.
2377#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002378#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002379#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002380#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002381 {
John McCall60d7b3a2010-08-24 06:29:42 +00002382 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002383 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002384 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002385
John McCall9ae2f072010-08-23 23:25:46 +00002386 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002387 }
Mike Stump1eb44332009-09-09 15:08:12 +00002388 }
2389
John McCall3fa5cae2010-10-26 07:05:15 +00002390 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002391}
Mike Stump1eb44332009-09-09 15:08:12 +00002392
2393
Douglas Gregor670444e2009-08-04 22:27:00 +00002394template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002395ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002396 if (!E)
2397 return SemaRef.Owned(E);
2398
2399 switch (E->getStmtClass()) {
2400 case Stmt::NoStmtClass: break;
2401#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002402#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002403#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002404 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002405#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002406 }
2407
John McCall3fa5cae2010-10-26 07:05:15 +00002408 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002409}
2410
2411template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002412bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2413 unsigned NumInputs,
2414 bool IsCall,
2415 llvm::SmallVectorImpl<Expr *> &Outputs,
2416 bool *ArgChanged) {
2417 for (unsigned I = 0; I != NumInputs; ++I) {
2418 // If requested, drop call arguments that need to be dropped.
2419 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2420 if (ArgChanged)
2421 *ArgChanged = true;
2422
2423 break;
2424 }
2425
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002426 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2427 Expr *Pattern = Expansion->getPattern();
2428
2429 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2430 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2431 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2432
2433 // Determine whether the set of unexpanded parameter packs can and should
2434 // be expanded.
2435 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002436 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002437 llvm::Optional<unsigned> OrigNumExpansions
2438 = Expansion->getNumExpansions();
2439 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002440 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2441 Pattern->getSourceRange(),
2442 Unexpanded.data(),
2443 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002444 Expand, RetainExpansion,
2445 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002446 return true;
2447
2448 if (!Expand) {
2449 // The transform has determined that we should perform a simple
2450 // transformation on the pack expansion, producing another pack
2451 // expansion.
2452 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2453 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2454 if (OutPattern.isInvalid())
2455 return true;
2456
2457 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002458 Expansion->getEllipsisLoc(),
2459 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002460 if (Out.isInvalid())
2461 return true;
2462
2463 if (ArgChanged)
2464 *ArgChanged = true;
2465 Outputs.push_back(Out.get());
2466 continue;
2467 }
2468
2469 // The transform has determined that we should perform an elementwise
2470 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002471 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002472 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2473 ExprResult Out = getDerived().TransformExpr(Pattern);
2474 if (Out.isInvalid())
2475 return true;
2476
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002477 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002478 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2479 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002480 if (Out.isInvalid())
2481 return true;
2482 }
2483
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002484 if (ArgChanged)
2485 *ArgChanged = true;
2486 Outputs.push_back(Out.get());
2487 }
2488
2489 continue;
2490 }
2491
Douglas Gregoraa165f82011-01-03 19:04:46 +00002492 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2493 if (Result.isInvalid())
2494 return true;
2495
2496 if (Result.get() != Inputs[I] && ArgChanged)
2497 *ArgChanged = true;
2498
2499 Outputs.push_back(Result.get());
2500 }
2501
2502 return false;
2503}
2504
2505template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002506NestedNameSpecifierLoc
2507TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2508 NestedNameSpecifierLoc NNS,
2509 QualType ObjectType,
2510 NamedDecl *FirstQualifierInScope) {
2511 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2512 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2513 Qualifier = Qualifier.getPrefix())
2514 Qualifiers.push_back(Qualifier);
2515
2516 CXXScopeSpec SS;
2517 while (!Qualifiers.empty()) {
2518 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2519 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2520
2521 switch (QNNS->getKind()) {
2522 case NestedNameSpecifier::Identifier:
2523 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2524 *QNNS->getAsIdentifier(),
2525 Q.getLocalBeginLoc(),
2526 Q.getLocalEndLoc(),
2527 ObjectType, false, SS,
2528 FirstQualifierInScope, false))
2529 return NestedNameSpecifierLoc();
2530
2531 break;
2532
2533 case NestedNameSpecifier::Namespace: {
2534 NamespaceDecl *NS
2535 = cast_or_null<NamespaceDecl>(
2536 getDerived().TransformDecl(
2537 Q.getLocalBeginLoc(),
2538 QNNS->getAsNamespace()));
2539 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2540 break;
2541 }
2542
2543 case NestedNameSpecifier::NamespaceAlias: {
2544 NamespaceAliasDecl *Alias
2545 = cast_or_null<NamespaceAliasDecl>(
2546 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2547 QNNS->getAsNamespaceAlias()));
2548 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2549 Q.getLocalEndLoc());
2550 break;
2551 }
2552
2553 case NestedNameSpecifier::Global:
2554 // There is no meaningful transformation that one could perform on the
2555 // global scope.
2556 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2557 break;
2558
2559 case NestedNameSpecifier::TypeSpecWithTemplate:
2560 case NestedNameSpecifier::TypeSpec: {
2561 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2562 FirstQualifierInScope, SS);
2563
2564 if (!TL)
2565 return NestedNameSpecifierLoc();
2566
2567 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2568 (SemaRef.getLangOptions().CPlusPlus0x &&
2569 TL.getType()->isEnumeralType())) {
2570 assert(!TL.getType().hasLocalQualifiers() &&
2571 "Can't get cv-qualifiers here");
2572 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2573 Q.getLocalEndLoc());
2574 break;
2575 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002576 // If the nested-name-specifier is an invalid type def, don't emit an
2577 // error because a previous error should have already been emitted.
2578 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2579 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2580 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2581 << TL.getType() << SS.getRange();
2582 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002583 return NestedNameSpecifierLoc();
2584 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002585 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002586
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002587 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002588 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002589 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002590 }
2591
2592 // Don't rebuild the nested-name-specifier if we don't have to.
2593 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2594 !getDerived().AlwaysRebuild())
2595 return NNS;
2596
2597 // If we can re-use the source-location data from the original
2598 // nested-name-specifier, do so.
2599 if (SS.location_size() == NNS.getDataLength() &&
2600 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2601 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2602
2603 // Allocate new nested-name-specifier location information.
2604 return SS.getWithLocInContext(SemaRef.Context);
2605}
2606
2607template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002608DeclarationNameInfo
2609TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002610::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002611 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002612 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002613 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002614
2615 switch (Name.getNameKind()) {
2616 case DeclarationName::Identifier:
2617 case DeclarationName::ObjCZeroArgSelector:
2618 case DeclarationName::ObjCOneArgSelector:
2619 case DeclarationName::ObjCMultiArgSelector:
2620 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002621 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002622 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002623 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002624
Douglas Gregor81499bb2009-09-03 22:13:48 +00002625 case DeclarationName::CXXConstructorName:
2626 case DeclarationName::CXXDestructorName:
2627 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002628 TypeSourceInfo *NewTInfo;
2629 CanQualType NewCanTy;
2630 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002631 NewTInfo = getDerived().TransformType(OldTInfo);
2632 if (!NewTInfo)
2633 return DeclarationNameInfo();
2634 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002635 }
2636 else {
2637 NewTInfo = 0;
2638 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002639 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002640 if (NewT.isNull())
2641 return DeclarationNameInfo();
2642 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2643 }
Mike Stump1eb44332009-09-09 15:08:12 +00002644
Abramo Bagnara25777432010-08-11 22:01:17 +00002645 DeclarationName NewName
2646 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2647 NewCanTy);
2648 DeclarationNameInfo NewNameInfo(NameInfo);
2649 NewNameInfo.setName(NewName);
2650 NewNameInfo.setNamedTypeInfo(NewTInfo);
2651 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002652 }
Mike Stump1eb44332009-09-09 15:08:12 +00002653 }
2654
Abramo Bagnara25777432010-08-11 22:01:17 +00002655 assert(0 && "Unknown name kind.");
2656 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002657}
2658
2659template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002660TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002661TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2662 TemplateName Name,
2663 SourceLocation NameLoc,
2664 QualType ObjectType,
2665 NamedDecl *FirstQualifierInScope) {
2666 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2667 TemplateDecl *Template = QTN->getTemplateDecl();
2668 assert(Template && "qualified template name must refer to a template");
2669
2670 TemplateDecl *TransTemplate
2671 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2672 Template));
2673 if (!TransTemplate)
2674 return TemplateName();
2675
2676 if (!getDerived().AlwaysRebuild() &&
2677 SS.getScopeRep() == QTN->getQualifier() &&
2678 TransTemplate == Template)
2679 return Name;
2680
2681 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2682 TransTemplate);
2683 }
2684
2685 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2686 if (SS.getScopeRep()) {
2687 // These apply to the scope specifier, not the template.
2688 ObjectType = QualType();
2689 FirstQualifierInScope = 0;
2690 }
2691
2692 if (!getDerived().AlwaysRebuild() &&
2693 SS.getScopeRep() == DTN->getQualifier() &&
2694 ObjectType.isNull())
2695 return Name;
2696
2697 if (DTN->isIdentifier()) {
2698 return getDerived().RebuildTemplateName(SS,
2699 *DTN->getIdentifier(),
2700 NameLoc,
2701 ObjectType,
2702 FirstQualifierInScope);
2703 }
2704
2705 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2706 ObjectType);
2707 }
2708
2709 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2710 TemplateDecl *TransTemplate
2711 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2712 Template));
2713 if (!TransTemplate)
2714 return TemplateName();
2715
2716 if (!getDerived().AlwaysRebuild() &&
2717 TransTemplate == Template)
2718 return Name;
2719
2720 return TemplateName(TransTemplate);
2721 }
2722
2723 if (SubstTemplateTemplateParmPackStorage *SubstPack
2724 = Name.getAsSubstTemplateTemplateParmPack()) {
2725 TemplateTemplateParmDecl *TransParam
2726 = cast_or_null<TemplateTemplateParmDecl>(
2727 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2728 if (!TransParam)
2729 return TemplateName();
2730
2731 if (!getDerived().AlwaysRebuild() &&
2732 TransParam == SubstPack->getParameterPack())
2733 return Name;
2734
2735 return getDerived().RebuildTemplateName(TransParam,
2736 SubstPack->getArgumentPack());
2737 }
2738
2739 // These should be getting filtered out before they reach the AST.
2740 llvm_unreachable("overloaded function decl survived to here");
2741 return TemplateName();
2742}
2743
2744template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002745void TreeTransform<Derived>::InventTemplateArgumentLoc(
2746 const TemplateArgument &Arg,
2747 TemplateArgumentLoc &Output) {
2748 SourceLocation Loc = getDerived().getBaseLocation();
2749 switch (Arg.getKind()) {
2750 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002751 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002752 break;
2753
2754 case TemplateArgument::Type:
2755 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002756 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002757
John McCall833ca992009-10-29 08:12:44 +00002758 break;
2759
Douglas Gregor788cd062009-11-11 01:00:40 +00002760 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002761 case TemplateArgument::TemplateExpansion: {
2762 NestedNameSpecifierLocBuilder Builder;
2763 TemplateName Template = Arg.getAsTemplate();
2764 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2765 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2766 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2767 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2768
2769 if (Arg.getKind() == TemplateArgument::Template)
2770 Output = TemplateArgumentLoc(Arg,
2771 Builder.getWithLocInContext(SemaRef.Context),
2772 Loc);
2773 else
2774 Output = TemplateArgumentLoc(Arg,
2775 Builder.getWithLocInContext(SemaRef.Context),
2776 Loc, Loc);
2777
Douglas Gregor788cd062009-11-11 01:00:40 +00002778 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002779 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002780
John McCall833ca992009-10-29 08:12:44 +00002781 case TemplateArgument::Expression:
2782 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2783 break;
2784
2785 case TemplateArgument::Declaration:
2786 case TemplateArgument::Integral:
2787 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002788 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002789 break;
2790 }
2791}
2792
2793template<typename Derived>
2794bool TreeTransform<Derived>::TransformTemplateArgument(
2795 const TemplateArgumentLoc &Input,
2796 TemplateArgumentLoc &Output) {
2797 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002798 switch (Arg.getKind()) {
2799 case TemplateArgument::Null:
2800 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002801 Output = Input;
2802 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002803
Douglas Gregor670444e2009-08-04 22:27:00 +00002804 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002805 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002806 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002807 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002808
2809 DI = getDerived().TransformType(DI);
2810 if (!DI) return true;
2811
2812 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2813 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002814 }
Mike Stump1eb44332009-09-09 15:08:12 +00002815
Douglas Gregor670444e2009-08-04 22:27:00 +00002816 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002817 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002818 DeclarationName Name;
2819 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2820 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002821 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002822 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002823 if (!D) return true;
2824
John McCall828bff22009-10-29 18:45:58 +00002825 Expr *SourceExpr = Input.getSourceDeclExpression();
2826 if (SourceExpr) {
2827 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002828 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002829 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002830 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002831 }
2832
2833 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002834 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002835 }
Mike Stump1eb44332009-09-09 15:08:12 +00002836
Douglas Gregor788cd062009-11-11 01:00:40 +00002837 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002838 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2839 if (QualifierLoc) {
2840 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2841 if (!QualifierLoc)
2842 return true;
2843 }
2844
Douglas Gregor1d752d72011-03-02 18:46:51 +00002845 CXXScopeSpec SS;
2846 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002847 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002848 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2849 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002850 if (Template.isNull())
2851 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002852
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002853 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002854 Input.getTemplateNameLoc());
2855 return false;
2856 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002857
2858 case TemplateArgument::TemplateExpansion:
2859 llvm_unreachable("Caller should expand pack expansions");
2860
Douglas Gregor670444e2009-08-04 22:27:00 +00002861 case TemplateArgument::Expression: {
2862 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002863 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002864 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002865
John McCall833ca992009-10-29 08:12:44 +00002866 Expr *InputExpr = Input.getSourceExpression();
2867 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2868
Chris Lattner223de242011-04-25 20:37:58 +00002869 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall833ca992009-10-29 08:12:44 +00002870 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002871 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002872 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002873 }
Mike Stump1eb44332009-09-09 15:08:12 +00002874
Douglas Gregor670444e2009-08-04 22:27:00 +00002875 case TemplateArgument::Pack: {
2876 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2877 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002878 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002879 AEnd = Arg.pack_end();
2880 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002881
John McCall833ca992009-10-29 08:12:44 +00002882 // FIXME: preserve source information here when we start
2883 // caring about parameter packs.
2884
John McCall828bff22009-10-29 18:45:58 +00002885 TemplateArgumentLoc InputArg;
2886 TemplateArgumentLoc OutputArg;
2887 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2888 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002889 return true;
2890
John McCall828bff22009-10-29 18:45:58 +00002891 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002892 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002893
2894 TemplateArgument *TransformedArgsPtr
2895 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2896 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2897 TransformedArgsPtr);
2898 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2899 TransformedArgs.size()),
2900 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002901 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002902 }
2903 }
Mike Stump1eb44332009-09-09 15:08:12 +00002904
Douglas Gregor670444e2009-08-04 22:27:00 +00002905 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002906 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002907}
2908
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002909/// \brief Iterator adaptor that invents template argument location information
2910/// for each of the template arguments in its underlying iterator.
2911template<typename Derived, typename InputIterator>
2912class TemplateArgumentLocInventIterator {
2913 TreeTransform<Derived> &Self;
2914 InputIterator Iter;
2915
2916public:
2917 typedef TemplateArgumentLoc value_type;
2918 typedef TemplateArgumentLoc reference;
2919 typedef typename std::iterator_traits<InputIterator>::difference_type
2920 difference_type;
2921 typedef std::input_iterator_tag iterator_category;
2922
2923 class pointer {
2924 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002925
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002926 public:
2927 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2928
2929 const TemplateArgumentLoc *operator->() const { return &Arg; }
2930 };
2931
2932 TemplateArgumentLocInventIterator() { }
2933
2934 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2935 InputIterator Iter)
2936 : Self(Self), Iter(Iter) { }
2937
2938 TemplateArgumentLocInventIterator &operator++() {
2939 ++Iter;
2940 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002941 }
2942
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002943 TemplateArgumentLocInventIterator operator++(int) {
2944 TemplateArgumentLocInventIterator Old(*this);
2945 ++(*this);
2946 return Old;
2947 }
2948
2949 reference operator*() const {
2950 TemplateArgumentLoc Result;
2951 Self.InventTemplateArgumentLoc(*Iter, Result);
2952 return Result;
2953 }
2954
2955 pointer operator->() const { return pointer(**this); }
2956
2957 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2958 const TemplateArgumentLocInventIterator &Y) {
2959 return X.Iter == Y.Iter;
2960 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002961
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002962 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2963 const TemplateArgumentLocInventIterator &Y) {
2964 return X.Iter != Y.Iter;
2965 }
2966};
2967
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002968template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002969template<typename InputIterator>
2970bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2971 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002972 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002973 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002974 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002975 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002976
2977 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2978 // Unpack argument packs, which we translate them into separate
2979 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002980 // FIXME: We could do much better if we could guarantee that the
2981 // TemplateArgumentLocInfo for the pack expansion would be usable for
2982 // all of the template arguments in the argument pack.
2983 typedef TemplateArgumentLocInventIterator<Derived,
2984 TemplateArgument::pack_iterator>
2985 PackLocIterator;
2986 if (TransformTemplateArguments(PackLocIterator(*this,
2987 In.getArgument().pack_begin()),
2988 PackLocIterator(*this,
2989 In.getArgument().pack_end()),
2990 Outputs))
2991 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002992
2993 continue;
2994 }
2995
2996 if (In.getArgument().isPackExpansion()) {
2997 // We have a pack expansion, for which we will be substituting into
2998 // the pattern.
2999 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003000 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003001 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003002 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3003 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003004
3005 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3006 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3007 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3008
3009 // Determine whether the set of unexpanded parameter packs can and should
3010 // be expanded.
3011 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003012 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003013 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003014 if (getDerived().TryExpandParameterPacks(Ellipsis,
3015 Pattern.getSourceRange(),
3016 Unexpanded.data(),
3017 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003018 Expand,
3019 RetainExpansion,
3020 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003021 return true;
3022
3023 if (!Expand) {
3024 // The transform has determined that we should perform a simple
3025 // transformation on the pack expansion, producing another pack
3026 // expansion.
3027 TemplateArgumentLoc OutPattern;
3028 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3029 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3030 return true;
3031
Douglas Gregorcded4f62011-01-14 17:04:44 +00003032 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3033 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003034 if (Out.getArgument().isNull())
3035 return true;
3036
3037 Outputs.addArgument(Out);
3038 continue;
3039 }
3040
3041 // The transform has determined that we should perform an elementwise
3042 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003043 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003044 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3045
3046 if (getDerived().TransformTemplateArgument(Pattern, Out))
3047 return true;
3048
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003049 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003050 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3051 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003052 if (Out.getArgument().isNull())
3053 return true;
3054 }
3055
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003056 Outputs.addArgument(Out);
3057 }
3058
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003059 // If we're supposed to retain a pack expansion, do so by temporarily
3060 // forgetting the partially-substituted parameter pack.
3061 if (RetainExpansion) {
3062 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3063
3064 if (getDerived().TransformTemplateArgument(Pattern, Out))
3065 return true;
3066
Douglas Gregorcded4f62011-01-14 17:04:44 +00003067 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3068 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003069 if (Out.getArgument().isNull())
3070 return true;
3071
3072 Outputs.addArgument(Out);
3073 }
Douglas Gregord3731192011-01-10 07:32:04 +00003074
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003075 continue;
3076 }
3077
3078 // The simple case:
3079 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003080 return true;
3081
3082 Outputs.addArgument(Out);
3083 }
3084
3085 return false;
3086
3087}
3088
Douglas Gregor577f75a2009-08-04 16:50:30 +00003089//===----------------------------------------------------------------------===//
3090// Type transformation
3091//===----------------------------------------------------------------------===//
3092
3093template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003094QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003095 if (getDerived().AlreadyTransformed(T))
3096 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003097
John McCalla2becad2009-10-21 00:40:46 +00003098 // Temporary workaround. All of these transformations should
3099 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003100 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3101 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003102
John McCall43fed0d2010-11-12 08:19:04 +00003103 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003104
John McCalla2becad2009-10-21 00:40:46 +00003105 if (!NewDI)
3106 return QualType();
3107
3108 return NewDI->getType();
3109}
3110
3111template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003112TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00003113 if (getDerived().AlreadyTransformed(DI->getType()))
3114 return DI;
3115
3116 TypeLocBuilder TLB;
3117
3118 TypeLoc TL = DI->getTypeLoc();
3119 TLB.reserve(TL.getFullDataSize());
3120
John McCall43fed0d2010-11-12 08:19:04 +00003121 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003122 if (Result.isNull())
3123 return 0;
3124
John McCalla93c9342009-12-07 02:54:59 +00003125 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003126}
3127
3128template<typename Derived>
3129QualType
John McCall43fed0d2010-11-12 08:19:04 +00003130TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003131 switch (T.getTypeLocClass()) {
3132#define ABSTRACT_TYPELOC(CLASS, PARENT)
3133#define TYPELOC(CLASS, PARENT) \
3134 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003135 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003136#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003137 }
Mike Stump1eb44332009-09-09 15:08:12 +00003138
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003139 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003140 return QualType();
3141}
3142
3143/// FIXME: By default, this routine adds type qualifiers only to types
3144/// that can have qualifiers, and silently suppresses those qualifiers
3145/// that are not permitted (e.g., qualifiers on reference or function
3146/// types). This is the right thing for template instantiation, but
3147/// probably not for other clients.
3148template<typename Derived>
3149QualType
3150TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003151 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003152 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003153
John McCall43fed0d2010-11-12 08:19:04 +00003154 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003155 if (Result.isNull())
3156 return QualType();
3157
3158 // Silently suppress qualifiers if the result type can't be qualified.
3159 // FIXME: this is the right thing for template instantiation, but
3160 // probably not for other clients.
3161 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003162 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003163
John McCall28654742010-06-05 06:41:15 +00003164 if (!Quals.empty()) {
3165 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3166 TLB.push<QualifiedTypeLoc>(Result);
3167 // No location information to preserve.
3168 }
John McCalla2becad2009-10-21 00:40:46 +00003169
3170 return Result;
3171}
3172
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003173template<typename Derived>
3174TypeLoc
3175TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3176 QualType ObjectType,
3177 NamedDecl *UnqualLookup,
3178 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003179 QualType T = TL.getType();
3180 if (getDerived().AlreadyTransformed(T))
3181 return TL;
3182
3183 TypeLocBuilder TLB;
3184 QualType Result;
3185
3186 if (isa<TemplateSpecializationType>(T)) {
3187 TemplateSpecializationTypeLoc SpecTL
3188 = cast<TemplateSpecializationTypeLoc>(TL);
3189
3190 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003191 getDerived().TransformTemplateName(SS,
3192 SpecTL.getTypePtr()->getTemplateName(),
3193 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003194 ObjectType, UnqualLookup);
3195 if (Template.isNull())
3196 return TypeLoc();
3197
3198 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3199 Template);
3200 } else if (isa<DependentTemplateSpecializationType>(T)) {
3201 DependentTemplateSpecializationTypeLoc SpecTL
3202 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3203
Douglas Gregora88f09f2011-02-28 17:23:35 +00003204 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003205 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003206 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003207 SpecTL.getNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003208 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003209 if (Template.isNull())
3210 return TypeLoc();
3211
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003212 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003213 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003214 Template,
3215 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003216 } else {
3217 // Nothing special needs to be done for these.
3218 Result = getDerived().TransformType(TLB, TL);
3219 }
3220
3221 if (Result.isNull())
3222 return TypeLoc();
3223
3224 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3225}
3226
Douglas Gregorb71d8212011-03-02 18:32:08 +00003227template<typename Derived>
3228TypeSourceInfo *
3229TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3230 QualType ObjectType,
3231 NamedDecl *UnqualLookup,
3232 CXXScopeSpec &SS) {
3233 // FIXME: Painfully copy-paste from the above!
3234
3235 QualType T = TSInfo->getType();
3236 if (getDerived().AlreadyTransformed(T))
3237 return TSInfo;
3238
3239 TypeLocBuilder TLB;
3240 QualType Result;
3241
3242 TypeLoc TL = TSInfo->getTypeLoc();
3243 if (isa<TemplateSpecializationType>(T)) {
3244 TemplateSpecializationTypeLoc SpecTL
3245 = cast<TemplateSpecializationTypeLoc>(TL);
3246
3247 TemplateName Template
3248 = getDerived().TransformTemplateName(SS,
3249 SpecTL.getTypePtr()->getTemplateName(),
3250 SpecTL.getTemplateNameLoc(),
3251 ObjectType, UnqualLookup);
3252 if (Template.isNull())
3253 return 0;
3254
3255 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3256 Template);
3257 } else if (isa<DependentTemplateSpecializationType>(T)) {
3258 DependentTemplateSpecializationTypeLoc SpecTL
3259 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3260
3261 TemplateName Template
3262 = getDerived().RebuildTemplateName(SS,
3263 *SpecTL.getTypePtr()->getIdentifier(),
3264 SpecTL.getNameLoc(),
3265 ObjectType, UnqualLookup);
3266 if (Template.isNull())
3267 return 0;
3268
3269 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3270 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003271 Template,
3272 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003273 } else {
3274 // Nothing special needs to be done for these.
3275 Result = getDerived().TransformType(TLB, TL);
3276 }
3277
3278 if (Result.isNull())
3279 return 0;
3280
3281 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3282}
3283
John McCalla2becad2009-10-21 00:40:46 +00003284template <class TyLoc> static inline
3285QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3286 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3287 NewT.setNameLoc(T.getNameLoc());
3288 return T.getType();
3289}
3290
John McCalla2becad2009-10-21 00:40:46 +00003291template<typename Derived>
3292QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003293 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003294 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3295 NewT.setBuiltinLoc(T.getBuiltinLoc());
3296 if (T.needsExtraLocalData())
3297 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3298 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003299}
Mike Stump1eb44332009-09-09 15:08:12 +00003300
Douglas Gregor577f75a2009-08-04 16:50:30 +00003301template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003302QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003303 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003304 // FIXME: recurse?
3305 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003306}
Mike Stump1eb44332009-09-09 15:08:12 +00003307
Douglas Gregor577f75a2009-08-04 16:50:30 +00003308template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003309QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003310 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003311 QualType PointeeType
3312 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003313 if (PointeeType.isNull())
3314 return QualType();
3315
3316 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003317 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003318 // A dependent pointer type 'T *' has is being transformed such
3319 // that an Objective-C class type is being replaced for 'T'. The
3320 // resulting pointer type is an ObjCObjectPointerType, not a
3321 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003322 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003323
John McCallc12c5bb2010-05-15 11:32:37 +00003324 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3325 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003326 return Result;
3327 }
John McCall43fed0d2010-11-12 08:19:04 +00003328
Douglas Gregor92e986e2010-04-22 16:44:27 +00003329 if (getDerived().AlwaysRebuild() ||
3330 PointeeType != TL.getPointeeLoc().getType()) {
3331 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3332 if (Result.isNull())
3333 return QualType();
3334 }
Sean Huntc3021132010-05-05 15:23:54 +00003335
Douglas Gregor92e986e2010-04-22 16:44:27 +00003336 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3337 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003338 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003339}
Mike Stump1eb44332009-09-09 15:08:12 +00003340
3341template<typename Derived>
3342QualType
John McCalla2becad2009-10-21 00:40:46 +00003343TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003344 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003345 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003346 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3347 if (PointeeType.isNull())
3348 return QualType();
3349
3350 QualType Result = TL.getType();
3351 if (getDerived().AlwaysRebuild() ||
3352 PointeeType != TL.getPointeeLoc().getType()) {
3353 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003354 TL.getSigilLoc());
3355 if (Result.isNull())
3356 return QualType();
3357 }
3358
Douglas Gregor39968ad2010-04-22 16:50:51 +00003359 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003360 NewT.setSigilLoc(TL.getSigilLoc());
3361 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003362}
3363
John McCall85737a72009-10-30 00:06:24 +00003364/// Transforms a reference type. Note that somewhat paradoxically we
3365/// don't care whether the type itself is an l-value type or an r-value
3366/// type; we only care if the type was *written* as an l-value type
3367/// or an r-value type.
3368template<typename Derived>
3369QualType
3370TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003371 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003372 const ReferenceType *T = TL.getTypePtr();
3373
3374 // Note that this works with the pointee-as-written.
3375 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3376 if (PointeeType.isNull())
3377 return QualType();
3378
3379 QualType Result = TL.getType();
3380 if (getDerived().AlwaysRebuild() ||
3381 PointeeType != T->getPointeeTypeAsWritten()) {
3382 Result = getDerived().RebuildReferenceType(PointeeType,
3383 T->isSpelledAsLValue(),
3384 TL.getSigilLoc());
3385 if (Result.isNull())
3386 return QualType();
3387 }
3388
3389 // r-value references can be rebuilt as l-value references.
3390 ReferenceTypeLoc NewTL;
3391 if (isa<LValueReferenceType>(Result))
3392 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3393 else
3394 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3395 NewTL.setSigilLoc(TL.getSigilLoc());
3396
3397 return Result;
3398}
3399
Mike Stump1eb44332009-09-09 15:08:12 +00003400template<typename Derived>
3401QualType
John McCalla2becad2009-10-21 00:40:46 +00003402TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003403 LValueReferenceTypeLoc TL) {
3404 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003405}
3406
Mike Stump1eb44332009-09-09 15:08:12 +00003407template<typename Derived>
3408QualType
John McCalla2becad2009-10-21 00:40:46 +00003409TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003410 RValueReferenceTypeLoc TL) {
3411 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003412}
Mike Stump1eb44332009-09-09 15:08:12 +00003413
Douglas Gregor577f75a2009-08-04 16:50:30 +00003414template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003415QualType
John McCalla2becad2009-10-21 00:40:46 +00003416TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003417 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003418 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003419 if (PointeeType.isNull())
3420 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003421
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003422 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3423 TypeSourceInfo* NewClsTInfo = 0;
3424 if (OldClsTInfo) {
3425 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3426 if (!NewClsTInfo)
3427 return QualType();
3428 }
3429
3430 const MemberPointerType *T = TL.getTypePtr();
3431 QualType OldClsType = QualType(T->getClass(), 0);
3432 QualType NewClsType;
3433 if (NewClsTInfo)
3434 NewClsType = NewClsTInfo->getType();
3435 else {
3436 NewClsType = getDerived().TransformType(OldClsType);
3437 if (NewClsType.isNull())
3438 return QualType();
3439 }
Mike Stump1eb44332009-09-09 15:08:12 +00003440
John McCalla2becad2009-10-21 00:40:46 +00003441 QualType Result = TL.getType();
3442 if (getDerived().AlwaysRebuild() ||
3443 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003444 NewClsType != OldClsType) {
3445 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003446 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003447 if (Result.isNull())
3448 return QualType();
3449 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003450
John McCalla2becad2009-10-21 00:40:46 +00003451 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3452 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003453 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003454
3455 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003456}
3457
Mike Stump1eb44332009-09-09 15:08:12 +00003458template<typename Derived>
3459QualType
John McCalla2becad2009-10-21 00:40:46 +00003460TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003461 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003462 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003463 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003464 if (ElementType.isNull())
3465 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003466
John McCalla2becad2009-10-21 00:40:46 +00003467 QualType Result = TL.getType();
3468 if (getDerived().AlwaysRebuild() ||
3469 ElementType != T->getElementType()) {
3470 Result = getDerived().RebuildConstantArrayType(ElementType,
3471 T->getSizeModifier(),
3472 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003473 T->getIndexTypeCVRQualifiers(),
3474 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003475 if (Result.isNull())
3476 return QualType();
3477 }
Sean Huntc3021132010-05-05 15:23:54 +00003478
John McCalla2becad2009-10-21 00:40:46 +00003479 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3480 NewTL.setLBracketLoc(TL.getLBracketLoc());
3481 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003482
John McCalla2becad2009-10-21 00:40:46 +00003483 Expr *Size = TL.getSizeExpr();
3484 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003485 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003486 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3487 }
3488 NewTL.setSizeExpr(Size);
3489
3490 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003491}
Mike Stump1eb44332009-09-09 15:08:12 +00003492
Douglas Gregor577f75a2009-08-04 16:50:30 +00003493template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003494QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003495 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003496 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003497 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003498 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003499 if (ElementType.isNull())
3500 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003501
John McCalla2becad2009-10-21 00:40:46 +00003502 QualType Result = TL.getType();
3503 if (getDerived().AlwaysRebuild() ||
3504 ElementType != T->getElementType()) {
3505 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003506 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003507 T->getIndexTypeCVRQualifiers(),
3508 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003509 if (Result.isNull())
3510 return QualType();
3511 }
Sean Huntc3021132010-05-05 15:23:54 +00003512
John McCalla2becad2009-10-21 00:40:46 +00003513 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3514 NewTL.setLBracketLoc(TL.getLBracketLoc());
3515 NewTL.setRBracketLoc(TL.getRBracketLoc());
3516 NewTL.setSizeExpr(0);
3517
3518 return Result;
3519}
3520
3521template<typename Derived>
3522QualType
3523TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003524 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003525 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003526 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3527 if (ElementType.isNull())
3528 return QualType();
3529
3530 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003531 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003532
John McCall60d7b3a2010-08-24 06:29:42 +00003533 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003534 = getDerived().TransformExpr(T->getSizeExpr());
3535 if (SizeResult.isInvalid())
3536 return QualType();
3537
John McCall9ae2f072010-08-23 23:25:46 +00003538 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003539
3540 QualType Result = TL.getType();
3541 if (getDerived().AlwaysRebuild() ||
3542 ElementType != T->getElementType() ||
3543 Size != T->getSizeExpr()) {
3544 Result = getDerived().RebuildVariableArrayType(ElementType,
3545 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003546 Size,
John McCalla2becad2009-10-21 00:40:46 +00003547 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003548 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003549 if (Result.isNull())
3550 return QualType();
3551 }
Sean Huntc3021132010-05-05 15:23:54 +00003552
John McCalla2becad2009-10-21 00:40:46 +00003553 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3554 NewTL.setLBracketLoc(TL.getLBracketLoc());
3555 NewTL.setRBracketLoc(TL.getRBracketLoc());
3556 NewTL.setSizeExpr(Size);
3557
3558 return Result;
3559}
3560
3561template<typename Derived>
3562QualType
3563TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003564 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003565 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003566 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3567 if (ElementType.isNull())
3568 return QualType();
3569
3570 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003571 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003572
John McCall3b657512011-01-19 10:06:00 +00003573 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3574 Expr *origSize = TL.getSizeExpr();
3575 if (!origSize) origSize = T->getSizeExpr();
3576
3577 ExprResult sizeResult
3578 = getDerived().TransformExpr(origSize);
3579 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003580 return QualType();
3581
John McCall3b657512011-01-19 10:06:00 +00003582 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003583
3584 QualType Result = TL.getType();
3585 if (getDerived().AlwaysRebuild() ||
3586 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003587 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003588 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3589 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003590 size,
John McCalla2becad2009-10-21 00:40:46 +00003591 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003592 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003593 if (Result.isNull())
3594 return QualType();
3595 }
John McCalla2becad2009-10-21 00:40:46 +00003596
3597 // We might have any sort of array type now, but fortunately they
3598 // all have the same location layout.
3599 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3600 NewTL.setLBracketLoc(TL.getLBracketLoc());
3601 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003602 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003603
3604 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003605}
Mike Stump1eb44332009-09-09 15:08:12 +00003606
3607template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003608QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003609 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003610 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003611 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003612
3613 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003614 QualType ElementType = getDerived().TransformType(T->getElementType());
3615 if (ElementType.isNull())
3616 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003617
Douglas Gregor670444e2009-08-04 22:27:00 +00003618 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003619 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003620
John McCall60d7b3a2010-08-24 06:29:42 +00003621 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003622 if (Size.isInvalid())
3623 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003624
John McCalla2becad2009-10-21 00:40:46 +00003625 QualType Result = TL.getType();
3626 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003627 ElementType != T->getElementType() ||
3628 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003629 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003630 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003631 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003632 if (Result.isNull())
3633 return QualType();
3634 }
John McCalla2becad2009-10-21 00:40:46 +00003635
3636 // Result might be dependent or not.
3637 if (isa<DependentSizedExtVectorType>(Result)) {
3638 DependentSizedExtVectorTypeLoc NewTL
3639 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3640 NewTL.setNameLoc(TL.getNameLoc());
3641 } else {
3642 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3643 NewTL.setNameLoc(TL.getNameLoc());
3644 }
3645
3646 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003647}
Mike Stump1eb44332009-09-09 15:08:12 +00003648
3649template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003650QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003651 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003652 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003653 QualType ElementType = getDerived().TransformType(T->getElementType());
3654 if (ElementType.isNull())
3655 return QualType();
3656
John McCalla2becad2009-10-21 00:40:46 +00003657 QualType Result = TL.getType();
3658 if (getDerived().AlwaysRebuild() ||
3659 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003660 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003661 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003662 if (Result.isNull())
3663 return QualType();
3664 }
Sean Huntc3021132010-05-05 15:23:54 +00003665
John McCalla2becad2009-10-21 00:40:46 +00003666 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3667 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003668
John McCalla2becad2009-10-21 00:40:46 +00003669 return Result;
3670}
3671
3672template<typename Derived>
3673QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003674 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003675 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003676 QualType ElementType = getDerived().TransformType(T->getElementType());
3677 if (ElementType.isNull())
3678 return QualType();
3679
3680 QualType Result = TL.getType();
3681 if (getDerived().AlwaysRebuild() ||
3682 ElementType != T->getElementType()) {
3683 Result = getDerived().RebuildExtVectorType(ElementType,
3684 T->getNumElements(),
3685 /*FIXME*/ SourceLocation());
3686 if (Result.isNull())
3687 return QualType();
3688 }
Sean Huntc3021132010-05-05 15:23:54 +00003689
John McCalla2becad2009-10-21 00:40:46 +00003690 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3691 NewTL.setNameLoc(TL.getNameLoc());
3692
3693 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003694}
Mike Stump1eb44332009-09-09 15:08:12 +00003695
3696template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003697ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003698TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003699 int indexAdjustment,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003700 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003701 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003702 TypeSourceInfo *NewDI = 0;
3703
3704 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3705 // If we're substituting into a pack expansion type and we know the
3706 TypeLoc OldTL = OldDI->getTypeLoc();
3707 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3708
3709 TypeLocBuilder TLB;
3710 TypeLoc NewTL = OldDI->getTypeLoc();
3711 TLB.reserve(NewTL.getFullDataSize());
3712
3713 QualType Result = getDerived().TransformType(TLB,
3714 OldExpansionTL.getPatternLoc());
3715 if (Result.isNull())
3716 return 0;
3717
3718 Result = RebuildPackExpansionType(Result,
3719 OldExpansionTL.getPatternLoc().getSourceRange(),
3720 OldExpansionTL.getEllipsisLoc(),
3721 NumExpansions);
3722 if (Result.isNull())
3723 return 0;
3724
3725 PackExpansionTypeLoc NewExpansionTL
3726 = TLB.push<PackExpansionTypeLoc>(Result);
3727 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3728 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3729 } else
3730 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003731 if (!NewDI)
3732 return 0;
3733
John McCallfb44de92011-05-01 22:35:37 +00003734 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003735 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003736
3737 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3738 OldParm->getDeclContext(),
3739 OldParm->getInnerLocStart(),
3740 OldParm->getLocation(),
3741 OldParm->getIdentifier(),
3742 NewDI->getType(),
3743 NewDI,
3744 OldParm->getStorageClass(),
3745 OldParm->getStorageClassAsWritten(),
3746 /* DefArg */ NULL);
3747 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3748 OldParm->getFunctionScopeIndex() + indexAdjustment);
3749 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003750}
3751
3752template<typename Derived>
3753bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003754 TransformFunctionTypeParams(SourceLocation Loc,
3755 ParmVarDecl **Params, unsigned NumParams,
3756 const QualType *ParamTypes,
3757 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3758 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003759 int indexAdjustment = 0;
3760
Douglas Gregora009b592011-01-07 00:20:55 +00003761 for (unsigned i = 0; i != NumParams; ++i) {
3762 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003763 assert(OldParm->getFunctionScopeIndex() == i);
3764
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003765 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003766 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003767 if (OldParm->isParameterPack()) {
3768 // We have a function parameter pack that may need to be expanded.
3769 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003770
Douglas Gregor603cfb42011-01-05 23:12:31 +00003771 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003772 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3773 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3774 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3775 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003776 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3777
Douglas Gregor603cfb42011-01-05 23:12:31 +00003778 // Determine whether we should expand the parameter packs.
3779 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003780 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003781 llvm::Optional<unsigned> OrigNumExpansions
3782 = ExpansionTL.getTypePtr()->getNumExpansions();
3783 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003784 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3785 Pattern.getSourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003786 Unexpanded.data(),
3787 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003788 ShouldExpand,
3789 RetainExpansion,
3790 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003791 return true;
3792 }
3793
3794 if (ShouldExpand) {
3795 // Expand the function parameter pack into multiple, separate
3796 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003797 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003798 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003799 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3800 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003801 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003802 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003803 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003804 if (!NewParm)
3805 return true;
3806
Douglas Gregora009b592011-01-07 00:20:55 +00003807 OutParamTypes.push_back(NewParm->getType());
3808 if (PVars)
3809 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003810 }
Douglas Gregord3731192011-01-10 07:32:04 +00003811
3812 // If we're supposed to retain a pack expansion, do so by temporarily
3813 // forgetting the partially-substituted parameter pack.
3814 if (RetainExpansion) {
3815 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3816 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003817 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003818 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003819 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003820 if (!NewParm)
3821 return true;
3822
3823 OutParamTypes.push_back(NewParm->getType());
3824 if (PVars)
3825 PVars->push_back(NewParm);
3826 }
3827
John McCallfb44de92011-05-01 22:35:37 +00003828 // The next parameter should have the same adjustment as the
3829 // last thing we pushed, but we post-incremented indexAdjustment
3830 // on every push. Also, if we push nothing, the adjustment should
3831 // go down by one.
3832 indexAdjustment--;
3833
Douglas Gregor603cfb42011-01-05 23:12:31 +00003834 // We're done with the pack expansion.
3835 continue;
3836 }
3837
3838 // We'll substitute the parameter now without expanding the pack
3839 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003840 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3841 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003842 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003843 NumExpansions);
3844 } else {
3845 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003846 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003847 llvm::Optional<unsigned>());
Douglas Gregor603cfb42011-01-05 23:12:31 +00003848 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003849
John McCall21ef0fa2010-03-11 09:03:00 +00003850 if (!NewParm)
3851 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003852
Douglas Gregora009b592011-01-07 00:20:55 +00003853 OutParamTypes.push_back(NewParm->getType());
3854 if (PVars)
3855 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003856 continue;
3857 }
John McCall21ef0fa2010-03-11 09:03:00 +00003858
3859 // Deal with the possibility that we don't have a parameter
3860 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003861 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003862 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003863 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003864 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003865 if (const PackExpansionType *Expansion
3866 = dyn_cast<PackExpansionType>(OldType)) {
3867 // We have a function parameter pack that may need to be expanded.
3868 QualType Pattern = Expansion->getPattern();
3869 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3870 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3871
3872 // Determine whether we should expand the parameter packs.
3873 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003874 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003875 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003876 Unexpanded.data(),
3877 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003878 ShouldExpand,
3879 RetainExpansion,
3880 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003881 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003882 }
3883
3884 if (ShouldExpand) {
3885 // Expand the function parameter pack into multiple, separate
3886 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003887 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003888 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3889 QualType NewType = getDerived().TransformType(Pattern);
3890 if (NewType.isNull())
3891 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003892
Douglas Gregora009b592011-01-07 00:20:55 +00003893 OutParamTypes.push_back(NewType);
3894 if (PVars)
3895 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003896 }
3897
3898 // We're done with the pack expansion.
3899 continue;
3900 }
3901
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003902 // If we're supposed to retain a pack expansion, do so by temporarily
3903 // forgetting the partially-substituted parameter pack.
3904 if (RetainExpansion) {
3905 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3906 QualType NewType = getDerived().TransformType(Pattern);
3907 if (NewType.isNull())
3908 return true;
3909
3910 OutParamTypes.push_back(NewType);
3911 if (PVars)
3912 PVars->push_back(0);
3913 }
Douglas Gregord3731192011-01-10 07:32:04 +00003914
Douglas Gregor603cfb42011-01-05 23:12:31 +00003915 // We'll substitute the parameter now without expanding the pack
3916 // expansion.
3917 OldType = Expansion->getPattern();
3918 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003919 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3920 NewType = getDerived().TransformType(OldType);
3921 } else {
3922 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003923 }
3924
Douglas Gregor603cfb42011-01-05 23:12:31 +00003925 if (NewType.isNull())
3926 return true;
3927
3928 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00003929 NewType = getSema().Context.getPackExpansionType(NewType,
3930 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003931
Douglas Gregora009b592011-01-07 00:20:55 +00003932 OutParamTypes.push_back(NewType);
3933 if (PVars)
3934 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00003935 }
3936
John McCallfb44de92011-05-01 22:35:37 +00003937#ifndef NDEBUG
3938 if (PVars) {
3939 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
3940 if (ParmVarDecl *parm = (*PVars)[i])
3941 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003942 }
John McCallfb44de92011-05-01 22:35:37 +00003943#endif
3944
3945 return false;
3946}
John McCall21ef0fa2010-03-11 09:03:00 +00003947
3948template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003949QualType
John McCalla2becad2009-10-21 00:40:46 +00003950TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003951 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003952 // Transform the parameters and return type.
3953 //
3954 // We instantiate in source order, with the return type first followed by
3955 // the parameters, because users tend to expect this (even if they shouldn't
3956 // rely on it!).
3957 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003958 // When the function has a trailing return type, we instantiate the
3959 // parameters before the return type, since the return type can then refer
3960 // to the parameters themselves (via decltype, sizeof, etc.).
3961 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003962 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003963 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00003964 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003965
Douglas Gregordab60ad2010-10-01 18:44:50 +00003966 QualType ResultType;
3967
3968 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00003969 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3970 TL.getParmArray(),
3971 TL.getNumArgs(),
3972 TL.getTypePtr()->arg_type_begin(),
3973 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003974 return QualType();
3975
3976 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3977 if (ResultType.isNull())
3978 return QualType();
3979 }
3980 else {
3981 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3982 if (ResultType.isNull())
3983 return QualType();
3984
Douglas Gregora009b592011-01-07 00:20:55 +00003985 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3986 TL.getParmArray(),
3987 TL.getNumArgs(),
3988 TL.getTypePtr()->arg_type_begin(),
3989 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003990 return QualType();
3991 }
3992
John McCalla2becad2009-10-21 00:40:46 +00003993 QualType Result = TL.getType();
3994 if (getDerived().AlwaysRebuild() ||
3995 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00003996 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00003997 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3998 Result = getDerived().RebuildFunctionProtoType(ResultType,
3999 ParamTypes.data(),
4000 ParamTypes.size(),
4001 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004002 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004003 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004004 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004005 if (Result.isNull())
4006 return QualType();
4007 }
Mike Stump1eb44332009-09-09 15:08:12 +00004008
John McCalla2becad2009-10-21 00:40:46 +00004009 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004010 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4011 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004012 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004013 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4014 NewTL.setArg(i, ParamDecls[i]);
4015
4016 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004017}
Mike Stump1eb44332009-09-09 15:08:12 +00004018
Douglas Gregor577f75a2009-08-04 16:50:30 +00004019template<typename Derived>
4020QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004021 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004022 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004023 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004024 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4025 if (ResultType.isNull())
4026 return QualType();
4027
4028 QualType Result = TL.getType();
4029 if (getDerived().AlwaysRebuild() ||
4030 ResultType != T->getResultType())
4031 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4032
4033 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004034 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4035 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004036 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004037
4038 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004039}
Mike Stump1eb44332009-09-09 15:08:12 +00004040
John McCalled976492009-12-04 22:46:56 +00004041template<typename Derived> QualType
4042TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004043 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004044 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004045 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004046 if (!D)
4047 return QualType();
4048
4049 QualType Result = TL.getType();
4050 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4051 Result = getDerived().RebuildUnresolvedUsingType(D);
4052 if (Result.isNull())
4053 return QualType();
4054 }
4055
4056 // We might get an arbitrary type spec type back. We should at
4057 // least always get a type spec type, though.
4058 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4059 NewTL.setNameLoc(TL.getNameLoc());
4060
4061 return Result;
4062}
4063
Douglas Gregor577f75a2009-08-04 16:50:30 +00004064template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004065QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004066 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004067 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004068 TypedefNameDecl *Typedef
4069 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4070 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004071 if (!Typedef)
4072 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004073
John McCalla2becad2009-10-21 00:40:46 +00004074 QualType Result = TL.getType();
4075 if (getDerived().AlwaysRebuild() ||
4076 Typedef != T->getDecl()) {
4077 Result = getDerived().RebuildTypedefType(Typedef);
4078 if (Result.isNull())
4079 return QualType();
4080 }
Mike Stump1eb44332009-09-09 15:08:12 +00004081
John McCalla2becad2009-10-21 00:40:46 +00004082 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4083 NewTL.setNameLoc(TL.getNameLoc());
4084
4085 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004086}
Mike Stump1eb44332009-09-09 15:08:12 +00004087
Douglas Gregor577f75a2009-08-04 16:50:30 +00004088template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004089QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004090 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004091 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004092 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004093
John McCall60d7b3a2010-08-24 06:29:42 +00004094 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004095 if (E.isInvalid())
4096 return QualType();
4097
John McCalla2becad2009-10-21 00:40:46 +00004098 QualType Result = TL.getType();
4099 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004100 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004101 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004102 if (Result.isNull())
4103 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004104 }
John McCalla2becad2009-10-21 00:40:46 +00004105 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004106
John McCalla2becad2009-10-21 00:40:46 +00004107 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004108 NewTL.setTypeofLoc(TL.getTypeofLoc());
4109 NewTL.setLParenLoc(TL.getLParenLoc());
4110 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004111
4112 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004113}
Mike Stump1eb44332009-09-09 15:08:12 +00004114
4115template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004116QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004117 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004118 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4119 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4120 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004121 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004122
John McCalla2becad2009-10-21 00:40:46 +00004123 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004124 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4125 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004126 if (Result.isNull())
4127 return QualType();
4128 }
Mike Stump1eb44332009-09-09 15:08:12 +00004129
John McCalla2becad2009-10-21 00:40:46 +00004130 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004131 NewTL.setTypeofLoc(TL.getTypeofLoc());
4132 NewTL.setLParenLoc(TL.getLParenLoc());
4133 NewTL.setRParenLoc(TL.getRParenLoc());
4134 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004135
4136 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004137}
Mike Stump1eb44332009-09-09 15:08:12 +00004138
4139template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004140QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004141 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004142 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004143
Douglas Gregor670444e2009-08-04 22:27:00 +00004144 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004145 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004146
John McCall60d7b3a2010-08-24 06:29:42 +00004147 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004148 if (E.isInvalid())
4149 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004150
John McCalla2becad2009-10-21 00:40:46 +00004151 QualType Result = TL.getType();
4152 if (getDerived().AlwaysRebuild() ||
4153 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004154 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004155 if (Result.isNull())
4156 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004157 }
John McCalla2becad2009-10-21 00:40:46 +00004158 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004159
John McCalla2becad2009-10-21 00:40:46 +00004160 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4161 NewTL.setNameLoc(TL.getNameLoc());
4162
4163 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004164}
4165
4166template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004167QualType TreeTransform<Derived>::TransformUnaryTransformType(
4168 TypeLocBuilder &TLB,
4169 UnaryTransformTypeLoc TL) {
4170 QualType Result = TL.getType();
4171 if (Result->isDependentType()) {
4172 const UnaryTransformType *T = TL.getTypePtr();
4173 QualType NewBase =
4174 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4175 Result = getDerived().RebuildUnaryTransformType(NewBase,
4176 T->getUTTKind(),
4177 TL.getKWLoc());
4178 if (Result.isNull())
4179 return QualType();
4180 }
4181
4182 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4183 NewTL.setKWLoc(TL.getKWLoc());
4184 NewTL.setParensRange(TL.getParensRange());
4185 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4186 return Result;
4187}
4188
4189template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004190QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4191 AutoTypeLoc TL) {
4192 const AutoType *T = TL.getTypePtr();
4193 QualType OldDeduced = T->getDeducedType();
4194 QualType NewDeduced;
4195 if (!OldDeduced.isNull()) {
4196 NewDeduced = getDerived().TransformType(OldDeduced);
4197 if (NewDeduced.isNull())
4198 return QualType();
4199 }
4200
4201 QualType Result = TL.getType();
4202 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4203 Result = getDerived().RebuildAutoType(NewDeduced);
4204 if (Result.isNull())
4205 return QualType();
4206 }
4207
4208 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4209 NewTL.setNameLoc(TL.getNameLoc());
4210
4211 return Result;
4212}
4213
4214template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004215QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004216 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004217 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004218 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004219 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4220 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004221 if (!Record)
4222 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004223
John McCalla2becad2009-10-21 00:40:46 +00004224 QualType Result = TL.getType();
4225 if (getDerived().AlwaysRebuild() ||
4226 Record != T->getDecl()) {
4227 Result = getDerived().RebuildRecordType(Record);
4228 if (Result.isNull())
4229 return QualType();
4230 }
Mike Stump1eb44332009-09-09 15:08:12 +00004231
John McCalla2becad2009-10-21 00:40:46 +00004232 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4233 NewTL.setNameLoc(TL.getNameLoc());
4234
4235 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004236}
Mike Stump1eb44332009-09-09 15:08:12 +00004237
4238template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004239QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004240 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004241 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004242 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004243 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4244 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004245 if (!Enum)
4246 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004247
John McCalla2becad2009-10-21 00:40:46 +00004248 QualType Result = TL.getType();
4249 if (getDerived().AlwaysRebuild() ||
4250 Enum != T->getDecl()) {
4251 Result = getDerived().RebuildEnumType(Enum);
4252 if (Result.isNull())
4253 return QualType();
4254 }
Mike Stump1eb44332009-09-09 15:08:12 +00004255
John McCalla2becad2009-10-21 00:40:46 +00004256 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4257 NewTL.setNameLoc(TL.getNameLoc());
4258
4259 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004260}
John McCall7da24312009-09-05 00:15:47 +00004261
John McCall3cb0ebd2010-03-10 03:28:59 +00004262template<typename Derived>
4263QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4264 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004265 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004266 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4267 TL.getTypePtr()->getDecl());
4268 if (!D) return QualType();
4269
4270 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4271 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4272 return T;
4273}
4274
Douglas Gregor577f75a2009-08-04 16:50:30 +00004275template<typename Derived>
4276QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004277 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004278 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004279 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004280}
4281
Mike Stump1eb44332009-09-09 15:08:12 +00004282template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004283QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004284 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004285 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004286 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4287
4288 // Substitute into the replacement type, which itself might involve something
4289 // that needs to be transformed. This only tends to occur with default
4290 // template arguments of template template parameters.
4291 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4292 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4293 if (Replacement.isNull())
4294 return QualType();
4295
4296 // Always canonicalize the replacement type.
4297 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4298 QualType Result
4299 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4300 Replacement);
4301
4302 // Propagate type-source information.
4303 SubstTemplateTypeParmTypeLoc NewTL
4304 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4305 NewTL.setNameLoc(TL.getNameLoc());
4306 return Result;
4307
John McCall49a832b2009-10-18 09:09:24 +00004308}
4309
4310template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004311QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4312 TypeLocBuilder &TLB,
4313 SubstTemplateTypeParmPackTypeLoc TL) {
4314 return TransformTypeSpecType(TLB, TL);
4315}
4316
4317template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004318QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004319 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004320 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004321 const TemplateSpecializationType *T = TL.getTypePtr();
4322
Douglas Gregor1d752d72011-03-02 18:46:51 +00004323 // The nested-name-specifier never matters in a TemplateSpecializationType,
4324 // because we can't have a dependent nested-name-specifier anyway.
4325 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004326 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004327 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4328 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004329 if (Template.isNull())
4330 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004331
John McCall43fed0d2010-11-12 08:19:04 +00004332 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4333}
4334
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004335namespace {
4336 /// \brief Simple iterator that traverses the template arguments in a
4337 /// container that provides a \c getArgLoc() member function.
4338 ///
4339 /// This iterator is intended to be used with the iterator form of
4340 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4341 template<typename ArgLocContainer>
4342 class TemplateArgumentLocContainerIterator {
4343 ArgLocContainer *Container;
4344 unsigned Index;
4345
4346 public:
4347 typedef TemplateArgumentLoc value_type;
4348 typedef TemplateArgumentLoc reference;
4349 typedef int difference_type;
4350 typedef std::input_iterator_tag iterator_category;
4351
4352 class pointer {
4353 TemplateArgumentLoc Arg;
4354
4355 public:
4356 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4357
4358 const TemplateArgumentLoc *operator->() const {
4359 return &Arg;
4360 }
4361 };
4362
4363
4364 TemplateArgumentLocContainerIterator() {}
4365
4366 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4367 unsigned Index)
4368 : Container(&Container), Index(Index) { }
4369
4370 TemplateArgumentLocContainerIterator &operator++() {
4371 ++Index;
4372 return *this;
4373 }
4374
4375 TemplateArgumentLocContainerIterator operator++(int) {
4376 TemplateArgumentLocContainerIterator Old(*this);
4377 ++(*this);
4378 return Old;
4379 }
4380
4381 TemplateArgumentLoc operator*() const {
4382 return Container->getArgLoc(Index);
4383 }
4384
4385 pointer operator->() const {
4386 return pointer(Container->getArgLoc(Index));
4387 }
4388
4389 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004390 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004391 return X.Container == Y.Container && X.Index == Y.Index;
4392 }
4393
4394 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004395 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004396 return !(X == Y);
4397 }
4398 };
4399}
4400
4401
John McCall43fed0d2010-11-12 08:19:04 +00004402template <typename Derived>
4403QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4404 TypeLocBuilder &TLB,
4405 TemplateSpecializationTypeLoc TL,
4406 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004407 TemplateArgumentListInfo NewTemplateArgs;
4408 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4409 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004410 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4411 ArgIterator;
4412 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4413 ArgIterator(TL, TL.getNumArgs()),
4414 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004415 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004416
John McCall833ca992009-10-29 08:12:44 +00004417 // FIXME: maybe don't rebuild if all the template arguments are the same.
4418
4419 QualType Result =
4420 getDerived().RebuildTemplateSpecializationType(Template,
4421 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004422 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004423
4424 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004425 // Specializations of template template parameters are represented as
4426 // TemplateSpecializationTypes, and substitution of type alias templates
4427 // within a dependent context can transform them into
4428 // DependentTemplateSpecializationTypes.
4429 if (isa<DependentTemplateSpecializationType>(Result)) {
4430 DependentTemplateSpecializationTypeLoc NewTL
4431 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4432 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4433 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4434 NewTL.setNameLoc(TL.getTemplateNameLoc());
4435 NewTL.setLAngleLoc(TL.getLAngleLoc());
4436 NewTL.setRAngleLoc(TL.getRAngleLoc());
4437 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4438 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4439 return Result;
4440 }
4441
John McCall833ca992009-10-29 08:12:44 +00004442 TemplateSpecializationTypeLoc NewTL
4443 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4444 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4445 NewTL.setLAngleLoc(TL.getLAngleLoc());
4446 NewTL.setRAngleLoc(TL.getRAngleLoc());
4447 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4448 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004449 }
Mike Stump1eb44332009-09-09 15:08:12 +00004450
John McCall833ca992009-10-29 08:12:44 +00004451 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004452}
Mike Stump1eb44332009-09-09 15:08:12 +00004453
Douglas Gregora88f09f2011-02-28 17:23:35 +00004454template <typename Derived>
4455QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4456 TypeLocBuilder &TLB,
4457 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004458 TemplateName Template,
4459 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004460 TemplateArgumentListInfo NewTemplateArgs;
4461 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4462 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4463 typedef TemplateArgumentLocContainerIterator<
4464 DependentTemplateSpecializationTypeLoc> ArgIterator;
4465 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4466 ArgIterator(TL, TL.getNumArgs()),
4467 NewTemplateArgs))
4468 return QualType();
4469
4470 // FIXME: maybe don't rebuild if all the template arguments are the same.
4471
4472 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4473 QualType Result
4474 = getSema().Context.getDependentTemplateSpecializationType(
4475 TL.getTypePtr()->getKeyword(),
4476 DTN->getQualifier(),
4477 DTN->getIdentifier(),
4478 NewTemplateArgs);
4479
4480 DependentTemplateSpecializationTypeLoc NewTL
4481 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4482 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004483
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004484 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregora88f09f2011-02-28 17:23:35 +00004485 NewTL.setNameLoc(TL.getNameLoc());
4486 NewTL.setLAngleLoc(TL.getLAngleLoc());
4487 NewTL.setRAngleLoc(TL.getRAngleLoc());
4488 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4489 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4490 return Result;
4491 }
4492
4493 QualType Result
4494 = getDerived().RebuildTemplateSpecializationType(Template,
4495 TL.getNameLoc(),
4496 NewTemplateArgs);
4497
4498 if (!Result.isNull()) {
4499 /// FIXME: Wrap this in an elaborated-type-specifier?
4500 TemplateSpecializationTypeLoc NewTL
4501 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4502 NewTL.setTemplateNameLoc(TL.getNameLoc());
4503 NewTL.setLAngleLoc(TL.getLAngleLoc());
4504 NewTL.setRAngleLoc(TL.getRAngleLoc());
4505 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4506 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4507 }
4508
4509 return Result;
4510}
4511
Mike Stump1eb44332009-09-09 15:08:12 +00004512template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004513QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004514TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004515 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004516 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004517
Douglas Gregor9e876872011-03-01 18:12:44 +00004518 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004519 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004520 if (TL.getQualifierLoc()) {
4521 QualifierLoc
4522 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4523 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004524 return QualType();
4525 }
Mike Stump1eb44332009-09-09 15:08:12 +00004526
John McCall43fed0d2010-11-12 08:19:04 +00004527 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4528 if (NamedT.isNull())
4529 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004530
Richard Smith3e4c6c42011-05-05 21:57:07 +00004531 // C++0x [dcl.type.elab]p2:
4532 // If the identifier resolves to a typedef-name or the simple-template-id
4533 // resolves to an alias template specialization, the
4534 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004535 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4536 if (const TemplateSpecializationType *TST =
4537 NamedT->getAs<TemplateSpecializationType>()) {
4538 TemplateName Template = TST->getTemplateName();
4539 if (TypeAliasTemplateDecl *TAT =
4540 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4541 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4542 diag::err_tag_reference_non_tag) << 4;
4543 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4544 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004545 }
4546 }
4547
John McCalla2becad2009-10-21 00:40:46 +00004548 QualType Result = TL.getType();
4549 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004550 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004551 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004552 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004553 T->getKeyword(),
4554 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004555 if (Result.isNull())
4556 return QualType();
4557 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004558
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004559 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004560 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004561 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004562 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004563}
Mike Stump1eb44332009-09-09 15:08:12 +00004564
4565template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004566QualType TreeTransform<Derived>::TransformAttributedType(
4567 TypeLocBuilder &TLB,
4568 AttributedTypeLoc TL) {
4569 const AttributedType *oldType = TL.getTypePtr();
4570 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4571 if (modifiedType.isNull())
4572 return QualType();
4573
4574 QualType result = TL.getType();
4575
4576 // FIXME: dependent operand expressions?
4577 if (getDerived().AlwaysRebuild() ||
4578 modifiedType != oldType->getModifiedType()) {
4579 // TODO: this is really lame; we should really be rebuilding the
4580 // equivalent type from first principles.
4581 QualType equivalentType
4582 = getDerived().TransformType(oldType->getEquivalentType());
4583 if (equivalentType.isNull())
4584 return QualType();
4585 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4586 modifiedType,
4587 equivalentType);
4588 }
4589
4590 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4591 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4592 if (TL.hasAttrOperand())
4593 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4594 if (TL.hasAttrExprOperand())
4595 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4596 else if (TL.hasAttrEnumOperand())
4597 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4598
4599 return result;
4600}
4601
4602template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004603QualType
4604TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4605 ParenTypeLoc TL) {
4606 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4607 if (Inner.isNull())
4608 return QualType();
4609
4610 QualType Result = TL.getType();
4611 if (getDerived().AlwaysRebuild() ||
4612 Inner != TL.getInnerLoc().getType()) {
4613 Result = getDerived().RebuildParenType(Inner);
4614 if (Result.isNull())
4615 return QualType();
4616 }
4617
4618 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4619 NewTL.setLParenLoc(TL.getLParenLoc());
4620 NewTL.setRParenLoc(TL.getRParenLoc());
4621 return Result;
4622}
4623
4624template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004625QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004626 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004627 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004628
Douglas Gregor2494dd02011-03-01 01:34:45 +00004629 NestedNameSpecifierLoc QualifierLoc
4630 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4631 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004632 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004633
John McCall33500952010-06-11 00:33:02 +00004634 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004635 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCall33500952010-06-11 00:33:02 +00004636 TL.getKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004637 QualifierLoc,
4638 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004639 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004640 if (Result.isNull())
4641 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004642
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004643 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4644 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004645 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4646
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004647 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4648 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004649 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004650 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004651 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4652 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004653 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004654 NewTL.setNameLoc(TL.getNameLoc());
4655 }
John McCalla2becad2009-10-21 00:40:46 +00004656 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004657}
Mike Stump1eb44332009-09-09 15:08:12 +00004658
Douglas Gregor577f75a2009-08-04 16:50:30 +00004659template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004660QualType TreeTransform<Derived>::
4661 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004662 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004663 NestedNameSpecifierLoc QualifierLoc;
4664 if (TL.getQualifierLoc()) {
4665 QualifierLoc
4666 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4667 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004668 return QualType();
4669 }
4670
John McCall43fed0d2010-11-12 08:19:04 +00004671 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004672 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004673}
4674
4675template<typename Derived>
4676QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004677TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4678 DependentTemplateSpecializationTypeLoc TL,
4679 NestedNameSpecifierLoc QualifierLoc) {
4680 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4681
4682 TemplateArgumentListInfo NewTemplateArgs;
4683 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4684 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4685
4686 typedef TemplateArgumentLocContainerIterator<
4687 DependentTemplateSpecializationTypeLoc> ArgIterator;
4688 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4689 ArgIterator(TL, TL.getNumArgs()),
4690 NewTemplateArgs))
4691 return QualType();
4692
4693 QualType Result
4694 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4695 QualifierLoc,
4696 T->getIdentifier(),
4697 TL.getNameLoc(),
4698 NewTemplateArgs);
4699 if (Result.isNull())
4700 return QualType();
4701
4702 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4703 QualType NamedT = ElabT->getNamedType();
4704
4705 // Copy information relevant to the template specialization.
4706 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004707 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004708 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004709 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4710 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004711 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004712 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004713
4714 // Copy information relevant to the elaborated type.
4715 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4716 NewTL.setKeywordLoc(TL.getKeywordLoc());
4717 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004718 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4719 DependentTemplateSpecializationTypeLoc SpecTL
4720 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor944cdae2011-03-07 15:13:34 +00004721 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004722 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004723 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004724 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4725 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004726 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004727 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004728 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004729 TemplateSpecializationTypeLoc SpecTL
4730 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004731 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004732 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4733 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004734 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004735 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004736 }
4737 return Result;
4738}
4739
4740template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004741QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4742 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004743 QualType Pattern
4744 = getDerived().TransformType(TLB, TL.getPatternLoc());
4745 if (Pattern.isNull())
4746 return QualType();
4747
4748 QualType Result = TL.getType();
4749 if (getDerived().AlwaysRebuild() ||
4750 Pattern != TL.getPatternLoc().getType()) {
4751 Result = getDerived().RebuildPackExpansionType(Pattern,
4752 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004753 TL.getEllipsisLoc(),
4754 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004755 if (Result.isNull())
4756 return QualType();
4757 }
4758
4759 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4760 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4761 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004762}
4763
4764template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004765QualType
4766TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004767 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004768 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004769 TLB.pushFullCopy(TL);
4770 return TL.getType();
4771}
4772
4773template<typename Derived>
4774QualType
4775TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004776 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004777 // ObjCObjectType is never dependent.
4778 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004779 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004780}
Mike Stump1eb44332009-09-09 15:08:12 +00004781
4782template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004783QualType
4784TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004785 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004786 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004787 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004788 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004789}
4790
Douglas Gregor577f75a2009-08-04 16:50:30 +00004791//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004792// Statement transformation
4793//===----------------------------------------------------------------------===//
4794template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004795StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004796TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004797 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004798}
4799
4800template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004801StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004802TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4803 return getDerived().TransformCompoundStmt(S, false);
4804}
4805
4806template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004807StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004808TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004809 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004810 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004811 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004812 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004813 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4814 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004815 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004816 if (Result.isInvalid()) {
4817 // Immediately fail if this was a DeclStmt, since it's very
4818 // likely that this will cause problems for future statements.
4819 if (isa<DeclStmt>(*B))
4820 return StmtError();
4821
4822 // Otherwise, just keep processing substatements and fail later.
4823 SubStmtInvalid = true;
4824 continue;
4825 }
Mike Stump1eb44332009-09-09 15:08:12 +00004826
Douglas Gregor43959a92009-08-20 07:17:43 +00004827 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4828 Statements.push_back(Result.takeAs<Stmt>());
4829 }
Mike Stump1eb44332009-09-09 15:08:12 +00004830
John McCall7114cba2010-08-27 19:56:05 +00004831 if (SubStmtInvalid)
4832 return StmtError();
4833
Douglas Gregor43959a92009-08-20 07:17:43 +00004834 if (!getDerived().AlwaysRebuild() &&
4835 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004836 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004837
4838 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4839 move_arg(Statements),
4840 S->getRBracLoc(),
4841 IsStmtExpr);
4842}
Mike Stump1eb44332009-09-09 15:08:12 +00004843
Douglas Gregor43959a92009-08-20 07:17:43 +00004844template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004845StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004846TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004847 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004848 {
4849 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004850 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004851
Eli Friedman264c1f82009-11-19 03:14:00 +00004852 // Transform the left-hand case value.
4853 LHS = getDerived().TransformExpr(S->getLHS());
4854 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004855 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004856
Eli Friedman264c1f82009-11-19 03:14:00 +00004857 // Transform the right-hand case value (for the GNU case-range extension).
4858 RHS = getDerived().TransformExpr(S->getRHS());
4859 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004860 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004861 }
Mike Stump1eb44332009-09-09 15:08:12 +00004862
Douglas Gregor43959a92009-08-20 07:17:43 +00004863 // Build the case statement.
4864 // Case statements are always rebuilt so that they will attached to their
4865 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004866 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004867 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004868 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004869 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004870 S->getColonLoc());
4871 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004872 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004873
Douglas Gregor43959a92009-08-20 07:17:43 +00004874 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004875 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004876 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004877 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004878
Douglas Gregor43959a92009-08-20 07:17:43 +00004879 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004880 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004881}
4882
4883template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004884StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004885TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004886 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00004887 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004888 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004889 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004890
Douglas Gregor43959a92009-08-20 07:17:43 +00004891 // Default statements are always rebuilt
4892 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004893 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004894}
Mike Stump1eb44332009-09-09 15:08:12 +00004895
Douglas Gregor43959a92009-08-20 07:17:43 +00004896template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004897StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004898TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004899 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004900 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004901 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004902
Chris Lattner57ad3782011-02-17 20:34:02 +00004903 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4904 S->getDecl());
4905 if (!LD)
4906 return StmtError();
4907
4908
Douglas Gregor43959a92009-08-20 07:17:43 +00004909 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00004910 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00004911 cast<LabelDecl>(LD), SourceLocation(),
4912 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004913}
Mike Stump1eb44332009-09-09 15:08:12 +00004914
Douglas Gregor43959a92009-08-20 07:17:43 +00004915template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004916StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004917TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004918 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004919 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004920 VarDecl *ConditionVar = 0;
4921 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004922 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004923 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004924 getDerived().TransformDefinition(
4925 S->getConditionVariable()->getLocation(),
4926 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004927 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004928 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004929 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004930 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004931
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004932 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004933 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004934
4935 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004936 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004937 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4938 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004939 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004940 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004941
John McCall9ae2f072010-08-23 23:25:46 +00004942 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004943 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004944 }
Sean Huntc3021132010-05-05 15:23:54 +00004945
John McCall9ae2f072010-08-23 23:25:46 +00004946 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4947 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004948 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004949
Douglas Gregor43959a92009-08-20 07:17:43 +00004950 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004951 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00004952 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004953 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004954
Douglas Gregor43959a92009-08-20 07:17:43 +00004955 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004956 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00004957 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004958 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004959
Douglas Gregor43959a92009-08-20 07:17:43 +00004960 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004961 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004962 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004963 Then.get() == S->getThen() &&
4964 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00004965 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004966
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004967 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00004968 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00004969 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004970}
4971
4972template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004973StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004974TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004975 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00004976 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00004977 VarDecl *ConditionVar = 0;
4978 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004979 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00004980 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004981 getDerived().TransformDefinition(
4982 S->getConditionVariable()->getLocation(),
4983 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00004984 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004985 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004986 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00004987 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004988
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004989 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004990 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004991 }
Mike Stump1eb44332009-09-09 15:08:12 +00004992
Douglas Gregor43959a92009-08-20 07:17:43 +00004993 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004994 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00004995 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00004996 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00004997 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004998 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004999
Douglas Gregor43959a92009-08-20 07:17:43 +00005000 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005001 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005002 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005003 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005004
Douglas Gregor43959a92009-08-20 07:17:43 +00005005 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005006 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5007 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005008}
Mike Stump1eb44332009-09-09 15:08:12 +00005009
Douglas Gregor43959a92009-08-20 07:17:43 +00005010template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005011StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005012TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005013 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005014 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005015 VarDecl *ConditionVar = 0;
5016 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005017 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005018 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005019 getDerived().TransformDefinition(
5020 S->getConditionVariable()->getLocation(),
5021 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005022 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005023 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005024 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005025 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005026
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005027 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005028 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005029
5030 if (S->getCond()) {
5031 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005032 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5033 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005034 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005035 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005036 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005037 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005038 }
Mike Stump1eb44332009-09-09 15:08:12 +00005039
John McCall9ae2f072010-08-23 23:25:46 +00005040 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5041 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005042 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005043
Douglas Gregor43959a92009-08-20 07:17:43 +00005044 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005045 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005046 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005047 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005048
Douglas Gregor43959a92009-08-20 07:17:43 +00005049 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005050 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005051 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005052 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005053 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005054
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005055 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005056 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005057}
Mike Stump1eb44332009-09-09 15:08:12 +00005058
Douglas Gregor43959a92009-08-20 07:17:43 +00005059template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005060StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005061TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005062 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005063 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005064 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005065 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005066
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005067 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005068 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005069 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005070 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005071
Douglas Gregor43959a92009-08-20 07:17:43 +00005072 if (!getDerived().AlwaysRebuild() &&
5073 Cond.get() == S->getCond() &&
5074 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005075 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005076
John McCall9ae2f072010-08-23 23:25:46 +00005077 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5078 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005079 S->getRParenLoc());
5080}
Mike Stump1eb44332009-09-09 15:08:12 +00005081
Douglas Gregor43959a92009-08-20 07:17:43 +00005082template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005083StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005084TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005085 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005086 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005087 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005088 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005089
Douglas Gregor43959a92009-08-20 07:17:43 +00005090 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005091 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005092 VarDecl *ConditionVar = 0;
5093 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005094 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005095 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005096 getDerived().TransformDefinition(
5097 S->getConditionVariable()->getLocation(),
5098 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005099 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005100 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005101 } else {
5102 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005103
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005104 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005105 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005106
5107 if (S->getCond()) {
5108 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005109 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5110 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005111 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005112 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005113
John McCall9ae2f072010-08-23 23:25:46 +00005114 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005115 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005116 }
Mike Stump1eb44332009-09-09 15:08:12 +00005117
John McCall9ae2f072010-08-23 23:25:46 +00005118 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5119 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005120 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005121
Douglas Gregor43959a92009-08-20 07:17:43 +00005122 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005123 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005124 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005125 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005126
John McCall9ae2f072010-08-23 23:25:46 +00005127 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5128 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005129 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005130
Douglas Gregor43959a92009-08-20 07:17:43 +00005131 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005132 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005133 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005134 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005135
Douglas Gregor43959a92009-08-20 07:17:43 +00005136 if (!getDerived().AlwaysRebuild() &&
5137 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005138 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005139 Inc.get() == S->getInc() &&
5140 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005141 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005142
Douglas Gregor43959a92009-08-20 07:17:43 +00005143 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005144 Init.get(), FullCond, ConditionVar,
5145 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005146}
5147
5148template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005149StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005150TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005151 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5152 S->getLabel());
5153 if (!LD)
5154 return StmtError();
5155
Douglas Gregor43959a92009-08-20 07:17:43 +00005156 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005157 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005158 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005159}
5160
5161template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005162StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005163TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005164 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005165 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005166 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005167
Douglas Gregor43959a92009-08-20 07:17:43 +00005168 if (!getDerived().AlwaysRebuild() &&
5169 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005170 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005171
5172 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005173 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005174}
5175
5176template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005177StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005178TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005179 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005180}
Mike Stump1eb44332009-09-09 15:08:12 +00005181
Douglas Gregor43959a92009-08-20 07:17:43 +00005182template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005183StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005184TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005185 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005186}
Mike Stump1eb44332009-09-09 15:08:12 +00005187
Douglas Gregor43959a92009-08-20 07:17:43 +00005188template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005189StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005190TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005191 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005192 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005193 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005194
Mike Stump1eb44332009-09-09 15:08:12 +00005195 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005196 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005197 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005198}
Mike Stump1eb44332009-09-09 15:08:12 +00005199
Douglas Gregor43959a92009-08-20 07:17:43 +00005200template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005201StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005202TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005203 bool DeclChanged = false;
5204 llvm::SmallVector<Decl *, 4> Decls;
5205 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5206 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005207 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5208 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005209 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005210 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005211
Douglas Gregor43959a92009-08-20 07:17:43 +00005212 if (Transformed != *D)
5213 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005214
Douglas Gregor43959a92009-08-20 07:17:43 +00005215 Decls.push_back(Transformed);
5216 }
Mike Stump1eb44332009-09-09 15:08:12 +00005217
Douglas Gregor43959a92009-08-20 07:17:43 +00005218 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005219 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005220
5221 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005222 S->getStartLoc(), S->getEndLoc());
5223}
Mike Stump1eb44332009-09-09 15:08:12 +00005224
Douglas Gregor43959a92009-08-20 07:17:43 +00005225template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005226StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005227TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005228
John McCallca0408f2010-08-23 06:44:23 +00005229 ASTOwningVector<Expr*> Constraints(getSema());
5230 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005231 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005232
John McCall60d7b3a2010-08-24 06:29:42 +00005233 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005234 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005235
5236 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005237
Anders Carlsson703e3942010-01-24 05:50:09 +00005238 // Go through the outputs.
5239 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005240 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005241
Anders Carlsson703e3942010-01-24 05:50:09 +00005242 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005243 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005244
Anders Carlsson703e3942010-01-24 05:50:09 +00005245 // Transform the output expr.
5246 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005247 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005248 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005249 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005250
Anders Carlsson703e3942010-01-24 05:50:09 +00005251 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005252
John McCall9ae2f072010-08-23 23:25:46 +00005253 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005254 }
Sean Huntc3021132010-05-05 15:23:54 +00005255
Anders Carlsson703e3942010-01-24 05:50:09 +00005256 // Go through the inputs.
5257 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005258 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005259
Anders Carlsson703e3942010-01-24 05:50:09 +00005260 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005261 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005262
Anders Carlsson703e3942010-01-24 05:50:09 +00005263 // Transform the input expr.
5264 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005265 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005266 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005267 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005268
Anders Carlsson703e3942010-01-24 05:50:09 +00005269 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005270
John McCall9ae2f072010-08-23 23:25:46 +00005271 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005272 }
Sean Huntc3021132010-05-05 15:23:54 +00005273
Anders Carlsson703e3942010-01-24 05:50:09 +00005274 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005275 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005276
5277 // Go through the clobbers.
5278 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005279 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005280
5281 // No need to transform the asm string literal.
5282 AsmString = SemaRef.Owned(S->getAsmString());
5283
5284 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5285 S->isSimple(),
5286 S->isVolatile(),
5287 S->getNumOutputs(),
5288 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005289 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005290 move_arg(Constraints),
5291 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005292 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005293 move_arg(Clobbers),
5294 S->getRParenLoc(),
5295 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005296}
5297
5298
5299template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005300StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005301TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005302 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005303 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005304 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005305 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005306
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005307 // Transform the @catch statements (if present).
5308 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005309 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005310 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005311 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005312 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005313 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005314 if (Catch.get() != S->getCatchStmt(I))
5315 AnyCatchChanged = true;
5316 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005317 }
Sean Huntc3021132010-05-05 15:23:54 +00005318
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005319 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005320 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005321 if (S->getFinallyStmt()) {
5322 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5323 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005324 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005325 }
5326
5327 // If nothing changed, just retain this statement.
5328 if (!getDerived().AlwaysRebuild() &&
5329 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005330 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005331 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005332 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005333
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005334 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005335 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5336 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005337}
Mike Stump1eb44332009-09-09 15:08:12 +00005338
Douglas Gregor43959a92009-08-20 07:17:43 +00005339template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005340StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005341TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005342 // Transform the @catch parameter, if there is one.
5343 VarDecl *Var = 0;
5344 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5345 TypeSourceInfo *TSInfo = 0;
5346 if (FromVar->getTypeSourceInfo()) {
5347 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5348 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005349 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005350 }
Sean Huntc3021132010-05-05 15:23:54 +00005351
Douglas Gregorbe270a02010-04-26 17:57:08 +00005352 QualType T;
5353 if (TSInfo)
5354 T = TSInfo->getType();
5355 else {
5356 T = getDerived().TransformType(FromVar->getType());
5357 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005358 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005359 }
Sean Huntc3021132010-05-05 15:23:54 +00005360
Douglas Gregorbe270a02010-04-26 17:57:08 +00005361 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5362 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005363 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005364 }
Sean Huntc3021132010-05-05 15:23:54 +00005365
John McCall60d7b3a2010-08-24 06:29:42 +00005366 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005367 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005368 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005369
5370 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005371 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005372 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005373}
Mike Stump1eb44332009-09-09 15:08:12 +00005374
Douglas Gregor43959a92009-08-20 07:17:43 +00005375template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005376StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005377TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005378 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005379 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005380 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005381 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005382
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005383 // If nothing changed, just retain this statement.
5384 if (!getDerived().AlwaysRebuild() &&
5385 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005386 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005387
5388 // Build a new statement.
5389 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005390 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005391}
Mike Stump1eb44332009-09-09 15:08:12 +00005392
Douglas Gregor43959a92009-08-20 07:17:43 +00005393template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005394StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005395TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005396 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005397 if (S->getThrowExpr()) {
5398 Operand = getDerived().TransformExpr(S->getThrowExpr());
5399 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005400 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005401 }
Sean Huntc3021132010-05-05 15:23:54 +00005402
Douglas Gregord1377b22010-04-22 21:44:01 +00005403 if (!getDerived().AlwaysRebuild() &&
5404 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005405 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005406
John McCall9ae2f072010-08-23 23:25:46 +00005407 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005408}
Mike Stump1eb44332009-09-09 15:08:12 +00005409
Douglas Gregor43959a92009-08-20 07:17:43 +00005410template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005411StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005412TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005413 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005414 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005415 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005416 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005417 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005418
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005419 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005420 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005421 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005422 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005423
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005424 // If nothing change, just retain the current statement.
5425 if (!getDerived().AlwaysRebuild() &&
5426 Object.get() == S->getSynchExpr() &&
5427 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005428 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005429
5430 // Build a new statement.
5431 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005432 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005433}
5434
5435template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005436StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005437TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005438 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005439 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005440 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005441 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005442 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005443
Douglas Gregorc3203e72010-04-22 23:10:45 +00005444 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005445 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005446 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005447 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005448
Douglas Gregorc3203e72010-04-22 23:10:45 +00005449 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005450 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005451 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005452 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005453
Douglas Gregorc3203e72010-04-22 23:10:45 +00005454 // If nothing changed, just retain this statement.
5455 if (!getDerived().AlwaysRebuild() &&
5456 Element.get() == S->getElement() &&
5457 Collection.get() == S->getCollection() &&
5458 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005459 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005460
Douglas Gregorc3203e72010-04-22 23:10:45 +00005461 // Build a new statement.
5462 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5463 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005464 Element.get(),
5465 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005466 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005467 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005468}
5469
5470
5471template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005472StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005473TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5474 // Transform the exception declaration, if any.
5475 VarDecl *Var = 0;
5476 if (S->getExceptionDecl()) {
5477 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005478 TypeSourceInfo *T = getDerived().TransformType(
5479 ExceptionDecl->getTypeSourceInfo());
5480 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005481 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005482
Douglas Gregor83cb9422010-09-09 17:09:21 +00005483 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005484 ExceptionDecl->getInnerLocStart(),
5485 ExceptionDecl->getLocation(),
5486 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005487 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005488 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005489 }
Mike Stump1eb44332009-09-09 15:08:12 +00005490
Douglas Gregor43959a92009-08-20 07:17:43 +00005491 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005492 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005493 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005494 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005495
Douglas Gregor43959a92009-08-20 07:17:43 +00005496 if (!getDerived().AlwaysRebuild() &&
5497 !Var &&
5498 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005499 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005500
5501 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5502 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005503 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005504}
Mike Stump1eb44332009-09-09 15:08:12 +00005505
Douglas Gregor43959a92009-08-20 07:17:43 +00005506template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005507StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005508TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5509 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005510 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005511 = getDerived().TransformCompoundStmt(S->getTryBlock());
5512 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005513 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005514
Douglas Gregor43959a92009-08-20 07:17:43 +00005515 // Transform the handlers.
5516 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005517 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005518 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005519 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005520 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5521 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005522 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005523
Douglas Gregor43959a92009-08-20 07:17:43 +00005524 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5525 Handlers.push_back(Handler.takeAs<Stmt>());
5526 }
Mike Stump1eb44332009-09-09 15:08:12 +00005527
Douglas Gregor43959a92009-08-20 07:17:43 +00005528 if (!getDerived().AlwaysRebuild() &&
5529 TryBlock.get() == S->getTryBlock() &&
5530 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005531 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005532
John McCall9ae2f072010-08-23 23:25:46 +00005533 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005534 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005535}
Mike Stump1eb44332009-09-09 15:08:12 +00005536
Richard Smithad762fc2011-04-14 22:09:26 +00005537template<typename Derived>
5538StmtResult
5539TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5540 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5541 if (Range.isInvalid())
5542 return StmtError();
5543
5544 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5545 if (BeginEnd.isInvalid())
5546 return StmtError();
5547
5548 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5549 if (Cond.isInvalid())
5550 return StmtError();
5551
5552 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5553 if (Inc.isInvalid())
5554 return StmtError();
5555
5556 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5557 if (LoopVar.isInvalid())
5558 return StmtError();
5559
5560 StmtResult NewStmt = S;
5561 if (getDerived().AlwaysRebuild() ||
5562 Range.get() != S->getRangeStmt() ||
5563 BeginEnd.get() != S->getBeginEndStmt() ||
5564 Cond.get() != S->getCond() ||
5565 Inc.get() != S->getInc() ||
5566 LoopVar.get() != S->getLoopVarStmt())
5567 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5568 S->getColonLoc(), Range.get(),
5569 BeginEnd.get(), Cond.get(),
5570 Inc.get(), LoopVar.get(),
5571 S->getRParenLoc());
5572
5573 StmtResult Body = getDerived().TransformStmt(S->getBody());
5574 if (Body.isInvalid())
5575 return StmtError();
5576
5577 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5578 // it now so we have a new statement to attach the body to.
5579 if (Body.get() != S->getBody() && NewStmt.get() == S)
5580 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5581 S->getColonLoc(), Range.get(),
5582 BeginEnd.get(), Cond.get(),
5583 Inc.get(), LoopVar.get(),
5584 S->getRParenLoc());
5585
5586 if (NewStmt.get() == S)
5587 return SemaRef.Owned(S);
5588
5589 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5590}
5591
John Wiegley28bbe4b2011-04-28 01:08:34 +00005592template<typename Derived>
5593StmtResult
5594TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5595 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5596 if(TryBlock.isInvalid()) return StmtError();
5597
5598 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5599 if(!getDerived().AlwaysRebuild() &&
5600 TryBlock.get() == S->getTryBlock() &&
5601 Handler.get() == S->getHandler())
5602 return SemaRef.Owned(S);
5603
5604 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5605 S->getTryLoc(),
5606 TryBlock.take(),
5607 Handler.take());
5608}
5609
5610template<typename Derived>
5611StmtResult
5612TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5613 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5614 if(Block.isInvalid()) return StmtError();
5615
5616 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5617 Block.take());
5618}
5619
5620template<typename Derived>
5621StmtResult
5622TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5623 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5624 if(FilterExpr.isInvalid()) return StmtError();
5625
5626 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5627 if(Block.isInvalid()) return StmtError();
5628
5629 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5630 FilterExpr.take(),
5631 Block.take());
5632}
5633
5634template<typename Derived>
5635StmtResult
5636TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5637 if(isa<SEHFinallyStmt>(Handler))
5638 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5639 else
5640 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5641}
5642
Douglas Gregor43959a92009-08-20 07:17:43 +00005643//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005644// Expression transformation
5645//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005646template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005647ExprResult
John McCall454feb92009-12-08 09:21:05 +00005648TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005649 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005650}
Mike Stump1eb44332009-09-09 15:08:12 +00005651
5652template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005653ExprResult
John McCall454feb92009-12-08 09:21:05 +00005654TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005655 NestedNameSpecifierLoc QualifierLoc;
5656 if (E->getQualifierLoc()) {
5657 QualifierLoc
5658 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5659 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005660 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005661 }
John McCalldbd872f2009-12-08 09:08:17 +00005662
5663 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005664 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5665 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005666 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005667 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005668
John McCallec8045d2010-08-17 21:27:17 +00005669 DeclarationNameInfo NameInfo = E->getNameInfo();
5670 if (NameInfo.getName()) {
5671 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5672 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005673 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005674 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005675
5676 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005677 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005678 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005679 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005680 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005681
5682 // Mark it referenced in the new context regardless.
5683 // FIXME: this is a bit instantiation-specific.
5684 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5685
John McCall3fa5cae2010-10-26 07:05:15 +00005686 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005687 }
John McCalldbd872f2009-12-08 09:08:17 +00005688
5689 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005690 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005691 TemplateArgs = &TransArgs;
5692 TransArgs.setLAngleLoc(E->getLAngleLoc());
5693 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005694 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5695 E->getNumTemplateArgs(),
5696 TransArgs))
5697 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005698 }
5699
Douglas Gregor40d96a62011-02-28 21:54:11 +00005700 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5701 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005702}
Mike Stump1eb44332009-09-09 15:08:12 +00005703
Douglas Gregorb98b1992009-08-11 05:31:07 +00005704template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005705ExprResult
John McCall454feb92009-12-08 09:21:05 +00005706TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005707 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005708}
Mike Stump1eb44332009-09-09 15:08:12 +00005709
Douglas Gregorb98b1992009-08-11 05:31:07 +00005710template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005711ExprResult
John McCall454feb92009-12-08 09:21:05 +00005712TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005713 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005714}
Mike Stump1eb44332009-09-09 15:08:12 +00005715
Douglas Gregorb98b1992009-08-11 05:31:07 +00005716template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005717ExprResult
John McCall454feb92009-12-08 09:21:05 +00005718TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005719 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005720}
Mike Stump1eb44332009-09-09 15:08:12 +00005721
Douglas Gregorb98b1992009-08-11 05:31:07 +00005722template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005723ExprResult
John McCall454feb92009-12-08 09:21:05 +00005724TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005725 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005726}
Mike Stump1eb44332009-09-09 15:08:12 +00005727
Douglas Gregorb98b1992009-08-11 05:31:07 +00005728template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005729ExprResult
John McCall454feb92009-12-08 09:21:05 +00005730TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005731 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005732}
5733
5734template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005735ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00005736TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5737 ExprResult ControllingExpr =
5738 getDerived().TransformExpr(E->getControllingExpr());
5739 if (ControllingExpr.isInvalid())
5740 return ExprError();
5741
5742 llvm::SmallVector<Expr *, 4> AssocExprs;
5743 llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5744 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5745 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5746 if (TS) {
5747 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5748 if (!AssocType)
5749 return ExprError();
5750 AssocTypes.push_back(AssocType);
5751 } else {
5752 AssocTypes.push_back(0);
5753 }
5754
5755 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5756 if (AssocExpr.isInvalid())
5757 return ExprError();
5758 AssocExprs.push_back(AssocExpr.release());
5759 }
5760
5761 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5762 E->getDefaultLoc(),
5763 E->getRParenLoc(),
5764 ControllingExpr.release(),
5765 AssocTypes.data(),
5766 AssocExprs.data(),
5767 E->getNumAssocs());
5768}
5769
5770template<typename Derived>
5771ExprResult
John McCall454feb92009-12-08 09:21:05 +00005772TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005773 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005774 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005775 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005776
Douglas Gregorb98b1992009-08-11 05:31:07 +00005777 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005778 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005779
John McCall9ae2f072010-08-23 23:25:46 +00005780 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005781 E->getRParen());
5782}
5783
Mike Stump1eb44332009-09-09 15:08:12 +00005784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005785ExprResult
John McCall454feb92009-12-08 09:21:05 +00005786TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005787 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005788 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005789 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005790
Douglas Gregorb98b1992009-08-11 05:31:07 +00005791 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005792 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005793
Douglas Gregorb98b1992009-08-11 05:31:07 +00005794 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5795 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005796 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005797}
Mike Stump1eb44332009-09-09 15:08:12 +00005798
Douglas Gregorb98b1992009-08-11 05:31:07 +00005799template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005800ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005801TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5802 // Transform the type.
5803 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5804 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005805 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005806
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005807 // Transform all of the components into components similar to what the
5808 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005809 // FIXME: It would be slightly more efficient in the non-dependent case to
5810 // just map FieldDecls, rather than requiring the rebuilder to look for
5811 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005812 // template code that we don't care.
5813 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005814 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005815 typedef OffsetOfExpr::OffsetOfNode Node;
5816 llvm::SmallVector<Component, 4> Components;
5817 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5818 const Node &ON = E->getComponent(I);
5819 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005820 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00005821 Comp.LocStart = ON.getSourceRange().getBegin();
5822 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005823 switch (ON.getKind()) {
5824 case Node::Array: {
5825 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005826 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005827 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005828 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005829
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005830 ExprChanged = ExprChanged || Index.get() != FromIndex;
5831 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005832 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005833 break;
5834 }
Sean Huntc3021132010-05-05 15:23:54 +00005835
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005836 case Node::Field:
5837 case Node::Identifier:
5838 Comp.isBrackets = false;
5839 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005840 if (!Comp.U.IdentInfo)
5841 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005842
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005843 break;
Sean Huntc3021132010-05-05 15:23:54 +00005844
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005845 case Node::Base:
5846 // Will be recomputed during the rebuild.
5847 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005848 }
Sean Huntc3021132010-05-05 15:23:54 +00005849
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005850 Components.push_back(Comp);
5851 }
Sean Huntc3021132010-05-05 15:23:54 +00005852
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005853 // If nothing changed, retain the existing expression.
5854 if (!getDerived().AlwaysRebuild() &&
5855 Type == E->getTypeSourceInfo() &&
5856 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005857 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00005858
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005859 // Build a new offsetof expression.
5860 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5861 Components.data(), Components.size(),
5862 E->getRParenLoc());
5863}
5864
5865template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005866ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00005867TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5868 assert(getDerived().AlreadyTransformed(E->getType()) &&
5869 "opaque value expression requires transformation");
5870 return SemaRef.Owned(E);
5871}
5872
5873template<typename Derived>
5874ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005875TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5876 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005877 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00005878 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00005879
John McCalla93c9342009-12-07 02:54:59 +00005880 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00005881 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005882 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005883
John McCall5ab75172009-11-04 07:28:41 +00005884 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00005885 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005886
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005887 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5888 E->getKind(),
5889 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005890 }
Mike Stump1eb44332009-09-09 15:08:12 +00005891
John McCall60d7b3a2010-08-24 06:29:42 +00005892 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00005893 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005894 // C++0x [expr.sizeof]p1:
5895 // The operand is either an expression, which is an unevaluated operand
5896 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00005897 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005898
Douglas Gregorb98b1992009-08-11 05:31:07 +00005899 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5900 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005901 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005902
Douglas Gregorb98b1992009-08-11 05:31:07 +00005903 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005904 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005905 }
Mike Stump1eb44332009-09-09 15:08:12 +00005906
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005907 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5908 E->getOperatorLoc(),
5909 E->getKind(),
5910 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005911}
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 McCall454feb92009-12-08 09:21:05 +00005915TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005916 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005917 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005918 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005919
John McCall60d7b3a2010-08-24 06:29:42 +00005920 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005921 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005922 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005923
5924
Douglas Gregorb98b1992009-08-11 05:31:07 +00005925 if (!getDerived().AlwaysRebuild() &&
5926 LHS.get() == E->getLHS() &&
5927 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005928 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005929
John McCall9ae2f072010-08-23 23:25:46 +00005930 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005931 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005932 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005933 E->getRBracketLoc());
5934}
Mike Stump1eb44332009-09-09 15:08:12 +00005935
5936template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005937ExprResult
John McCall454feb92009-12-08 09:21:05 +00005938TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005939 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00005940 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005941 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005942 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005943
5944 // Transform arguments.
5945 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005946 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005947 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5948 &ArgChanged))
5949 return ExprError();
5950
Douglas Gregorb98b1992009-08-11 05:31:07 +00005951 if (!getDerived().AlwaysRebuild() &&
5952 Callee.get() == E->getCallee() &&
5953 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005954 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005955
Douglas Gregorb98b1992009-08-11 05:31:07 +00005956 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00005957 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005958 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00005959 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005960 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005961 E->getRParenLoc());
5962}
Mike Stump1eb44332009-09-09 15:08:12 +00005963
5964template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005965ExprResult
John McCall454feb92009-12-08 09:21:05 +00005966TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005967 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005968 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005969 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005970
Douglas Gregor40d96a62011-02-28 21:54:11 +00005971 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005972 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005973 QualifierLoc
5974 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5975
5976 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005977 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005978 }
Mike Stump1eb44332009-09-09 15:08:12 +00005979
Eli Friedmanf595cc42009-12-04 06:40:45 +00005980 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005981 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5982 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005983 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00005984 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005985
John McCall6bb80172010-03-30 21:47:33 +00005986 NamedDecl *FoundDecl = E->getFoundDecl();
5987 if (FoundDecl == E->getMemberDecl()) {
5988 FoundDecl = Member;
5989 } else {
5990 FoundDecl = cast_or_null<NamedDecl>(
5991 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5992 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00005993 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00005994 }
5995
Douglas Gregorb98b1992009-08-11 05:31:07 +00005996 if (!getDerived().AlwaysRebuild() &&
5997 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005998 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005999 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006000 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006001 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006002
Anders Carlsson1f240322009-12-22 05:24:09 +00006003 // Mark it referenced in the new context regardless.
6004 // FIXME: this is a bit instantiation-specific.
6005 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00006006 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006007 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006008
John McCalld5532b62009-11-23 01:53:49 +00006009 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006010 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006011 TransArgs.setLAngleLoc(E->getLAngleLoc());
6012 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006013 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6014 E->getNumTemplateArgs(),
6015 TransArgs))
6016 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006017 }
Sean Huntc3021132010-05-05 15:23:54 +00006018
Douglas Gregorb98b1992009-08-11 05:31:07 +00006019 // FIXME: Bogus source location for the operator
6020 SourceLocation FakeOperatorLoc
6021 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6022
John McCallc2233c52010-01-15 08:34:02 +00006023 // FIXME: to do this check properly, we will need to preserve the
6024 // first-qualifier-in-scope here, just in case we had a dependent
6025 // base (and therefore couldn't do the check) and a
6026 // nested-name-qualifier (and therefore could do the lookup).
6027 NamedDecl *FirstQualifierInScope = 0;
6028
John McCall9ae2f072010-08-23 23:25:46 +00006029 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006030 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006031 QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006032 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006033 Member,
John McCall6bb80172010-03-30 21:47:33 +00006034 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006035 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006036 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006037 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006038}
Mike Stump1eb44332009-09-09 15:08:12 +00006039
Douglas Gregorb98b1992009-08-11 05:31:07 +00006040template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006041ExprResult
John McCall454feb92009-12-08 09:21:05 +00006042TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006043 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006044 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006045 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006046
John McCall60d7b3a2010-08-24 06:29:42 +00006047 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006048 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006049 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006050
Douglas Gregorb98b1992009-08-11 05:31:07 +00006051 if (!getDerived().AlwaysRebuild() &&
6052 LHS.get() == E->getLHS() &&
6053 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006054 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006055
Douglas Gregorb98b1992009-08-11 05:31:07 +00006056 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006057 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006058}
6059
Mike Stump1eb44332009-09-09 15:08:12 +00006060template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006061ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006062TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006063 CompoundAssignOperator *E) {
6064 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006065}
Mike Stump1eb44332009-09-09 15:08:12 +00006066
Douglas Gregorb98b1992009-08-11 05:31:07 +00006067template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006068ExprResult TreeTransform<Derived>::
6069TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6070 // Just rebuild the common and RHS expressions and see whether we
6071 // get any changes.
6072
6073 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6074 if (commonExpr.isInvalid())
6075 return ExprError();
6076
6077 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6078 if (rhs.isInvalid())
6079 return ExprError();
6080
6081 if (!getDerived().AlwaysRebuild() &&
6082 commonExpr.get() == e->getCommon() &&
6083 rhs.get() == e->getFalseExpr())
6084 return SemaRef.Owned(e);
6085
6086 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6087 e->getQuestionLoc(),
6088 0,
6089 e->getColonLoc(),
6090 rhs.get());
6091}
6092
6093template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006094ExprResult
John McCall454feb92009-12-08 09:21:05 +00006095TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006096 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006097 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006098 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006099
John McCall60d7b3a2010-08-24 06:29:42 +00006100 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006101 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006102 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006103
John McCall60d7b3a2010-08-24 06:29:42 +00006104 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006105 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006106 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006107
Douglas Gregorb98b1992009-08-11 05:31:07 +00006108 if (!getDerived().AlwaysRebuild() &&
6109 Cond.get() == E->getCond() &&
6110 LHS.get() == E->getLHS() &&
6111 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006112 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006113
John McCall9ae2f072010-08-23 23:25:46 +00006114 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006115 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006116 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006117 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006118 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006119}
Mike Stump1eb44332009-09-09 15:08:12 +00006120
6121template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006122ExprResult
John McCall454feb92009-12-08 09:21:05 +00006123TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006124 // Implicit casts are eliminated during transformation, since they
6125 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006126 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006127}
Mike Stump1eb44332009-09-09 15:08:12 +00006128
Douglas Gregorb98b1992009-08-11 05:31:07 +00006129template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006130ExprResult
John McCall454feb92009-12-08 09:21:05 +00006131TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006132 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6133 if (!Type)
6134 return ExprError();
6135
John McCall60d7b3a2010-08-24 06:29:42 +00006136 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006137 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006138 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006139 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006140
Douglas Gregorb98b1992009-08-11 05:31:07 +00006141 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006142 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006143 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006144 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006145
John McCall9d125032010-01-15 18:39:57 +00006146 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006147 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006148 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006149 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006150}
Mike Stump1eb44332009-09-09 15:08:12 +00006151
Douglas Gregorb98b1992009-08-11 05:31:07 +00006152template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006153ExprResult
John McCall454feb92009-12-08 09:21:05 +00006154TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006155 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6156 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6157 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006158 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006159
John McCall60d7b3a2010-08-24 06:29:42 +00006160 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006161 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006162 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006163
Douglas Gregorb98b1992009-08-11 05:31:07 +00006164 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006165 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006166 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00006167 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006168
John McCall1d7d8d62010-01-19 22:33:45 +00006169 // Note: the expression type doesn't necessarily match the
6170 // type-as-written, but that's okay, because it should always be
6171 // derivable from the initializer.
6172
John McCall42f56b52010-01-18 19:35:47 +00006173 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006174 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006175 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006176}
Mike Stump1eb44332009-09-09 15:08:12 +00006177
Douglas Gregorb98b1992009-08-11 05:31:07 +00006178template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006179ExprResult
John McCall454feb92009-12-08 09:21:05 +00006180TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006181 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006182 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006183 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006184
Douglas Gregorb98b1992009-08-11 05:31:07 +00006185 if (!getDerived().AlwaysRebuild() &&
6186 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006187 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006188
Douglas Gregorb98b1992009-08-11 05:31:07 +00006189 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006190 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006191 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006192 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006193 E->getAccessorLoc(),
6194 E->getAccessor());
6195}
Mike Stump1eb44332009-09-09 15:08:12 +00006196
Douglas Gregorb98b1992009-08-11 05:31:07 +00006197template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006198ExprResult
John McCall454feb92009-12-08 09:21:05 +00006199TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006200 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006201
John McCallca0408f2010-08-23 06:44:23 +00006202 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006203 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6204 Inits, &InitChanged))
6205 return ExprError();
6206
Douglas Gregorb98b1992009-08-11 05:31:07 +00006207 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006208 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006209
Douglas Gregorb98b1992009-08-11 05:31:07 +00006210 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006211 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006212}
Mike Stump1eb44332009-09-09 15:08:12 +00006213
Douglas Gregorb98b1992009-08-11 05:31:07 +00006214template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006215ExprResult
John McCall454feb92009-12-08 09:21:05 +00006216TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006218
Douglas Gregor43959a92009-08-20 07:17:43 +00006219 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006220 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006221 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006222 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006223
Douglas Gregor43959a92009-08-20 07:17:43 +00006224 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006225 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006226 bool ExprChanged = false;
6227 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6228 DEnd = E->designators_end();
6229 D != DEnd; ++D) {
6230 if (D->isFieldDesignator()) {
6231 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6232 D->getDotLoc(),
6233 D->getFieldLoc()));
6234 continue;
6235 }
Mike Stump1eb44332009-09-09 15:08:12 +00006236
Douglas Gregorb98b1992009-08-11 05:31:07 +00006237 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006238 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006239 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006240 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006241
6242 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006243 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006244
Douglas Gregorb98b1992009-08-11 05:31:07 +00006245 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6246 ArrayExprs.push_back(Index.release());
6247 continue;
6248 }
Mike Stump1eb44332009-09-09 15:08:12 +00006249
Douglas Gregorb98b1992009-08-11 05:31:07 +00006250 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006251 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006252 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6253 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006254 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006255
John McCall60d7b3a2010-08-24 06:29:42 +00006256 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006257 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006258 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006259
6260 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006261 End.get(),
6262 D->getLBracketLoc(),
6263 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006264
Douglas Gregorb98b1992009-08-11 05:31:07 +00006265 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6266 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006267
Douglas Gregorb98b1992009-08-11 05:31:07 +00006268 ArrayExprs.push_back(Start.release());
6269 ArrayExprs.push_back(End.release());
6270 }
Mike Stump1eb44332009-09-09 15:08:12 +00006271
Douglas Gregorb98b1992009-08-11 05:31:07 +00006272 if (!getDerived().AlwaysRebuild() &&
6273 Init.get() == E->getInit() &&
6274 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006275 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006276
Douglas Gregorb98b1992009-08-11 05:31:07 +00006277 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6278 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006279 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006280}
Mike Stump1eb44332009-09-09 15:08:12 +00006281
Douglas Gregorb98b1992009-08-11 05:31:07 +00006282template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006283ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006284TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006285 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006286 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006287
Douglas Gregor5557b252009-10-28 00:29:27 +00006288 // FIXME: Will we ever have proper type location here? Will we actually
6289 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006290 QualType T = getDerived().TransformType(E->getType());
6291 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006292 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006293
Douglas Gregorb98b1992009-08-11 05:31:07 +00006294 if (!getDerived().AlwaysRebuild() &&
6295 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006296 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006297
Douglas Gregorb98b1992009-08-11 05:31:07 +00006298 return getDerived().RebuildImplicitValueInitExpr(T);
6299}
Mike Stump1eb44332009-09-09 15:08:12 +00006300
Douglas Gregorb98b1992009-08-11 05:31:07 +00006301template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006302ExprResult
John McCall454feb92009-12-08 09:21:05 +00006303TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006304 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6305 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006306 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006307
John McCall60d7b3a2010-08-24 06:29:42 +00006308 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006309 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006310 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006311
Douglas Gregorb98b1992009-08-11 05:31:07 +00006312 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006313 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006314 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006315 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006316
John McCall9ae2f072010-08-23 23:25:46 +00006317 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006318 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006319}
6320
6321template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006322ExprResult
John McCall454feb92009-12-08 09:21:05 +00006323TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006324 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006325 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006326 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6327 &ArgumentChanged))
6328 return ExprError();
6329
Douglas Gregorb98b1992009-08-11 05:31:07 +00006330 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6331 move_arg(Inits),
6332 E->getRParenLoc());
6333}
Mike Stump1eb44332009-09-09 15:08:12 +00006334
Douglas Gregorb98b1992009-08-11 05:31:07 +00006335/// \brief Transform an address-of-label expression.
6336///
6337/// By default, the transformation of an address-of-label expression always
6338/// rebuilds the expression, so that the label identifier can be resolved to
6339/// the corresponding label statement by semantic analysis.
6340template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006341ExprResult
John McCall454feb92009-12-08 09:21:05 +00006342TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006343 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6344 E->getLabel());
6345 if (!LD)
6346 return ExprError();
6347
Douglas Gregorb98b1992009-08-11 05:31:07 +00006348 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006349 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006350}
Mike Stump1eb44332009-09-09 15:08:12 +00006351
6352template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006353ExprResult
John McCall454feb92009-12-08 09:21:05 +00006354TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006355 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006356 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6357 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006358 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006359
Douglas Gregorb98b1992009-08-11 05:31:07 +00006360 if (!getDerived().AlwaysRebuild() &&
6361 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00006362 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006363
6364 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006365 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006366 E->getRParenLoc());
6367}
Mike Stump1eb44332009-09-09 15:08:12 +00006368
Douglas Gregorb98b1992009-08-11 05:31:07 +00006369template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006370ExprResult
John McCall454feb92009-12-08 09:21:05 +00006371TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006372 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006373 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006374 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006375
John McCall60d7b3a2010-08-24 06:29:42 +00006376 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006377 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006378 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006379
John McCall60d7b3a2010-08-24 06:29:42 +00006380 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006381 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006382 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006383
Douglas Gregorb98b1992009-08-11 05:31:07 +00006384 if (!getDerived().AlwaysRebuild() &&
6385 Cond.get() == E->getCond() &&
6386 LHS.get() == E->getLHS() &&
6387 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006388 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006389
Douglas Gregorb98b1992009-08-11 05:31:07 +00006390 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006391 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006392 E->getRParenLoc());
6393}
Mike Stump1eb44332009-09-09 15:08:12 +00006394
Douglas Gregorb98b1992009-08-11 05:31:07 +00006395template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006396ExprResult
John McCall454feb92009-12-08 09:21:05 +00006397TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006398 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006399}
6400
6401template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006402ExprResult
John McCall454feb92009-12-08 09:21:05 +00006403TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006404 switch (E->getOperator()) {
6405 case OO_New:
6406 case OO_Delete:
6407 case OO_Array_New:
6408 case OO_Array_Delete:
6409 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006410 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006411
Douglas Gregor668d6d92009-12-13 20:44:55 +00006412 case OO_Call: {
6413 // This is a call to an object's operator().
6414 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6415
6416 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006417 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006418 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006419 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006420
6421 // FIXME: Poor location information
6422 SourceLocation FakeLParenLoc
6423 = SemaRef.PP.getLocForEndOfToken(
6424 static_cast<Expr *>(Object.get())->getLocEnd());
6425
6426 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006427 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006428 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6429 Args))
6430 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006431
John McCall9ae2f072010-08-23 23:25:46 +00006432 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006433 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006434 E->getLocEnd());
6435 }
6436
6437#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6438 case OO_##Name:
6439#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6440#include "clang/Basic/OperatorKinds.def"
6441 case OO_Subscript:
6442 // Handled below.
6443 break;
6444
6445 case OO_Conditional:
6446 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006447 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006448
6449 case OO_None:
6450 case NUM_OVERLOADED_OPERATORS:
6451 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006452 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006453 }
6454
John McCall60d7b3a2010-08-24 06:29:42 +00006455 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006456 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006457 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006458
John McCall60d7b3a2010-08-24 06:29:42 +00006459 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006460 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006461 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006462
John McCall60d7b3a2010-08-24 06:29:42 +00006463 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006464 if (E->getNumArgs() == 2) {
6465 Second = getDerived().TransformExpr(E->getArg(1));
6466 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006467 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006468 }
Mike Stump1eb44332009-09-09 15:08:12 +00006469
Douglas Gregorb98b1992009-08-11 05:31:07 +00006470 if (!getDerived().AlwaysRebuild() &&
6471 Callee.get() == E->getCallee() &&
6472 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006473 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00006474 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006475
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6477 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006478 Callee.get(),
6479 First.get(),
6480 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006481}
Mike Stump1eb44332009-09-09 15:08:12 +00006482
Douglas Gregorb98b1992009-08-11 05:31:07 +00006483template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006484ExprResult
John McCall454feb92009-12-08 09:21:05 +00006485TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6486 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006487}
Mike Stump1eb44332009-09-09 15:08:12 +00006488
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006490ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006491TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6492 // Transform the callee.
6493 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6494 if (Callee.isInvalid())
6495 return ExprError();
6496
6497 // Transform exec config.
6498 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6499 if (EC.isInvalid())
6500 return ExprError();
6501
6502 // Transform arguments.
6503 bool ArgChanged = false;
6504 ASTOwningVector<Expr*> Args(SemaRef);
6505 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6506 &ArgChanged))
6507 return ExprError();
6508
6509 if (!getDerived().AlwaysRebuild() &&
6510 Callee.get() == E->getCallee() &&
6511 !ArgChanged)
6512 return SemaRef.Owned(E);
6513
6514 // FIXME: Wrong source location information for the '('.
6515 SourceLocation FakeLParenLoc
6516 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6517 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6518 move_arg(Args),
6519 E->getRParenLoc(), EC.get());
6520}
6521
6522template<typename Derived>
6523ExprResult
John McCall454feb92009-12-08 09:21:05 +00006524TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006525 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6526 if (!Type)
6527 return ExprError();
6528
John McCall60d7b3a2010-08-24 06:29:42 +00006529 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006530 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006531 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006532 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006533
Douglas Gregorb98b1992009-08-11 05:31:07 +00006534 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006535 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006536 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006537 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006538
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006540 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6542 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6543 SourceLocation FakeRParenLoc
6544 = SemaRef.PP.getLocForEndOfToken(
6545 E->getSubExpr()->getSourceRange().getEnd());
6546 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006547 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006549 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006550 FakeRAngleLoc,
6551 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006552 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006553 FakeRParenLoc);
6554}
Mike Stump1eb44332009-09-09 15:08:12 +00006555
Douglas Gregorb98b1992009-08-11 05:31:07 +00006556template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006557ExprResult
John McCall454feb92009-12-08 09:21:05 +00006558TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6559 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006560}
Mike Stump1eb44332009-09-09 15:08:12 +00006561
6562template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006563ExprResult
John McCall454feb92009-12-08 09:21:05 +00006564TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6565 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006566}
6567
Douglas Gregorb98b1992009-08-11 05:31:07 +00006568template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006569ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006570TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006571 CXXReinterpretCastExpr *E) {
6572 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006573}
Mike Stump1eb44332009-09-09 15:08:12 +00006574
Douglas Gregorb98b1992009-08-11 05:31:07 +00006575template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006576ExprResult
John McCall454feb92009-12-08 09:21:05 +00006577TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6578 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006579}
Mike Stump1eb44332009-09-09 15:08:12 +00006580
Douglas Gregorb98b1992009-08-11 05:31:07 +00006581template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006582ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006583TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006584 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006585 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6586 if (!Type)
6587 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006588
John McCall60d7b3a2010-08-24 06:29:42 +00006589 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006590 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006592 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006593
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006595 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006596 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006597 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006598
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006599 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006600 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006601 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006602 E->getRParenLoc());
6603}
Mike Stump1eb44332009-09-09 15:08:12 +00006604
Douglas Gregorb98b1992009-08-11 05:31:07 +00006605template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006606ExprResult
John McCall454feb92009-12-08 09:21:05 +00006607TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006609 TypeSourceInfo *TInfo
6610 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6611 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006612 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006613
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006615 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006616 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006617
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006618 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6619 E->getLocStart(),
6620 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 E->getLocEnd());
6622 }
Mike Stump1eb44332009-09-09 15:08:12 +00006623
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624 // We don't know whether the expression is potentially evaluated until
6625 // after we perform semantic analysis, so the expression is potentially
6626 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006627 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006628 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006629
John McCall60d7b3a2010-08-24 06:29:42 +00006630 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006632 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006633
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634 if (!getDerived().AlwaysRebuild() &&
6635 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006636 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006637
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006638 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6639 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006640 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641 E->getLocEnd());
6642}
6643
6644template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006645ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006646TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6647 if (E->isTypeOperand()) {
6648 TypeSourceInfo *TInfo
6649 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6650 if (!TInfo)
6651 return ExprError();
6652
6653 if (!getDerived().AlwaysRebuild() &&
6654 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006655 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006656
Douglas Gregor3c52a212011-03-06 17:40:41 +00006657 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006658 E->getLocStart(),
6659 TInfo,
6660 E->getLocEnd());
6661 }
6662
6663 // We don't know whether the expression is potentially evaluated until
6664 // after we perform semantic analysis, so the expression is potentially
6665 // potentially evaluated.
6666 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6667
6668 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6669 if (SubExpr.isInvalid())
6670 return ExprError();
6671
6672 if (!getDerived().AlwaysRebuild() &&
6673 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006674 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006675
6676 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6677 E->getLocStart(),
6678 SubExpr.get(),
6679 E->getLocEnd());
6680}
6681
6682template<typename Derived>
6683ExprResult
John McCall454feb92009-12-08 09:21:05 +00006684TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006685 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006686}
Mike Stump1eb44332009-09-09 15:08:12 +00006687
Douglas Gregorb98b1992009-08-11 05:31:07 +00006688template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006689ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006691 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006692 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693}
Mike Stump1eb44332009-09-09 15:08:12 +00006694
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006696ExprResult
John McCall454feb92009-12-08 09:21:05 +00006697TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006698 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6699 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6700 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00006701
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006702 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006703 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006704
Douglas Gregor828a1972010-01-07 23:12:05 +00006705 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006706}
Mike Stump1eb44332009-09-09 15:08:12 +00006707
Douglas Gregorb98b1992009-08-11 05:31:07 +00006708template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006709ExprResult
John McCall454feb92009-12-08 09:21:05 +00006710TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006711 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006713 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006714
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715 if (!getDerived().AlwaysRebuild() &&
6716 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006717 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718
John McCall9ae2f072010-08-23 23:25:46 +00006719 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006720}
Mike Stump1eb44332009-09-09 15:08:12 +00006721
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006723ExprResult
John McCall454feb92009-12-08 09:21:05 +00006724TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006725 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006726 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6727 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006729 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006730
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006731 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006732 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006733 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006734
Douglas Gregor036aed12009-12-23 23:03:06 +00006735 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006736}
Mike Stump1eb44332009-09-09 15:08:12 +00006737
Douglas Gregorb98b1992009-08-11 05:31:07 +00006738template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006739ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006740TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6741 CXXScalarValueInitExpr *E) {
6742 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6743 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006744 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006745
Douglas Gregorb98b1992009-08-11 05:31:07 +00006746 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006747 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006748 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006749
Douglas Gregorab6677e2010-09-08 00:15:04 +00006750 return getDerived().RebuildCXXScalarValueInitExpr(T,
6751 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006752 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753}
Mike Stump1eb44332009-09-09 15:08:12 +00006754
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006756ExprResult
John McCall454feb92009-12-08 09:21:05 +00006757TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006759 TypeSourceInfo *AllocTypeInfo
6760 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6761 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006762 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006763
Douglas Gregorb98b1992009-08-11 05:31:07 +00006764 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006765 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006766 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006767 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006768
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 // Transform the placement arguments (if any).
6770 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006771 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006772 if (getDerived().TransformExprs(E->getPlacementArgs(),
6773 E->getNumPlacementArgs(), true,
6774 PlacementArgs, &ArgumentChanged))
6775 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006776
Douglas Gregor43959a92009-08-20 07:17:43 +00006777 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00006778 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006779 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6780 ConstructorArgs, &ArgumentChanged))
6781 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006782
Douglas Gregor1af74512010-02-26 00:38:10 +00006783 // Transform constructor, new operator, and delete operator.
6784 CXXConstructorDecl *Constructor = 0;
6785 if (E->getConstructor()) {
6786 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006787 getDerived().TransformDecl(E->getLocStart(),
6788 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006789 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006790 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006791 }
6792
6793 FunctionDecl *OperatorNew = 0;
6794 if (E->getOperatorNew()) {
6795 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006796 getDerived().TransformDecl(E->getLocStart(),
6797 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006798 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006799 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006800 }
6801
6802 FunctionDecl *OperatorDelete = 0;
6803 if (E->getOperatorDelete()) {
6804 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006805 getDerived().TransformDecl(E->getLocStart(),
6806 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006807 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006808 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006809 }
Sean Huntc3021132010-05-05 15:23:54 +00006810
Douglas Gregorb98b1992009-08-11 05:31:07 +00006811 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006812 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006813 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006814 Constructor == E->getConstructor() &&
6815 OperatorNew == E->getOperatorNew() &&
6816 OperatorDelete == E->getOperatorDelete() &&
6817 !ArgumentChanged) {
6818 // Mark any declarations we need as referenced.
6819 // FIXME: instantiation-specific.
6820 if (Constructor)
6821 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6822 if (OperatorNew)
6823 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6824 if (OperatorDelete)
6825 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00006826 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006827 }
Mike Stump1eb44332009-09-09 15:08:12 +00006828
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006829 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006830 if (!ArraySize.get()) {
6831 // If no array size was specified, but the new expression was
6832 // instantiated with an array type (e.g., "new T" where T is
6833 // instantiated with "int[4]"), extract the outer bound from the
6834 // array type as our array size. We do this with constant and
6835 // dependently-sized array types.
6836 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6837 if (!ArrayT) {
6838 // Do nothing
6839 } else if (const ConstantArrayType *ConsArrayT
6840 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00006841 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006842 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6843 ConsArrayT->getSize(),
6844 SemaRef.Context.getSizeType(),
6845 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006846 AllocType = ConsArrayT->getElementType();
6847 } else if (const DependentSizedArrayType *DepArrayT
6848 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6849 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00006850 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006851 AllocType = DepArrayT->getElementType();
6852 }
6853 }
6854 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006855
Douglas Gregorb98b1992009-08-11 05:31:07 +00006856 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6857 E->isGlobalNew(),
6858 /*FIXME:*/E->getLocStart(),
6859 move_arg(PlacementArgs),
6860 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00006861 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006862 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006863 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00006864 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006865 /*FIXME:*/E->getLocStart(),
6866 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00006867 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006868}
Mike Stump1eb44332009-09-09 15:08:12 +00006869
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006871ExprResult
John McCall454feb92009-12-08 09:21:05 +00006872TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006873 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006874 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006875 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006876
Douglas Gregor1af74512010-02-26 00:38:10 +00006877 // Transform the delete operator, if known.
6878 FunctionDecl *OperatorDelete = 0;
6879 if (E->getOperatorDelete()) {
6880 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006881 getDerived().TransformDecl(E->getLocStart(),
6882 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006883 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006884 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006885 }
Sean Huntc3021132010-05-05 15:23:54 +00006886
Douglas Gregorb98b1992009-08-11 05:31:07 +00006887 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006888 Operand.get() == E->getArgument() &&
6889 OperatorDelete == E->getOperatorDelete()) {
6890 // Mark any declarations we need as referenced.
6891 // FIXME: instantiation-specific.
6892 if (OperatorDelete)
6893 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00006894
6895 if (!E->getArgument()->isTypeDependent()) {
6896 QualType Destroyed = SemaRef.Context.getBaseElementType(
6897 E->getDestroyedType());
6898 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6899 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6900 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6901 SemaRef.LookupDestructor(Record));
6902 }
6903 }
6904
John McCall3fa5cae2010-10-26 07:05:15 +00006905 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006906 }
Mike Stump1eb44332009-09-09 15:08:12 +00006907
Douglas Gregorb98b1992009-08-11 05:31:07 +00006908 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6909 E->isGlobalDelete(),
6910 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00006911 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006912}
Mike Stump1eb44332009-09-09 15:08:12 +00006913
Douglas Gregorb98b1992009-08-11 05:31:07 +00006914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006915ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00006916TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00006917 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006918 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00006919 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006920 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006921
John McCallb3d87482010-08-24 05:47:05 +00006922 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006923 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006924 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006925 E->getOperatorLoc(),
6926 E->isArrow()? tok::arrow : tok::period,
6927 ObjectTypePtr,
6928 MayBePseudoDestructor);
6929 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006930 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006931
John McCallb3d87482010-08-24 05:47:05 +00006932 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006933 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6934 if (QualifierLoc) {
6935 QualifierLoc
6936 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6937 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00006938 return ExprError();
6939 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006940 CXXScopeSpec SS;
6941 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00006942
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006943 PseudoDestructorTypeStorage Destroyed;
6944 if (E->getDestroyedTypeInfo()) {
6945 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00006946 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00006947 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006948 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006949 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006950 Destroyed = DestroyedTypeInfo;
6951 } else if (ObjectType->isDependentType()) {
6952 // We aren't likely to be able to resolve the identifier down to a type
6953 // now anyway, so just retain the identifier.
6954 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6955 E->getDestroyedTypeLoc());
6956 } else {
6957 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00006958 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006959 *E->getDestroyedTypeIdentifier(),
6960 E->getDestroyedTypeLoc(),
6961 /*Scope=*/0,
6962 SS, ObjectTypePtr,
6963 false);
6964 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006965 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006966
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006967 Destroyed
6968 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6969 E->getDestroyedTypeLoc());
6970 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006971
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006972 TypeSourceInfo *ScopeTypeInfo = 0;
6973 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00006974 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006975 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006976 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00006977 }
Sean Huntc3021132010-05-05 15:23:54 +00006978
John McCall9ae2f072010-08-23 23:25:46 +00006979 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006980 E->getOperatorLoc(),
6981 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006982 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006983 ScopeTypeInfo,
6984 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006985 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006986 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00006987}
Mike Stump1eb44332009-09-09 15:08:12 +00006988
Douglas Gregora71d8192009-09-04 17:36:40 +00006989template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006990ExprResult
John McCallba135432009-11-21 08:51:07 +00006991TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00006992 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00006993 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6994 Sema::LookupOrdinaryName);
6995
6996 // Transform all the decls.
6997 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6998 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006999 NamedDecl *InstD = static_cast<NamedDecl*>(
7000 getDerived().TransformDecl(Old->getNameLoc(),
7001 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007002 if (!InstD) {
7003 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7004 // This can happen because of dependent hiding.
7005 if (isa<UsingShadowDecl>(*I))
7006 continue;
7007 else
John McCallf312b1e2010-08-26 23:41:50 +00007008 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007009 }
John McCallf7a1a742009-11-24 19:00:30 +00007010
7011 // Expand using declarations.
7012 if (isa<UsingDecl>(InstD)) {
7013 UsingDecl *UD = cast<UsingDecl>(InstD);
7014 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7015 E = UD->shadow_end(); I != E; ++I)
7016 R.addDecl(*I);
7017 continue;
7018 }
7019
7020 R.addDecl(InstD);
7021 }
7022
7023 // Resolve a kind, but don't do any further analysis. If it's
7024 // ambiguous, the callee needs to deal with it.
7025 R.resolveKind();
7026
7027 // Rebuild the nested-name qualifier, if present.
7028 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007029 if (Old->getQualifierLoc()) {
7030 NestedNameSpecifierLoc QualifierLoc
7031 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7032 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007033 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007034
Douglas Gregor4c9be892011-02-28 20:01:57 +00007035 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007036 }
7037
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007038 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007039 CXXRecordDecl *NamingClass
7040 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7041 Old->getNameLoc(),
7042 Old->getNamingClass()));
7043 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007044 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007045
Douglas Gregor66c45152010-04-27 16:10:10 +00007046 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007047 }
7048
7049 // If we have no template arguments, it's a normal declaration name.
7050 if (!Old->hasExplicitTemplateArgs())
7051 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7052
7053 // If we have template arguments, rebuild them, then rebuild the
7054 // templateid expression.
7055 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007056 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7057 Old->getNumTemplateArgs(),
7058 TransArgs))
7059 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007060
7061 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7062 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007063}
Mike Stump1eb44332009-09-09 15:08:12 +00007064
Douglas Gregorb98b1992009-08-11 05:31:07 +00007065template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007066ExprResult
John McCall454feb92009-12-08 09:21:05 +00007067TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007068 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7069 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007070 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007071
Douglas Gregorb98b1992009-08-11 05:31:07 +00007072 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007073 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007074 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007075
Mike Stump1eb44332009-09-09 15:08:12 +00007076 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007077 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007078 T,
7079 E->getLocEnd());
7080}
Mike Stump1eb44332009-09-09 15:08:12 +00007081
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007083ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007084TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7085 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7086 if (!LhsT)
7087 return ExprError();
7088
7089 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7090 if (!RhsT)
7091 return ExprError();
7092
7093 if (!getDerived().AlwaysRebuild() &&
7094 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7095 return SemaRef.Owned(E);
7096
7097 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7098 E->getLocStart(),
7099 LhsT, RhsT,
7100 E->getLocEnd());
7101}
7102
7103template<typename Derived>
7104ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007105TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7106 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7107 if (!T)
7108 return ExprError();
7109
7110 if (!getDerived().AlwaysRebuild() &&
7111 T == E->getQueriedTypeSourceInfo())
7112 return SemaRef.Owned(E);
7113
7114 ExprResult SubExpr;
7115 {
7116 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7117 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7118 if (SubExpr.isInvalid())
7119 return ExprError();
7120
7121 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7122 return SemaRef.Owned(E);
7123 }
7124
7125 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7126 E->getLocStart(),
7127 T,
7128 SubExpr.get(),
7129 E->getLocEnd());
7130}
7131
7132template<typename Derived>
7133ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007134TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7135 ExprResult SubExpr;
7136 {
7137 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7138 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7139 if (SubExpr.isInvalid())
7140 return ExprError();
7141
7142 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7143 return SemaRef.Owned(E);
7144 }
7145
7146 return getDerived().RebuildExpressionTrait(
7147 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7148}
7149
7150template<typename Derived>
7151ExprResult
John McCall865d4472009-11-19 22:55:06 +00007152TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007153 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007154 NestedNameSpecifierLoc QualifierLoc
7155 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7156 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007157 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007158
John McCall43fed0d2010-11-12 08:19:04 +00007159 // TODO: If this is a conversion-function-id, verify that the
7160 // destination type name (if present) resolves the same way after
7161 // instantiation as it did in the local scope.
7162
Abramo Bagnara25777432010-08-11 22:01:17 +00007163 DeclarationNameInfo NameInfo
7164 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7165 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007166 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007167
John McCallf7a1a742009-11-24 19:00:30 +00007168 if (!E->hasExplicitTemplateArgs()) {
7169 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007170 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007171 // Note: it is sufficient to compare the Name component of NameInfo:
7172 // if name has not changed, DNLoc has not changed either.
7173 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007174 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007175
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007176 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007177 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007178 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007179 }
John McCalld5532b62009-11-23 01:53:49 +00007180
7181 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007182 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7183 E->getNumTemplateArgs(),
7184 TransArgs))
7185 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007187 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007188 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007189 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007190}
7191
7192template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007193ExprResult
John McCall454feb92009-12-08 09:21:05 +00007194TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007195 // CXXConstructExprs are always implicit, so when we have a
7196 // 1-argument construction we just transform that argument.
7197 if (E->getNumArgs() == 1 ||
7198 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7199 return getDerived().TransformExpr(E->getArg(0));
7200
Douglas Gregorb98b1992009-08-11 05:31:07 +00007201 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7202
7203 QualType T = getDerived().TransformType(E->getType());
7204 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007205 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007206
7207 CXXConstructorDecl *Constructor
7208 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007209 getDerived().TransformDecl(E->getLocStart(),
7210 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007211 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007212 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007213
Douglas Gregorb98b1992009-08-11 05:31:07 +00007214 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007215 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007216 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7217 &ArgumentChanged))
7218 return ExprError();
7219
Douglas Gregorb98b1992009-08-11 05:31:07 +00007220 if (!getDerived().AlwaysRebuild() &&
7221 T == E->getType() &&
7222 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007223 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007224 // Mark the constructor as referenced.
7225 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00007226 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007227 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007228 }
Mike Stump1eb44332009-09-09 15:08:12 +00007229
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007230 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7231 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007232 move_arg(Args),
7233 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007234 E->getConstructionKind(),
7235 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007236}
Mike Stump1eb44332009-09-09 15:08:12 +00007237
Douglas Gregorb98b1992009-08-11 05:31:07 +00007238/// \brief Transform a C++ temporary-binding expression.
7239///
Douglas Gregor51326552009-12-24 18:51:59 +00007240/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7241/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007242template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007243ExprResult
John McCall454feb92009-12-08 09:21:05 +00007244TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007245 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007246}
Mike Stump1eb44332009-09-09 15:08:12 +00007247
John McCall4765fa02010-12-06 08:20:24 +00007248/// \brief Transform a C++ expression that contains cleanups that should
7249/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007250///
John McCall4765fa02010-12-06 08:20:24 +00007251/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007252/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007253template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007254ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007255TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007256 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007257}
Mike Stump1eb44332009-09-09 15:08:12 +00007258
Douglas Gregorb98b1992009-08-11 05:31:07 +00007259template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007260ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007261TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007262 CXXTemporaryObjectExpr *E) {
7263 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7264 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007265 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007266
Douglas Gregorb98b1992009-08-11 05:31:07 +00007267 CXXConstructorDecl *Constructor
7268 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007269 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007270 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007271 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007272 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007273
Douglas Gregorb98b1992009-08-11 05:31:07 +00007274 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007275 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007276 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007277 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7278 &ArgumentChanged))
7279 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007280
Douglas Gregorb98b1992009-08-11 05:31:07 +00007281 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007282 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007283 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007284 !ArgumentChanged) {
7285 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00007286 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007287 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007288 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007289
7290 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7291 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007292 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007293 E->getLocEnd());
7294}
Mike Stump1eb44332009-09-09 15:08:12 +00007295
Douglas Gregorb98b1992009-08-11 05:31:07 +00007296template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007297ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007298TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007299 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007300 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7301 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007302 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007303
Douglas Gregorb98b1992009-08-11 05:31:07 +00007304 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007305 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007306 Args.reserve(E->arg_size());
7307 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7308 &ArgumentChanged))
7309 return ExprError();
7310
Douglas Gregorb98b1992009-08-11 05:31:07 +00007311 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007312 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007313 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007314 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007315
Douglas Gregorb98b1992009-08-11 05:31:07 +00007316 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007317 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007318 E->getLParenLoc(),
7319 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007320 E->getRParenLoc());
7321}
Mike Stump1eb44332009-09-09 15:08:12 +00007322
Douglas Gregorb98b1992009-08-11 05:31:07 +00007323template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007324ExprResult
John McCall865d4472009-11-19 22:55:06 +00007325TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007326 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007327 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007328 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007329 Expr *OldBase;
7330 QualType BaseType;
7331 QualType ObjectType;
7332 if (!E->isImplicitAccess()) {
7333 OldBase = E->getBase();
7334 Base = getDerived().TransformExpr(OldBase);
7335 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007336 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007337
John McCallaa81e162009-12-01 22:10:20 +00007338 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007339 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007340 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007341 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007342 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007343 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007344 ObjectTy,
7345 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007346 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007347 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007348
John McCallb3d87482010-08-24 05:47:05 +00007349 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007350 BaseType = ((Expr*) Base.get())->getType();
7351 } else {
7352 OldBase = 0;
7353 BaseType = getDerived().TransformType(E->getBaseType());
7354 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7355 }
Mike Stump1eb44332009-09-09 15:08:12 +00007356
Douglas Gregor6cd21982009-10-20 05:58:46 +00007357 // Transform the first part of the nested-name-specifier that qualifies
7358 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007359 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007360 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007361 E->getFirstQualifierFoundInScope(),
7362 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007363
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007364 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007365 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007366 QualifierLoc
7367 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7368 ObjectType,
7369 FirstQualifierInScope);
7370 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007371 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007372 }
Mike Stump1eb44332009-09-09 15:08:12 +00007373
John McCall43fed0d2010-11-12 08:19:04 +00007374 // TODO: If this is a conversion-function-id, verify that the
7375 // destination type name (if present) resolves the same way after
7376 // instantiation as it did in the local scope.
7377
Abramo Bagnara25777432010-08-11 22:01:17 +00007378 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007379 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007380 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007381 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007382
John McCallaa81e162009-12-01 22:10:20 +00007383 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007384 // This is a reference to a member without an explicitly-specified
7385 // template argument list. Optimize for this common case.
7386 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007387 Base.get() == OldBase &&
7388 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007389 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007390 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007391 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007392 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007393
John McCall9ae2f072010-08-23 23:25:46 +00007394 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007395 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007396 E->isArrow(),
7397 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007398 QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00007399 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007400 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007401 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007402 }
7403
John McCalld5532b62009-11-23 01:53:49 +00007404 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007405 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7406 E->getNumTemplateArgs(),
7407 TransArgs))
7408 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007409
John McCall9ae2f072010-08-23 23:25:46 +00007410 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007411 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007412 E->isArrow(),
7413 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007414 QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007415 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007416 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007417 &TransArgs);
7418}
7419
7420template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007421ExprResult
John McCall454feb92009-12-08 09:21:05 +00007422TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007423 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007424 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007425 QualType BaseType;
7426 if (!Old->isImplicitAccess()) {
7427 Base = getDerived().TransformExpr(Old->getBase());
7428 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007429 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007430 BaseType = ((Expr*) Base.get())->getType();
7431 } else {
7432 BaseType = getDerived().TransformType(Old->getBaseType());
7433 }
John McCall129e2df2009-11-30 22:42:35 +00007434
Douglas Gregor4c9be892011-02-28 20:01:57 +00007435 NestedNameSpecifierLoc QualifierLoc;
7436 if (Old->getQualifierLoc()) {
7437 QualifierLoc
7438 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7439 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007440 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007441 }
7442
Abramo Bagnara25777432010-08-11 22:01:17 +00007443 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007444 Sema::LookupOrdinaryName);
7445
7446 // Transform all the decls.
7447 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7448 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007449 NamedDecl *InstD = static_cast<NamedDecl*>(
7450 getDerived().TransformDecl(Old->getMemberLoc(),
7451 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007452 if (!InstD) {
7453 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7454 // This can happen because of dependent hiding.
7455 if (isa<UsingShadowDecl>(*I))
7456 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007457 else {
7458 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007459 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007460 }
John McCall9f54ad42009-12-10 09:41:52 +00007461 }
John McCall129e2df2009-11-30 22:42:35 +00007462
7463 // Expand using declarations.
7464 if (isa<UsingDecl>(InstD)) {
7465 UsingDecl *UD = cast<UsingDecl>(InstD);
7466 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7467 E = UD->shadow_end(); I != E; ++I)
7468 R.addDecl(*I);
7469 continue;
7470 }
7471
7472 R.addDecl(InstD);
7473 }
7474
7475 R.resolveKind();
7476
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007477 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007478 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007479 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007480 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007481 Old->getMemberLoc(),
7482 Old->getNamingClass()));
7483 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007484 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007485
Douglas Gregor66c45152010-04-27 16:10:10 +00007486 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007487 }
Sean Huntc3021132010-05-05 15:23:54 +00007488
John McCall129e2df2009-11-30 22:42:35 +00007489 TemplateArgumentListInfo TransArgs;
7490 if (Old->hasExplicitTemplateArgs()) {
7491 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7492 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007493 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7494 Old->getNumTemplateArgs(),
7495 TransArgs))
7496 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007497 }
John McCallc2233c52010-01-15 08:34:02 +00007498
7499 // FIXME: to do this check properly, we will need to preserve the
7500 // first-qualifier-in-scope here, just in case we had a dependent
7501 // base (and therefore couldn't do the check) and a
7502 // nested-name-qualifier (and therefore could do the lookup).
7503 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007504
John McCall9ae2f072010-08-23 23:25:46 +00007505 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007506 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007507 Old->getOperatorLoc(),
7508 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007509 QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00007510 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007511 R,
7512 (Old->hasExplicitTemplateArgs()
7513 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007514}
7515
7516template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007517ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007518TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00007519 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00007520 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7521 if (SubExpr.isInvalid())
7522 return ExprError();
7523
7524 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007525 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007526
7527 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7528}
7529
7530template<typename Derived>
7531ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007532TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007533 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7534 if (Pattern.isInvalid())
7535 return ExprError();
7536
7537 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7538 return SemaRef.Owned(E);
7539
Douglas Gregor67fd1252011-01-14 21:20:45 +00007540 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7541 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007542}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007543
7544template<typename Derived>
7545ExprResult
7546TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7547 // If E is not value-dependent, then nothing will change when we transform it.
7548 // Note: This is an instantiation-centric view.
7549 if (!E->isValueDependent())
7550 return SemaRef.Owned(E);
7551
7552 // Note: None of the implementations of TryExpandParameterPacks can ever
7553 // produce a diagnostic when given only a single unexpanded parameter pack,
7554 // so
7555 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7556 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007557 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007558 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007559 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7560 &Unexpanded, 1,
Douglas Gregord3731192011-01-10 07:32:04 +00007561 ShouldExpand, RetainExpansion,
7562 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007563 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007564
Douglas Gregord3731192011-01-10 07:32:04 +00007565 if (!ShouldExpand || RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007566 return SemaRef.Owned(E);
7567
7568 // We now know the length of the parameter pack, so build a new expression
7569 // that stores that length.
7570 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7571 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00007572 *NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007573}
7574
Douglas Gregorbe230c32011-01-03 17:17:50 +00007575template<typename Derived>
7576ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007577TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7578 SubstNonTypeTemplateParmPackExpr *E) {
7579 // Default behavior is to do nothing with this transformation.
7580 return SemaRef.Owned(E);
7581}
7582
7583template<typename Derived>
7584ExprResult
John McCall454feb92009-12-08 09:21:05 +00007585TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007586 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007587}
7588
Mike Stump1eb44332009-09-09 15:08:12 +00007589template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007590ExprResult
John McCall454feb92009-12-08 09:21:05 +00007591TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007592 TypeSourceInfo *EncodedTypeInfo
7593 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7594 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007595 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007596
Douglas Gregorb98b1992009-08-11 05:31:07 +00007597 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007598 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007599 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007600
7601 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007602 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007603 E->getRParenLoc());
7604}
Mike Stump1eb44332009-09-09 15:08:12 +00007605
Douglas Gregorb98b1992009-08-11 05:31:07 +00007606template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007607ExprResult
John McCall454feb92009-12-08 09:21:05 +00007608TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007609 // Transform arguments.
7610 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007611 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007612 Args.reserve(E->getNumArgs());
7613 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7614 &ArgChanged))
7615 return ExprError();
7616
Douglas Gregor92e986e2010-04-22 16:44:27 +00007617 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7618 // Class message: transform the receiver type.
7619 TypeSourceInfo *ReceiverTypeInfo
7620 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7621 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007622 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007623
Douglas Gregor92e986e2010-04-22 16:44:27 +00007624 // If nothing changed, just retain the existing message send.
7625 if (!getDerived().AlwaysRebuild() &&
7626 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007627 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007628
7629 // Build a new class message send.
7630 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7631 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007632 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007633 E->getMethodDecl(),
7634 E->getLeftLoc(),
7635 move_arg(Args),
7636 E->getRightLoc());
7637 }
7638
7639 // Instance message: transform the receiver
7640 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7641 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007642 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007643 = getDerived().TransformExpr(E->getInstanceReceiver());
7644 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007645 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007646
7647 // If nothing changed, just retain the existing message send.
7648 if (!getDerived().AlwaysRebuild() &&
7649 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007650 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007651
Douglas Gregor92e986e2010-04-22 16:44:27 +00007652 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00007653 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007654 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007655 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007656 E->getMethodDecl(),
7657 E->getLeftLoc(),
7658 move_arg(Args),
7659 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007660}
7661
Mike Stump1eb44332009-09-09 15:08:12 +00007662template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007663ExprResult
John McCall454feb92009-12-08 09:21:05 +00007664TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007665 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007666}
7667
Mike Stump1eb44332009-09-09 15:08:12 +00007668template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007669ExprResult
John McCall454feb92009-12-08 09:21:05 +00007670TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007671 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007672}
7673
Mike Stump1eb44332009-09-09 15:08:12 +00007674template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007675ExprResult
John McCall454feb92009-12-08 09:21:05 +00007676TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007677 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007678 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007679 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007680 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007681
7682 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007683
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007684 // If nothing changed, just retain the existing expression.
7685 if (!getDerived().AlwaysRebuild() &&
7686 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007687 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007688
John McCall9ae2f072010-08-23 23:25:46 +00007689 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007690 E->getLocation(),
7691 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007692}
7693
Mike Stump1eb44332009-09-09 15:08:12 +00007694template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007695ExprResult
John McCall454feb92009-12-08 09:21:05 +00007696TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00007697 // 'super' and types never change. Property never changes. Just
7698 // retain the existing expression.
7699 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00007700 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00007701
Douglas Gregore3303542010-04-26 20:47:02 +00007702 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007703 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00007704 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007705 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007706
Douglas Gregore3303542010-04-26 20:47:02 +00007707 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007708
Douglas Gregore3303542010-04-26 20:47:02 +00007709 // If nothing changed, just retain the existing expression.
7710 if (!getDerived().AlwaysRebuild() &&
7711 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007712 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007713
John McCall12f78a62010-12-02 01:19:52 +00007714 if (E->isExplicitProperty())
7715 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7716 E->getExplicitProperty(),
7717 E->getLocation());
7718
7719 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7720 E->getType(),
7721 E->getImplicitPropertyGetter(),
7722 E->getImplicitPropertySetter(),
7723 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007724}
7725
Mike Stump1eb44332009-09-09 15:08:12 +00007726template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007727ExprResult
John McCall454feb92009-12-08 09:21:05 +00007728TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007729 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007730 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007731 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007732 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007733
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007734 // If nothing changed, just retain the existing expression.
7735 if (!getDerived().AlwaysRebuild() &&
7736 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007737 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007738
John McCall9ae2f072010-08-23 23:25:46 +00007739 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007740 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007741}
7742
Mike Stump1eb44332009-09-09 15:08:12 +00007743template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007744ExprResult
John McCall454feb92009-12-08 09:21:05 +00007745TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007746 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007747 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007748 SubExprs.reserve(E->getNumSubExprs());
7749 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7750 SubExprs, &ArgumentChanged))
7751 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007752
Douglas Gregorb98b1992009-08-11 05:31:07 +00007753 if (!getDerived().AlwaysRebuild() &&
7754 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007755 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007756
Douglas Gregorb98b1992009-08-11 05:31:07 +00007757 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7758 move_arg(SubExprs),
7759 E->getRParenLoc());
7760}
7761
Mike Stump1eb44332009-09-09 15:08:12 +00007762template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007763ExprResult
John McCall454feb92009-12-08 09:21:05 +00007764TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00007765 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007766
John McCallc6ac9c32011-02-04 18:33:18 +00007767 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7768 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7769
7770 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanianff365592011-05-05 17:18:12 +00007771 // We built a new blockScopeInfo in call to ActOnBlockStart
7772 // in above, CapturesCXXThis need be set here from the block
7773 // expression.
7774 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7775
John McCallc6ac9c32011-02-04 18:33:18 +00007776 llvm::SmallVector<ParmVarDecl*, 4> params;
7777 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007778
7779 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00007780 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7781 oldBlock->param_begin(),
7782 oldBlock->param_size(),
7783 0, paramTypes, &params))
Douglas Gregora779d9c2011-01-19 21:32:01 +00007784 return true;
John McCallc6ac9c32011-02-04 18:33:18 +00007785
7786 const FunctionType *exprFunctionType = E->getFunctionType();
7787 QualType exprResultType = exprFunctionType->getResultType();
7788 if (!exprResultType.isNull()) {
7789 if (!exprResultType->isDependentType())
7790 blockScope->ReturnType = exprResultType;
7791 else if (exprResultType != getSema().Context.DependentTy)
7792 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007793 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00007794
7795 // If the return type has not been determined yet, leave it as a dependent
7796 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00007797 if (blockScope->ReturnType.isNull())
7798 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007799
7800 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00007801 if (blockScope->ReturnType->isObjCObjectType()) {
7802 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00007803 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00007804 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007805 return ExprError();
7806 }
John McCall711c52b2011-01-05 12:14:39 +00007807
John McCallc6ac9c32011-02-04 18:33:18 +00007808 QualType functionType = getDerived().RebuildFunctionProtoType(
7809 blockScope->ReturnType,
7810 paramTypes.data(),
7811 paramTypes.size(),
7812 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00007813 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00007814 exprFunctionType->getExtInfo());
7815 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00007816
7817 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00007818 if (!params.empty())
7819 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregora779d9c2011-01-19 21:32:01 +00007820
7821 // If the return type wasn't explicitly set, it will have been marked as a
7822 // dependent type (DependentTy); clear out the return type setting so
7823 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00007824 if (blockScope->ReturnType == getSema().Context.DependentTy)
7825 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00007826
John McCall711c52b2011-01-05 12:14:39 +00007827 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00007828 StmtResult body = getDerived().TransformStmt(E->getBody());
7829 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00007830 return ExprError();
7831
John McCallc6ac9c32011-02-04 18:33:18 +00007832#ifndef NDEBUG
7833 // In builds with assertions, make sure that we captured everything we
7834 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00007835 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
7836 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7837 e = oldBlock->capture_end(); i != e; ++i) {
7838 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00007839
Douglas Gregorfc921372011-05-20 15:32:55 +00007840 // Ignore parameter packs.
7841 if (isa<ParmVarDecl>(oldCapture) &&
7842 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7843 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00007844
Douglas Gregorfc921372011-05-20 15:32:55 +00007845 VarDecl *newCapture =
7846 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7847 oldCapture));
7848 assert(blockScope->CaptureMap.count(newCapture));
7849 }
John McCallc6ac9c32011-02-04 18:33:18 +00007850 }
7851#endif
7852
7853 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7854 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007855}
7856
Mike Stump1eb44332009-09-09 15:08:12 +00007857template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007858ExprResult
John McCall454feb92009-12-08 09:21:05 +00007859TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007860 ValueDecl *ND
7861 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7862 E->getDecl()));
7863 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00007864 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00007865
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007866 if (!getDerived().AlwaysRebuild() &&
7867 ND == E->getDecl()) {
7868 // Mark it referenced in the new context regardless.
7869 // FIXME: this is a bit instantiation-specific.
7870 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7871
John McCall3fa5cae2010-10-26 07:05:15 +00007872 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007873 }
7874
Abramo Bagnara25777432010-08-11 22:01:17 +00007875 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00007876 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00007877 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007878}
Mike Stump1eb44332009-09-09 15:08:12 +00007879
Tanya Lattner61eee0c2011-06-04 00:47:47 +00007880template<typename Derived>
7881ExprResult
7882TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
7883 assert(false && "Cannot transform asType expressions yet");
7884 return SemaRef.Owned(E);
7885}
7886
Douglas Gregorb98b1992009-08-11 05:31:07 +00007887//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00007888// Type reconstruction
7889//===----------------------------------------------------------------------===//
7890
Mike Stump1eb44332009-09-09 15:08:12 +00007891template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007892QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7893 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007894 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007895 getDerived().getBaseEntity());
7896}
7897
Mike Stump1eb44332009-09-09 15:08:12 +00007898template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007899QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7900 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007901 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007902 getDerived().getBaseEntity());
7903}
7904
Mike Stump1eb44332009-09-09 15:08:12 +00007905template<typename Derived>
7906QualType
John McCall85737a72009-10-30 00:06:24 +00007907TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7908 bool WrittenAsLValue,
7909 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007910 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00007911 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007912}
7913
7914template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007915QualType
John McCall85737a72009-10-30 00:06:24 +00007916TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7917 QualType ClassType,
7918 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007919 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00007920 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007921}
7922
7923template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007924QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00007925TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7926 ArrayType::ArraySizeModifier SizeMod,
7927 const llvm::APInt *Size,
7928 Expr *SizeExpr,
7929 unsigned IndexTypeQuals,
7930 SourceRange BracketsRange) {
7931 if (SizeExpr || !Size)
7932 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7933 IndexTypeQuals, BracketsRange,
7934 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00007935
7936 QualType Types[] = {
7937 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7938 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7939 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00007940 };
7941 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7942 QualType SizeType;
7943 for (unsigned I = 0; I != NumTypes; ++I)
7944 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7945 SizeType = Types[I];
7946 break;
7947 }
Mike Stump1eb44332009-09-09 15:08:12 +00007948
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007949 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7950 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00007951 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007952 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00007953 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007954}
Mike Stump1eb44332009-09-09 15:08:12 +00007955
Douglas Gregor577f75a2009-08-04 16:50:30 +00007956template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007957QualType
7958TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007959 ArrayType::ArraySizeModifier SizeMod,
7960 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00007961 unsigned IndexTypeQuals,
7962 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007963 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00007964 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007965}
7966
7967template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007968QualType
Mike Stump1eb44332009-09-09 15:08:12 +00007969TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007970 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00007971 unsigned IndexTypeQuals,
7972 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007973 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00007974 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007975}
Mike Stump1eb44332009-09-09 15:08:12 +00007976
Douglas Gregor577f75a2009-08-04 16:50:30 +00007977template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007978QualType
7979TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007980 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007981 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007982 unsigned IndexTypeQuals,
7983 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007984 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007985 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007986 IndexTypeQuals, BracketsRange);
7987}
7988
7989template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007990QualType
7991TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007992 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007993 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007994 unsigned IndexTypeQuals,
7995 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007996 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007997 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007998 IndexTypeQuals, BracketsRange);
7999}
8000
8001template<typename Derived>
8002QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008003 unsigned NumElements,
8004 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008005 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008006 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008007}
Mike Stump1eb44332009-09-09 15:08:12 +00008008
Douglas Gregor577f75a2009-08-04 16:50:30 +00008009template<typename Derived>
8010QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8011 unsigned NumElements,
8012 SourceLocation AttributeLoc) {
8013 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8014 NumElements, true);
8015 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008016 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8017 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008018 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008019}
Mike Stump1eb44332009-09-09 15:08:12 +00008020
Douglas Gregor577f75a2009-08-04 16:50:30 +00008021template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008022QualType
8023TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008024 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008025 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008026 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008027}
Mike Stump1eb44332009-09-09 15:08:12 +00008028
Douglas Gregor577f75a2009-08-04 16:50:30 +00008029template<typename Derived>
8030QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008031 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008032 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008033 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00008034 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008035 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008036 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008037 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00008038 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008039 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008040 getDerived().getBaseEntity(),
8041 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008042}
Mike Stump1eb44332009-09-09 15:08:12 +00008043
Douglas Gregor577f75a2009-08-04 16:50:30 +00008044template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008045QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8046 return SemaRef.Context.getFunctionNoProtoType(T);
8047}
8048
8049template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008050QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8051 assert(D && "no decl found");
8052 if (D->isInvalidDecl()) return QualType();
8053
Douglas Gregor92e986e2010-04-22 16:44:27 +00008054 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008055 TypeDecl *Ty;
8056 if (isa<UsingDecl>(D)) {
8057 UsingDecl *Using = cast<UsingDecl>(D);
8058 assert(Using->isTypeName() &&
8059 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8060
8061 // A valid resolved using typename decl points to exactly one type decl.
8062 assert(++Using->shadow_begin() == Using->shadow_end());
8063 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008064
John McCalled976492009-12-04 22:46:56 +00008065 } else {
8066 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8067 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8068 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8069 }
8070
8071 return SemaRef.Context.getTypeDeclType(Ty);
8072}
8073
8074template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008075QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8076 SourceLocation Loc) {
8077 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008078}
8079
8080template<typename Derived>
8081QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8082 return SemaRef.Context.getTypeOfType(Underlying);
8083}
8084
8085template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008086QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8087 SourceLocation Loc) {
8088 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008089}
8090
8091template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008092QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8093 UnaryTransformType::UTTKind UKind,
8094 SourceLocation Loc) {
8095 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8096}
8097
8098template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008099QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008100 TemplateName Template,
8101 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008102 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008103 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008104}
Mike Stump1eb44332009-09-09 15:08:12 +00008105
Douglas Gregordcee1a12009-08-06 05:28:30 +00008106template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008107TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008108TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008109 bool TemplateKW,
8110 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008111 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008112 Template);
8113}
8114
8115template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008116TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008117TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8118 const IdentifierInfo &Name,
8119 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008120 QualType ObjectType,
8121 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008122 UnqualifiedId TemplateName;
8123 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008124 Sema::TemplateTy Template;
8125 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008126 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008127 SS,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008128 TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008129 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008130 /*EnteringContext=*/false,
8131 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008132 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008133}
Mike Stump1eb44332009-09-09 15:08:12 +00008134
Douglas Gregorb98b1992009-08-11 05:31:07 +00008135template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008136TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008137TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008138 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008139 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008140 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008141 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008142 // FIXME: Bogus location information.
8143 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8144 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008145 Sema::TemplateTy Template;
8146 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008147 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008148 SS,
8149 Name,
John McCallb3d87482010-08-24 05:47:05 +00008150 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008151 /*EnteringContext=*/false,
8152 Template);
8153 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008154}
Sean Huntc3021132010-05-05 15:23:54 +00008155
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008156template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008157ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008158TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8159 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008160 Expr *OrigCallee,
8161 Expr *First,
8162 Expr *Second) {
8163 Expr *Callee = OrigCallee->IgnoreParenCasts();
8164 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008165
Douglas Gregorb98b1992009-08-11 05:31:07 +00008166 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008167 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008168 if (!First->getType()->isOverloadableType() &&
8169 !Second->getType()->isOverloadableType())
8170 return getSema().CreateBuiltinArraySubscriptExpr(First,
8171 Callee->getLocStart(),
8172 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008173 } else if (Op == OO_Arrow) {
8174 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008175 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8176 } else if (Second == 0 || isPostIncDec) {
8177 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008178 // The argument is not of overloadable type, so try to create a
8179 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008180 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008181 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008182
John McCall9ae2f072010-08-23 23:25:46 +00008183 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008184 }
8185 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008186 if (!First->getType()->isOverloadableType() &&
8187 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008188 // Neither of the arguments is an overloadable type, so try to
8189 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008190 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008191 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008192 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008193 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008194 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008195
Douglas Gregorb98b1992009-08-11 05:31:07 +00008196 return move(Result);
8197 }
8198 }
Mike Stump1eb44332009-09-09 15:08:12 +00008199
8200 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008201 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008202 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008203
John McCall9ae2f072010-08-23 23:25:46 +00008204 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008205 assert(ULE->requiresADL());
8206
8207 // FIXME: Do we have to check
8208 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008209 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008210 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008211 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008212 }
Mike Stump1eb44332009-09-09 15:08:12 +00008213
Douglas Gregorb98b1992009-08-11 05:31:07 +00008214 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008215 Expr *Args[2] = { First, Second };
8216 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008217
Douglas Gregorb98b1992009-08-11 05:31:07 +00008218 // Create the overloaded operator invocation for unary operators.
8219 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008220 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008221 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008222 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008223 }
Mike Stump1eb44332009-09-09 15:08:12 +00008224
Sebastian Redlf322ed62009-10-29 20:17:01 +00008225 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00008226 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00008227 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008228 First,
8229 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00008230
Douglas Gregorb98b1992009-08-11 05:31:07 +00008231 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008232 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008233 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008234 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8235 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008236 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008237
Mike Stump1eb44332009-09-09 15:08:12 +00008238 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008239}
Mike Stump1eb44332009-09-09 15:08:12 +00008240
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008241template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008242ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008243TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008244 SourceLocation OperatorLoc,
8245 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008246 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008247 TypeSourceInfo *ScopeType,
8248 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008249 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008250 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008251 QualType BaseType = Base->getType();
8252 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008253 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008254 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008255 !BaseType->getAs<PointerType>()->getPointeeType()
8256 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008257 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008258 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008259 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008260 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008261 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008262 /*FIXME?*/true);
8263 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008264
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008265 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008266 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8267 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8268 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8269 NameInfo.setNamedTypeInfo(DestroyedType);
8270
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008271 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008272
John McCall9ae2f072010-08-23 23:25:46 +00008273 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008274 OperatorLoc, isArrow,
8275 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008276 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008277 /*TemplateArgs*/ 0);
8278}
8279
Douglas Gregor577f75a2009-08-04 16:50:30 +00008280} // end namespace clang
8281
8282#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H