blob: 5485dfb7e4aa43d591c26d079e176ee09a793489 [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"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000024#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000025#include "clang/AST/ExprCXX.h"
26#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000027#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000030#include "clang/Sema/Ownership.h"
31#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000032#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000033#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000034#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000035#include <algorithm>
36
37namespace clang {
John McCall781472f2010-08-25 08:40:02 +000038using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000039
Douglas Gregor577f75a2009-08-04 16:50:30 +000040/// \brief A semantic tree transformation that allows one to transform one
41/// abstract syntax tree into another.
42///
Mike Stump1eb44332009-09-09 15:08:12 +000043/// A new tree transformation is defined by creating a new subclass \c X of
44/// \c TreeTransform<X> and then overriding certain operations to provide
45/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000046/// instantiation is implemented as a tree transformation where the
47/// transformation of TemplateTypeParmType nodes involves substituting the
48/// template arguments for their corresponding template parameters; a similar
49/// transformation is performed for non-type template parameters and
50/// template template parameters.
51///
52/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000053/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000054/// override any of the transformation or rebuild operators by providing an
55/// operation with the same signature as the default implementation. The
56/// overridding function should not be virtual.
57///
58/// Semantic tree transformations are split into two stages, either of which
59/// can be replaced by a subclass. The "transform" step transforms an AST node
60/// or the parts of an AST node using the various transformation functions,
61/// then passes the pieces on to the "rebuild" step, which constructs a new AST
62/// node of the appropriate kind from the pieces. The default transformation
63/// routines recursively transform the operands to composite AST nodes (e.g.,
64/// the pointee type of a PointerType node) and, if any of those operand nodes
65/// were changed by the transformation, invokes the rebuild operation to create
66/// a new AST node.
67///
Mike Stump1eb44332009-09-09 15:08:12 +000068/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000069/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000070/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
71/// TransformTemplateName(), or TransformTemplateArgument() with entirely
72/// new implementations.
73///
74/// For more fine-grained transformations, subclasses can replace any of the
75/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000076/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000077/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000078/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// parameters. Additionally, subclasses can override the \c RebuildXXX
80/// functions to control how AST nodes are rebuilt when their operands change.
81/// By default, \c TreeTransform will invoke semantic analysis to rebuild
82/// AST nodes. However, certain other tree transformations (e.g, cloning) may
83/// be able to use more efficient rebuild steps.
84///
85/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000086/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000087/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
88/// operands have not changed (\c AlwaysRebuild()), and customize the
89/// default locations and entity names used for type-checking
90/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000091template<typename Derived>
92class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000093 /// \brief Private RAII object that helps us forget and then re-remember
94 /// the template argument corresponding to a partially-substituted parameter
95 /// pack.
96 class ForgetPartiallySubstitutedPackRAII {
97 Derived &Self;
98 TemplateArgument Old;
99
100 public:
101 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
102 Old = Self.ForgetPartiallySubstitutedPack();
103 }
104
105 ~ForgetPartiallySubstitutedPackRAII() {
106 Self.RememberPartiallySubstitutedPack(Old);
107 }
108 };
109
Douglas Gregor577f75a2009-08-04 16:50:30 +0000110protected:
111 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000112
Mike Stump1eb44332009-09-09 15:08:12 +0000113public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000114 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000115 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000116
Douglas Gregor577f75a2009-08-04 16:50:30 +0000117 /// \brief Retrieves a reference to the derived class.
118 Derived &getDerived() { return static_cast<Derived&>(*this); }
119
120 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000121 const Derived &getDerived() const {
122 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000123 }
124
John McCall60d7b3a2010-08-24 06:29:42 +0000125 static inline ExprResult Owned(Expr *E) { return E; }
126 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000127
Douglas Gregor577f75a2009-08-04 16:50:30 +0000128 /// \brief Retrieves a reference to the semantic analysis object used for
129 /// this tree transform.
130 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000131
Douglas Gregor577f75a2009-08-04 16:50:30 +0000132 /// \brief Whether the transformation should always rebuild AST nodes, even
133 /// if none of the children have changed.
134 ///
135 /// Subclasses may override this function to specify when the transformation
136 /// should rebuild all AST nodes.
137 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000138
Douglas Gregor577f75a2009-08-04 16:50:30 +0000139 /// \brief Returns the location of the entity being transformed, if that
140 /// information was not available elsewhere in the AST.
141 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000142 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000143 /// provide an alternative implementation that provides better location
144 /// information.
145 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000146
Douglas Gregor577f75a2009-08-04 16:50:30 +0000147 /// \brief Returns the name of the entity being transformed, if that
148 /// information was not available elsewhere in the AST.
149 ///
150 /// By default, returns an empty name. Subclasses can provide an alternative
151 /// implementation with a more precise name.
152 DeclarationName getBaseEntity() { return DeclarationName(); }
153
Douglas Gregorb98b1992009-08-11 05:31:07 +0000154 /// \brief Sets the "base" location and entity when that
155 /// information is known based on another transformation.
156 ///
157 /// By default, the source location and entity are ignored. Subclasses can
158 /// override this function to provide a customized implementation.
159 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000160
Douglas Gregorb98b1992009-08-11 05:31:07 +0000161 /// \brief RAII object that temporarily sets the base location and entity
162 /// used for reporting diagnostics in types.
163 class TemporaryBase {
164 TreeTransform &Self;
165 SourceLocation OldLocation;
166 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000167
Douglas Gregorb98b1992009-08-11 05:31:07 +0000168 public:
169 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000170 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000171 OldLocation = Self.getDerived().getBaseLocation();
172 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregorae201f72011-01-25 17:51:48 +0000173
174 if (Location.isValid())
175 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000176 }
Mike Stump1eb44332009-09-09 15:08:12 +0000177
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 ~TemporaryBase() {
179 Self.getDerived().setBase(OldLocation, OldEntity);
180 }
181 };
Mike Stump1eb44332009-09-09 15:08:12 +0000182
183 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000184 /// transformed.
185 ///
186 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000187 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000188 /// not change. For example, template instantiation need not traverse
189 /// non-dependent types.
190 bool AlreadyTransformed(QualType T) {
191 return T.isNull();
192 }
193
Douglas Gregor6eef5192009-12-14 19:27:10 +0000194 /// \brief Determine whether the given call argument should be dropped, e.g.,
195 /// because it is a default argument.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine to
198 /// determine which kinds of call arguments get dropped. By default,
199 /// CXXDefaultArgument nodes are dropped (prior to transformation).
200 bool DropCallArgument(Expr *E) {
201 return E->isDefaultArgument();
202 }
Sean Huntc3021132010-05-05 15:23:54 +0000203
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000204 /// \brief Determine whether we should expand a pack expansion with the
205 /// given set of parameter packs into separate arguments by repeatedly
206 /// transforming the pattern.
207 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000208 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000209 /// Subclasses can override this routine to provide different behavior.
210 ///
211 /// \param EllipsisLoc The location of the ellipsis that identifies the
212 /// pack expansion.
213 ///
214 /// \param PatternRange The source range that covers the entire pattern of
215 /// the pack expansion.
216 ///
217 /// \param Unexpanded The set of unexpanded parameter packs within the
218 /// pattern.
219 ///
220 /// \param NumUnexpanded The number of unexpanded parameter packs in
221 /// \p Unexpanded.
222 ///
223 /// \param ShouldExpand Will be set to \c true if the transformer should
224 /// expand the corresponding pack expansions into separate arguments. When
225 /// set, \c NumExpansions must also be set.
226 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000227 /// \param RetainExpansion Whether the caller should add an unexpanded
228 /// pack expansion after all of the expanded arguments. This is used
229 /// when extending explicitly-specified template argument packs per
230 /// C++0x [temp.arg.explicit]p9.
231 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000232 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000233 /// the expanded form of the corresponding pack expansion. This is both an
234 /// input and an output parameter, which can be set by the caller if the
235 /// number of expansions is known a priori (e.g., due to a prior substitution)
236 /// and will be set by the callee when the number of expansions is known.
237 /// The callee must set this value when \c ShouldExpand is \c true; it may
238 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000239 ///
240 /// \returns true if an error occurred (e.g., because the parameter packs
241 /// are to be instantiated with arguments of different lengths), false
242 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
243 /// must be set.
244 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
245 SourceRange PatternRange,
246 const UnexpandedParameterPack *Unexpanded,
247 unsigned NumUnexpanded,
248 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000249 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000250 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000251 ShouldExpand = false;
252 return false;
253 }
254
Douglas Gregord3731192011-01-10 07:32:04 +0000255 /// \brief "Forget" about the partially-substituted pack template argument,
256 /// when performing an instantiation that must preserve the parameter pack
257 /// use.
258 ///
259 /// This routine is meant to be overridden by the template instantiator.
260 TemplateArgument ForgetPartiallySubstitutedPack() {
261 return TemplateArgument();
262 }
263
264 /// \brief "Remember" the partially-substituted pack template argument
265 /// after performing an instantiation that must preserve the parameter pack
266 /// use.
267 ///
268 /// This routine is meant to be overridden by the template instantiator.
269 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
270
Douglas Gregor12c9c002011-01-07 16:43:16 +0000271 /// \brief Note to the derived class when a function parameter pack is
272 /// being expanded.
273 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
274
Douglas Gregor577f75a2009-08-04 16:50:30 +0000275 /// \brief Transforms the given type into another type.
276 ///
John McCalla2becad2009-10-21 00:40:46 +0000277 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000278 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000279 /// function. This is expensive, but we don't mind, because
280 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000281 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000282 ///
283 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000284 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000285
John McCalla2becad2009-10-21 00:40:46 +0000286 /// \brief Transforms the given type-with-location into a new
287 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000288 ///
John McCalla2becad2009-10-21 00:40:46 +0000289 /// By default, this routine transforms a type by delegating to the
290 /// appropriate TransformXXXType to build a new type. Subclasses
291 /// may override this function (to take over all type
292 /// transformations) or some set of the TransformXXXType functions
293 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000294 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000295
296 /// \brief Transform the given type-with-location into a new
297 /// type, collecting location information in the given builder
298 /// as necessary.
299 ///
John McCall43fed0d2010-11-12 08:19:04 +0000300 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000301
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000302 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000303 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000304 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000305 /// appropriate TransformXXXStmt function to transform a specific kind of
306 /// statement or the TransformExpr() function to transform an expression.
307 /// Subclasses may override this function to transform statements using some
308 /// other mechanism.
309 ///
310 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000311 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000312
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000313 /// \brief Transform the given expression.
314 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000315 /// By default, this routine transforms an expression by delegating to the
316 /// appropriate TransformXXXExpr function to build a new expression.
317 /// Subclasses may override this function to transform expressions using some
318 /// other mechanism.
319 ///
320 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000321 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000322
Douglas Gregoraa165f82011-01-03 19:04:46 +0000323 /// \brief Transform the given list of expressions.
324 ///
325 /// This routine transforms a list of expressions by invoking
326 /// \c TransformExpr() for each subexpression. However, it also provides
327 /// support for variadic templates by expanding any pack expansions (if the
328 /// derived class permits such expansion) along the way. When pack expansions
329 /// are present, the number of outputs may not equal the number of inputs.
330 ///
331 /// \param Inputs The set of expressions to be transformed.
332 ///
333 /// \param NumInputs The number of expressions in \c Inputs.
334 ///
335 /// \param IsCall If \c true, then this transform is being performed on
336 /// function-call arguments, and any arguments that should be dropped, will
337 /// be.
338 ///
339 /// \param Outputs The transformed input expressions will be added to this
340 /// vector.
341 ///
342 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
343 /// due to transformation.
344 ///
345 /// \returns true if an error occurred, false otherwise.
346 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
347 llvm::SmallVectorImpl<Expr *> &Outputs,
348 bool *ArgChanged = 0);
349
Douglas Gregor577f75a2009-08-04 16:50:30 +0000350 /// \brief Transform the given declaration, which is referenced from a type
351 /// or expression.
352 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000353 /// By default, acts as the identity function on declarations. Subclasses
354 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000355 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000356
357 /// \brief Transform the definition of the given declaration.
358 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000359 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000360 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000361 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
362 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000363 }
Mike Stump1eb44332009-09-09 15:08:12 +0000364
Douglas Gregor6cd21982009-10-20 05:58:46 +0000365 /// \brief Transform the given declaration, which was the first part of a
366 /// nested-name-specifier in a member access expression.
367 ///
Sean Huntc3021132010-05-05 15:23:54 +0000368 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000369 /// identifier in a nested-name-specifier of a member access expression, e.g.,
370 /// the \c T in \c x->T::member
371 ///
372 /// By default, invokes TransformDecl() to transform the declaration.
373 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000374 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
375 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000376 }
Sean Huntc3021132010-05-05 15:23:54 +0000377
Douglas Gregor577f75a2009-08-04 16:50:30 +0000378 /// \brief Transform the given nested-name-specifier.
379 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000380 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000381 /// nested-name-specifier. Subclasses may override this function to provide
382 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000383 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000384 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000385 QualType ObjectType = QualType(),
386 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000387
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000388 /// \brief Transform the given nested-name-specifier with source-location
389 /// information.
390 ///
391 /// By default, transforms all of the types and declarations within the
392 /// nested-name-specifier. Subclasses may override this function to provide
393 /// alternate behavior.
394 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
395 NestedNameSpecifierLoc NNS,
396 QualType ObjectType = QualType(),
397 NamedDecl *FirstQualifierInScope = 0);
398
Douglas Gregor81499bb2009-09-03 22:13:48 +0000399 /// \brief Transform the given declaration name.
400 ///
401 /// By default, transforms the types of conversion function, constructor,
402 /// and destructor names and then (if needed) rebuilds the declaration name.
403 /// Identifiers and selectors are returned unmodified. Sublcasses may
404 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000405 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000406 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000407
Douglas Gregor577f75a2009-08-04 16:50:30 +0000408 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000409 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000410 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000411 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000412 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000413 TemplateName TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +0000414 QualType ObjectType = QualType(),
415 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000416
Douglas Gregor577f75a2009-08-04 16:50:30 +0000417 /// \brief Transform the given template argument.
418 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000419 /// By default, this operation transforms the type, expression, or
420 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000421 /// new template argument from the transformed result. Subclasses may
422 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000423 ///
424 /// Returns true if there was an error.
425 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
426 TemplateArgumentLoc &Output);
427
Douglas Gregorfcc12532010-12-20 17:31:10 +0000428 /// \brief Transform the given set of template arguments.
429 ///
430 /// By default, this operation transforms all of the template arguments
431 /// in the input set using \c TransformTemplateArgument(), and appends
432 /// the transformed arguments to the output list.
433 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000434 /// Note that this overload of \c TransformTemplateArguments() is merely
435 /// a convenience function. Subclasses that wish to override this behavior
436 /// should override the iterator-based member template version.
437 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000438 /// \param Inputs The set of template arguments to be transformed.
439 ///
440 /// \param NumInputs The number of template arguments in \p Inputs.
441 ///
442 /// \param Outputs The set of transformed template arguments output by this
443 /// routine.
444 ///
445 /// Returns true if an error occurred.
446 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
447 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000448 TemplateArgumentListInfo &Outputs) {
449 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
450 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000451
452 /// \brief Transform the given set of template arguments.
453 ///
454 /// By default, this operation transforms all of the template arguments
455 /// in the input set using \c TransformTemplateArgument(), and appends
456 /// the transformed arguments to the output list.
457 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000458 /// \param First An iterator to the first template argument.
459 ///
460 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000461 ///
462 /// \param Outputs The set of transformed template arguments output by this
463 /// routine.
464 ///
465 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000466 template<typename InputIterator>
467 bool TransformTemplateArguments(InputIterator First,
468 InputIterator Last,
469 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000470
John McCall833ca992009-10-29 08:12:44 +0000471 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
472 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
473 TemplateArgumentLoc &ArgLoc);
474
John McCalla93c9342009-12-07 02:54:59 +0000475 /// \brief Fakes up a TypeSourceInfo for a type.
476 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
477 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000478 getDerived().getBaseLocation());
479 }
Mike Stump1eb44332009-09-09 15:08:12 +0000480
John McCalla2becad2009-10-21 00:40:46 +0000481#define ABSTRACT_TYPELOC(CLASS, PARENT)
482#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000483 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000484#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000485
John McCall43fed0d2010-11-12 08:19:04 +0000486 QualType
487 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
488 TemplateSpecializationTypeLoc TL,
489 TemplateName Template);
490
491 QualType
492 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
493 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregora88f09f2011-02-28 17:23:35 +0000494 TemplateName Template);
495
496 QualType
497 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
498 DependentTemplateSpecializationTypeLoc TL,
John McCall43fed0d2010-11-12 08:19:04 +0000499 NestedNameSpecifier *Prefix);
500
John McCall21ef0fa2010-03-11 09:03:00 +0000501 /// \brief Transforms the parameters of a function type into the
502 /// given vectors.
503 ///
504 /// The result vectors should be kept in sync; null entries in the
505 /// variables vector are acceptable.
506 ///
507 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000508 bool TransformFunctionTypeParams(SourceLocation Loc,
509 ParmVarDecl **Params, unsigned NumParams,
510 const QualType *ParamTypes,
John McCall21ef0fa2010-03-11 09:03:00 +0000511 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregora009b592011-01-07 00:20:55 +0000512 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000513
514 /// \brief Transforms a single function-type parameter. Return null
515 /// on error.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000516 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
517 llvm::Optional<unsigned> NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +0000518
John McCall43fed0d2010-11-12 08:19:04 +0000519 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000520
John McCall60d7b3a2010-08-24 06:29:42 +0000521 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
522 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000523
Douglas Gregor43959a92009-08-20 07:17:43 +0000524#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000525 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000526#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000527 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000528#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000529#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000530
Douglas Gregor577f75a2009-08-04 16:50:30 +0000531 /// \brief Build a new pointer type given its pointee type.
532 ///
533 /// By default, performs semantic analysis when building the pointer type.
534 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000535 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000536
537 /// \brief Build a new block pointer type given its pointee type.
538 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000539 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000540 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000541 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000542
John McCall85737a72009-10-30 00:06:24 +0000543 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000544 ///
John McCall85737a72009-10-30 00:06:24 +0000545 /// By default, performs semantic analysis when building the
546 /// reference type. Subclasses may override this routine to provide
547 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000548 ///
John McCall85737a72009-10-30 00:06:24 +0000549 /// \param LValue whether the type was written with an lvalue sigil
550 /// or an rvalue sigil.
551 QualType RebuildReferenceType(QualType ReferentType,
552 bool LValue,
553 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000554
Douglas Gregor577f75a2009-08-04 16:50:30 +0000555 /// \brief Build a new member pointer type given the pointee type and the
556 /// class type it refers into.
557 ///
558 /// By default, performs semantic analysis when building the member pointer
559 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000560 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
561 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000562
Douglas Gregor577f75a2009-08-04 16:50:30 +0000563 /// \brief Build a new array type given the element type, size
564 /// modifier, size of the array (if known), size expression, and index type
565 /// qualifiers.
566 ///
567 /// By default, performs semantic analysis when building the array type.
568 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000569 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000570 QualType RebuildArrayType(QualType ElementType,
571 ArrayType::ArraySizeModifier SizeMod,
572 const llvm::APInt *Size,
573 Expr *SizeExpr,
574 unsigned IndexTypeQuals,
575 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000576
Douglas Gregor577f75a2009-08-04 16:50:30 +0000577 /// \brief Build a new constant array type given the element type, size
578 /// modifier, (known) size of the array, and index type qualifiers.
579 ///
580 /// By default, performs semantic analysis when building the array type.
581 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000582 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000583 ArrayType::ArraySizeModifier SizeMod,
584 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000585 unsigned IndexTypeQuals,
586 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000587
Douglas Gregor577f75a2009-08-04 16:50:30 +0000588 /// \brief Build a new incomplete array type given the element type, size
589 /// modifier, and index type qualifiers.
590 ///
591 /// By default, performs semantic analysis when building the array type.
592 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000593 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000594 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000595 unsigned IndexTypeQuals,
596 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000597
Mike Stump1eb44332009-09-09 15:08:12 +0000598 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000599 /// size modifier, size expression, and index type qualifiers.
600 ///
601 /// By default, performs semantic analysis when building the array type.
602 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000603 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000604 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000605 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000606 unsigned IndexTypeQuals,
607 SourceRange BracketsRange);
608
Mike Stump1eb44332009-09-09 15:08:12 +0000609 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000610 /// size modifier, size expression, and index type qualifiers.
611 ///
612 /// By default, performs semantic analysis when building the array type.
613 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000614 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000615 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000616 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000617 unsigned IndexTypeQuals,
618 SourceRange BracketsRange);
619
620 /// \brief Build a new vector type given the element type and
621 /// number of elements.
622 ///
623 /// By default, performs semantic analysis when building the vector type.
624 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000625 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000626 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000627
Douglas Gregor577f75a2009-08-04 16:50:30 +0000628 /// \brief Build a new extended vector type given the element type and
629 /// number of elements.
630 ///
631 /// By default, performs semantic analysis when building the vector type.
632 /// Subclasses may override this routine to provide different behavior.
633 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
634 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000635
636 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000637 /// given the element type and 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.
Mike Stump1eb44332009-09-09 15:08:12 +0000641 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000642 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000643 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000644
Douglas Gregor577f75a2009-08-04 16:50:30 +0000645 /// \brief Build a new function type.
646 ///
647 /// By default, performs semantic analysis when building the function type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000650 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000651 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000652 bool Variadic, unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000653 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000654 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000655
John McCalla2becad2009-10-21 00:40:46 +0000656 /// \brief Build a new unprototyped function type.
657 QualType RebuildFunctionNoProtoType(QualType ResultType);
658
John McCalled976492009-12-04 22:46:56 +0000659 /// \brief Rebuild an unresolved typename type, given the decl that
660 /// the UnresolvedUsingTypenameDecl was transformed to.
661 QualType RebuildUnresolvedUsingType(Decl *D);
662
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663 /// \brief Build a new typedef type.
664 QualType RebuildTypedefType(TypedefDecl *Typedef) {
665 return SemaRef.Context.getTypeDeclType(Typedef);
666 }
667
668 /// \brief Build a new class/struct/union type.
669 QualType RebuildRecordType(RecordDecl *Record) {
670 return SemaRef.Context.getTypeDeclType(Record);
671 }
672
673 /// \brief Build a new Enum type.
674 QualType RebuildEnumType(EnumDecl *Enum) {
675 return SemaRef.Context.getTypeDeclType(Enum);
676 }
John McCall7da24312009-09-05 00:15:47 +0000677
Mike Stump1eb44332009-09-09 15:08:12 +0000678 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000679 ///
680 /// By default, performs semantic analysis when building the typeof type.
681 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000682 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000683
Mike Stump1eb44332009-09-09 15:08:12 +0000684 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000685 ///
686 /// By default, builds a new TypeOfType with the given underlying type.
687 QualType RebuildTypeOfType(QualType Underlying);
688
Mike Stump1eb44332009-09-09 15:08:12 +0000689 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000690 ///
691 /// By default, performs semantic analysis when building the decltype type.
692 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000693 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000694
Richard Smith34b41d92011-02-20 03:19:35 +0000695 /// \brief Build a new C++0x auto type.
696 ///
697 /// By default, builds a new AutoType with the given deduced type.
698 QualType RebuildAutoType(QualType Deduced) {
699 return SemaRef.Context.getAutoType(Deduced);
700 }
701
Douglas Gregor577f75a2009-08-04 16:50:30 +0000702 /// \brief Build a new template specialization type.
703 ///
704 /// By default, performs semantic analysis when building the template
705 /// specialization type. Subclasses may override this routine to provide
706 /// different behavior.
707 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000708 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000709 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000710
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000711 /// \brief Build a new parenthesized type.
712 ///
713 /// By default, builds a new ParenType type from the inner type.
714 /// Subclasses may override this routine to provide different behavior.
715 QualType RebuildParenType(QualType InnerType) {
716 return SemaRef.Context.getParenType(InnerType);
717 }
718
Douglas Gregor577f75a2009-08-04 16:50:30 +0000719 /// \brief Build a new qualified name type.
720 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000721 /// By default, builds a new ElaboratedType type from the keyword,
722 /// the nested-name-specifier and the named type.
723 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000724 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
725 ElaboratedTypeKeyword Keyword,
Douglas Gregor239cbb02011-03-01 03:11:17 +0000726 NestedNameSpecifierLoc QualifierLoc,
727 QualType Named) {
728 return SemaRef.Context.getElaboratedType(Keyword,
729 QualifierLoc.getNestedNameSpecifier(),
730 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000731 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000732
733 /// \brief Build a new typename type that refers to a template-id.
734 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000735 /// By default, builds a new DependentNameType type from the
736 /// nested-name-specifier and the given type. Subclasses may override
737 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000738 QualType RebuildDependentTemplateSpecializationType(
739 ElaboratedTypeKeyword Keyword,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000740 NestedNameSpecifier *Qualifier,
741 SourceRange QualifierRange,
John McCall33500952010-06-11 00:33:02 +0000742 const IdentifierInfo *Name,
743 SourceLocation NameLoc,
744 const TemplateArgumentListInfo &Args) {
745 // Rebuild the template name.
746 // TODO: avoid TemplateName abstraction
747 TemplateName InstName =
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000748 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall43fed0d2010-11-12 08:19:04 +0000749 QualType(), 0);
John McCall33500952010-06-11 00:33:02 +0000750
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000751 if (InstName.isNull())
752 return QualType();
753
John McCall33500952010-06-11 00:33:02 +0000754 // If it's still dependent, make a dependent specialization.
755 if (InstName.getAsDependentTemplateName())
756 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000757 Keyword, Qualifier, Name, Args);
John McCall33500952010-06-11 00:33:02 +0000758
759 // Otherwise, make an elaborated type wrapping a non-dependent
760 // specialization.
761 QualType T =
762 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
763 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000764
Douglas Gregora88f09f2011-02-28 17:23:35 +0000765 if (Keyword == ETK_None && Qualifier == 0)
Douglas Gregoraa2187d2011-02-28 00:04:36 +0000766 return T;
767
Douglas Gregora88f09f2011-02-28 17:23:35 +0000768 return SemaRef.Context.getElaboratedType(Keyword, Qualifier, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000769 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000770
771 /// \brief Build a new typename type that refers to an identifier.
772 ///
773 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000774 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000775 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000776 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000777 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000778 NestedNameSpecifierLoc QualifierLoc,
779 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000780 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000781 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000782 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000783
Douglas Gregor2494dd02011-03-01 01:34:45 +0000784 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000785 // If the name is still dependent, just build a new dependent name type.
786 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000787 return SemaRef.Context.getDependentNameType(Keyword,
788 QualifierLoc.getNestedNameSpecifier(),
789 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000790 }
791
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000792 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000793 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000794 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000795
796 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
797
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000798 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000799 // into a non-dependent elaborated-type-specifier. Find the tag we're
800 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000801 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000802 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
803 if (!DC)
804 return QualType();
805
John McCall56138762010-05-27 06:40:31 +0000806 if (SemaRef.RequireCompleteDeclContext(SS, DC))
807 return QualType();
808
Douglas Gregor40336422010-03-31 22:19:08 +0000809 TagDecl *Tag = 0;
810 SemaRef.LookupQualifiedName(Result, DC);
811 switch (Result.getResultKind()) {
812 case LookupResult::NotFound:
813 case LookupResult::NotFoundInCurrentInstantiation:
814 break;
Sean Huntc3021132010-05-05 15:23:54 +0000815
Douglas Gregor40336422010-03-31 22:19:08 +0000816 case LookupResult::Found:
817 Tag = Result.getAsSingle<TagDecl>();
818 break;
Sean Huntc3021132010-05-05 15:23:54 +0000819
Douglas Gregor40336422010-03-31 22:19:08 +0000820 case LookupResult::FoundOverloaded:
821 case LookupResult::FoundUnresolvedValue:
822 llvm_unreachable("Tag lookup cannot find non-tags");
823 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000824
Douglas Gregor40336422010-03-31 22:19:08 +0000825 case LookupResult::Ambiguous:
826 // Let the LookupResult structure handle ambiguities.
827 return QualType();
828 }
829
830 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000831 // Check where the name exists but isn't a tag type and use that to emit
832 // better diagnostics.
833 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
834 SemaRef.LookupQualifiedName(Result, DC);
835 switch (Result.getResultKind()) {
836 case LookupResult::Found:
837 case LookupResult::FoundOverloaded:
838 case LookupResult::FoundUnresolvedValue: {
839 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
840 unsigned Kind = 0;
841 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
842 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
843 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
844 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
845 break;
846 }
847 default:
848 // FIXME: Would be nice to highlight just the source range.
849 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
850 << Kind << Id << DC;
851 break;
852 }
Douglas Gregor40336422010-03-31 22:19:08 +0000853 return QualType();
854 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000855
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000856 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
857 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000858 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
859 return QualType();
860 }
861
862 // Build the elaborated-type-specifier type.
863 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000864 return SemaRef.Context.getElaboratedType(Keyword,
865 QualifierLoc.getNestedNameSpecifier(),
866 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000867 }
Mike Stump1eb44332009-09-09 15:08:12 +0000868
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000869 /// \brief Build a new pack expansion type.
870 ///
871 /// By default, builds a new PackExpansionType type from the given pattern.
872 /// Subclasses may override this routine to provide different behavior.
873 QualType RebuildPackExpansionType(QualType Pattern,
874 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000875 SourceLocation EllipsisLoc,
876 llvm::Optional<unsigned> NumExpansions) {
877 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
878 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000879 }
880
Douglas Gregordcee1a12009-08-06 05:28:30 +0000881 /// \brief Build a new nested-name-specifier given the prefix and an
882 /// identifier that names the next step in the nested-name-specifier.
883 ///
884 /// By default, performs semantic analysis when building the new
885 /// nested-name-specifier. Subclasses may override this routine to provide
886 /// different behavior.
887 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
888 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000889 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000890 QualType ObjectType,
891 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000892
893 /// \brief Build a new nested-name-specifier given the prefix and the
894 /// namespace named in the next step in the nested-name-specifier.
895 ///
896 /// By default, performs semantic analysis when building the new
897 /// nested-name-specifier. Subclasses may override this routine to provide
898 /// different behavior.
899 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
900 SourceRange Range,
901 NamespaceDecl *NS);
902
903 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor14aba762011-02-24 02:36:08 +0000904 /// namespace alias named in the next step in the nested-name-specifier.
905 ///
906 /// By default, performs semantic analysis when building the new
907 /// nested-name-specifier. Subclasses may override this routine to provide
908 /// different behavior.
909 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
910 SourceRange Range,
911 NamespaceAliasDecl *Alias);
912
913 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000914 /// type named in the next step in the nested-name-specifier.
915 ///
916 /// By default, performs semantic analysis when building the new
917 /// nested-name-specifier. Subclasses may override this routine to provide
918 /// different behavior.
919 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
920 SourceRange Range,
921 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000922 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000923
924 /// \brief Build a new template name given a nested name specifier, a flag
925 /// indicating whether the "template" keyword was provided, and the template
926 /// that the template name refers to.
927 ///
928 /// By default, builds the new template name directly. Subclasses may override
929 /// this routine to provide different behavior.
930 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
931 bool TemplateKW,
932 TemplateDecl *Template);
933
Douglas Gregord1067e52009-08-06 06:41:21 +0000934 /// \brief Build a new template name given a nested name specifier and the
935 /// name that is referred to as a template.
936 ///
937 /// By default, performs semantic analysis to determine whether the name can
938 /// be resolved to a specific template, then builds the appropriate kind of
939 /// template name. Subclasses may override this routine to provide different
940 /// behavior.
941 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000942 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000943 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +0000944 QualType ObjectType,
945 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000946
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000947 /// \brief Build a new template name given a nested name specifier and the
948 /// overloaded operator name that is referred to as a template.
949 ///
950 /// By default, performs semantic analysis to determine whether the name can
951 /// be resolved to a specific template, then builds the appropriate kind of
952 /// template name. Subclasses may override this routine to provide different
953 /// behavior.
954 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
955 OverloadedOperatorKind Operator,
956 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000957
958 /// \brief Build a new template name given a template template parameter pack
959 /// and the
960 ///
961 /// By default, performs semantic analysis to determine whether the name can
962 /// be resolved to a specific template, then builds the appropriate kind of
963 /// template name. Subclasses may override this routine to provide different
964 /// behavior.
965 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
966 const TemplateArgument &ArgPack) {
967 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
968 }
969
Douglas Gregor43959a92009-08-20 07:17:43 +0000970 /// \brief Build a new compound statement.
971 ///
972 /// By default, performs semantic analysis to build the new statement.
973 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000974 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000975 MultiStmtArg Statements,
976 SourceLocation RBraceLoc,
977 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000978 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000979 IsStmtExpr);
980 }
981
982 /// \brief Build a new case statement.
983 ///
984 /// By default, performs semantic analysis to build the new statement.
985 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000986 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000987 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000988 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000989 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000990 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000991 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000992 ColonLoc);
993 }
Mike Stump1eb44332009-09-09 15:08:12 +0000994
Douglas Gregor43959a92009-08-20 07:17:43 +0000995 /// \brief Attach the body to a new case statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000999 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001000 getSema().ActOnCaseStmtBody(S, Body);
1001 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001002 }
Mike Stump1eb44332009-09-09 15:08:12 +00001003
Douglas Gregor43959a92009-08-20 07:17:43 +00001004 /// \brief Build a new default statement.
1005 ///
1006 /// By default, performs semantic analysis to build the new statement.
1007 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001008 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001009 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001010 Stmt *SubStmt) {
1011 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001012 /*CurScope=*/0);
1013 }
Mike Stump1eb44332009-09-09 15:08:12 +00001014
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 /// \brief Build a new label statement.
1016 ///
1017 /// By default, performs semantic analysis to build the new statement.
1018 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001019 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1020 SourceLocation ColonLoc, Stmt *SubStmt) {
1021 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001022 }
Mike Stump1eb44332009-09-09 15:08:12 +00001023
Douglas Gregor43959a92009-08-20 07:17:43 +00001024 /// \brief Build a new "if" statement.
1025 ///
1026 /// By default, performs semantic analysis to build the new statement.
1027 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001028 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001029 VarDecl *CondVar, Stmt *Then,
1030 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001031 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 }
Mike Stump1eb44332009-09-09 15:08:12 +00001033
Douglas Gregor43959a92009-08-20 07:17:43 +00001034 /// \brief Start building a new switch statement.
1035 ///
1036 /// By default, performs semantic analysis to build the new statement.
1037 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001038 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001039 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001040 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001041 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001042 }
Mike Stump1eb44332009-09-09 15:08:12 +00001043
Douglas Gregor43959a92009-08-20 07:17:43 +00001044 /// \brief Attach the body to the switch statement.
1045 ///
1046 /// By default, performs semantic analysis to build the new statement.
1047 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001048 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001049 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001050 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001051 }
1052
1053 /// \brief Build a new while statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001057 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1058 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001059 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001060 }
Mike Stump1eb44332009-09-09 15:08:12 +00001061
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 /// \brief Build a new do-while statement.
1063 ///
1064 /// By default, performs semantic analysis to build the new statement.
1065 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001066 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001067 SourceLocation WhileLoc, SourceLocation LParenLoc,
1068 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001069 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1070 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001071 }
1072
1073 /// \brief Build a new for statement.
1074 ///
1075 /// By default, performs semantic analysis to build the new statement.
1076 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001077 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1078 Stmt *Init, Sema::FullExprArg Cond,
1079 VarDecl *CondVar, Sema::FullExprArg Inc,
1080 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001081 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001082 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001083 }
Mike Stump1eb44332009-09-09 15:08:12 +00001084
Douglas Gregor43959a92009-08-20 07:17:43 +00001085 /// \brief Build a new goto statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001089 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1090 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001091 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001092 }
1093
1094 /// \brief Build a new indirect goto statement.
1095 ///
1096 /// By default, performs semantic analysis to build the new statement.
1097 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001098 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001099 SourceLocation StarLoc,
1100 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001101 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001102 }
Mike Stump1eb44332009-09-09 15:08:12 +00001103
Douglas Gregor43959a92009-08-20 07:17:43 +00001104 /// \brief Build a new return statement.
1105 ///
1106 /// By default, performs semantic analysis to build the new statement.
1107 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001108 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001109 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001110 }
Mike Stump1eb44332009-09-09 15:08:12 +00001111
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 /// \brief Build a new declaration statement.
1113 ///
1114 /// By default, performs semantic analysis to build the new statement.
1115 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001116 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001117 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001118 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001119 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1120 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 }
Mike Stump1eb44332009-09-09 15:08:12 +00001122
Anders Carlsson703e3942010-01-24 05:50:09 +00001123 /// \brief Build a new inline asm statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001127 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001128 bool IsSimple,
1129 bool IsVolatile,
1130 unsigned NumOutputs,
1131 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001132 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001133 MultiExprArg Constraints,
1134 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001135 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001136 MultiExprArg Clobbers,
1137 SourceLocation RParenLoc,
1138 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001139 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001140 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001141 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001142 RParenLoc, MSAsm);
1143 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001144
1145 /// \brief Build a new Objective-C @try statement.
1146 ///
1147 /// By default, performs semantic analysis to build the new statement.
1148 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001149 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001150 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001151 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001152 Stmt *Finally) {
1153 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1154 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001155 }
1156
Douglas Gregorbe270a02010-04-26 17:57:08 +00001157 /// \brief Rebuild an Objective-C exception declaration.
1158 ///
1159 /// By default, performs semantic analysis to build the new declaration.
1160 /// Subclasses may override this routine to provide different behavior.
1161 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1162 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +00001163 return getSema().BuildObjCExceptionDecl(TInfo, T,
1164 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00001165 ExceptionDecl->getLocation());
1166 }
Sean Huntc3021132010-05-05 15:23:54 +00001167
Douglas Gregorbe270a02010-04-26 17:57:08 +00001168 /// \brief Build a new Objective-C @catch statement.
1169 ///
1170 /// By default, performs semantic analysis to build the new statement.
1171 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001172 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001173 SourceLocation RParenLoc,
1174 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001175 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001176 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001177 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001178 }
Sean Huntc3021132010-05-05 15:23:54 +00001179
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001180 /// \brief Build a new Objective-C @finally statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001184 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001185 Stmt *Body) {
1186 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001187 }
Sean Huntc3021132010-05-05 15:23:54 +00001188
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001189 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001193 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001194 Expr *Operand) {
1195 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001196 }
Sean Huntc3021132010-05-05 15:23:54 +00001197
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001198 /// \brief Build a new Objective-C @synchronized statement.
1199 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001200 /// By default, performs semantic analysis to build the new statement.
1201 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001202 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001203 Expr *Object,
1204 Stmt *Body) {
1205 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1206 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001207 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001208
1209 /// \brief Build a new Objective-C fast enumeration statement.
1210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001213 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001214 SourceLocation LParenLoc,
1215 Stmt *Element,
1216 Expr *Collection,
1217 SourceLocation RParenLoc,
1218 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001219 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001220 Element,
1221 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001222 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001223 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001224 }
Sean Huntc3021132010-05-05 15:23:54 +00001225
Douglas Gregor43959a92009-08-20 07:17:43 +00001226 /// \brief Build a new C++ exception declaration.
1227 ///
1228 /// By default, performs semantic analysis to build the new decaration.
1229 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor83cb9422010-09-09 17:09:21 +00001230 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001231 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +00001232 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +00001233 SourceLocation Loc) {
1234 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001235 }
1236
1237 /// \brief Build a new C++ catch statement.
1238 ///
1239 /// By default, performs semantic analysis to build the new statement.
1240 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001241 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001242 VarDecl *ExceptionDecl,
1243 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001244 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1245 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001246 }
Mike Stump1eb44332009-09-09 15:08:12 +00001247
Douglas Gregor43959a92009-08-20 07:17:43 +00001248 /// \brief Build a new C++ try statement.
1249 ///
1250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001252 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001253 Stmt *TryBlock,
1254 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001255 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001256 }
Mike Stump1eb44332009-09-09 15:08:12 +00001257
Douglas Gregorb98b1992009-08-11 05:31:07 +00001258 /// \brief Build a new expression that references a declaration.
1259 ///
1260 /// By default, performs semantic analysis to build the new expression.
1261 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001262 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001263 LookupResult &R,
1264 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001265 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1266 }
1267
1268
1269 /// \brief Build a new expression that references a declaration.
1270 ///
1271 /// By default, performs semantic analysis to build the new expression.
1272 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001273 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001274 ValueDecl *VD,
1275 const DeclarationNameInfo &NameInfo,
1276 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001277 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001278 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001279
1280 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001281
1282 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001283 }
Mike Stump1eb44332009-09-09 15:08:12 +00001284
Douglas Gregorb98b1992009-08-11 05:31:07 +00001285 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001286 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001287 /// By default, performs semantic analysis to build the new expression.
1288 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001289 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001290 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001291 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001292 }
1293
Douglas Gregora71d8192009-09-04 17:36:40 +00001294 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001295 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001296 /// By default, performs semantic analysis to build the new expression.
1297 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001298 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001299 SourceLocation OperatorLoc,
1300 bool isArrow,
1301 CXXScopeSpec &SS,
1302 TypeSourceInfo *ScopeType,
1303 SourceLocation CCLoc,
1304 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001305 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001306
Douglas Gregorb98b1992009-08-11 05:31:07 +00001307 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001308 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001309 /// By default, performs semantic analysis to build the new expression.
1310 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001311 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001312 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001313 Expr *SubExpr) {
1314 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001315 }
Mike Stump1eb44332009-09-09 15:08:12 +00001316
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001317 /// \brief Build a new builtin offsetof expression.
1318 ///
1319 /// By default, performs semantic analysis to build the new expression.
1320 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001321 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001322 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001323 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001324 unsigned NumComponents,
1325 SourceLocation RParenLoc) {
1326 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1327 NumComponents, RParenLoc);
1328 }
Sean Huntc3021132010-05-05 15:23:54 +00001329
Douglas Gregorb98b1992009-08-11 05:31:07 +00001330 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001331 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001332 /// By default, performs semantic analysis to build the new expression.
1333 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001334 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001335 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001336 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001337 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001338 }
1339
Mike Stump1eb44332009-09-09 15:08:12 +00001340 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001341 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001342 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001343 /// By default, performs semantic analysis to build the new expression.
1344 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001345 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001346 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001347 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001348 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001349 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001350 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001351
Douglas Gregorb98b1992009-08-11 05:31:07 +00001352 return move(Result);
1353 }
Mike Stump1eb44332009-09-09 15:08:12 +00001354
Douglas Gregorb98b1992009-08-11 05:31:07 +00001355 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001356 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001357 /// By default, performs semantic analysis to build the new expression.
1358 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001359 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001360 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001361 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001362 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001363 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1364 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001365 RBracketLoc);
1366 }
1367
1368 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001369 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001370 /// By default, performs semantic analysis to build the new expression.
1371 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001372 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001373 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001374 SourceLocation RParenLoc,
1375 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001376 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001377 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001378 }
1379
1380 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001381 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001382 /// By default, performs semantic analysis to build the new expression.
1383 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001384 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001385 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001386 NestedNameSpecifierLoc QualifierLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001387 const DeclarationNameInfo &MemberNameInfo,
1388 ValueDecl *Member,
1389 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001390 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001391 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001392 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001393 // We have a reference to an unnamed field. This is always the
1394 // base of an anonymous struct/union member access, i.e. the
1395 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001396 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001397 assert(Member->getType()->isRecordType() &&
1398 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001399
Douglas Gregor40d96a62011-02-28 21:54:11 +00001400 if (getSema().PerformObjectMemberConversion(Base,
1401 QualifierLoc.getNestedNameSpecifier(),
John McCall6bb80172010-03-30 21:47:33 +00001402 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001403 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001404
John McCallf89e55a2010-11-18 06:31:45 +00001405 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001406 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001407 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001408 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001409 cast<FieldDecl>(Member)->getType(),
1410 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001411 return getSema().Owned(ME);
1412 }
Mike Stump1eb44332009-09-09 15:08:12 +00001413
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001414 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001415 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001416
John McCall9ae2f072010-08-23 23:25:46 +00001417 getSema().DefaultFunctionArrayConversion(Base);
1418 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001419
John McCall6bb80172010-03-30 21:47:33 +00001420 // FIXME: this involves duplicating earlier analysis in a lot of
1421 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001422 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001423 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001424 R.resolveKind();
1425
John McCall9ae2f072010-08-23 23:25:46 +00001426 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001427 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001428 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 }
Mike Stump1eb44332009-09-09 15:08:12 +00001430
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001432 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001433 /// By default, performs semantic analysis to build the new expression.
1434 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001435 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001436 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001437 Expr *LHS, Expr *RHS) {
1438 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 }
1440
1441 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001442 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001443 /// By default, performs semantic analysis to build the new expression.
1444 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001445 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001446 SourceLocation QuestionLoc,
1447 Expr *LHS,
1448 SourceLocation ColonLoc,
1449 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001450 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1451 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001452 }
1453
Douglas Gregorb98b1992009-08-11 05:31:07 +00001454 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001455 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 /// By default, performs semantic analysis to build the new expression.
1457 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001458 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001459 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001460 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001461 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001462 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001463 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001464 }
Mike Stump1eb44332009-09-09 15:08:12 +00001465
Douglas Gregorb98b1992009-08-11 05:31:07 +00001466 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001467 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001468 /// By default, performs semantic analysis to build the new expression.
1469 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001470 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001471 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001472 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001473 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001474 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001475 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001476 }
Mike Stump1eb44332009-09-09 15:08:12 +00001477
Douglas Gregorb98b1992009-08-11 05:31:07 +00001478 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001479 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 /// By default, performs semantic analysis to build the new expression.
1481 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001482 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 SourceLocation OpLoc,
1484 SourceLocation AccessorLoc,
1485 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001486
John McCall129e2df2009-11-30 22:42:35 +00001487 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001488 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001489 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001490 OpLoc, /*IsArrow*/ false,
1491 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001492 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001493 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 }
Mike Stump1eb44332009-09-09 15:08:12 +00001495
Douglas Gregorb98b1992009-08-11 05:31:07 +00001496 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001497 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 /// By default, performs semantic analysis to build the new expression.
1499 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001500 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001502 SourceLocation RBraceLoc,
1503 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001504 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001505 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1506 if (Result.isInvalid() || ResultTy->isDependentType())
1507 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001508
Douglas Gregore48319a2009-11-09 17:16:50 +00001509 // Patch in the result type we were given, which may have been computed
1510 // when the initial InitListExpr was built.
1511 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1512 ILE->setType(ResultTy);
1513 return move(Result);
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 designated initializer 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 RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001521 MultiExprArg ArrayExprs,
1522 SourceLocation EqualOrColonLoc,
1523 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001524 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001525 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001526 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001527 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001528 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001529 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001530
Douglas Gregorb98b1992009-08-11 05:31:07 +00001531 ArrayExprs.release();
1532 return move(Result);
1533 }
Mike Stump1eb44332009-09-09 15:08:12 +00001534
Douglas Gregorb98b1992009-08-11 05:31:07 +00001535 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001536 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001537 /// By default, builds the implicit value initialization without performing
1538 /// any semantic analysis. Subclasses may override this routine to provide
1539 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001540 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001541 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1542 }
Mike Stump1eb44332009-09-09 15:08:12 +00001543
Douglas Gregorb98b1992009-08-11 05:31:07 +00001544 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001545 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001546 /// By default, performs semantic analysis to build the new expression.
1547 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001548 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001549 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001550 SourceLocation RParenLoc) {
1551 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001552 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001553 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001554 }
1555
1556 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001557 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001558 /// By default, performs semantic analysis to build the new expression.
1559 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001560 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001561 MultiExprArg SubExprs,
1562 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001563 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001564 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 }
Mike Stump1eb44332009-09-09 15:08:12 +00001566
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001568 ///
1569 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 /// rather than attempting to map the label statement itself.
1571 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001572 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001573 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001574 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001575 }
Mike Stump1eb44332009-09-09 15:08:12 +00001576
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001578 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 /// By default, performs semantic analysis to build the new expression.
1580 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001581 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001582 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001584 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 }
Mike Stump1eb44332009-09-09 15:08:12 +00001586
Douglas Gregorb98b1992009-08-11 05:31:07 +00001587 /// \brief Build a new __builtin_choose_expr expression.
1588 ///
1589 /// By default, performs semantic analysis to build the new expression.
1590 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001591 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001592 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 SourceLocation RParenLoc) {
1594 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001595 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 RParenLoc);
1597 }
Mike Stump1eb44332009-09-09 15:08:12 +00001598
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 /// \brief Build a new overloaded operator call expression.
1600 ///
1601 /// By default, performs semantic analysis to build the new expression.
1602 /// The semantic analysis provides the behavior of template instantiation,
1603 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001604 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001605 /// argument-dependent lookup, etc. Subclasses may override this routine to
1606 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001607 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001609 Expr *Callee,
1610 Expr *First,
1611 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001612
1613 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 /// reinterpret_cast.
1615 ///
1616 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001617 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001619 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 Stmt::StmtClass Class,
1621 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001622 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001623 SourceLocation RAngleLoc,
1624 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001625 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001626 SourceLocation RParenLoc) {
1627 switch (Class) {
1628 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001629 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001630 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001631 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632
1633 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001634 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001635 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001636 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001637
Douglas Gregorb98b1992009-08-11 05:31:07 +00001638 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001639 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001640 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001641 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001643
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001645 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001646 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001647 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001648
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 default:
1650 assert(false && "Invalid C++ named cast");
1651 break;
1652 }
Mike Stump1eb44332009-09-09 15:08:12 +00001653
John McCallf312b1e2010-08-26 23:41:50 +00001654 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 }
Mike Stump1eb44332009-09-09 15:08:12 +00001656
Douglas Gregorb98b1992009-08-11 05:31:07 +00001657 /// \brief Build a new C++ static_cast expression.
1658 ///
1659 /// By default, performs semantic analysis to build the new expression.
1660 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001661 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001663 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 SourceLocation RAngleLoc,
1665 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001666 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001668 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001669 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001670 SourceRange(LAngleLoc, RAngleLoc),
1671 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 }
1673
1674 /// \brief Build a new C++ dynamic_cast expression.
1675 ///
1676 /// By default, performs semantic analysis to build the new expression.
1677 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001678 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001680 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 SourceLocation RAngleLoc,
1682 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001683 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001684 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001685 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001686 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001687 SourceRange(LAngleLoc, RAngleLoc),
1688 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001689 }
1690
1691 /// \brief Build a new C++ reinterpret_cast expression.
1692 ///
1693 /// By default, performs semantic analysis to build the new expression.
1694 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001695 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001697 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 SourceLocation RAngleLoc,
1699 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001700 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001702 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001703 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001704 SourceRange(LAngleLoc, RAngleLoc),
1705 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 }
1707
1708 /// \brief Build a new C++ const_cast expression.
1709 ///
1710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001712 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001714 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001715 SourceLocation RAngleLoc,
1716 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001717 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001719 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001720 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001721 SourceRange(LAngleLoc, RAngleLoc),
1722 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 }
Mike Stump1eb44332009-09-09 15:08:12 +00001724
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 /// \brief Build a new C++ functional-style cast expression.
1726 ///
1727 /// By default, performs semantic analysis to build the new expression.
1728 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001729 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1730 SourceLocation LParenLoc,
1731 Expr *Sub,
1732 SourceLocation RParenLoc) {
1733 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001734 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001735 RParenLoc);
1736 }
Mike Stump1eb44332009-09-09 15:08:12 +00001737
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 /// \brief Build a new C++ typeid(type) expression.
1739 ///
1740 /// By default, performs semantic analysis to build the new expression.
1741 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001742 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001743 SourceLocation TypeidLoc,
1744 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001746 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001747 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 }
Mike Stump1eb44332009-09-09 15:08:12 +00001749
Francois Pichet01b7c302010-09-08 12:20:18 +00001750
Douglas Gregorb98b1992009-08-11 05:31:07 +00001751 /// \brief Build a new C++ typeid(expr) expression.
1752 ///
1753 /// By default, performs semantic analysis to build the new expression.
1754 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001755 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001756 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001757 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001758 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001759 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001760 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001761 }
1762
Francois Pichet01b7c302010-09-08 12:20:18 +00001763 /// \brief Build a new C++ __uuidof(type) expression.
1764 ///
1765 /// By default, performs semantic analysis to build the new expression.
1766 /// Subclasses may override this routine to provide different behavior.
1767 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1768 SourceLocation TypeidLoc,
1769 TypeSourceInfo *Operand,
1770 SourceLocation RParenLoc) {
1771 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1772 RParenLoc);
1773 }
1774
1775 /// \brief Build a new C++ __uuidof(expr) expression.
1776 ///
1777 /// By default, performs semantic analysis to build the new expression.
1778 /// Subclasses may override this routine to provide different behavior.
1779 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1780 SourceLocation TypeidLoc,
1781 Expr *Operand,
1782 SourceLocation RParenLoc) {
1783 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1784 RParenLoc);
1785 }
1786
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 /// \brief Build a new C++ "this" expression.
1788 ///
1789 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001790 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001792 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001793 QualType ThisType,
1794 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001796 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1797 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001798 }
1799
1800 /// \brief Build a new C++ throw expression.
1801 ///
1802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001804 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001805 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 }
1807
1808 /// \brief Build a new C++ default-argument expression.
1809 ///
1810 /// By default, builds a new default-argument expression, which does not
1811 /// require any semantic analysis. Subclasses may override this routine to
1812 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001813 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001814 ParmVarDecl *Param) {
1815 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1816 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001817 }
1818
1819 /// \brief Build a new C++ zero-initialization expression.
1820 ///
1821 /// By default, performs semantic analysis to build the new expression.
1822 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001823 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1824 SourceLocation LParenLoc,
1825 SourceLocation RParenLoc) {
1826 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001827 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001828 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001829 }
Mike Stump1eb44332009-09-09 15:08:12 +00001830
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 /// \brief Build a new C++ "new" expression.
1832 ///
1833 /// By default, performs semantic analysis to build the new expression.
1834 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001835 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001836 bool UseGlobal,
1837 SourceLocation PlacementLParen,
1838 MultiExprArg PlacementArgs,
1839 SourceLocation PlacementRParen,
1840 SourceRange TypeIdParens,
1841 QualType AllocatedType,
1842 TypeSourceInfo *AllocatedTypeInfo,
1843 Expr *ArraySize,
1844 SourceLocation ConstructorLParen,
1845 MultiExprArg ConstructorArgs,
1846 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001847 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001848 PlacementLParen,
1849 move(PlacementArgs),
1850 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001851 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001852 AllocatedType,
1853 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001854 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001855 ConstructorLParen,
1856 move(ConstructorArgs),
1857 ConstructorRParen);
1858 }
Mike Stump1eb44332009-09-09 15:08:12 +00001859
Douglas Gregorb98b1992009-08-11 05:31:07 +00001860 /// \brief Build a new C++ "delete" expression.
1861 ///
1862 /// By default, performs semantic analysis to build the new expression.
1863 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001864 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001865 bool IsGlobalDelete,
1866 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001867 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001868 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001869 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001870 }
Mike Stump1eb44332009-09-09 15:08:12 +00001871
Douglas Gregorb98b1992009-08-11 05:31:07 +00001872 /// \brief Build a new unary type trait expression.
1873 ///
1874 /// By default, performs semantic analysis to build the new expression.
1875 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001876 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001877 SourceLocation StartLoc,
1878 TypeSourceInfo *T,
1879 SourceLocation RParenLoc) {
1880 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001881 }
1882
Francois Pichet6ad6f282010-12-07 00:08:36 +00001883 /// \brief Build a new binary type trait expression.
1884 ///
1885 /// By default, performs semantic analysis to build the new expression.
1886 /// Subclasses may override this routine to provide different behavior.
1887 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1888 SourceLocation StartLoc,
1889 TypeSourceInfo *LhsT,
1890 TypeSourceInfo *RhsT,
1891 SourceLocation RParenLoc) {
1892 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1893 }
1894
Mike Stump1eb44332009-09-09 15:08:12 +00001895 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001896 /// expression.
1897 ///
1898 /// By default, performs semantic analysis to build the new expression.
1899 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001900 ExprResult RebuildDependentScopeDeclRefExpr(
1901 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001902 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001903 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001904 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001905 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00001906
1907 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001908 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001909 *TemplateArgs);
1910
Abramo Bagnara25777432010-08-11 22:01:17 +00001911 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001912 }
1913
1914 /// \brief Build a new template-id 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 RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001919 LookupResult &R,
1920 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001921 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001922 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001923 }
1924
1925 /// \brief Build a new object-construction expression.
1926 ///
1927 /// By default, performs semantic analysis to build the new expression.
1928 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001929 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001930 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001931 CXXConstructorDecl *Constructor,
1932 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001933 MultiExprArg Args,
1934 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00001935 CXXConstructExpr::ConstructionKind ConstructKind,
1936 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00001937 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001938 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001939 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001940 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001941
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001942 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001943 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00001944 RequiresZeroInit, ConstructKind,
1945 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946 }
1947
1948 /// \brief Build a new object-construction expression.
1949 ///
1950 /// By default, performs semantic analysis to build the new expression.
1951 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001952 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1953 SourceLocation LParenLoc,
1954 MultiExprArg Args,
1955 SourceLocation RParenLoc) {
1956 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001957 LParenLoc,
1958 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 RParenLoc);
1960 }
1961
1962 /// \brief Build a new object-construction expression.
1963 ///
1964 /// By default, performs semantic analysis to build the new expression.
1965 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001966 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1967 SourceLocation LParenLoc,
1968 MultiExprArg Args,
1969 SourceLocation RParenLoc) {
1970 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001971 LParenLoc,
1972 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 RParenLoc);
1974 }
Mike Stump1eb44332009-09-09 15:08:12 +00001975
Douglas Gregorb98b1992009-08-11 05:31:07 +00001976 /// \brief Build a new member reference expression.
1977 ///
1978 /// By default, performs semantic analysis to build the new expression.
1979 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001980 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001981 QualType BaseType,
1982 bool IsArrow,
1983 SourceLocation OperatorLoc,
1984 NestedNameSpecifierLoc QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00001985 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001986 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001987 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001988 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001989 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001990
John McCall9ae2f072010-08-23 23:25:46 +00001991 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001992 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001993 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001994 MemberNameInfo,
1995 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001996 }
1997
John McCall129e2df2009-11-30 22:42:35 +00001998 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001999 ///
2000 /// By default, performs semantic analysis to build the new expression.
2001 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002002 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00002003 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00002004 SourceLocation OperatorLoc,
2005 bool IsArrow,
Douglas Gregor4c9be892011-02-28 20:01:57 +00002006 NestedNameSpecifierLoc QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00002007 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00002008 LookupResult &R,
2009 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002010 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002011 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002012
John McCall9ae2f072010-08-23 23:25:46 +00002013 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002014 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00002015 SS, FirstQualifierInScope,
2016 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002017 }
Mike Stump1eb44332009-09-09 15:08:12 +00002018
Sebastian Redl2e156222010-09-10 20:55:43 +00002019 /// \brief Build a new noexcept expression.
2020 ///
2021 /// By default, performs semantic analysis to build the new expression.
2022 /// Subclasses may override this routine to provide different behavior.
2023 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2024 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2025 }
2026
Douglas Gregoree8aff02011-01-04 17:33:58 +00002027 /// \brief Build a new expression to compute the length of a parameter pack.
2028 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2029 SourceLocation PackLoc,
2030 SourceLocation RParenLoc,
2031 unsigned Length) {
2032 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2033 OperatorLoc, Pack, PackLoc,
2034 RParenLoc, Length);
2035 }
2036
Douglas Gregorb98b1992009-08-11 05:31:07 +00002037 /// \brief Build a new Objective-C @encode expression.
2038 ///
2039 /// By default, performs semantic analysis to build the new expression.
2040 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002041 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002042 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002043 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002044 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002045 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002046 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002047
Douglas Gregor92e986e2010-04-22 16:44:27 +00002048 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002049 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002050 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002051 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002052 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002053 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002054 MultiExprArg Args,
2055 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002056 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2057 ReceiverTypeInfo->getType(),
2058 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002059 Sel, Method, LBracLoc, SelectorLoc,
2060 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002061 }
2062
2063 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002064 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002065 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002066 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002067 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002068 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002069 MultiExprArg Args,
2070 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002071 return SemaRef.BuildInstanceMessage(Receiver,
2072 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002073 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002074 Sel, Method, LBracLoc, SelectorLoc,
2075 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002076 }
2077
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002078 /// \brief Build a new Objective-C ivar reference expression.
2079 ///
2080 /// By default, performs semantic analysis to build the new expression.
2081 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002082 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002083 SourceLocation IvarLoc,
2084 bool IsArrow, bool IsFreeIvar) {
2085 // FIXME: We lose track of the IsFreeIvar bit.
2086 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002087 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002088 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2089 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002090 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002091 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002092 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002093 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002094 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002095 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002096
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002097 if (Result.get())
2098 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002099
John McCall9ae2f072010-08-23 23:25:46 +00002100 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002101 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002102 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002103 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002104 /*TemplateArgs=*/0);
2105 }
Douglas Gregore3303542010-04-26 20:47:02 +00002106
2107 /// \brief Build a new Objective-C property reference expression.
2108 ///
2109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002111 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002112 ObjCPropertyDecl *Property,
2113 SourceLocation PropertyLoc) {
2114 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002115 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00002116 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2117 Sema::LookupMemberName);
2118 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002119 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002120 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002121 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00002122 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002123 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002124
Douglas Gregore3303542010-04-26 20:47:02 +00002125 if (Result.get())
2126 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002127
John McCall9ae2f072010-08-23 23:25:46 +00002128 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002129 /*FIXME:*/PropertyLoc, IsArrow,
2130 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002131 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002132 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002133 /*TemplateArgs=*/0);
2134 }
Sean Huntc3021132010-05-05 15:23:54 +00002135
John McCall12f78a62010-12-02 01:19:52 +00002136 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002137 ///
2138 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002139 /// Subclasses may override this routine to provide different behavior.
2140 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2141 ObjCMethodDecl *Getter,
2142 ObjCMethodDecl *Setter,
2143 SourceLocation PropertyLoc) {
2144 // Since these expressions can only be value-dependent, we do not
2145 // need to perform semantic analysis again.
2146 return Owned(
2147 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2148 VK_LValue, OK_ObjCProperty,
2149 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002150 }
2151
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002152 /// \brief Build a new Objective-C "isa" expression.
2153 ///
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002156 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002157 bool IsArrow) {
2158 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002159 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002160 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2161 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002162 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002163 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002164 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002165 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002166 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002167
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002168 if (Result.get())
2169 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002170
John McCall9ae2f072010-08-23 23:25:46 +00002171 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002172 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002173 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002174 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002175 /*TemplateArgs=*/0);
2176 }
Sean Huntc3021132010-05-05 15:23:54 +00002177
Douglas Gregorb98b1992009-08-11 05:31:07 +00002178 /// \brief Build a new shuffle vector expression.
2179 ///
2180 /// By default, performs semantic analysis to build the new expression.
2181 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002182 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002183 MultiExprArg SubExprs,
2184 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002185 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002186 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002187 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2188 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2189 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2190 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002191
Douglas Gregorb98b1992009-08-11 05:31:07 +00002192 // Build a reference to the __builtin_shufflevector builtin
2193 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00002194 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00002195 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCallf89e55a2010-11-18 06:31:45 +00002196 VK_LValue, BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002197 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00002198
2199 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002200 unsigned NumSubExprs = SubExprs.size();
2201 Expr **Subs = (Expr **)SubExprs.release();
2202 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2203 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002204 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002205 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002206 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00002207 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00002208
Douglas Gregorb98b1992009-08-11 05:31:07 +00002209 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00002210 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002211 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002212 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002213
Douglas Gregorb98b1992009-08-11 05:31:07 +00002214 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00002215 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002216 }
John McCall43fed0d2010-11-12 08:19:04 +00002217
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002218 /// \brief Build a new template argument pack expansion.
2219 ///
2220 /// By default, performs semantic analysis to build a new pack expansion
2221 /// for a template argument. Subclasses may override this routine to provide
2222 /// different behavior.
2223 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002224 SourceLocation EllipsisLoc,
2225 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002226 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002227 case TemplateArgument::Expression: {
2228 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002229 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2230 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002231 if (Result.isInvalid())
2232 return TemplateArgumentLoc();
2233
2234 return TemplateArgumentLoc(Result.get(), Result.get());
2235 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002236
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002237 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002238 return TemplateArgumentLoc(TemplateArgument(
2239 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002240 NumExpansions),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002241 Pattern.getTemplateQualifierRange(),
2242 Pattern.getTemplateNameLoc(),
2243 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002244
2245 case TemplateArgument::Null:
2246 case TemplateArgument::Integral:
2247 case TemplateArgument::Declaration:
2248 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002249 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002250 llvm_unreachable("Pack expansion pattern has no parameter packs");
2251
2252 case TemplateArgument::Type:
2253 if (TypeSourceInfo *Expansion
2254 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002255 EllipsisLoc,
2256 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002257 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2258 Expansion);
2259 break;
2260 }
2261
2262 return TemplateArgumentLoc();
2263 }
2264
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002265 /// \brief Build a new expression pack expansion.
2266 ///
2267 /// By default, performs semantic analysis to build a new pack expansion
2268 /// for an expression. Subclasses may override this routine to provide
2269 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002270 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2271 llvm::Optional<unsigned> NumExpansions) {
2272 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002273 }
2274
John McCall43fed0d2010-11-12 08:19:04 +00002275private:
2276 QualType TransformTypeInObjectScope(QualType T,
2277 QualType ObjectType,
2278 NamedDecl *FirstQualifierInScope,
2279 NestedNameSpecifier *Prefix);
2280
2281 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2282 QualType ObjectType,
2283 NamedDecl *FirstQualifierInScope,
2284 NestedNameSpecifier *Prefix);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002285
2286 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2287 QualType ObjectType,
2288 NamedDecl *FirstQualifierInScope,
2289 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002290};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002291
Douglas Gregor43959a92009-08-20 07:17:43 +00002292template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002293StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002294 if (!S)
2295 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002296
Douglas Gregor43959a92009-08-20 07:17:43 +00002297 switch (S->getStmtClass()) {
2298 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002299
Douglas Gregor43959a92009-08-20 07:17:43 +00002300 // Transform individual statement nodes
2301#define STMT(Node, Parent) \
2302 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002303#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002304#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002305#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002306
Douglas Gregor43959a92009-08-20 07:17:43 +00002307 // Transform expressions by calling TransformExpr.
2308#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002309#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002310#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002311#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002312 {
John McCall60d7b3a2010-08-24 06:29:42 +00002313 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002314 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002315 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002316
John McCall9ae2f072010-08-23 23:25:46 +00002317 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002318 }
Mike Stump1eb44332009-09-09 15:08:12 +00002319 }
2320
John McCall3fa5cae2010-10-26 07:05:15 +00002321 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002322}
Mike Stump1eb44332009-09-09 15:08:12 +00002323
2324
Douglas Gregor670444e2009-08-04 22:27:00 +00002325template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002326ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002327 if (!E)
2328 return SemaRef.Owned(E);
2329
2330 switch (E->getStmtClass()) {
2331 case Stmt::NoStmtClass: break;
2332#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002333#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002334#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002335 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002336#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002337 }
2338
John McCall3fa5cae2010-10-26 07:05:15 +00002339 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002340}
2341
2342template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002343bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2344 unsigned NumInputs,
2345 bool IsCall,
2346 llvm::SmallVectorImpl<Expr *> &Outputs,
2347 bool *ArgChanged) {
2348 for (unsigned I = 0; I != NumInputs; ++I) {
2349 // If requested, drop call arguments that need to be dropped.
2350 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2351 if (ArgChanged)
2352 *ArgChanged = true;
2353
2354 break;
2355 }
2356
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002357 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2358 Expr *Pattern = Expansion->getPattern();
2359
2360 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2361 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2362 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2363
2364 // Determine whether the set of unexpanded parameter packs can and should
2365 // be expanded.
2366 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002367 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002368 llvm::Optional<unsigned> OrigNumExpansions
2369 = Expansion->getNumExpansions();
2370 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002371 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2372 Pattern->getSourceRange(),
2373 Unexpanded.data(),
2374 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002375 Expand, RetainExpansion,
2376 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002377 return true;
2378
2379 if (!Expand) {
2380 // The transform has determined that we should perform a simple
2381 // transformation on the pack expansion, producing another pack
2382 // expansion.
2383 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2384 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2385 if (OutPattern.isInvalid())
2386 return true;
2387
2388 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002389 Expansion->getEllipsisLoc(),
2390 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002391 if (Out.isInvalid())
2392 return true;
2393
2394 if (ArgChanged)
2395 *ArgChanged = true;
2396 Outputs.push_back(Out.get());
2397 continue;
2398 }
2399
2400 // The transform has determined that we should perform an elementwise
2401 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002402 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002403 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2404 ExprResult Out = getDerived().TransformExpr(Pattern);
2405 if (Out.isInvalid())
2406 return true;
2407
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002408 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002409 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2410 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002411 if (Out.isInvalid())
2412 return true;
2413 }
2414
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002415 if (ArgChanged)
2416 *ArgChanged = true;
2417 Outputs.push_back(Out.get());
2418 }
2419
2420 continue;
2421 }
2422
Douglas Gregoraa165f82011-01-03 19:04:46 +00002423 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2424 if (Result.isInvalid())
2425 return true;
2426
2427 if (Result.get() != Inputs[I] && ArgChanged)
2428 *ArgChanged = true;
2429
2430 Outputs.push_back(Result.get());
2431 }
2432
2433 return false;
2434}
2435
2436template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002437NestedNameSpecifier *
2438TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002439 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002440 QualType ObjectType,
2441 NamedDecl *FirstQualifierInScope) {
John McCall43fed0d2010-11-12 08:19:04 +00002442 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump1eb44332009-09-09 15:08:12 +00002443
Douglas Gregor43959a92009-08-20 07:17:43 +00002444 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002445 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002446 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002447 ObjectType,
2448 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002449 if (!Prefix)
2450 return 0;
2451 }
Mike Stump1eb44332009-09-09 15:08:12 +00002452
Douglas Gregordcee1a12009-08-06 05:28:30 +00002453 switch (NNS->getKind()) {
2454 case NestedNameSpecifier::Identifier:
John McCall43fed0d2010-11-12 08:19:04 +00002455 if (Prefix) {
2456 // The object type and qualifier-in-scope really apply to the
2457 // leftmost entity.
2458 ObjectType = QualType();
2459 FirstQualifierInScope = 0;
2460 }
2461
Mike Stump1eb44332009-09-09 15:08:12 +00002462 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002463 "Identifier nested-name-specifier with no prefix or object type");
2464 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2465 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002466 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002467
2468 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002469 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002470 ObjectType,
2471 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002472
Douglas Gregordcee1a12009-08-06 05:28:30 +00002473 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002474 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002475 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002476 getDerived().TransformDecl(Range.getBegin(),
2477 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002478 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002479 Prefix == NNS->getPrefix() &&
2480 NS == NNS->getAsNamespace())
2481 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002482
Douglas Gregordcee1a12009-08-06 05:28:30 +00002483 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2484 }
Mike Stump1eb44332009-09-09 15:08:12 +00002485
Douglas Gregor14aba762011-02-24 02:36:08 +00002486 case NestedNameSpecifier::NamespaceAlias: {
2487 NamespaceAliasDecl *Alias
2488 = cast_or_null<NamespaceAliasDecl>(
2489 getDerived().TransformDecl(Range.getBegin(),
2490 NNS->getAsNamespaceAlias()));
2491 if (!getDerived().AlwaysRebuild() &&
2492 Prefix == NNS->getPrefix() &&
2493 Alias == NNS->getAsNamespaceAlias())
2494 return NNS;
2495
2496 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, Alias);
2497 }
2498
Douglas Gregordcee1a12009-08-06 05:28:30 +00002499 case NestedNameSpecifier::Global:
2500 // There is no meaningful transformation that one could perform on the
2501 // global scope.
2502 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002503
Douglas Gregordcee1a12009-08-06 05:28:30 +00002504 case NestedNameSpecifier::TypeSpecWithTemplate:
2505 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002506 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall43fed0d2010-11-12 08:19:04 +00002507 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2508 ObjectType,
2509 FirstQualifierInScope,
2510 Prefix);
Douglas Gregord1067e52009-08-06 06:41:21 +00002511 if (T.isNull())
2512 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002513
Douglas Gregordcee1a12009-08-06 05:28:30 +00002514 if (!getDerived().AlwaysRebuild() &&
2515 Prefix == NNS->getPrefix() &&
2516 T == QualType(NNS->getAsType(), 0))
2517 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002518
2519 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2520 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002521 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002522 }
2523 }
Mike Stump1eb44332009-09-09 15:08:12 +00002524
Douglas Gregordcee1a12009-08-06 05:28:30 +00002525 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002526 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002527}
2528
2529template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002530NestedNameSpecifierLoc
2531TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2532 NestedNameSpecifierLoc NNS,
2533 QualType ObjectType,
2534 NamedDecl *FirstQualifierInScope) {
2535 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2536 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2537 Qualifier = Qualifier.getPrefix())
2538 Qualifiers.push_back(Qualifier);
2539
2540 CXXScopeSpec SS;
2541 while (!Qualifiers.empty()) {
2542 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2543 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2544
2545 switch (QNNS->getKind()) {
2546 case NestedNameSpecifier::Identifier:
2547 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2548 *QNNS->getAsIdentifier(),
2549 Q.getLocalBeginLoc(),
2550 Q.getLocalEndLoc(),
2551 ObjectType, false, SS,
2552 FirstQualifierInScope, false))
2553 return NestedNameSpecifierLoc();
2554
2555 break;
2556
2557 case NestedNameSpecifier::Namespace: {
2558 NamespaceDecl *NS
2559 = cast_or_null<NamespaceDecl>(
2560 getDerived().TransformDecl(
2561 Q.getLocalBeginLoc(),
2562 QNNS->getAsNamespace()));
2563 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2564 break;
2565 }
2566
2567 case NestedNameSpecifier::NamespaceAlias: {
2568 NamespaceAliasDecl *Alias
2569 = cast_or_null<NamespaceAliasDecl>(
2570 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2571 QNNS->getAsNamespaceAlias()));
2572 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2573 Q.getLocalEndLoc());
2574 break;
2575 }
2576
2577 case NestedNameSpecifier::Global:
2578 // There is no meaningful transformation that one could perform on the
2579 // global scope.
2580 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2581 break;
2582
2583 case NestedNameSpecifier::TypeSpecWithTemplate:
2584 case NestedNameSpecifier::TypeSpec: {
2585 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2586 FirstQualifierInScope, SS);
2587
2588 if (!TL)
2589 return NestedNameSpecifierLoc();
2590
2591 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2592 (SemaRef.getLangOptions().CPlusPlus0x &&
2593 TL.getType()->isEnumeralType())) {
2594 assert(!TL.getType().hasLocalQualifiers() &&
2595 "Can't get cv-qualifiers here");
2596 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2597 Q.getLocalEndLoc());
2598 break;
2599 }
2600
2601 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2602 << TL.getType() << SS.getRange();
2603 return NestedNameSpecifierLoc();
2604 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002605 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002606
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002607 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002608 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002609 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002610 }
2611
2612 // Don't rebuild the nested-name-specifier if we don't have to.
2613 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2614 !getDerived().AlwaysRebuild())
2615 return NNS;
2616
2617 // If we can re-use the source-location data from the original
2618 // nested-name-specifier, do so.
2619 if (SS.location_size() == NNS.getDataLength() &&
2620 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2621 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2622
2623 // Allocate new nested-name-specifier location information.
2624 return SS.getWithLocInContext(SemaRef.Context);
2625}
2626
2627template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002628DeclarationNameInfo
2629TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002630::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002631 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002632 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002633 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002634
2635 switch (Name.getNameKind()) {
2636 case DeclarationName::Identifier:
2637 case DeclarationName::ObjCZeroArgSelector:
2638 case DeclarationName::ObjCOneArgSelector:
2639 case DeclarationName::ObjCMultiArgSelector:
2640 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002641 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002642 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002643 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002644
Douglas Gregor81499bb2009-09-03 22:13:48 +00002645 case DeclarationName::CXXConstructorName:
2646 case DeclarationName::CXXDestructorName:
2647 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002648 TypeSourceInfo *NewTInfo;
2649 CanQualType NewCanTy;
2650 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002651 NewTInfo = getDerived().TransformType(OldTInfo);
2652 if (!NewTInfo)
2653 return DeclarationNameInfo();
2654 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002655 }
2656 else {
2657 NewTInfo = 0;
2658 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002659 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002660 if (NewT.isNull())
2661 return DeclarationNameInfo();
2662 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2663 }
Mike Stump1eb44332009-09-09 15:08:12 +00002664
Abramo Bagnara25777432010-08-11 22:01:17 +00002665 DeclarationName NewName
2666 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2667 NewCanTy);
2668 DeclarationNameInfo NewNameInfo(NameInfo);
2669 NewNameInfo.setName(NewName);
2670 NewNameInfo.setNamedTypeInfo(NewTInfo);
2671 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002672 }
Mike Stump1eb44332009-09-09 15:08:12 +00002673 }
2674
Abramo Bagnara25777432010-08-11 22:01:17 +00002675 assert(0 && "Unknown name kind.");
2676 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002677}
2678
2679template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002680TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002681TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +00002682 QualType ObjectType,
2683 NamedDecl *FirstQualifierInScope) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002684 SourceLocation Loc = getDerived().getBaseLocation();
2685
Douglas Gregord1067e52009-08-06 06:41:21 +00002686 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002687 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002688 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002689 /*FIXME*/ SourceRange(Loc),
2690 ObjectType,
2691 FirstQualifierInScope);
Douglas Gregord1067e52009-08-06 06:41:21 +00002692 if (!NNS)
2693 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002694
Douglas Gregord1067e52009-08-06 06:41:21 +00002695 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002696 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002697 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002698 if (!TransTemplate)
2699 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002700
Douglas Gregord1067e52009-08-06 06:41:21 +00002701 if (!getDerived().AlwaysRebuild() &&
2702 NNS == QTN->getQualifier() &&
2703 TransTemplate == Template)
2704 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002705
Douglas Gregord1067e52009-08-06 06:41:21 +00002706 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2707 TransTemplate);
2708 }
Mike Stump1eb44332009-09-09 15:08:12 +00002709
John McCallf7a1a742009-11-24 19:00:30 +00002710 // These should be getting filtered out before they make it into the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002711 llvm_unreachable("overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002712 }
Mike Stump1eb44332009-09-09 15:08:12 +00002713
Douglas Gregord1067e52009-08-06 06:41:21 +00002714 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall43fed0d2010-11-12 08:19:04 +00002715 NestedNameSpecifier *NNS = DTN->getQualifier();
2716 if (NNS) {
2717 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2718 /*FIXME:*/SourceRange(Loc),
2719 ObjectType,
2720 FirstQualifierInScope);
2721 if (!NNS) return TemplateName();
2722
2723 // These apply to the scope specifier, not the template.
2724 ObjectType = QualType();
2725 FirstQualifierInScope = 0;
2726 }
Mike Stump1eb44332009-09-09 15:08:12 +00002727
Douglas Gregord1067e52009-08-06 06:41:21 +00002728 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002729 NNS == DTN->getQualifier() &&
2730 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002731 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002732
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002733 if (DTN->isIdentifier()) {
2734 // FIXME: Bad range
2735 SourceRange QualifierRange(getDerived().getBaseLocation());
2736 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2737 *DTN->getIdentifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002738 ObjectType,
2739 FirstQualifierInScope);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002740 }
Sean Huntc3021132010-05-05 15:23:54 +00002741
2742 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002743 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002744 }
Mike Stump1eb44332009-09-09 15:08:12 +00002745
Douglas Gregord1067e52009-08-06 06:41:21 +00002746 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002747 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002748 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002749 if (!TransTemplate)
2750 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002751
Douglas Gregord1067e52009-08-06 06:41:21 +00002752 if (!getDerived().AlwaysRebuild() &&
2753 TransTemplate == Template)
2754 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002755
Douglas Gregord1067e52009-08-06 06:41:21 +00002756 return TemplateName(TransTemplate);
2757 }
Mike Stump1eb44332009-09-09 15:08:12 +00002758
Douglas Gregor1aee05d2011-01-15 06:45:20 +00002759 if (SubstTemplateTemplateParmPackStorage *SubstPack
2760 = Name.getAsSubstTemplateTemplateParmPack()) {
2761 TemplateTemplateParmDecl *TransParam
2762 = cast_or_null<TemplateTemplateParmDecl>(
2763 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2764 if (!TransParam)
2765 return TemplateName();
2766
2767 if (!getDerived().AlwaysRebuild() &&
2768 TransParam == SubstPack->getParameterPack())
2769 return Name;
2770
2771 return getDerived().RebuildTemplateName(TransParam,
2772 SubstPack->getArgumentPack());
2773 }
2774
John McCallf7a1a742009-11-24 19:00:30 +00002775 // These should be getting filtered out before they reach the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002776 llvm_unreachable("overloaded function decl survived to here");
John McCallf7a1a742009-11-24 19:00:30 +00002777 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002778}
2779
2780template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002781void TreeTransform<Derived>::InventTemplateArgumentLoc(
2782 const TemplateArgument &Arg,
2783 TemplateArgumentLoc &Output) {
2784 SourceLocation Loc = getDerived().getBaseLocation();
2785 switch (Arg.getKind()) {
2786 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002787 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002788 break;
2789
2790 case TemplateArgument::Type:
2791 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002792 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002793
John McCall833ca992009-10-29 08:12:44 +00002794 break;
2795
Douglas Gregor788cd062009-11-11 01:00:40 +00002796 case TemplateArgument::Template:
2797 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2798 break;
Douglas Gregora7fc9012011-01-05 18:58:31 +00002799
2800 case TemplateArgument::TemplateExpansion:
2801 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2802 break;
2803
John McCall833ca992009-10-29 08:12:44 +00002804 case TemplateArgument::Expression:
2805 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2806 break;
2807
2808 case TemplateArgument::Declaration:
2809 case TemplateArgument::Integral:
2810 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002811 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002812 break;
2813 }
2814}
2815
2816template<typename Derived>
2817bool TreeTransform<Derived>::TransformTemplateArgument(
2818 const TemplateArgumentLoc &Input,
2819 TemplateArgumentLoc &Output) {
2820 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002821 switch (Arg.getKind()) {
2822 case TemplateArgument::Null:
2823 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002824 Output = Input;
2825 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002826
Douglas Gregor670444e2009-08-04 22:27:00 +00002827 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002828 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002829 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002830 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002831
2832 DI = getDerived().TransformType(DI);
2833 if (!DI) return true;
2834
2835 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2836 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002837 }
Mike Stump1eb44332009-09-09 15:08:12 +00002838
Douglas Gregor670444e2009-08-04 22:27:00 +00002839 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002840 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002841 DeclarationName Name;
2842 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2843 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002844 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002845 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002846 if (!D) return true;
2847
John McCall828bff22009-10-29 18:45:58 +00002848 Expr *SourceExpr = Input.getSourceDeclExpression();
2849 if (SourceExpr) {
2850 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002851 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002852 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002853 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002854 }
2855
2856 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002857 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002858 }
Mike Stump1eb44332009-09-09 15:08:12 +00002859
Douglas Gregor788cd062009-11-11 01:00:40 +00002860 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002861 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002862 TemplateName Template
2863 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2864 if (Template.isNull())
2865 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002866
Douglas Gregor788cd062009-11-11 01:00:40 +00002867 Output = TemplateArgumentLoc(TemplateArgument(Template),
2868 Input.getTemplateQualifierRange(),
2869 Input.getTemplateNameLoc());
2870 return false;
2871 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002872
2873 case TemplateArgument::TemplateExpansion:
2874 llvm_unreachable("Caller should expand pack expansions");
2875
Douglas Gregor670444e2009-08-04 22:27:00 +00002876 case TemplateArgument::Expression: {
2877 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002878 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002879 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002880
John McCall833ca992009-10-29 08:12:44 +00002881 Expr *InputExpr = Input.getSourceExpression();
2882 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2883
John McCall60d7b3a2010-08-24 06:29:42 +00002884 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002885 = getDerived().TransformExpr(InputExpr);
2886 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002887 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002888 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002889 }
Mike Stump1eb44332009-09-09 15:08:12 +00002890
Douglas Gregor670444e2009-08-04 22:27:00 +00002891 case TemplateArgument::Pack: {
2892 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2893 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002894 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002895 AEnd = Arg.pack_end();
2896 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002897
John McCall833ca992009-10-29 08:12:44 +00002898 // FIXME: preserve source information here when we start
2899 // caring about parameter packs.
2900
John McCall828bff22009-10-29 18:45:58 +00002901 TemplateArgumentLoc InputArg;
2902 TemplateArgumentLoc OutputArg;
2903 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2904 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002905 return true;
2906
John McCall828bff22009-10-29 18:45:58 +00002907 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002908 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002909
2910 TemplateArgument *TransformedArgsPtr
2911 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2912 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2913 TransformedArgsPtr);
2914 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2915 TransformedArgs.size()),
2916 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002917 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002918 }
2919 }
Mike Stump1eb44332009-09-09 15:08:12 +00002920
Douglas Gregor670444e2009-08-04 22:27:00 +00002921 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002922 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002923}
2924
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002925/// \brief Iterator adaptor that invents template argument location information
2926/// for each of the template arguments in its underlying iterator.
2927template<typename Derived, typename InputIterator>
2928class TemplateArgumentLocInventIterator {
2929 TreeTransform<Derived> &Self;
2930 InputIterator Iter;
2931
2932public:
2933 typedef TemplateArgumentLoc value_type;
2934 typedef TemplateArgumentLoc reference;
2935 typedef typename std::iterator_traits<InputIterator>::difference_type
2936 difference_type;
2937 typedef std::input_iterator_tag iterator_category;
2938
2939 class pointer {
2940 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002941
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002942 public:
2943 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2944
2945 const TemplateArgumentLoc *operator->() const { return &Arg; }
2946 };
2947
2948 TemplateArgumentLocInventIterator() { }
2949
2950 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2951 InputIterator Iter)
2952 : Self(Self), Iter(Iter) { }
2953
2954 TemplateArgumentLocInventIterator &operator++() {
2955 ++Iter;
2956 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002957 }
2958
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002959 TemplateArgumentLocInventIterator operator++(int) {
2960 TemplateArgumentLocInventIterator Old(*this);
2961 ++(*this);
2962 return Old;
2963 }
2964
2965 reference operator*() const {
2966 TemplateArgumentLoc Result;
2967 Self.InventTemplateArgumentLoc(*Iter, Result);
2968 return Result;
2969 }
2970
2971 pointer operator->() const { return pointer(**this); }
2972
2973 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2974 const TemplateArgumentLocInventIterator &Y) {
2975 return X.Iter == Y.Iter;
2976 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002977
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002978 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2979 const TemplateArgumentLocInventIterator &Y) {
2980 return X.Iter != Y.Iter;
2981 }
2982};
2983
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002984template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002985template<typename InputIterator>
2986bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2987 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002988 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002989 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002990 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002991 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002992
2993 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2994 // Unpack argument packs, which we translate them into separate
2995 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002996 // FIXME: We could do much better if we could guarantee that the
2997 // TemplateArgumentLocInfo for the pack expansion would be usable for
2998 // all of the template arguments in the argument pack.
2999 typedef TemplateArgumentLocInventIterator<Derived,
3000 TemplateArgument::pack_iterator>
3001 PackLocIterator;
3002 if (TransformTemplateArguments(PackLocIterator(*this,
3003 In.getArgument().pack_begin()),
3004 PackLocIterator(*this,
3005 In.getArgument().pack_end()),
3006 Outputs))
3007 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003008
3009 continue;
3010 }
3011
3012 if (In.getArgument().isPackExpansion()) {
3013 // We have a pack expansion, for which we will be substituting into
3014 // the pattern.
3015 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003016 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003017 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003018 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3019 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003020
3021 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3022 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3023 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3024
3025 // Determine whether the set of unexpanded parameter packs can and should
3026 // be expanded.
3027 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003028 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003029 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003030 if (getDerived().TryExpandParameterPacks(Ellipsis,
3031 Pattern.getSourceRange(),
3032 Unexpanded.data(),
3033 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003034 Expand,
3035 RetainExpansion,
3036 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003037 return true;
3038
3039 if (!Expand) {
3040 // The transform has determined that we should perform a simple
3041 // transformation on the pack expansion, producing another pack
3042 // expansion.
3043 TemplateArgumentLoc OutPattern;
3044 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3045 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3046 return true;
3047
Douglas Gregorcded4f62011-01-14 17:04:44 +00003048 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3049 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003050 if (Out.getArgument().isNull())
3051 return true;
3052
3053 Outputs.addArgument(Out);
3054 continue;
3055 }
3056
3057 // The transform has determined that we should perform an elementwise
3058 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003059 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003060 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3061
3062 if (getDerived().TransformTemplateArgument(Pattern, Out))
3063 return true;
3064
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003065 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003066 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3067 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003068 if (Out.getArgument().isNull())
3069 return true;
3070 }
3071
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003072 Outputs.addArgument(Out);
3073 }
3074
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003075 // If we're supposed to retain a pack expansion, do so by temporarily
3076 // forgetting the partially-substituted parameter pack.
3077 if (RetainExpansion) {
3078 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3079
3080 if (getDerived().TransformTemplateArgument(Pattern, Out))
3081 return true;
3082
Douglas Gregorcded4f62011-01-14 17:04:44 +00003083 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3084 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003085 if (Out.getArgument().isNull())
3086 return true;
3087
3088 Outputs.addArgument(Out);
3089 }
Douglas Gregord3731192011-01-10 07:32:04 +00003090
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003091 continue;
3092 }
3093
3094 // The simple case:
3095 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003096 return true;
3097
3098 Outputs.addArgument(Out);
3099 }
3100
3101 return false;
3102
3103}
3104
Douglas Gregor577f75a2009-08-04 16:50:30 +00003105//===----------------------------------------------------------------------===//
3106// Type transformation
3107//===----------------------------------------------------------------------===//
3108
3109template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003110QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003111 if (getDerived().AlreadyTransformed(T))
3112 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003113
John McCalla2becad2009-10-21 00:40:46 +00003114 // Temporary workaround. All of these transformations should
3115 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003116 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3117 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003118
John McCall43fed0d2010-11-12 08:19:04 +00003119 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003120
John McCalla2becad2009-10-21 00:40:46 +00003121 if (!NewDI)
3122 return QualType();
3123
3124 return NewDI->getType();
3125}
3126
3127template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003128TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00003129 if (getDerived().AlreadyTransformed(DI->getType()))
3130 return DI;
3131
3132 TypeLocBuilder TLB;
3133
3134 TypeLoc TL = DI->getTypeLoc();
3135 TLB.reserve(TL.getFullDataSize());
3136
John McCall43fed0d2010-11-12 08:19:04 +00003137 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003138 if (Result.isNull())
3139 return 0;
3140
John McCalla93c9342009-12-07 02:54:59 +00003141 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003142}
3143
3144template<typename Derived>
3145QualType
John McCall43fed0d2010-11-12 08:19:04 +00003146TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003147 switch (T.getTypeLocClass()) {
3148#define ABSTRACT_TYPELOC(CLASS, PARENT)
3149#define TYPELOC(CLASS, PARENT) \
3150 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003151 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003152#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003153 }
Mike Stump1eb44332009-09-09 15:08:12 +00003154
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003155 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003156 return QualType();
3157}
3158
3159/// FIXME: By default, this routine adds type qualifiers only to types
3160/// that can have qualifiers, and silently suppresses those qualifiers
3161/// that are not permitted (e.g., qualifiers on reference or function
3162/// types). This is the right thing for template instantiation, but
3163/// probably not for other clients.
3164template<typename Derived>
3165QualType
3166TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003167 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003168 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003169
John McCall43fed0d2010-11-12 08:19:04 +00003170 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003171 if (Result.isNull())
3172 return QualType();
3173
3174 // Silently suppress qualifiers if the result type can't be qualified.
3175 // FIXME: this is the right thing for template instantiation, but
3176 // probably not for other clients.
3177 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003178 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003179
John McCall28654742010-06-05 06:41:15 +00003180 if (!Quals.empty()) {
3181 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3182 TLB.push<QualifiedTypeLoc>(Result);
3183 // No location information to preserve.
3184 }
John McCalla2becad2009-10-21 00:40:46 +00003185
3186 return Result;
3187}
3188
John McCall43fed0d2010-11-12 08:19:04 +00003189/// \brief Transforms a type that was written in a scope specifier,
3190/// given an object type, the results of unqualified lookup, and
3191/// an already-instantiated prefix.
3192///
3193/// The object type is provided iff the scope specifier qualifies the
3194/// member of a dependent member-access expression. The prefix is
3195/// provided iff the the scope specifier in which this appears has a
3196/// prefix.
3197///
3198/// This is private to TreeTransform.
3199template<typename Derived>
3200QualType
3201TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3202 QualType ObjectType,
3203 NamedDecl *UnqualLookup,
3204 NestedNameSpecifier *Prefix) {
3205 if (getDerived().AlreadyTransformed(T))
3206 return T;
3207
3208 TypeSourceInfo *TSI =
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003209 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall43fed0d2010-11-12 08:19:04 +00003210
3211 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3212 UnqualLookup, Prefix);
3213 if (!TSI) return QualType();
3214 return TSI->getType();
3215}
3216
3217template<typename Derived>
3218TypeSourceInfo *
3219TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3220 QualType ObjectType,
3221 NamedDecl *UnqualLookup,
3222 NestedNameSpecifier *Prefix) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003223 // TODO: in some cases, we might have some verification to do here.
John McCall43fed0d2010-11-12 08:19:04 +00003224 if (ObjectType.isNull())
3225 return getDerived().TransformType(TSI);
3226
3227 QualType T = TSI->getType();
3228 if (getDerived().AlreadyTransformed(T))
3229 return TSI;
3230
3231 TypeLocBuilder TLB;
3232 QualType Result;
3233
3234 if (isa<TemplateSpecializationType>(T)) {
3235 TemplateSpecializationTypeLoc TL
3236 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3237
3238 TemplateName Template =
3239 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3240 ObjectType, UnqualLookup);
3241 if (Template.isNull()) return 0;
3242
3243 Result = getDerived()
3244 .TransformTemplateSpecializationType(TLB, TL, Template);
3245 } else if (isa<DependentTemplateSpecializationType>(T)) {
3246 DependentTemplateSpecializationTypeLoc TL
3247 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3248
Douglas Gregora88f09f2011-02-28 17:23:35 +00003249 TemplateName Template
3250 = SemaRef.Context.getDependentTemplateName(
3251 TL.getTypePtr()->getQualifier(),
3252 TL.getTypePtr()->getIdentifier());
3253
3254 Template = getDerived().TransformTemplateName(Template, ObjectType,
3255 UnqualLookup);
3256 if (Template.isNull())
3257 return 0;
3258
3259 Result = getDerived().TransformDependentTemplateSpecializationType(TLB, TL,
3260 Template);
John McCall43fed0d2010-11-12 08:19:04 +00003261 } else {
3262 // Nothing special needs to be done for these.
3263 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3264 }
3265
3266 if (Result.isNull()) return 0;
3267 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3268}
3269
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003270template<typename Derived>
3271TypeLoc
3272TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3273 QualType ObjectType,
3274 NamedDecl *UnqualLookup,
3275 CXXScopeSpec &SS) {
3276 // FIXME: Painfully copy-paste from the above!
3277
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003278 QualType T = TL.getType();
3279 if (getDerived().AlreadyTransformed(T))
3280 return TL;
3281
3282 TypeLocBuilder TLB;
3283 QualType Result;
3284
3285 if (isa<TemplateSpecializationType>(T)) {
3286 TemplateSpecializationTypeLoc SpecTL
3287 = cast<TemplateSpecializationTypeLoc>(TL);
3288
3289 TemplateName Template =
3290 getDerived().TransformTemplateName(SpecTL.getTypePtr()->getTemplateName(),
3291 ObjectType, UnqualLookup);
3292 if (Template.isNull())
3293 return TypeLoc();
3294
3295 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3296 Template);
3297 } else if (isa<DependentTemplateSpecializationType>(T)) {
3298 DependentTemplateSpecializationTypeLoc SpecTL
3299 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3300
Douglas Gregora88f09f2011-02-28 17:23:35 +00003301 TemplateName Template
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003302 = getDerived().RebuildTemplateName(SS.getScopeRep(), SS.getRange(),
3303 *SpecTL.getTypePtr()->getIdentifier(),
3304 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003305 if (Template.isNull())
3306 return TypeLoc();
3307
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003308 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003309 SpecTL,
3310 Template);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003311 } else {
3312 // Nothing special needs to be done for these.
3313 Result = getDerived().TransformType(TLB, TL);
3314 }
3315
3316 if (Result.isNull())
3317 return TypeLoc();
3318
3319 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3320}
3321
John McCalla2becad2009-10-21 00:40:46 +00003322template <class TyLoc> static inline
3323QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3324 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3325 NewT.setNameLoc(T.getNameLoc());
3326 return T.getType();
3327}
3328
John McCalla2becad2009-10-21 00:40:46 +00003329template<typename Derived>
3330QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003331 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003332 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3333 NewT.setBuiltinLoc(T.getBuiltinLoc());
3334 if (T.needsExtraLocalData())
3335 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3336 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003337}
Mike Stump1eb44332009-09-09 15:08:12 +00003338
Douglas Gregor577f75a2009-08-04 16:50:30 +00003339template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003340QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003341 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003342 // FIXME: recurse?
3343 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003344}
Mike Stump1eb44332009-09-09 15:08:12 +00003345
Douglas Gregor577f75a2009-08-04 16:50:30 +00003346template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003347QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003348 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003349 QualType PointeeType
3350 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003351 if (PointeeType.isNull())
3352 return QualType();
3353
3354 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003355 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003356 // A dependent pointer type 'T *' has is being transformed such
3357 // that an Objective-C class type is being replaced for 'T'. The
3358 // resulting pointer type is an ObjCObjectPointerType, not a
3359 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003360 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003361
John McCallc12c5bb2010-05-15 11:32:37 +00003362 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3363 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003364 return Result;
3365 }
John McCall43fed0d2010-11-12 08:19:04 +00003366
Douglas Gregor92e986e2010-04-22 16:44:27 +00003367 if (getDerived().AlwaysRebuild() ||
3368 PointeeType != TL.getPointeeLoc().getType()) {
3369 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3370 if (Result.isNull())
3371 return QualType();
3372 }
Sean Huntc3021132010-05-05 15:23:54 +00003373
Douglas Gregor92e986e2010-04-22 16:44:27 +00003374 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3375 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003376 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003377}
Mike Stump1eb44332009-09-09 15:08:12 +00003378
3379template<typename Derived>
3380QualType
John McCalla2becad2009-10-21 00:40:46 +00003381TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003382 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003383 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003384 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3385 if (PointeeType.isNull())
3386 return QualType();
3387
3388 QualType Result = TL.getType();
3389 if (getDerived().AlwaysRebuild() ||
3390 PointeeType != TL.getPointeeLoc().getType()) {
3391 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003392 TL.getSigilLoc());
3393 if (Result.isNull())
3394 return QualType();
3395 }
3396
Douglas Gregor39968ad2010-04-22 16:50:51 +00003397 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003398 NewT.setSigilLoc(TL.getSigilLoc());
3399 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003400}
3401
John McCall85737a72009-10-30 00:06:24 +00003402/// Transforms a reference type. Note that somewhat paradoxically we
3403/// don't care whether the type itself is an l-value type or an r-value
3404/// type; we only care if the type was *written* as an l-value type
3405/// or an r-value type.
3406template<typename Derived>
3407QualType
3408TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003409 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003410 const ReferenceType *T = TL.getTypePtr();
3411
3412 // Note that this works with the pointee-as-written.
3413 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3414 if (PointeeType.isNull())
3415 return QualType();
3416
3417 QualType Result = TL.getType();
3418 if (getDerived().AlwaysRebuild() ||
3419 PointeeType != T->getPointeeTypeAsWritten()) {
3420 Result = getDerived().RebuildReferenceType(PointeeType,
3421 T->isSpelledAsLValue(),
3422 TL.getSigilLoc());
3423 if (Result.isNull())
3424 return QualType();
3425 }
3426
3427 // r-value references can be rebuilt as l-value references.
3428 ReferenceTypeLoc NewTL;
3429 if (isa<LValueReferenceType>(Result))
3430 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3431 else
3432 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3433 NewTL.setSigilLoc(TL.getSigilLoc());
3434
3435 return Result;
3436}
3437
Mike Stump1eb44332009-09-09 15:08:12 +00003438template<typename Derived>
3439QualType
John McCalla2becad2009-10-21 00:40:46 +00003440TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003441 LValueReferenceTypeLoc TL) {
3442 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003443}
3444
Mike Stump1eb44332009-09-09 15:08:12 +00003445template<typename Derived>
3446QualType
John McCalla2becad2009-10-21 00:40:46 +00003447TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003448 RValueReferenceTypeLoc TL) {
3449 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003450}
Mike Stump1eb44332009-09-09 15:08:12 +00003451
Douglas Gregor577f75a2009-08-04 16:50:30 +00003452template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003453QualType
John McCalla2becad2009-10-21 00:40:46 +00003454TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003455 MemberPointerTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003456 const MemberPointerType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003457
3458 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003459 if (PointeeType.isNull())
3460 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003461
John McCalla2becad2009-10-21 00:40:46 +00003462 // TODO: preserve source information for this.
3463 QualType ClassType
3464 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003465 if (ClassType.isNull())
3466 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003467
John McCalla2becad2009-10-21 00:40:46 +00003468 QualType Result = TL.getType();
3469 if (getDerived().AlwaysRebuild() ||
3470 PointeeType != T->getPointeeType() ||
3471 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00003472 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3473 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003474 if (Result.isNull())
3475 return QualType();
3476 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003477
John McCalla2becad2009-10-21 00:40:46 +00003478 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3479 NewTL.setSigilLoc(TL.getSigilLoc());
3480
3481 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003482}
3483
Mike Stump1eb44332009-09-09 15:08:12 +00003484template<typename Derived>
3485QualType
John McCalla2becad2009-10-21 00:40:46 +00003486TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003487 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003488 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003489 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003490 if (ElementType.isNull())
3491 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003492
John McCalla2becad2009-10-21 00:40:46 +00003493 QualType Result = TL.getType();
3494 if (getDerived().AlwaysRebuild() ||
3495 ElementType != T->getElementType()) {
3496 Result = getDerived().RebuildConstantArrayType(ElementType,
3497 T->getSizeModifier(),
3498 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003499 T->getIndexTypeCVRQualifiers(),
3500 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003501 if (Result.isNull())
3502 return QualType();
3503 }
Sean Huntc3021132010-05-05 15:23:54 +00003504
John McCalla2becad2009-10-21 00:40:46 +00003505 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3506 NewTL.setLBracketLoc(TL.getLBracketLoc());
3507 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003508
John McCalla2becad2009-10-21 00:40:46 +00003509 Expr *Size = TL.getSizeExpr();
3510 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003511 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003512 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3513 }
3514 NewTL.setSizeExpr(Size);
3515
3516 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003517}
Mike Stump1eb44332009-09-09 15:08:12 +00003518
Douglas Gregor577f75a2009-08-04 16:50:30 +00003519template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003520QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003521 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003522 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003523 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003524 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003525 if (ElementType.isNull())
3526 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003527
John McCalla2becad2009-10-21 00:40:46 +00003528 QualType Result = TL.getType();
3529 if (getDerived().AlwaysRebuild() ||
3530 ElementType != T->getElementType()) {
3531 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003532 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003533 T->getIndexTypeCVRQualifiers(),
3534 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003535 if (Result.isNull())
3536 return QualType();
3537 }
Sean Huntc3021132010-05-05 15:23:54 +00003538
John McCalla2becad2009-10-21 00:40:46 +00003539 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3540 NewTL.setLBracketLoc(TL.getLBracketLoc());
3541 NewTL.setRBracketLoc(TL.getRBracketLoc());
3542 NewTL.setSizeExpr(0);
3543
3544 return Result;
3545}
3546
3547template<typename Derived>
3548QualType
3549TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003550 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003551 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003552 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3553 if (ElementType.isNull())
3554 return QualType();
3555
3556 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003557 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003558
John McCall60d7b3a2010-08-24 06:29:42 +00003559 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003560 = getDerived().TransformExpr(T->getSizeExpr());
3561 if (SizeResult.isInvalid())
3562 return QualType();
3563
John McCall9ae2f072010-08-23 23:25:46 +00003564 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003565
3566 QualType Result = TL.getType();
3567 if (getDerived().AlwaysRebuild() ||
3568 ElementType != T->getElementType() ||
3569 Size != T->getSizeExpr()) {
3570 Result = getDerived().RebuildVariableArrayType(ElementType,
3571 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003572 Size,
John McCalla2becad2009-10-21 00:40:46 +00003573 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003574 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003575 if (Result.isNull())
3576 return QualType();
3577 }
Sean Huntc3021132010-05-05 15:23:54 +00003578
John McCalla2becad2009-10-21 00:40:46 +00003579 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3580 NewTL.setLBracketLoc(TL.getLBracketLoc());
3581 NewTL.setRBracketLoc(TL.getRBracketLoc());
3582 NewTL.setSizeExpr(Size);
3583
3584 return Result;
3585}
3586
3587template<typename Derived>
3588QualType
3589TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003590 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003591 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003592 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3593 if (ElementType.isNull())
3594 return QualType();
3595
3596 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003597 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003598
John McCall3b657512011-01-19 10:06:00 +00003599 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3600 Expr *origSize = TL.getSizeExpr();
3601 if (!origSize) origSize = T->getSizeExpr();
3602
3603 ExprResult sizeResult
3604 = getDerived().TransformExpr(origSize);
3605 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003606 return QualType();
3607
John McCall3b657512011-01-19 10:06:00 +00003608 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003609
3610 QualType Result = TL.getType();
3611 if (getDerived().AlwaysRebuild() ||
3612 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003613 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003614 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3615 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003616 size,
John McCalla2becad2009-10-21 00:40:46 +00003617 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003618 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003619 if (Result.isNull())
3620 return QualType();
3621 }
John McCalla2becad2009-10-21 00:40:46 +00003622
3623 // We might have any sort of array type now, but fortunately they
3624 // all have the same location layout.
3625 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3626 NewTL.setLBracketLoc(TL.getLBracketLoc());
3627 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003628 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003629
3630 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003631}
Mike Stump1eb44332009-09-09 15:08:12 +00003632
3633template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003634QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003635 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003636 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003637 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003638
3639 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003640 QualType ElementType = getDerived().TransformType(T->getElementType());
3641 if (ElementType.isNull())
3642 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003643
Douglas Gregor670444e2009-08-04 22:27:00 +00003644 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003645 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003646
John McCall60d7b3a2010-08-24 06:29:42 +00003647 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003648 if (Size.isInvalid())
3649 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003650
John McCalla2becad2009-10-21 00:40:46 +00003651 QualType Result = TL.getType();
3652 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003653 ElementType != T->getElementType() ||
3654 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003655 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003656 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003657 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003658 if (Result.isNull())
3659 return QualType();
3660 }
John McCalla2becad2009-10-21 00:40:46 +00003661
3662 // Result might be dependent or not.
3663 if (isa<DependentSizedExtVectorType>(Result)) {
3664 DependentSizedExtVectorTypeLoc NewTL
3665 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3666 NewTL.setNameLoc(TL.getNameLoc());
3667 } else {
3668 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3669 NewTL.setNameLoc(TL.getNameLoc());
3670 }
3671
3672 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003673}
Mike Stump1eb44332009-09-09 15:08:12 +00003674
3675template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003676QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003677 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003678 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003679 QualType ElementType = getDerived().TransformType(T->getElementType());
3680 if (ElementType.isNull())
3681 return QualType();
3682
John McCalla2becad2009-10-21 00:40:46 +00003683 QualType Result = TL.getType();
3684 if (getDerived().AlwaysRebuild() ||
3685 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003686 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003687 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003688 if (Result.isNull())
3689 return QualType();
3690 }
Sean Huntc3021132010-05-05 15:23:54 +00003691
John McCalla2becad2009-10-21 00:40:46 +00003692 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3693 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003694
John McCalla2becad2009-10-21 00:40:46 +00003695 return Result;
3696}
3697
3698template<typename Derived>
3699QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003700 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003701 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003702 QualType ElementType = getDerived().TransformType(T->getElementType());
3703 if (ElementType.isNull())
3704 return QualType();
3705
3706 QualType Result = TL.getType();
3707 if (getDerived().AlwaysRebuild() ||
3708 ElementType != T->getElementType()) {
3709 Result = getDerived().RebuildExtVectorType(ElementType,
3710 T->getNumElements(),
3711 /*FIXME*/ SourceLocation());
3712 if (Result.isNull())
3713 return QualType();
3714 }
Sean Huntc3021132010-05-05 15:23:54 +00003715
John McCalla2becad2009-10-21 00:40:46 +00003716 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3717 NewTL.setNameLoc(TL.getNameLoc());
3718
3719 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003720}
Mike Stump1eb44332009-09-09 15:08:12 +00003721
3722template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003723ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003724TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3725 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003726 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003727 TypeSourceInfo *NewDI = 0;
3728
3729 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3730 // If we're substituting into a pack expansion type and we know the
3731 TypeLoc OldTL = OldDI->getTypeLoc();
3732 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3733
3734 TypeLocBuilder TLB;
3735 TypeLoc NewTL = OldDI->getTypeLoc();
3736 TLB.reserve(NewTL.getFullDataSize());
3737
3738 QualType Result = getDerived().TransformType(TLB,
3739 OldExpansionTL.getPatternLoc());
3740 if (Result.isNull())
3741 return 0;
3742
3743 Result = RebuildPackExpansionType(Result,
3744 OldExpansionTL.getPatternLoc().getSourceRange(),
3745 OldExpansionTL.getEllipsisLoc(),
3746 NumExpansions);
3747 if (Result.isNull())
3748 return 0;
3749
3750 PackExpansionTypeLoc NewExpansionTL
3751 = TLB.push<PackExpansionTypeLoc>(Result);
3752 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3753 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3754 } else
3755 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003756 if (!NewDI)
3757 return 0;
3758
3759 if (NewDI == OldDI)
3760 return OldParm;
3761 else
3762 return ParmVarDecl::Create(SemaRef.Context,
3763 OldParm->getDeclContext(),
3764 OldParm->getLocation(),
3765 OldParm->getIdentifier(),
3766 NewDI->getType(),
3767 NewDI,
3768 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00003769 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00003770 /* DefArg */ NULL);
3771}
3772
3773template<typename Derived>
3774bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003775 TransformFunctionTypeParams(SourceLocation Loc,
3776 ParmVarDecl **Params, unsigned NumParams,
3777 const QualType *ParamTypes,
3778 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3779 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3780 for (unsigned i = 0; i != NumParams; ++i) {
3781 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003782 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003783 if (OldParm->isParameterPack()) {
3784 // We have a function parameter pack that may need to be expanded.
3785 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003786
Douglas Gregor603cfb42011-01-05 23:12:31 +00003787 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003788 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3789 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3790 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3791 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003792
3793 // Determine whether we should expand the parameter packs.
3794 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003795 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003796 llvm::Optional<unsigned> OrigNumExpansions
3797 = ExpansionTL.getTypePtr()->getNumExpansions();
3798 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003799 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3800 Pattern.getSourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003801 Unexpanded.data(),
3802 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003803 ShouldExpand,
3804 RetainExpansion,
3805 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003806 return true;
3807 }
3808
3809 if (ShouldExpand) {
3810 // Expand the function parameter pack into multiple, separate
3811 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003812 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003813 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003814 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3815 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003816 = getDerived().TransformFunctionTypeParam(OldParm,
3817 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003818 if (!NewParm)
3819 return true;
3820
Douglas Gregora009b592011-01-07 00:20:55 +00003821 OutParamTypes.push_back(NewParm->getType());
3822 if (PVars)
3823 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003824 }
Douglas Gregord3731192011-01-10 07:32:04 +00003825
3826 // If we're supposed to retain a pack expansion, do so by temporarily
3827 // forgetting the partially-substituted parameter pack.
3828 if (RetainExpansion) {
3829 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3830 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003831 = getDerived().TransformFunctionTypeParam(OldParm,
3832 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003833 if (!NewParm)
3834 return true;
3835
3836 OutParamTypes.push_back(NewParm->getType());
3837 if (PVars)
3838 PVars->push_back(NewParm);
3839 }
3840
Douglas Gregor603cfb42011-01-05 23:12:31 +00003841 // We're done with the pack expansion.
3842 continue;
3843 }
3844
3845 // We'll substitute the parameter now without expanding the pack
3846 // expansion.
3847 }
3848
3849 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003850 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3851 NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +00003852 if (!NewParm)
3853 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003854
Douglas Gregora009b592011-01-07 00:20:55 +00003855 OutParamTypes.push_back(NewParm->getType());
3856 if (PVars)
3857 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003858 continue;
3859 }
John McCall21ef0fa2010-03-11 09:03:00 +00003860
3861 // Deal with the possibility that we don't have a parameter
3862 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003863 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003864 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003865 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003866 if (const PackExpansionType *Expansion
3867 = dyn_cast<PackExpansionType>(OldType)) {
3868 // We have a function parameter pack that may need to be expanded.
3869 QualType Pattern = Expansion->getPattern();
3870 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3871 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3872
3873 // Determine whether we should expand the parameter packs.
3874 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003875 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003876 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003877 Unexpanded.data(),
3878 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003879 ShouldExpand,
3880 RetainExpansion,
3881 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003882 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003883 }
3884
3885 if (ShouldExpand) {
3886 // Expand the function parameter pack into multiple, separate
3887 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003888 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003889 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3890 QualType NewType = getDerived().TransformType(Pattern);
3891 if (NewType.isNull())
3892 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003893
Douglas Gregora009b592011-01-07 00:20:55 +00003894 OutParamTypes.push_back(NewType);
3895 if (PVars)
3896 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003897 }
3898
3899 // We're done with the pack expansion.
3900 continue;
3901 }
3902
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003903 // If we're supposed to retain a pack expansion, do so by temporarily
3904 // forgetting the partially-substituted parameter pack.
3905 if (RetainExpansion) {
3906 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3907 QualType NewType = getDerived().TransformType(Pattern);
3908 if (NewType.isNull())
3909 return true;
3910
3911 OutParamTypes.push_back(NewType);
3912 if (PVars)
3913 PVars->push_back(0);
3914 }
Douglas Gregord3731192011-01-10 07:32:04 +00003915
Douglas Gregor603cfb42011-01-05 23:12:31 +00003916 // We'll substitute the parameter now without expanding the pack
3917 // expansion.
3918 OldType = Expansion->getPattern();
3919 IsPackExpansion = true;
3920 }
3921
3922 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3923 QualType NewType = getDerived().TransformType(OldType);
3924 if (NewType.isNull())
3925 return true;
3926
3927 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00003928 NewType = getSema().Context.getPackExpansionType(NewType,
3929 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003930
Douglas Gregora009b592011-01-07 00:20:55 +00003931 OutParamTypes.push_back(NewType);
3932 if (PVars)
3933 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00003934 }
3935
3936 return false;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003937 }
John McCall21ef0fa2010-03-11 09:03:00 +00003938
3939template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003940QualType
John McCalla2becad2009-10-21 00:40:46 +00003941TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003942 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003943 // Transform the parameters and return type.
3944 //
3945 // We instantiate in source order, with the return type first followed by
3946 // the parameters, because users tend to expect this (even if they shouldn't
3947 // rely on it!).
3948 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003949 // When the function has a trailing return type, we instantiate the
3950 // parameters before the return type, since the return type can then refer
3951 // to the parameters themselves (via decltype, sizeof, etc.).
3952 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003953 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003954 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00003955 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003956
Douglas Gregordab60ad2010-10-01 18:44:50 +00003957 QualType ResultType;
3958
3959 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00003960 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3961 TL.getParmArray(),
3962 TL.getNumArgs(),
3963 TL.getTypePtr()->arg_type_begin(),
3964 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003965 return QualType();
3966
3967 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3968 if (ResultType.isNull())
3969 return QualType();
3970 }
3971 else {
3972 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3973 if (ResultType.isNull())
3974 return QualType();
3975
Douglas Gregora009b592011-01-07 00:20:55 +00003976 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3977 TL.getParmArray(),
3978 TL.getNumArgs(),
3979 TL.getTypePtr()->arg_type_begin(),
3980 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003981 return QualType();
3982 }
3983
John McCalla2becad2009-10-21 00:40:46 +00003984 QualType Result = TL.getType();
3985 if (getDerived().AlwaysRebuild() ||
3986 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00003987 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00003988 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3989 Result = getDerived().RebuildFunctionProtoType(ResultType,
3990 ParamTypes.data(),
3991 ParamTypes.size(),
3992 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003993 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00003994 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003995 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00003996 if (Result.isNull())
3997 return QualType();
3998 }
Mike Stump1eb44332009-09-09 15:08:12 +00003999
John McCalla2becad2009-10-21 00:40:46 +00004000 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4001 NewTL.setLParenLoc(TL.getLParenLoc());
4002 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004003 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004004 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4005 NewTL.setArg(i, ParamDecls[i]);
4006
4007 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004008}
Mike Stump1eb44332009-09-09 15:08:12 +00004009
Douglas Gregor577f75a2009-08-04 16:50:30 +00004010template<typename Derived>
4011QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004012 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004013 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004014 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004015 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4016 if (ResultType.isNull())
4017 return QualType();
4018
4019 QualType Result = TL.getType();
4020 if (getDerived().AlwaysRebuild() ||
4021 ResultType != T->getResultType())
4022 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4023
4024 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4025 NewTL.setLParenLoc(TL.getLParenLoc());
4026 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004027 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004028
4029 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004030}
Mike Stump1eb44332009-09-09 15:08:12 +00004031
John McCalled976492009-12-04 22:46:56 +00004032template<typename Derived> QualType
4033TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004034 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004035 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004036 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004037 if (!D)
4038 return QualType();
4039
4040 QualType Result = TL.getType();
4041 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4042 Result = getDerived().RebuildUnresolvedUsingType(D);
4043 if (Result.isNull())
4044 return QualType();
4045 }
4046
4047 // We might get an arbitrary type spec type back. We should at
4048 // least always get a type spec type, though.
4049 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4050 NewTL.setNameLoc(TL.getNameLoc());
4051
4052 return Result;
4053}
4054
Douglas Gregor577f75a2009-08-04 16:50:30 +00004055template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004056QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004057 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004058 const TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004059 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004060 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4061 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004062 if (!Typedef)
4063 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004064
John McCalla2becad2009-10-21 00:40:46 +00004065 QualType Result = TL.getType();
4066 if (getDerived().AlwaysRebuild() ||
4067 Typedef != T->getDecl()) {
4068 Result = getDerived().RebuildTypedefType(Typedef);
4069 if (Result.isNull())
4070 return QualType();
4071 }
Mike Stump1eb44332009-09-09 15:08:12 +00004072
John McCalla2becad2009-10-21 00:40:46 +00004073 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4074 NewTL.setNameLoc(TL.getNameLoc());
4075
4076 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004077}
Mike Stump1eb44332009-09-09 15:08:12 +00004078
Douglas Gregor577f75a2009-08-04 16:50:30 +00004079template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004080QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004081 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004082 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004083 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004084
John McCall60d7b3a2010-08-24 06:29:42 +00004085 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004086 if (E.isInvalid())
4087 return QualType();
4088
John McCalla2becad2009-10-21 00:40:46 +00004089 QualType Result = TL.getType();
4090 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004091 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004092 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004093 if (Result.isNull())
4094 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004095 }
John McCalla2becad2009-10-21 00:40:46 +00004096 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004097
John McCalla2becad2009-10-21 00:40:46 +00004098 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004099 NewTL.setTypeofLoc(TL.getTypeofLoc());
4100 NewTL.setLParenLoc(TL.getLParenLoc());
4101 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004102
4103 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004104}
Mike Stump1eb44332009-09-09 15:08:12 +00004105
4106template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004107QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004108 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004109 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4110 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4111 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004112 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004113
John McCalla2becad2009-10-21 00:40:46 +00004114 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004115 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4116 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004117 if (Result.isNull())
4118 return QualType();
4119 }
Mike Stump1eb44332009-09-09 15:08:12 +00004120
John McCalla2becad2009-10-21 00:40:46 +00004121 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004122 NewTL.setTypeofLoc(TL.getTypeofLoc());
4123 NewTL.setLParenLoc(TL.getLParenLoc());
4124 NewTL.setRParenLoc(TL.getRParenLoc());
4125 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004126
4127 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004128}
Mike Stump1eb44332009-09-09 15:08:12 +00004129
4130template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004131QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004132 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004133 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004134
Douglas Gregor670444e2009-08-04 22:27:00 +00004135 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004136 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004137
John McCall60d7b3a2010-08-24 06:29:42 +00004138 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004139 if (E.isInvalid())
4140 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004141
John McCalla2becad2009-10-21 00:40:46 +00004142 QualType Result = TL.getType();
4143 if (getDerived().AlwaysRebuild() ||
4144 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004145 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004146 if (Result.isNull())
4147 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004148 }
John McCalla2becad2009-10-21 00:40:46 +00004149 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004150
John McCalla2becad2009-10-21 00:40:46 +00004151 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4152 NewTL.setNameLoc(TL.getNameLoc());
4153
4154 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004155}
4156
4157template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004158QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4159 AutoTypeLoc TL) {
4160 const AutoType *T = TL.getTypePtr();
4161 QualType OldDeduced = T->getDeducedType();
4162 QualType NewDeduced;
4163 if (!OldDeduced.isNull()) {
4164 NewDeduced = getDerived().TransformType(OldDeduced);
4165 if (NewDeduced.isNull())
4166 return QualType();
4167 }
4168
4169 QualType Result = TL.getType();
4170 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4171 Result = getDerived().RebuildAutoType(NewDeduced);
4172 if (Result.isNull())
4173 return QualType();
4174 }
4175
4176 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4177 NewTL.setNameLoc(TL.getNameLoc());
4178
4179 return Result;
4180}
4181
4182template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004183QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004184 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004185 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004186 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004187 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4188 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004189 if (!Record)
4190 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004191
John McCalla2becad2009-10-21 00:40:46 +00004192 QualType Result = TL.getType();
4193 if (getDerived().AlwaysRebuild() ||
4194 Record != T->getDecl()) {
4195 Result = getDerived().RebuildRecordType(Record);
4196 if (Result.isNull())
4197 return QualType();
4198 }
Mike Stump1eb44332009-09-09 15:08:12 +00004199
John McCalla2becad2009-10-21 00:40:46 +00004200 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4201 NewTL.setNameLoc(TL.getNameLoc());
4202
4203 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004204}
Mike Stump1eb44332009-09-09 15:08:12 +00004205
4206template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004207QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004208 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004209 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004210 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004211 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4212 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004213 if (!Enum)
4214 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004215
John McCalla2becad2009-10-21 00:40:46 +00004216 QualType Result = TL.getType();
4217 if (getDerived().AlwaysRebuild() ||
4218 Enum != T->getDecl()) {
4219 Result = getDerived().RebuildEnumType(Enum);
4220 if (Result.isNull())
4221 return QualType();
4222 }
Mike Stump1eb44332009-09-09 15:08:12 +00004223
John McCalla2becad2009-10-21 00:40:46 +00004224 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4225 NewTL.setNameLoc(TL.getNameLoc());
4226
4227 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004228}
John McCall7da24312009-09-05 00:15:47 +00004229
John McCall3cb0ebd2010-03-10 03:28:59 +00004230template<typename Derived>
4231QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4232 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004233 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004234 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4235 TL.getTypePtr()->getDecl());
4236 if (!D) return QualType();
4237
4238 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4239 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4240 return T;
4241}
4242
Douglas Gregor577f75a2009-08-04 16:50:30 +00004243template<typename Derived>
4244QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004245 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004246 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004247 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004248}
4249
Mike Stump1eb44332009-09-09 15:08:12 +00004250template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004251QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004252 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004253 SubstTemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004254 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00004255}
4256
4257template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004258QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4259 TypeLocBuilder &TLB,
4260 SubstTemplateTypeParmPackTypeLoc TL) {
4261 return TransformTypeSpecType(TLB, TL);
4262}
4263
4264template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004265QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004266 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004267 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004268 const TemplateSpecializationType *T = TL.getTypePtr();
4269
Mike Stump1eb44332009-09-09 15:08:12 +00004270 TemplateName Template
John McCall43fed0d2010-11-12 08:19:04 +00004271 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004272 if (Template.isNull())
4273 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004274
John McCall43fed0d2010-11-12 08:19:04 +00004275 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4276}
4277
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004278namespace {
4279 /// \brief Simple iterator that traverses the template arguments in a
4280 /// container that provides a \c getArgLoc() member function.
4281 ///
4282 /// This iterator is intended to be used with the iterator form of
4283 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4284 template<typename ArgLocContainer>
4285 class TemplateArgumentLocContainerIterator {
4286 ArgLocContainer *Container;
4287 unsigned Index;
4288
4289 public:
4290 typedef TemplateArgumentLoc value_type;
4291 typedef TemplateArgumentLoc reference;
4292 typedef int difference_type;
4293 typedef std::input_iterator_tag iterator_category;
4294
4295 class pointer {
4296 TemplateArgumentLoc Arg;
4297
4298 public:
4299 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4300
4301 const TemplateArgumentLoc *operator->() const {
4302 return &Arg;
4303 }
4304 };
4305
4306
4307 TemplateArgumentLocContainerIterator() {}
4308
4309 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4310 unsigned Index)
4311 : Container(&Container), Index(Index) { }
4312
4313 TemplateArgumentLocContainerIterator &operator++() {
4314 ++Index;
4315 return *this;
4316 }
4317
4318 TemplateArgumentLocContainerIterator operator++(int) {
4319 TemplateArgumentLocContainerIterator Old(*this);
4320 ++(*this);
4321 return Old;
4322 }
4323
4324 TemplateArgumentLoc operator*() const {
4325 return Container->getArgLoc(Index);
4326 }
4327
4328 pointer operator->() const {
4329 return pointer(Container->getArgLoc(Index));
4330 }
4331
4332 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004333 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004334 return X.Container == Y.Container && X.Index == Y.Index;
4335 }
4336
4337 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004338 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004339 return !(X == Y);
4340 }
4341 };
4342}
4343
4344
John McCall43fed0d2010-11-12 08:19:04 +00004345template <typename Derived>
4346QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4347 TypeLocBuilder &TLB,
4348 TemplateSpecializationTypeLoc TL,
4349 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004350 TemplateArgumentListInfo NewTemplateArgs;
4351 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4352 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004353 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4354 ArgIterator;
4355 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4356 ArgIterator(TL, TL.getNumArgs()),
4357 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004358 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004359
John McCall833ca992009-10-29 08:12:44 +00004360 // FIXME: maybe don't rebuild if all the template arguments are the same.
4361
4362 QualType Result =
4363 getDerived().RebuildTemplateSpecializationType(Template,
4364 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004365 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004366
4367 if (!Result.isNull()) {
4368 TemplateSpecializationTypeLoc NewTL
4369 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4370 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4371 NewTL.setLAngleLoc(TL.getLAngleLoc());
4372 NewTL.setRAngleLoc(TL.getRAngleLoc());
4373 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4374 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004375 }
Mike Stump1eb44332009-09-09 15:08:12 +00004376
John McCall833ca992009-10-29 08:12:44 +00004377 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004378}
Mike Stump1eb44332009-09-09 15:08:12 +00004379
Douglas Gregora88f09f2011-02-28 17:23:35 +00004380template <typename Derived>
4381QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4382 TypeLocBuilder &TLB,
4383 DependentTemplateSpecializationTypeLoc TL,
4384 TemplateName Template) {
4385 TemplateArgumentListInfo NewTemplateArgs;
4386 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4387 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4388 typedef TemplateArgumentLocContainerIterator<
4389 DependentTemplateSpecializationTypeLoc> ArgIterator;
4390 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4391 ArgIterator(TL, TL.getNumArgs()),
4392 NewTemplateArgs))
4393 return QualType();
4394
4395 // FIXME: maybe don't rebuild if all the template arguments are the same.
4396
4397 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4398 QualType Result
4399 = getSema().Context.getDependentTemplateSpecializationType(
4400 TL.getTypePtr()->getKeyword(),
4401 DTN->getQualifier(),
4402 DTN->getIdentifier(),
4403 NewTemplateArgs);
4404
4405 DependentTemplateSpecializationTypeLoc NewTL
4406 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4407 NewTL.setKeywordLoc(TL.getKeywordLoc());
4408 NewTL.setQualifierRange(TL.getQualifierRange());
4409 NewTL.setNameLoc(TL.getNameLoc());
4410 NewTL.setLAngleLoc(TL.getLAngleLoc());
4411 NewTL.setRAngleLoc(TL.getRAngleLoc());
4412 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4413 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4414 return Result;
4415 }
4416
4417 QualType Result
4418 = getDerived().RebuildTemplateSpecializationType(Template,
4419 TL.getNameLoc(),
4420 NewTemplateArgs);
4421
4422 if (!Result.isNull()) {
4423 /// FIXME: Wrap this in an elaborated-type-specifier?
4424 TemplateSpecializationTypeLoc NewTL
4425 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4426 NewTL.setTemplateNameLoc(TL.getNameLoc());
4427 NewTL.setLAngleLoc(TL.getLAngleLoc());
4428 NewTL.setRAngleLoc(TL.getRAngleLoc());
4429 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4430 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4431 }
4432
4433 return Result;
4434}
4435
Mike Stump1eb44332009-09-09 15:08:12 +00004436template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004437QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004438TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004439 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004440 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004441
Douglas Gregor239cbb02011-03-01 03:11:17 +00004442 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004443 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor239cbb02011-03-01 03:11:17 +00004444 if (TL.getQualifierLoc()) {
4445 QualifierLoc
4446 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4447 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004448 return QualType();
4449 }
Mike Stump1eb44332009-09-09 15:08:12 +00004450
John McCall43fed0d2010-11-12 08:19:04 +00004451 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4452 if (NamedT.isNull())
4453 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004454
John McCalla2becad2009-10-21 00:40:46 +00004455 QualType Result = TL.getType();
4456 if (getDerived().AlwaysRebuild() ||
Douglas Gregor239cbb02011-03-01 03:11:17 +00004457 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004458 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004459 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor239cbb02011-03-01 03:11:17 +00004460 T->getKeyword(),
4461 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004462 if (Result.isNull())
4463 return QualType();
4464 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004465
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004466 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004467 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor239cbb02011-03-01 03:11:17 +00004468 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004469 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004470}
Mike Stump1eb44332009-09-09 15:08:12 +00004471
4472template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004473QualType TreeTransform<Derived>::TransformAttributedType(
4474 TypeLocBuilder &TLB,
4475 AttributedTypeLoc TL) {
4476 const AttributedType *oldType = TL.getTypePtr();
4477 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4478 if (modifiedType.isNull())
4479 return QualType();
4480
4481 QualType result = TL.getType();
4482
4483 // FIXME: dependent operand expressions?
4484 if (getDerived().AlwaysRebuild() ||
4485 modifiedType != oldType->getModifiedType()) {
4486 // TODO: this is really lame; we should really be rebuilding the
4487 // equivalent type from first principles.
4488 QualType equivalentType
4489 = getDerived().TransformType(oldType->getEquivalentType());
4490 if (equivalentType.isNull())
4491 return QualType();
4492 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4493 modifiedType,
4494 equivalentType);
4495 }
4496
4497 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4498 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4499 if (TL.hasAttrOperand())
4500 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4501 if (TL.hasAttrExprOperand())
4502 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4503 else if (TL.hasAttrEnumOperand())
4504 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4505
4506 return result;
4507}
4508
4509template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004510QualType
4511TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4512 ParenTypeLoc TL) {
4513 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4514 if (Inner.isNull())
4515 return QualType();
4516
4517 QualType Result = TL.getType();
4518 if (getDerived().AlwaysRebuild() ||
4519 Inner != TL.getInnerLoc().getType()) {
4520 Result = getDerived().RebuildParenType(Inner);
4521 if (Result.isNull())
4522 return QualType();
4523 }
4524
4525 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4526 NewTL.setLParenLoc(TL.getLParenLoc());
4527 NewTL.setRParenLoc(TL.getRParenLoc());
4528 return Result;
4529}
4530
4531template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004532QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004533 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004534 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004535
Douglas Gregor2494dd02011-03-01 01:34:45 +00004536 NestedNameSpecifierLoc QualifierLoc
4537 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4538 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004539 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004540
John McCall33500952010-06-11 00:33:02 +00004541 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004542 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCall33500952010-06-11 00:33:02 +00004543 TL.getKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004544 QualifierLoc,
4545 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004546 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004547 if (Result.isNull())
4548 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004549
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004550 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4551 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004552 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4553
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004554 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4555 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor239cbb02011-03-01 03:11:17 +00004556 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004557 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004558 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4559 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004560 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004561 NewTL.setNameLoc(TL.getNameLoc());
4562 }
John McCalla2becad2009-10-21 00:40:46 +00004563 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004564}
Mike Stump1eb44332009-09-09 15:08:12 +00004565
Douglas Gregor577f75a2009-08-04 16:50:30 +00004566template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004567QualType TreeTransform<Derived>::
4568 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004569 DependentTemplateSpecializationTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004570 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall33500952010-06-11 00:33:02 +00004571
Douglas Gregora88f09f2011-02-28 17:23:35 +00004572 NestedNameSpecifier *NNS = 0;
4573 if (T->getQualifier()) {
4574 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
4575 TL.getQualifierRange());
4576 if (!NNS)
4577 return QualType();
4578 }
4579
John McCall43fed0d2010-11-12 08:19:04 +00004580 return getDerived()
4581 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4582}
4583
4584template<typename Derived>
4585QualType TreeTransform<Derived>::
4586 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4587 DependentTemplateSpecializationTypeLoc TL,
4588 NestedNameSpecifier *NNS) {
John McCallf4c73712011-01-19 06:33:43 +00004589 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall43fed0d2010-11-12 08:19:04 +00004590
John McCall33500952010-06-11 00:33:02 +00004591 TemplateArgumentListInfo NewTemplateArgs;
4592 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4593 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00004594
4595 // FIXME: Nested-name-specifier source location info!
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004596 typedef TemplateArgumentLocContainerIterator<
4597 DependentTemplateSpecializationTypeLoc> ArgIterator;
4598 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4599 ArgIterator(TL, TL.getNumArgs()),
4600 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004601 return QualType();
John McCall33500952010-06-11 00:33:02 +00004602
Douglas Gregor1efb6c72010-09-08 23:56:00 +00004603 QualType Result
4604 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4605 NNS,
4606 TL.getQualifierRange(),
4607 T->getIdentifier(),
4608 TL.getNameLoc(),
4609 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00004610 if (Result.isNull())
4611 return QualType();
4612
4613 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4614 QualType NamedT = ElabT->getNamedType();
4615
4616 // Copy information relevant to the template specialization.
4617 TemplateSpecializationTypeLoc NamedTL
4618 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4619 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4620 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4621 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4622 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4623
4624 // Copy information relevant to the elaborated type.
4625 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4626 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor239cbb02011-03-01 03:11:17 +00004627
4628 // FIXME: DependentTemplateSpecializationType needs better source-location
4629 // info.
4630 NestedNameSpecifierLocBuilder Builder;
4631 Builder.MakeTrivial(SemaRef.Context, NNS, TL.getQualifierRange());
4632 NewTL.setQualifierLoc(Builder.getWithLocInContext(SemaRef.Context));
John McCall33500952010-06-11 00:33:02 +00004633 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00004634 TypeLoc NewTL(Result, TL.getOpaqueData());
4635 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00004636 }
4637 return Result;
4638}
4639
4640template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004641QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4642 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004643 QualType Pattern
4644 = getDerived().TransformType(TLB, TL.getPatternLoc());
4645 if (Pattern.isNull())
4646 return QualType();
4647
4648 QualType Result = TL.getType();
4649 if (getDerived().AlwaysRebuild() ||
4650 Pattern != TL.getPatternLoc().getType()) {
4651 Result = getDerived().RebuildPackExpansionType(Pattern,
4652 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004653 TL.getEllipsisLoc(),
4654 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004655 if (Result.isNull())
4656 return QualType();
4657 }
4658
4659 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4660 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4661 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004662}
4663
4664template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004665QualType
4666TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004667 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004668 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004669 TLB.pushFullCopy(TL);
4670 return TL.getType();
4671}
4672
4673template<typename Derived>
4674QualType
4675TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004676 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004677 // ObjCObjectType is never dependent.
4678 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004679 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004680}
Mike Stump1eb44332009-09-09 15:08:12 +00004681
4682template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004683QualType
4684TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004685 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004686 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004687 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004688 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004689}
4690
Douglas Gregor577f75a2009-08-04 16:50:30 +00004691//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004692// Statement transformation
4693//===----------------------------------------------------------------------===//
4694template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004695StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004696TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004697 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004698}
4699
4700template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004701StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004702TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4703 return getDerived().TransformCompoundStmt(S, false);
4704}
4705
4706template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004707StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004708TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004709 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004710 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004711 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004712 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004713 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4714 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004715 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004716 if (Result.isInvalid()) {
4717 // Immediately fail if this was a DeclStmt, since it's very
4718 // likely that this will cause problems for future statements.
4719 if (isa<DeclStmt>(*B))
4720 return StmtError();
4721
4722 // Otherwise, just keep processing substatements and fail later.
4723 SubStmtInvalid = true;
4724 continue;
4725 }
Mike Stump1eb44332009-09-09 15:08:12 +00004726
Douglas Gregor43959a92009-08-20 07:17:43 +00004727 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4728 Statements.push_back(Result.takeAs<Stmt>());
4729 }
Mike Stump1eb44332009-09-09 15:08:12 +00004730
John McCall7114cba2010-08-27 19:56:05 +00004731 if (SubStmtInvalid)
4732 return StmtError();
4733
Douglas Gregor43959a92009-08-20 07:17:43 +00004734 if (!getDerived().AlwaysRebuild() &&
4735 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004736 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004737
4738 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4739 move_arg(Statements),
4740 S->getRBracLoc(),
4741 IsStmtExpr);
4742}
Mike Stump1eb44332009-09-09 15:08:12 +00004743
Douglas Gregor43959a92009-08-20 07:17:43 +00004744template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004745StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004746TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004747 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004748 {
4749 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004750 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004751
Eli Friedman264c1f82009-11-19 03:14:00 +00004752 // Transform the left-hand case value.
4753 LHS = getDerived().TransformExpr(S->getLHS());
4754 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004755 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004756
Eli Friedman264c1f82009-11-19 03:14:00 +00004757 // Transform the right-hand case value (for the GNU case-range extension).
4758 RHS = getDerived().TransformExpr(S->getRHS());
4759 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004760 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004761 }
Mike Stump1eb44332009-09-09 15:08:12 +00004762
Douglas Gregor43959a92009-08-20 07:17:43 +00004763 // Build the case statement.
4764 // Case statements are always rebuilt so that they will attached to their
4765 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004766 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004767 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004768 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004769 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004770 S->getColonLoc());
4771 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004772 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004773
Douglas Gregor43959a92009-08-20 07:17:43 +00004774 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004775 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004776 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004777 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004778
Douglas Gregor43959a92009-08-20 07:17:43 +00004779 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004780 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004781}
4782
4783template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004784StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004785TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004786 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00004787 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004788 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004789 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004790
Douglas Gregor43959a92009-08-20 07:17:43 +00004791 // Default statements are always rebuilt
4792 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004793 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004794}
Mike Stump1eb44332009-09-09 15:08:12 +00004795
Douglas Gregor43959a92009-08-20 07:17:43 +00004796template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004797StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004798TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004799 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004800 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004801 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004802
Chris Lattner57ad3782011-02-17 20:34:02 +00004803 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4804 S->getDecl());
4805 if (!LD)
4806 return StmtError();
4807
4808
Douglas Gregor43959a92009-08-20 07:17:43 +00004809 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00004810 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00004811 cast<LabelDecl>(LD), SourceLocation(),
4812 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004813}
Mike Stump1eb44332009-09-09 15:08:12 +00004814
Douglas Gregor43959a92009-08-20 07:17:43 +00004815template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004816StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004817TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004818 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004819 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004820 VarDecl *ConditionVar = 0;
4821 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004822 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004823 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004824 getDerived().TransformDefinition(
4825 S->getConditionVariable()->getLocation(),
4826 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004827 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004828 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004829 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004830 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004831
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004832 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004833 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004834
4835 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004836 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004837 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4838 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004839 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004840 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004841
John McCall9ae2f072010-08-23 23:25:46 +00004842 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004843 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004844 }
Sean Huntc3021132010-05-05 15:23:54 +00004845
John McCall9ae2f072010-08-23 23:25:46 +00004846 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4847 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004848 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004849
Douglas Gregor43959a92009-08-20 07:17:43 +00004850 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004851 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00004852 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004853 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004854
Douglas Gregor43959a92009-08-20 07:17:43 +00004855 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004856 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00004857 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004858 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004859
Douglas Gregor43959a92009-08-20 07:17:43 +00004860 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004861 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004862 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004863 Then.get() == S->getThen() &&
4864 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00004865 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004866
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004867 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00004868 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00004869 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004870}
4871
4872template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004873StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004874TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004875 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00004876 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00004877 VarDecl *ConditionVar = 0;
4878 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004879 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00004880 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004881 getDerived().TransformDefinition(
4882 S->getConditionVariable()->getLocation(),
4883 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00004884 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004885 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004886 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00004887 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004888
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004889 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004890 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004891 }
Mike Stump1eb44332009-09-09 15:08:12 +00004892
Douglas Gregor43959a92009-08-20 07:17:43 +00004893 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004894 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00004895 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00004896 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00004897 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004898 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004899
Douglas Gregor43959a92009-08-20 07:17:43 +00004900 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004901 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004902 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004903 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004904
Douglas Gregor43959a92009-08-20 07:17:43 +00004905 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00004906 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4907 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004908}
Mike Stump1eb44332009-09-09 15:08:12 +00004909
Douglas Gregor43959a92009-08-20 07:17:43 +00004910template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004911StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004912TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004913 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004914 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00004915 VarDecl *ConditionVar = 0;
4916 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004917 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00004918 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004919 getDerived().TransformDefinition(
4920 S->getConditionVariable()->getLocation(),
4921 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00004922 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004923 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004924 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00004925 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004926
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004927 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004928 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004929
4930 if (S->getCond()) {
4931 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004932 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4933 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004934 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004935 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00004936 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004937 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004938 }
Mike Stump1eb44332009-09-09 15:08:12 +00004939
John McCall9ae2f072010-08-23 23:25:46 +00004940 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4941 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004942 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004943
Douglas Gregor43959a92009-08-20 07:17:43 +00004944 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004945 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004946 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004947 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004948
Douglas Gregor43959a92009-08-20 07:17:43 +00004949 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004950 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004951 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004952 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00004953 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004954
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004955 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00004956 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004957}
Mike Stump1eb44332009-09-09 15:08:12 +00004958
Douglas Gregor43959a92009-08-20 07:17:43 +00004959template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004960StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004961TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004962 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004963 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004964 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004965 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004966
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004967 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004968 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004969 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004970 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004971
Douglas Gregor43959a92009-08-20 07:17:43 +00004972 if (!getDerived().AlwaysRebuild() &&
4973 Cond.get() == S->getCond() &&
4974 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004975 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004976
John McCall9ae2f072010-08-23 23:25:46 +00004977 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4978 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004979 S->getRParenLoc());
4980}
Mike Stump1eb44332009-09-09 15:08:12 +00004981
Douglas Gregor43959a92009-08-20 07:17:43 +00004982template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004983StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004984TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004985 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00004986 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00004987 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004988 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004989
Douglas Gregor43959a92009-08-20 07:17:43 +00004990 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004991 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004992 VarDecl *ConditionVar = 0;
4993 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004994 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004995 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004996 getDerived().TransformDefinition(
4997 S->getConditionVariable()->getLocation(),
4998 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004999 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005000 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005001 } else {
5002 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005003
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005004 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005005 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005006
5007 if (S->getCond()) {
5008 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005009 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5010 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005011 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005012 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005013
John McCall9ae2f072010-08-23 23:25:46 +00005014 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005015 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005016 }
Mike Stump1eb44332009-09-09 15:08:12 +00005017
John McCall9ae2f072010-08-23 23:25:46 +00005018 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5019 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005020 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005021
Douglas Gregor43959a92009-08-20 07:17:43 +00005022 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005023 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005024 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005025 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005026
John McCall9ae2f072010-08-23 23:25:46 +00005027 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5028 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005029 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005030
Douglas Gregor43959a92009-08-20 07:17:43 +00005031 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005032 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005033 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005034 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005035
Douglas Gregor43959a92009-08-20 07:17:43 +00005036 if (!getDerived().AlwaysRebuild() &&
5037 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005038 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005039 Inc.get() == S->getInc() &&
5040 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005041 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005042
Douglas Gregor43959a92009-08-20 07:17:43 +00005043 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005044 Init.get(), FullCond, ConditionVar,
5045 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005046}
5047
5048template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005049StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005050TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005051 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5052 S->getLabel());
5053 if (!LD)
5054 return StmtError();
5055
Douglas Gregor43959a92009-08-20 07:17:43 +00005056 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005057 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005058 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005059}
5060
5061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005062StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005063TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005064 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005065 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005066 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005067
Douglas Gregor43959a92009-08-20 07:17:43 +00005068 if (!getDerived().AlwaysRebuild() &&
5069 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005070 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005071
5072 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005073 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005074}
5075
5076template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005077StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005078TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005079 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005080}
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>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005085 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005086}
Mike Stump1eb44332009-09-09 15:08:12 +00005087
Douglas Gregor43959a92009-08-20 07:17:43 +00005088template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005089StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005090TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005091 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005092 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005093 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005094
Mike Stump1eb44332009-09-09 15:08:12 +00005095 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005096 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005097 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005098}
Mike Stump1eb44332009-09-09 15:08:12 +00005099
Douglas Gregor43959a92009-08-20 07:17:43 +00005100template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005101StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005102TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005103 bool DeclChanged = false;
5104 llvm::SmallVector<Decl *, 4> Decls;
5105 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5106 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005107 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5108 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005109 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005110 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005111
Douglas Gregor43959a92009-08-20 07:17:43 +00005112 if (Transformed != *D)
5113 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005114
Douglas Gregor43959a92009-08-20 07:17:43 +00005115 Decls.push_back(Transformed);
5116 }
Mike Stump1eb44332009-09-09 15:08:12 +00005117
Douglas Gregor43959a92009-08-20 07:17:43 +00005118 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005119 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005120
5121 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005122 S->getStartLoc(), S->getEndLoc());
5123}
Mike Stump1eb44332009-09-09 15:08:12 +00005124
Douglas Gregor43959a92009-08-20 07:17:43 +00005125template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005126StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005127TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005128
John McCallca0408f2010-08-23 06:44:23 +00005129 ASTOwningVector<Expr*> Constraints(getSema());
5130 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005131 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005132
John McCall60d7b3a2010-08-24 06:29:42 +00005133 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005134 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005135
5136 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005137
Anders Carlsson703e3942010-01-24 05:50:09 +00005138 // Go through the outputs.
5139 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005140 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005141
Anders Carlsson703e3942010-01-24 05:50:09 +00005142 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005143 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005144
Anders Carlsson703e3942010-01-24 05:50:09 +00005145 // Transform the output expr.
5146 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005147 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005148 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005149 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005150
Anders Carlsson703e3942010-01-24 05:50:09 +00005151 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005152
John McCall9ae2f072010-08-23 23:25:46 +00005153 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005154 }
Sean Huntc3021132010-05-05 15:23:54 +00005155
Anders Carlsson703e3942010-01-24 05:50:09 +00005156 // Go through the inputs.
5157 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005158 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005159
Anders Carlsson703e3942010-01-24 05:50:09 +00005160 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005161 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005162
Anders Carlsson703e3942010-01-24 05:50:09 +00005163 // Transform the input expr.
5164 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005165 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005166 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005167 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005168
Anders Carlsson703e3942010-01-24 05:50:09 +00005169 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005170
John McCall9ae2f072010-08-23 23:25:46 +00005171 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005172 }
Sean Huntc3021132010-05-05 15:23:54 +00005173
Anders Carlsson703e3942010-01-24 05:50:09 +00005174 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005175 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005176
5177 // Go through the clobbers.
5178 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005179 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005180
5181 // No need to transform the asm string literal.
5182 AsmString = SemaRef.Owned(S->getAsmString());
5183
5184 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5185 S->isSimple(),
5186 S->isVolatile(),
5187 S->getNumOutputs(),
5188 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005189 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005190 move_arg(Constraints),
5191 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005192 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005193 move_arg(Clobbers),
5194 S->getRParenLoc(),
5195 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005196}
5197
5198
5199template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005200StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005201TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005202 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005203 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005204 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005205 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005206
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005207 // Transform the @catch statements (if present).
5208 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005209 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005210 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005211 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005212 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005213 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005214 if (Catch.get() != S->getCatchStmt(I))
5215 AnyCatchChanged = true;
5216 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005217 }
Sean Huntc3021132010-05-05 15:23:54 +00005218
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005219 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005220 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005221 if (S->getFinallyStmt()) {
5222 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5223 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005224 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005225 }
5226
5227 // If nothing changed, just retain this statement.
5228 if (!getDerived().AlwaysRebuild() &&
5229 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005230 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005231 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005232 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005233
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005234 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005235 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5236 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005237}
Mike Stump1eb44332009-09-09 15:08:12 +00005238
Douglas Gregor43959a92009-08-20 07:17:43 +00005239template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005240StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005241TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005242 // Transform the @catch parameter, if there is one.
5243 VarDecl *Var = 0;
5244 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5245 TypeSourceInfo *TSInfo = 0;
5246 if (FromVar->getTypeSourceInfo()) {
5247 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5248 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005249 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005250 }
Sean Huntc3021132010-05-05 15:23:54 +00005251
Douglas Gregorbe270a02010-04-26 17:57:08 +00005252 QualType T;
5253 if (TSInfo)
5254 T = TSInfo->getType();
5255 else {
5256 T = getDerived().TransformType(FromVar->getType());
5257 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005258 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005259 }
Sean Huntc3021132010-05-05 15:23:54 +00005260
Douglas Gregorbe270a02010-04-26 17:57:08 +00005261 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5262 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005263 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005264 }
Sean Huntc3021132010-05-05 15:23:54 +00005265
John McCall60d7b3a2010-08-24 06:29:42 +00005266 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005267 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005268 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005269
5270 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005271 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005272 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005273}
Mike Stump1eb44332009-09-09 15:08:12 +00005274
Douglas Gregor43959a92009-08-20 07:17:43 +00005275template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005276StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005277TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005278 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005279 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005280 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005281 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005282
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005283 // If nothing changed, just retain this statement.
5284 if (!getDerived().AlwaysRebuild() &&
5285 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005286 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005287
5288 // Build a new statement.
5289 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005290 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005291}
Mike Stump1eb44332009-09-09 15:08:12 +00005292
Douglas Gregor43959a92009-08-20 07:17:43 +00005293template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005294StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005295TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005296 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005297 if (S->getThrowExpr()) {
5298 Operand = getDerived().TransformExpr(S->getThrowExpr());
5299 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005300 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005301 }
Sean Huntc3021132010-05-05 15:23:54 +00005302
Douglas Gregord1377b22010-04-22 21:44:01 +00005303 if (!getDerived().AlwaysRebuild() &&
5304 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005305 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005306
John McCall9ae2f072010-08-23 23:25:46 +00005307 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005308}
Mike Stump1eb44332009-09-09 15:08:12 +00005309
Douglas Gregor43959a92009-08-20 07:17:43 +00005310template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005311StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005312TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005313 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005314 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005315 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005316 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005317 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005318
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005319 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005320 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005321 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005322 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005323
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005324 // If nothing change, just retain the current statement.
5325 if (!getDerived().AlwaysRebuild() &&
5326 Object.get() == S->getSynchExpr() &&
5327 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005328 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005329
5330 // Build a new statement.
5331 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005332 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005333}
5334
5335template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005336StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005337TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005338 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005339 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005340 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005341 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005342 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005343
Douglas Gregorc3203e72010-04-22 23:10:45 +00005344 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005345 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005346 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005347 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005348
Douglas Gregorc3203e72010-04-22 23:10:45 +00005349 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005350 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005351 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005352 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005353
Douglas Gregorc3203e72010-04-22 23:10:45 +00005354 // If nothing changed, just retain this statement.
5355 if (!getDerived().AlwaysRebuild() &&
5356 Element.get() == S->getElement() &&
5357 Collection.get() == S->getCollection() &&
5358 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005359 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005360
Douglas Gregorc3203e72010-04-22 23:10:45 +00005361 // Build a new statement.
5362 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5363 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005364 Element.get(),
5365 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005366 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005367 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005368}
5369
5370
5371template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005372StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005373TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5374 // Transform the exception declaration, if any.
5375 VarDecl *Var = 0;
5376 if (S->getExceptionDecl()) {
5377 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005378 TypeSourceInfo *T = getDerived().TransformType(
5379 ExceptionDecl->getTypeSourceInfo());
5380 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005381 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005382
Douglas Gregor83cb9422010-09-09 17:09:21 +00005383 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00005384 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00005385 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00005386 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005387 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005388 }
Mike Stump1eb44332009-09-09 15:08:12 +00005389
Douglas Gregor43959a92009-08-20 07:17:43 +00005390 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005391 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005392 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005393 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005394
Douglas Gregor43959a92009-08-20 07:17:43 +00005395 if (!getDerived().AlwaysRebuild() &&
5396 !Var &&
5397 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005398 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005399
5400 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5401 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005402 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005403}
Mike Stump1eb44332009-09-09 15:08:12 +00005404
Douglas Gregor43959a92009-08-20 07:17:43 +00005405template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005406StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005407TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5408 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005409 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005410 = getDerived().TransformCompoundStmt(S->getTryBlock());
5411 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005412 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005413
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 // Transform the handlers.
5415 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005416 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005417 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005418 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005419 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5420 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005421 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005422
Douglas Gregor43959a92009-08-20 07:17:43 +00005423 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5424 Handlers.push_back(Handler.takeAs<Stmt>());
5425 }
Mike Stump1eb44332009-09-09 15:08:12 +00005426
Douglas Gregor43959a92009-08-20 07:17:43 +00005427 if (!getDerived().AlwaysRebuild() &&
5428 TryBlock.get() == S->getTryBlock() &&
5429 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005430 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005431
John McCall9ae2f072010-08-23 23:25:46 +00005432 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005433 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005434}
Mike Stump1eb44332009-09-09 15:08:12 +00005435
Douglas Gregor43959a92009-08-20 07:17:43 +00005436//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005437// Expression transformation
5438//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005439template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005440ExprResult
John McCall454feb92009-12-08 09:21:05 +00005441TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005442 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005443}
Mike Stump1eb44332009-09-09 15:08:12 +00005444
5445template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005446ExprResult
John McCall454feb92009-12-08 09:21:05 +00005447TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005448 NestedNameSpecifierLoc QualifierLoc;
5449 if (E->getQualifierLoc()) {
5450 QualifierLoc
5451 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5452 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005453 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005454 }
John McCalldbd872f2009-12-08 09:08:17 +00005455
5456 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005457 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5458 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005459 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005460 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005461
John McCallec8045d2010-08-17 21:27:17 +00005462 DeclarationNameInfo NameInfo = E->getNameInfo();
5463 if (NameInfo.getName()) {
5464 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5465 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005466 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005467 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005468
5469 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005470 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005471 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005472 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005473 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005474
5475 // Mark it referenced in the new context regardless.
5476 // FIXME: this is a bit instantiation-specific.
5477 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5478
John McCall3fa5cae2010-10-26 07:05:15 +00005479 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005480 }
John McCalldbd872f2009-12-08 09:08:17 +00005481
5482 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005483 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005484 TemplateArgs = &TransArgs;
5485 TransArgs.setLAngleLoc(E->getLAngleLoc());
5486 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005487 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5488 E->getNumTemplateArgs(),
5489 TransArgs))
5490 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005491 }
5492
Douglas Gregor40d96a62011-02-28 21:54:11 +00005493 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5494 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005495}
Mike Stump1eb44332009-09-09 15:08:12 +00005496
Douglas Gregorb98b1992009-08-11 05:31:07 +00005497template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005498ExprResult
John McCall454feb92009-12-08 09:21:05 +00005499TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005500 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005501}
Mike Stump1eb44332009-09-09 15:08:12 +00005502
Douglas Gregorb98b1992009-08-11 05:31:07 +00005503template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005504ExprResult
John McCall454feb92009-12-08 09:21:05 +00005505TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005506 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005507}
Mike Stump1eb44332009-09-09 15:08:12 +00005508
Douglas Gregorb98b1992009-08-11 05:31:07 +00005509template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005510ExprResult
John McCall454feb92009-12-08 09:21:05 +00005511TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005512 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005513}
Mike Stump1eb44332009-09-09 15:08:12 +00005514
Douglas Gregorb98b1992009-08-11 05:31:07 +00005515template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005516ExprResult
John McCall454feb92009-12-08 09:21:05 +00005517TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005518 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005519}
Mike Stump1eb44332009-09-09 15:08:12 +00005520
Douglas Gregorb98b1992009-08-11 05:31:07 +00005521template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005522ExprResult
John McCall454feb92009-12-08 09:21:05 +00005523TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005524 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005525}
5526
5527template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005528ExprResult
John McCall454feb92009-12-08 09:21:05 +00005529TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005530 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005531 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005532 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005533
Douglas Gregorb98b1992009-08-11 05:31:07 +00005534 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005535 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005536
John McCall9ae2f072010-08-23 23:25:46 +00005537 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005538 E->getRParen());
5539}
5540
Mike Stump1eb44332009-09-09 15:08:12 +00005541template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005542ExprResult
John McCall454feb92009-12-08 09:21:05 +00005543TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005544 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005545 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005546 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005547
Douglas Gregorb98b1992009-08-11 05:31:07 +00005548 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005549 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005550
Douglas Gregorb98b1992009-08-11 05:31:07 +00005551 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5552 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005553 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005554}
Mike Stump1eb44332009-09-09 15:08:12 +00005555
Douglas Gregorb98b1992009-08-11 05:31:07 +00005556template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005557ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005558TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5559 // Transform the type.
5560 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5561 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005562 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005563
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005564 // Transform all of the components into components similar to what the
5565 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005566 // FIXME: It would be slightly more efficient in the non-dependent case to
5567 // just map FieldDecls, rather than requiring the rebuilder to look for
5568 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005569 // template code that we don't care.
5570 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005571 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005572 typedef OffsetOfExpr::OffsetOfNode Node;
5573 llvm::SmallVector<Component, 4> Components;
5574 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5575 const Node &ON = E->getComponent(I);
5576 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005577 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005578 Comp.LocStart = ON.getRange().getBegin();
5579 Comp.LocEnd = ON.getRange().getEnd();
5580 switch (ON.getKind()) {
5581 case Node::Array: {
5582 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005583 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005584 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005585 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005586
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005587 ExprChanged = ExprChanged || Index.get() != FromIndex;
5588 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005589 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005590 break;
5591 }
Sean Huntc3021132010-05-05 15:23:54 +00005592
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005593 case Node::Field:
5594 case Node::Identifier:
5595 Comp.isBrackets = false;
5596 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005597 if (!Comp.U.IdentInfo)
5598 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005599
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005600 break;
Sean Huntc3021132010-05-05 15:23:54 +00005601
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005602 case Node::Base:
5603 // Will be recomputed during the rebuild.
5604 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005605 }
Sean Huntc3021132010-05-05 15:23:54 +00005606
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005607 Components.push_back(Comp);
5608 }
Sean Huntc3021132010-05-05 15:23:54 +00005609
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005610 // If nothing changed, retain the existing expression.
5611 if (!getDerived().AlwaysRebuild() &&
5612 Type == E->getTypeSourceInfo() &&
5613 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005614 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00005615
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005616 // Build a new offsetof expression.
5617 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5618 Components.data(), Components.size(),
5619 E->getRParenLoc());
5620}
5621
5622template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005623ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00005624TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5625 assert(getDerived().AlreadyTransformed(E->getType()) &&
5626 "opaque value expression requires transformation");
5627 return SemaRef.Owned(E);
5628}
5629
5630template<typename Derived>
5631ExprResult
John McCall454feb92009-12-08 09:21:05 +00005632TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005633 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00005634 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00005635
John McCalla93c9342009-12-07 02:54:59 +00005636 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00005637 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005638 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005639
John McCall5ab75172009-11-04 07:28:41 +00005640 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00005641 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005642
John McCall5ab75172009-11-04 07:28:41 +00005643 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005644 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005645 E->getSourceRange());
5646 }
Mike Stump1eb44332009-09-09 15:08:12 +00005647
John McCall60d7b3a2010-08-24 06:29:42 +00005648 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00005649 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005650 // C++0x [expr.sizeof]p1:
5651 // The operand is either an expression, which is an unevaluated operand
5652 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00005653 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005654
Douglas Gregorb98b1992009-08-11 05:31:07 +00005655 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5656 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005657 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005658
Douglas Gregorb98b1992009-08-11 05:31:07 +00005659 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005660 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005661 }
Mike Stump1eb44332009-09-09 15:08:12 +00005662
John McCall9ae2f072010-08-23 23:25:46 +00005663 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005664 E->isSizeOf(),
5665 E->getSourceRange());
5666}
Mike Stump1eb44332009-09-09 15:08:12 +00005667
Douglas Gregorb98b1992009-08-11 05:31:07 +00005668template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005669ExprResult
John McCall454feb92009-12-08 09:21:05 +00005670TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005671 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005672 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005673 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005674
John McCall60d7b3a2010-08-24 06:29:42 +00005675 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005676 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005677 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005678
5679
Douglas Gregorb98b1992009-08-11 05:31:07 +00005680 if (!getDerived().AlwaysRebuild() &&
5681 LHS.get() == E->getLHS() &&
5682 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005683 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005684
John McCall9ae2f072010-08-23 23:25:46 +00005685 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005686 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005687 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005688 E->getRBracketLoc());
5689}
Mike Stump1eb44332009-09-09 15:08:12 +00005690
5691template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005692ExprResult
John McCall454feb92009-12-08 09:21:05 +00005693TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005694 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00005695 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005696 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005697 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005698
5699 // Transform arguments.
5700 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005701 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005702 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5703 &ArgChanged))
5704 return ExprError();
5705
Douglas Gregorb98b1992009-08-11 05:31:07 +00005706 if (!getDerived().AlwaysRebuild() &&
5707 Callee.get() == E->getCallee() &&
5708 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005709 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005710
Douglas Gregorb98b1992009-08-11 05:31:07 +00005711 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00005712 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005713 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00005714 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005715 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005716 E->getRParenLoc());
5717}
Mike Stump1eb44332009-09-09 15:08:12 +00005718
5719template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005720ExprResult
John McCall454feb92009-12-08 09:21:05 +00005721TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005722 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005723 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005724 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005725
Douglas Gregor40d96a62011-02-28 21:54:11 +00005726 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005727 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005728 QualifierLoc
5729 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5730
5731 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005732 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005733 }
Mike Stump1eb44332009-09-09 15:08:12 +00005734
Eli Friedmanf595cc42009-12-04 06:40:45 +00005735 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005736 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5737 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005738 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00005739 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005740
John McCall6bb80172010-03-30 21:47:33 +00005741 NamedDecl *FoundDecl = E->getFoundDecl();
5742 if (FoundDecl == E->getMemberDecl()) {
5743 FoundDecl = Member;
5744 } else {
5745 FoundDecl = cast_or_null<NamedDecl>(
5746 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5747 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00005748 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00005749 }
5750
Douglas Gregorb98b1992009-08-11 05:31:07 +00005751 if (!getDerived().AlwaysRebuild() &&
5752 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005753 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005754 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00005755 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00005756 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00005757
Anders Carlsson1f240322009-12-22 05:24:09 +00005758 // Mark it referenced in the new context regardless.
5759 // FIXME: this is a bit instantiation-specific.
5760 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00005761 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00005762 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005763
John McCalld5532b62009-11-23 01:53:49 +00005764 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00005765 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00005766 TransArgs.setLAngleLoc(E->getLAngleLoc());
5767 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005768 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5769 E->getNumTemplateArgs(),
5770 TransArgs))
5771 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005772 }
Sean Huntc3021132010-05-05 15:23:54 +00005773
Douglas Gregorb98b1992009-08-11 05:31:07 +00005774 // FIXME: Bogus source location for the operator
5775 SourceLocation FakeOperatorLoc
5776 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5777
John McCallc2233c52010-01-15 08:34:02 +00005778 // FIXME: to do this check properly, we will need to preserve the
5779 // first-qualifier-in-scope here, just in case we had a dependent
5780 // base (and therefore couldn't do the check) and a
5781 // nested-name-qualifier (and therefore could do the lookup).
5782 NamedDecl *FirstQualifierInScope = 0;
5783
John McCall9ae2f072010-08-23 23:25:46 +00005784 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005785 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00005786 QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00005787 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005788 Member,
John McCall6bb80172010-03-30 21:47:33 +00005789 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00005790 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00005791 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00005792 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005793}
Mike Stump1eb44332009-09-09 15:08:12 +00005794
Douglas Gregorb98b1992009-08-11 05:31:07 +00005795template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005796ExprResult
John McCall454feb92009-12-08 09:21:05 +00005797TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005798 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005799 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005800 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005801
John McCall60d7b3a2010-08-24 06:29:42 +00005802 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005803 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005804 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005805
Douglas Gregorb98b1992009-08-11 05:31:07 +00005806 if (!getDerived().AlwaysRebuild() &&
5807 LHS.get() == E->getLHS() &&
5808 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005809 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005810
Douglas Gregorb98b1992009-08-11 05:31:07 +00005811 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005812 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005813}
5814
Mike Stump1eb44332009-09-09 15:08:12 +00005815template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005816ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005817TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00005818 CompoundAssignOperator *E) {
5819 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005820}
Mike Stump1eb44332009-09-09 15:08:12 +00005821
Douglas Gregorb98b1992009-08-11 05:31:07 +00005822template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00005823ExprResult TreeTransform<Derived>::
5824TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5825 // Just rebuild the common and RHS expressions and see whether we
5826 // get any changes.
5827
5828 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5829 if (commonExpr.isInvalid())
5830 return ExprError();
5831
5832 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5833 if (rhs.isInvalid())
5834 return ExprError();
5835
5836 if (!getDerived().AlwaysRebuild() &&
5837 commonExpr.get() == e->getCommon() &&
5838 rhs.get() == e->getFalseExpr())
5839 return SemaRef.Owned(e);
5840
5841 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5842 e->getQuestionLoc(),
5843 0,
5844 e->getColonLoc(),
5845 rhs.get());
5846}
5847
5848template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005849ExprResult
John McCall454feb92009-12-08 09:21:05 +00005850TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005851 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005852 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005853 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005854
John McCall60d7b3a2010-08-24 06:29:42 +00005855 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005856 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005857 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005858
John McCall60d7b3a2010-08-24 06:29:42 +00005859 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005860 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005861 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005862
Douglas Gregorb98b1992009-08-11 05:31:07 +00005863 if (!getDerived().AlwaysRebuild() &&
5864 Cond.get() == E->getCond() &&
5865 LHS.get() == E->getLHS() &&
5866 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005867 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005868
John McCall9ae2f072010-08-23 23:25:46 +00005869 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005870 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005871 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005872 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005873 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005874}
Mike Stump1eb44332009-09-09 15:08:12 +00005875
5876template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005877ExprResult
John McCall454feb92009-12-08 09:21:05 +00005878TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005879 // Implicit casts are eliminated during transformation, since they
5880 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00005881 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005882}
Mike Stump1eb44332009-09-09 15:08:12 +00005883
Douglas Gregorb98b1992009-08-11 05:31:07 +00005884template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005885ExprResult
John McCall454feb92009-12-08 09:21:05 +00005886TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005887 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5888 if (!Type)
5889 return ExprError();
5890
John McCall60d7b3a2010-08-24 06:29:42 +00005891 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005892 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005893 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005894 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005895
Douglas Gregorb98b1992009-08-11 05:31:07 +00005896 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005897 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005898 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005899 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005900
John McCall9d125032010-01-15 18:39:57 +00005901 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005902 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005903 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005904 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005905}
Mike Stump1eb44332009-09-09 15:08:12 +00005906
Douglas Gregorb98b1992009-08-11 05:31:07 +00005907template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005908ExprResult
John McCall454feb92009-12-08 09:21:05 +00005909TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00005910 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5911 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5912 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005913 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005914
John McCall60d7b3a2010-08-24 06:29:42 +00005915 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005916 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005917 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005918
Douglas Gregorb98b1992009-08-11 05:31:07 +00005919 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00005920 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005921 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00005922 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005923
John McCall1d7d8d62010-01-19 22:33:45 +00005924 // Note: the expression type doesn't necessarily match the
5925 // type-as-written, but that's okay, because it should always be
5926 // derivable from the initializer.
5927
John McCall42f56b52010-01-18 19:35:47 +00005928 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005929 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00005930 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005931}
Mike Stump1eb44332009-09-09 15:08:12 +00005932
Douglas Gregorb98b1992009-08-11 05:31:07 +00005933template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005934ExprResult
John McCall454feb92009-12-08 09:21:05 +00005935TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005936 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005937 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005938 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005939
Douglas Gregorb98b1992009-08-11 05:31:07 +00005940 if (!getDerived().AlwaysRebuild() &&
5941 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00005942 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005943
Douglas Gregorb98b1992009-08-11 05:31:07 +00005944 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00005945 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005946 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00005947 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005948 E->getAccessorLoc(),
5949 E->getAccessor());
5950}
Mike Stump1eb44332009-09-09 15:08:12 +00005951
Douglas Gregorb98b1992009-08-11 05:31:07 +00005952template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005953ExprResult
John McCall454feb92009-12-08 09:21:05 +00005954TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005955 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00005956
John McCallca0408f2010-08-23 06:44:23 +00005957 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005958 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5959 Inits, &InitChanged))
5960 return ExprError();
5961
Douglas Gregorb98b1992009-08-11 05:31:07 +00005962 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005963 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005964
Douglas Gregorb98b1992009-08-11 05:31:07 +00005965 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00005966 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005967}
Mike Stump1eb44332009-09-09 15:08:12 +00005968
Douglas Gregorb98b1992009-08-11 05:31:07 +00005969template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005970ExprResult
John McCall454feb92009-12-08 09:21:05 +00005971TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005972 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00005973
Douglas Gregor43959a92009-08-20 07:17:43 +00005974 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00005975 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005976 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005977 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005978
Douglas Gregor43959a92009-08-20 07:17:43 +00005979 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00005980 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005981 bool ExprChanged = false;
5982 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5983 DEnd = E->designators_end();
5984 D != DEnd; ++D) {
5985 if (D->isFieldDesignator()) {
5986 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5987 D->getDotLoc(),
5988 D->getFieldLoc()));
5989 continue;
5990 }
Mike Stump1eb44332009-09-09 15:08:12 +00005991
Douglas Gregorb98b1992009-08-11 05:31:07 +00005992 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00005993 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005994 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005995 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005996
5997 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005998 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005999
Douglas Gregorb98b1992009-08-11 05:31:07 +00006000 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6001 ArrayExprs.push_back(Index.release());
6002 continue;
6003 }
Mike Stump1eb44332009-09-09 15:08:12 +00006004
Douglas Gregorb98b1992009-08-11 05:31:07 +00006005 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006006 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006007 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6008 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006009 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006010
John McCall60d7b3a2010-08-24 06:29:42 +00006011 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006012 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006013 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006014
6015 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006016 End.get(),
6017 D->getLBracketLoc(),
6018 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006019
Douglas Gregorb98b1992009-08-11 05:31:07 +00006020 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6021 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006022
Douglas Gregorb98b1992009-08-11 05:31:07 +00006023 ArrayExprs.push_back(Start.release());
6024 ArrayExprs.push_back(End.release());
6025 }
Mike Stump1eb44332009-09-09 15:08:12 +00006026
Douglas Gregorb98b1992009-08-11 05:31:07 +00006027 if (!getDerived().AlwaysRebuild() &&
6028 Init.get() == E->getInit() &&
6029 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006030 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006031
Douglas Gregorb98b1992009-08-11 05:31:07 +00006032 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6033 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006034 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006035}
Mike Stump1eb44332009-09-09 15:08:12 +00006036
Douglas Gregorb98b1992009-08-11 05:31:07 +00006037template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006038ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006039TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006040 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006041 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006042
Douglas Gregor5557b252009-10-28 00:29:27 +00006043 // FIXME: Will we ever have proper type location here? Will we actually
6044 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006045 QualType T = getDerived().TransformType(E->getType());
6046 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006047 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006048
Douglas Gregorb98b1992009-08-11 05:31:07 +00006049 if (!getDerived().AlwaysRebuild() &&
6050 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006051 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006052
Douglas Gregorb98b1992009-08-11 05:31:07 +00006053 return getDerived().RebuildImplicitValueInitExpr(T);
6054}
Mike Stump1eb44332009-09-09 15:08:12 +00006055
Douglas Gregorb98b1992009-08-11 05:31:07 +00006056template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006057ExprResult
John McCall454feb92009-12-08 09:21:05 +00006058TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006059 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6060 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006061 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006062
John McCall60d7b3a2010-08-24 06:29:42 +00006063 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006064 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006065 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006066
Douglas Gregorb98b1992009-08-11 05:31:07 +00006067 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006068 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006069 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006070 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006071
John McCall9ae2f072010-08-23 23:25:46 +00006072 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006073 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006074}
6075
6076template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006077ExprResult
John McCall454feb92009-12-08 09:21:05 +00006078TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006079 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006080 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006081 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6082 &ArgumentChanged))
6083 return ExprError();
6084
Douglas Gregorb98b1992009-08-11 05:31:07 +00006085 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6086 move_arg(Inits),
6087 E->getRParenLoc());
6088}
Mike Stump1eb44332009-09-09 15:08:12 +00006089
Douglas Gregorb98b1992009-08-11 05:31:07 +00006090/// \brief Transform an address-of-label expression.
6091///
6092/// By default, the transformation of an address-of-label expression always
6093/// rebuilds the expression, so that the label identifier can be resolved to
6094/// the corresponding label statement by semantic analysis.
6095template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006096ExprResult
John McCall454feb92009-12-08 09:21:05 +00006097TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006098 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6099 E->getLabel());
6100 if (!LD)
6101 return ExprError();
6102
Douglas Gregorb98b1992009-08-11 05:31:07 +00006103 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006104 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006105}
Mike Stump1eb44332009-09-09 15:08:12 +00006106
6107template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006108ExprResult
John McCall454feb92009-12-08 09:21:05 +00006109TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006110 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006111 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6112 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006113 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006114
Douglas Gregorb98b1992009-08-11 05:31:07 +00006115 if (!getDerived().AlwaysRebuild() &&
6116 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00006117 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006118
6119 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006120 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006121 E->getRParenLoc());
6122}
Mike Stump1eb44332009-09-09 15:08:12 +00006123
Douglas Gregorb98b1992009-08-11 05:31:07 +00006124template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006125ExprResult
John McCall454feb92009-12-08 09:21:05 +00006126TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006127 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006128 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006129 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006130
John McCall60d7b3a2010-08-24 06:29:42 +00006131 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006132 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006133 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006134
John McCall60d7b3a2010-08-24 06:29:42 +00006135 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006136 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006137 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006138
Douglas Gregorb98b1992009-08-11 05:31:07 +00006139 if (!getDerived().AlwaysRebuild() &&
6140 Cond.get() == E->getCond() &&
6141 LHS.get() == E->getLHS() &&
6142 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006143 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006144
Douglas Gregorb98b1992009-08-11 05:31:07 +00006145 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006146 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006147 E->getRParenLoc());
6148}
Mike Stump1eb44332009-09-09 15:08:12 +00006149
Douglas Gregorb98b1992009-08-11 05:31:07 +00006150template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006151ExprResult
John McCall454feb92009-12-08 09:21:05 +00006152TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006153 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006154}
6155
6156template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006157ExprResult
John McCall454feb92009-12-08 09:21:05 +00006158TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006159 switch (E->getOperator()) {
6160 case OO_New:
6161 case OO_Delete:
6162 case OO_Array_New:
6163 case OO_Array_Delete:
6164 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006165 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006166
Douglas Gregor668d6d92009-12-13 20:44:55 +00006167 case OO_Call: {
6168 // This is a call to an object's operator().
6169 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6170
6171 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006172 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006173 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006174 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006175
6176 // FIXME: Poor location information
6177 SourceLocation FakeLParenLoc
6178 = SemaRef.PP.getLocForEndOfToken(
6179 static_cast<Expr *>(Object.get())->getLocEnd());
6180
6181 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006182 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006183 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6184 Args))
6185 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006186
John McCall9ae2f072010-08-23 23:25:46 +00006187 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006188 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006189 E->getLocEnd());
6190 }
6191
6192#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6193 case OO_##Name:
6194#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6195#include "clang/Basic/OperatorKinds.def"
6196 case OO_Subscript:
6197 // Handled below.
6198 break;
6199
6200 case OO_Conditional:
6201 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006202 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006203
6204 case OO_None:
6205 case NUM_OVERLOADED_OPERATORS:
6206 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006207 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006208 }
6209
John McCall60d7b3a2010-08-24 06:29:42 +00006210 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006211 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006212 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006213
John McCall60d7b3a2010-08-24 06:29:42 +00006214 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006216 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217
John McCall60d7b3a2010-08-24 06:29:42 +00006218 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006219 if (E->getNumArgs() == 2) {
6220 Second = getDerived().TransformExpr(E->getArg(1));
6221 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006222 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006223 }
Mike Stump1eb44332009-09-09 15:08:12 +00006224
Douglas Gregorb98b1992009-08-11 05:31:07 +00006225 if (!getDerived().AlwaysRebuild() &&
6226 Callee.get() == E->getCallee() &&
6227 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006228 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00006229 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006230
Douglas Gregorb98b1992009-08-11 05:31:07 +00006231 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6232 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006233 Callee.get(),
6234 First.get(),
6235 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006236}
Mike Stump1eb44332009-09-09 15:08:12 +00006237
Douglas Gregorb98b1992009-08-11 05:31:07 +00006238template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006239ExprResult
John McCall454feb92009-12-08 09:21:05 +00006240TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6241 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006242}
Mike Stump1eb44332009-09-09 15:08:12 +00006243
Douglas Gregorb98b1992009-08-11 05:31:07 +00006244template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006245ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006246TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6247 // Transform the callee.
6248 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6249 if (Callee.isInvalid())
6250 return ExprError();
6251
6252 // Transform exec config.
6253 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6254 if (EC.isInvalid())
6255 return ExprError();
6256
6257 // Transform arguments.
6258 bool ArgChanged = false;
6259 ASTOwningVector<Expr*> Args(SemaRef);
6260 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6261 &ArgChanged))
6262 return ExprError();
6263
6264 if (!getDerived().AlwaysRebuild() &&
6265 Callee.get() == E->getCallee() &&
6266 !ArgChanged)
6267 return SemaRef.Owned(E);
6268
6269 // FIXME: Wrong source location information for the '('.
6270 SourceLocation FakeLParenLoc
6271 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6272 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6273 move_arg(Args),
6274 E->getRParenLoc(), EC.get());
6275}
6276
6277template<typename Derived>
6278ExprResult
John McCall454feb92009-12-08 09:21:05 +00006279TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006280 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6281 if (!Type)
6282 return ExprError();
6283
John McCall60d7b3a2010-08-24 06:29:42 +00006284 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006285 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006286 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006287 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006288
Douglas Gregorb98b1992009-08-11 05:31:07 +00006289 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006290 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006291 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006292 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006293
Douglas Gregorb98b1992009-08-11 05:31:07 +00006294 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006295 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006296 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6297 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6298 SourceLocation FakeRParenLoc
6299 = SemaRef.PP.getLocForEndOfToken(
6300 E->getSubExpr()->getSourceRange().getEnd());
6301 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006302 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006303 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006304 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006305 FakeRAngleLoc,
6306 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006307 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006308 FakeRParenLoc);
6309}
Mike Stump1eb44332009-09-09 15:08:12 +00006310
Douglas Gregorb98b1992009-08-11 05:31:07 +00006311template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006312ExprResult
John McCall454feb92009-12-08 09:21:05 +00006313TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6314 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006315}
Mike Stump1eb44332009-09-09 15:08:12 +00006316
6317template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006318ExprResult
John McCall454feb92009-12-08 09:21:05 +00006319TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6320 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006321}
6322
Douglas Gregorb98b1992009-08-11 05:31:07 +00006323template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006324ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006325TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006326 CXXReinterpretCastExpr *E) {
6327 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006328}
Mike Stump1eb44332009-09-09 15:08:12 +00006329
Douglas Gregorb98b1992009-08-11 05:31:07 +00006330template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006331ExprResult
John McCall454feb92009-12-08 09:21:05 +00006332TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6333 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006334}
Mike Stump1eb44332009-09-09 15:08:12 +00006335
Douglas Gregorb98b1992009-08-11 05:31:07 +00006336template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006337ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006338TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006339 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006340 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6341 if (!Type)
6342 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006343
John McCall60d7b3a2010-08-24 06:29:42 +00006344 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006345 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006346 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006347 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006348
Douglas Gregorb98b1992009-08-11 05:31:07 +00006349 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006350 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006351 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006352 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006353
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006354 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006355 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006356 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006357 E->getRParenLoc());
6358}
Mike Stump1eb44332009-09-09 15:08:12 +00006359
Douglas Gregorb98b1992009-08-11 05:31:07 +00006360template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006361ExprResult
John McCall454feb92009-12-08 09:21:05 +00006362TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006363 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006364 TypeSourceInfo *TInfo
6365 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6366 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006367 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006368
Douglas Gregorb98b1992009-08-11 05:31:07 +00006369 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006370 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006371 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006372
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006373 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6374 E->getLocStart(),
6375 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006376 E->getLocEnd());
6377 }
Mike Stump1eb44332009-09-09 15:08:12 +00006378
Douglas Gregorb98b1992009-08-11 05:31:07 +00006379 // We don't know whether the expression is potentially evaluated until
6380 // after we perform semantic analysis, so the expression is potentially
6381 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006382 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006383 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006384
John McCall60d7b3a2010-08-24 06:29:42 +00006385 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006386 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006387 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006388
Douglas Gregorb98b1992009-08-11 05:31:07 +00006389 if (!getDerived().AlwaysRebuild() &&
6390 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006391 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006392
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006393 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6394 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006395 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006396 E->getLocEnd());
6397}
6398
6399template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006400ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006401TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6402 if (E->isTypeOperand()) {
6403 TypeSourceInfo *TInfo
6404 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6405 if (!TInfo)
6406 return ExprError();
6407
6408 if (!getDerived().AlwaysRebuild() &&
6409 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006410 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006411
6412 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6413 E->getLocStart(),
6414 TInfo,
6415 E->getLocEnd());
6416 }
6417
6418 // We don't know whether the expression is potentially evaluated until
6419 // after we perform semantic analysis, so the expression is potentially
6420 // potentially evaluated.
6421 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6422
6423 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6424 if (SubExpr.isInvalid())
6425 return ExprError();
6426
6427 if (!getDerived().AlwaysRebuild() &&
6428 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006429 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006430
6431 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6432 E->getLocStart(),
6433 SubExpr.get(),
6434 E->getLocEnd());
6435}
6436
6437template<typename Derived>
6438ExprResult
John McCall454feb92009-12-08 09:21:05 +00006439TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006440 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006441}
Mike Stump1eb44332009-09-09 15:08:12 +00006442
Douglas Gregorb98b1992009-08-11 05:31:07 +00006443template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006444ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006445TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006446 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006447 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006448}
Mike Stump1eb44332009-09-09 15:08:12 +00006449
Douglas Gregorb98b1992009-08-11 05:31:07 +00006450template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006451ExprResult
John McCall454feb92009-12-08 09:21:05 +00006452TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006453 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6454 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6455 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00006456
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006457 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006458 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006459
Douglas Gregor828a1972010-01-07 23:12:05 +00006460 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461}
Mike Stump1eb44332009-09-09 15:08:12 +00006462
Douglas Gregorb98b1992009-08-11 05:31:07 +00006463template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006464ExprResult
John McCall454feb92009-12-08 09:21:05 +00006465TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006466 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006467 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006468 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006469
Douglas Gregorb98b1992009-08-11 05:31:07 +00006470 if (!getDerived().AlwaysRebuild() &&
6471 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006472 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006473
John McCall9ae2f072010-08-23 23:25:46 +00006474 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006475}
Mike Stump1eb44332009-09-09 15:08:12 +00006476
Douglas Gregorb98b1992009-08-11 05:31:07 +00006477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006478ExprResult
John McCall454feb92009-12-08 09:21:05 +00006479TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006480 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006481 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6482 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006483 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006484 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006485
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006486 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006487 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006488 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006489
Douglas Gregor036aed12009-12-23 23:03:06 +00006490 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491}
Mike Stump1eb44332009-09-09 15:08:12 +00006492
Douglas Gregorb98b1992009-08-11 05:31:07 +00006493template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006494ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006495TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6496 CXXScalarValueInitExpr *E) {
6497 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6498 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006499 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006500
Douglas Gregorb98b1992009-08-11 05:31:07 +00006501 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006502 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006503 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006504
Douglas Gregorab6677e2010-09-08 00:15:04 +00006505 return getDerived().RebuildCXXScalarValueInitExpr(T,
6506 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006507 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006508}
Mike Stump1eb44332009-09-09 15:08:12 +00006509
Douglas Gregorb98b1992009-08-11 05:31:07 +00006510template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006511ExprResult
John McCall454feb92009-12-08 09:21:05 +00006512TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006513 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006514 TypeSourceInfo *AllocTypeInfo
6515 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6516 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006517 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006518
Douglas Gregorb98b1992009-08-11 05:31:07 +00006519 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006520 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006521 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006522 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006523
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524 // Transform the placement arguments (if any).
6525 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006526 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006527 if (getDerived().TransformExprs(E->getPlacementArgs(),
6528 E->getNumPlacementArgs(), true,
6529 PlacementArgs, &ArgumentChanged))
6530 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006531
Douglas Gregor43959a92009-08-20 07:17:43 +00006532 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00006533 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006534 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6535 ConstructorArgs, &ArgumentChanged))
6536 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006537
Douglas Gregor1af74512010-02-26 00:38:10 +00006538 // Transform constructor, new operator, and delete operator.
6539 CXXConstructorDecl *Constructor = 0;
6540 if (E->getConstructor()) {
6541 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006542 getDerived().TransformDecl(E->getLocStart(),
6543 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006544 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006545 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006546 }
6547
6548 FunctionDecl *OperatorNew = 0;
6549 if (E->getOperatorNew()) {
6550 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006551 getDerived().TransformDecl(E->getLocStart(),
6552 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006553 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006554 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006555 }
6556
6557 FunctionDecl *OperatorDelete = 0;
6558 if (E->getOperatorDelete()) {
6559 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006560 getDerived().TransformDecl(E->getLocStart(),
6561 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006562 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006563 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006564 }
Sean Huntc3021132010-05-05 15:23:54 +00006565
Douglas Gregorb98b1992009-08-11 05:31:07 +00006566 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006567 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006568 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006569 Constructor == E->getConstructor() &&
6570 OperatorNew == E->getOperatorNew() &&
6571 OperatorDelete == E->getOperatorDelete() &&
6572 !ArgumentChanged) {
6573 // Mark any declarations we need as referenced.
6574 // FIXME: instantiation-specific.
6575 if (Constructor)
6576 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6577 if (OperatorNew)
6578 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6579 if (OperatorDelete)
6580 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00006581 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006582 }
Mike Stump1eb44332009-09-09 15:08:12 +00006583
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006584 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006585 if (!ArraySize.get()) {
6586 // If no array size was specified, but the new expression was
6587 // instantiated with an array type (e.g., "new T" where T is
6588 // instantiated with "int[4]"), extract the outer bound from the
6589 // array type as our array size. We do this with constant and
6590 // dependently-sized array types.
6591 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6592 if (!ArrayT) {
6593 // Do nothing
6594 } else if (const ConstantArrayType *ConsArrayT
6595 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00006596 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006597 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6598 ConsArrayT->getSize(),
6599 SemaRef.Context.getSizeType(),
6600 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006601 AllocType = ConsArrayT->getElementType();
6602 } else if (const DependentSizedArrayType *DepArrayT
6603 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6604 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00006605 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006606 AllocType = DepArrayT->getElementType();
6607 }
6608 }
6609 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006610
Douglas Gregorb98b1992009-08-11 05:31:07 +00006611 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6612 E->isGlobalNew(),
6613 /*FIXME:*/E->getLocStart(),
6614 move_arg(PlacementArgs),
6615 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00006616 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006617 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006618 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00006619 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620 /*FIXME:*/E->getLocStart(),
6621 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00006622 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623}
Mike Stump1eb44332009-09-09 15:08:12 +00006624
Douglas Gregorb98b1992009-08-11 05:31:07 +00006625template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006626ExprResult
John McCall454feb92009-12-08 09:21:05 +00006627TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006628 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006630 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006631
Douglas Gregor1af74512010-02-26 00:38:10 +00006632 // Transform the delete operator, if known.
6633 FunctionDecl *OperatorDelete = 0;
6634 if (E->getOperatorDelete()) {
6635 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006636 getDerived().TransformDecl(E->getLocStart(),
6637 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006638 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006639 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006640 }
Sean Huntc3021132010-05-05 15:23:54 +00006641
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006643 Operand.get() == E->getArgument() &&
6644 OperatorDelete == E->getOperatorDelete()) {
6645 // Mark any declarations we need as referenced.
6646 // FIXME: instantiation-specific.
6647 if (OperatorDelete)
6648 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00006649
6650 if (!E->getArgument()->isTypeDependent()) {
6651 QualType Destroyed = SemaRef.Context.getBaseElementType(
6652 E->getDestroyedType());
6653 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6654 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6655 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6656 SemaRef.LookupDestructor(Record));
6657 }
6658 }
6659
John McCall3fa5cae2010-10-26 07:05:15 +00006660 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006661 }
Mike Stump1eb44332009-09-09 15:08:12 +00006662
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6664 E->isGlobalDelete(),
6665 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00006666 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667}
Mike Stump1eb44332009-09-09 15:08:12 +00006668
Douglas Gregorb98b1992009-08-11 05:31:07 +00006669template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006670ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00006671TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00006672 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006673 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00006674 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006675 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006676
John McCallb3d87482010-08-24 05:47:05 +00006677 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006678 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006679 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006680 E->getOperatorLoc(),
6681 E->isArrow()? tok::arrow : tok::period,
6682 ObjectTypePtr,
6683 MayBePseudoDestructor);
6684 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006685 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006686
John McCallb3d87482010-08-24 05:47:05 +00006687 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006688 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6689 if (QualifierLoc) {
6690 QualifierLoc
6691 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6692 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00006693 return ExprError();
6694 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006695 CXXScopeSpec SS;
6696 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00006697
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006698 PseudoDestructorTypeStorage Destroyed;
6699 if (E->getDestroyedTypeInfo()) {
6700 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00006701 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006702 ObjectType, 0,
6703 QualifierLoc.getNestedNameSpecifier());
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006704 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006705 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006706 Destroyed = DestroyedTypeInfo;
6707 } else if (ObjectType->isDependentType()) {
6708 // We aren't likely to be able to resolve the identifier down to a type
6709 // now anyway, so just retain the identifier.
6710 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6711 E->getDestroyedTypeLoc());
6712 } else {
6713 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00006714 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006715 *E->getDestroyedTypeIdentifier(),
6716 E->getDestroyedTypeLoc(),
6717 /*Scope=*/0,
6718 SS, ObjectTypePtr,
6719 false);
6720 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006721 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006722
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006723 Destroyed
6724 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6725 E->getDestroyedTypeLoc());
6726 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006727
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006728 TypeSourceInfo *ScopeTypeInfo = 0;
6729 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00006730 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006731 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006732 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00006733 }
Sean Huntc3021132010-05-05 15:23:54 +00006734
John McCall9ae2f072010-08-23 23:25:46 +00006735 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006736 E->getOperatorLoc(),
6737 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006738 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006739 ScopeTypeInfo,
6740 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006741 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006742 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00006743}
Mike Stump1eb44332009-09-09 15:08:12 +00006744
Douglas Gregora71d8192009-09-04 17:36:40 +00006745template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006746ExprResult
John McCallba135432009-11-21 08:51:07 +00006747TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00006748 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00006749 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6750
6751 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6752 Sema::LookupOrdinaryName);
6753
6754 // Transform all the decls.
6755 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6756 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006757 NamedDecl *InstD = static_cast<NamedDecl*>(
6758 getDerived().TransformDecl(Old->getNameLoc(),
6759 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006760 if (!InstD) {
6761 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6762 // This can happen because of dependent hiding.
6763 if (isa<UsingShadowDecl>(*I))
6764 continue;
6765 else
John McCallf312b1e2010-08-26 23:41:50 +00006766 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006767 }
John McCallf7a1a742009-11-24 19:00:30 +00006768
6769 // Expand using declarations.
6770 if (isa<UsingDecl>(InstD)) {
6771 UsingDecl *UD = cast<UsingDecl>(InstD);
6772 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6773 E = UD->shadow_end(); I != E; ++I)
6774 R.addDecl(*I);
6775 continue;
6776 }
6777
6778 R.addDecl(InstD);
6779 }
6780
6781 // Resolve a kind, but don't do any further analysis. If it's
6782 // ambiguous, the callee needs to deal with it.
6783 R.resolveKind();
6784
6785 // Rebuild the nested-name qualifier, if present.
6786 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00006787 if (Old->getQualifierLoc()) {
6788 NestedNameSpecifierLoc QualifierLoc
6789 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6790 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006791 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006792
Douglas Gregor4c9be892011-02-28 20:01:57 +00006793 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00006794 }
6795
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006796 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00006797 CXXRecordDecl *NamingClass
6798 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6799 Old->getNameLoc(),
6800 Old->getNamingClass()));
6801 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006802 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006803
Douglas Gregor66c45152010-04-27 16:10:10 +00006804 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00006805 }
6806
6807 // If we have no template arguments, it's a normal declaration name.
6808 if (!Old->hasExplicitTemplateArgs())
6809 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6810
6811 // If we have template arguments, rebuild them, then rebuild the
6812 // templateid expression.
6813 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006814 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6815 Old->getNumTemplateArgs(),
6816 TransArgs))
6817 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00006818
6819 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6820 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006821}
Mike Stump1eb44332009-09-09 15:08:12 +00006822
Douglas Gregorb98b1992009-08-11 05:31:07 +00006823template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006824ExprResult
John McCall454feb92009-12-08 09:21:05 +00006825TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006826 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6827 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006828 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006829
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006831 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006832 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006833
Mike Stump1eb44332009-09-09 15:08:12 +00006834 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006835 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836 T,
6837 E->getLocEnd());
6838}
Mike Stump1eb44332009-09-09 15:08:12 +00006839
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006841ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00006842TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6843 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6844 if (!LhsT)
6845 return ExprError();
6846
6847 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6848 if (!RhsT)
6849 return ExprError();
6850
6851 if (!getDerived().AlwaysRebuild() &&
6852 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6853 return SemaRef.Owned(E);
6854
6855 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6856 E->getLocStart(),
6857 LhsT, RhsT,
6858 E->getLocEnd());
6859}
6860
6861template<typename Derived>
6862ExprResult
John McCall865d4472009-11-19 22:55:06 +00006863TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006864 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00006865 NestedNameSpecifierLoc QualifierLoc
6866 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6867 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006868 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006869
John McCall43fed0d2010-11-12 08:19:04 +00006870 // TODO: If this is a conversion-function-id, verify that the
6871 // destination type name (if present) resolves the same way after
6872 // instantiation as it did in the local scope.
6873
Abramo Bagnara25777432010-08-11 22:01:17 +00006874 DeclarationNameInfo NameInfo
6875 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6876 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006877 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006878
John McCallf7a1a742009-11-24 19:00:30 +00006879 if (!E->hasExplicitTemplateArgs()) {
6880 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00006881 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006882 // Note: it is sufficient to compare the Name component of NameInfo:
6883 // if name has not changed, DNLoc has not changed either.
6884 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00006885 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006886
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00006887 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006888 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006889 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00006890 }
John McCalld5532b62009-11-23 01:53:49 +00006891
6892 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006893 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6894 E->getNumTemplateArgs(),
6895 TransArgs))
6896 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006897
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00006898 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006899 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006900 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006901}
6902
6903template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006904ExprResult
John McCall454feb92009-12-08 09:21:05 +00006905TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00006906 // CXXConstructExprs are always implicit, so when we have a
6907 // 1-argument construction we just transform that argument.
6908 if (E->getNumArgs() == 1 ||
6909 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6910 return getDerived().TransformExpr(E->getArg(0));
6911
Douglas Gregorb98b1992009-08-11 05:31:07 +00006912 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6913
6914 QualType T = getDerived().TransformType(E->getType());
6915 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006916 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917
6918 CXXConstructorDecl *Constructor
6919 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006920 getDerived().TransformDecl(E->getLocStart(),
6921 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006922 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006923 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006924
Douglas Gregorb98b1992009-08-11 05:31:07 +00006925 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006926 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006927 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6928 &ArgumentChanged))
6929 return ExprError();
6930
Douglas Gregorb98b1992009-08-11 05:31:07 +00006931 if (!getDerived().AlwaysRebuild() &&
6932 T == E->getType() &&
6933 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00006934 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00006935 // Mark the constructor as referenced.
6936 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00006937 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006938 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00006939 }
Mike Stump1eb44332009-09-09 15:08:12 +00006940
Douglas Gregor4411d2e2009-12-14 16:27:04 +00006941 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6942 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00006943 move_arg(Args),
6944 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00006945 E->getConstructionKind(),
6946 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006947}
Mike Stump1eb44332009-09-09 15:08:12 +00006948
Douglas Gregorb98b1992009-08-11 05:31:07 +00006949/// \brief Transform a C++ temporary-binding expression.
6950///
Douglas Gregor51326552009-12-24 18:51:59 +00006951/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6952/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006953template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006954ExprResult
John McCall454feb92009-12-08 09:21:05 +00006955TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006956 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006957}
Mike Stump1eb44332009-09-09 15:08:12 +00006958
John McCall4765fa02010-12-06 08:20:24 +00006959/// \brief Transform a C++ expression that contains cleanups that should
6960/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006961///
John McCall4765fa02010-12-06 08:20:24 +00006962/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00006963/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006964template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006965ExprResult
John McCall4765fa02010-12-06 08:20:24 +00006966TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006967 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006968}
Mike Stump1eb44332009-09-09 15:08:12 +00006969
Douglas Gregorb98b1992009-08-11 05:31:07 +00006970template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006971ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00006973 CXXTemporaryObjectExpr *E) {
6974 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6975 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006976 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006977
Douglas Gregorb98b1992009-08-11 05:31:07 +00006978 CXXConstructorDecl *Constructor
6979 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00006980 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006981 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006982 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006983 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006984
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006986 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006987 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00006988 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6989 &ArgumentChanged))
6990 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006991
Douglas Gregorb98b1992009-08-11 05:31:07 +00006992 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006993 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006994 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00006995 !ArgumentChanged) {
6996 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00006997 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006998 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00006999 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007000
7001 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7002 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007003 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004 E->getLocEnd());
7005}
Mike Stump1eb44332009-09-09 15:08:12 +00007006
Douglas Gregorb98b1992009-08-11 05:31:07 +00007007template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007008ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007009TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007010 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007011 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7012 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007013 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007014
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007016 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007017 Args.reserve(E->arg_size());
7018 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7019 &ArgumentChanged))
7020 return ExprError();
7021
Douglas Gregorb98b1992009-08-11 05:31:07 +00007022 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007023 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007025 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007026
Douglas Gregorb98b1992009-08-11 05:31:07 +00007027 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007028 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029 E->getLParenLoc(),
7030 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031 E->getRParenLoc());
7032}
Mike Stump1eb44332009-09-09 15:08:12 +00007033
Douglas Gregorb98b1992009-08-11 05:31:07 +00007034template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007035ExprResult
John McCall865d4472009-11-19 22:55:06 +00007036TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007037 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007038 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007039 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007040 Expr *OldBase;
7041 QualType BaseType;
7042 QualType ObjectType;
7043 if (!E->isImplicitAccess()) {
7044 OldBase = E->getBase();
7045 Base = getDerived().TransformExpr(OldBase);
7046 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007047 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007048
John McCallaa81e162009-12-01 22:10:20 +00007049 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007050 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007051 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007052 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007053 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007054 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007055 ObjectTy,
7056 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007057 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007058 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007059
John McCallb3d87482010-08-24 05:47:05 +00007060 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007061 BaseType = ((Expr*) Base.get())->getType();
7062 } else {
7063 OldBase = 0;
7064 BaseType = getDerived().TransformType(E->getBaseType());
7065 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7066 }
Mike Stump1eb44332009-09-09 15:08:12 +00007067
Douglas Gregor6cd21982009-10-20 05:58:46 +00007068 // Transform the first part of the nested-name-specifier that qualifies
7069 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007070 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007071 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007072 E->getFirstQualifierFoundInScope(),
7073 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007074
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007075 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007076 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007077 QualifierLoc
7078 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7079 ObjectType,
7080 FirstQualifierInScope);
7081 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007082 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007083 }
Mike Stump1eb44332009-09-09 15:08:12 +00007084
John McCall43fed0d2010-11-12 08:19:04 +00007085 // TODO: If this is a conversion-function-id, verify that the
7086 // destination type name (if present) resolves the same way after
7087 // instantiation as it did in the local scope.
7088
Abramo Bagnara25777432010-08-11 22:01:17 +00007089 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007090 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007091 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007092 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007093
John McCallaa81e162009-12-01 22:10:20 +00007094 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007095 // This is a reference to a member without an explicitly-specified
7096 // template argument list. Optimize for this common case.
7097 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007098 Base.get() == OldBase &&
7099 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007100 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007101 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007102 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007103 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007104
John McCall9ae2f072010-08-23 23:25:46 +00007105 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007106 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007107 E->isArrow(),
7108 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007109 QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00007110 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007111 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007112 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007113 }
7114
John McCalld5532b62009-11-23 01:53:49 +00007115 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007116 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7117 E->getNumTemplateArgs(),
7118 TransArgs))
7119 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007120
John McCall9ae2f072010-08-23 23:25:46 +00007121 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007122 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007123 E->isArrow(),
7124 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007125 QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007126 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007127 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007128 &TransArgs);
7129}
7130
7131template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007132ExprResult
John McCall454feb92009-12-08 09:21:05 +00007133TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007134 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007135 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007136 QualType BaseType;
7137 if (!Old->isImplicitAccess()) {
7138 Base = getDerived().TransformExpr(Old->getBase());
7139 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007140 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007141 BaseType = ((Expr*) Base.get())->getType();
7142 } else {
7143 BaseType = getDerived().TransformType(Old->getBaseType());
7144 }
John McCall129e2df2009-11-30 22:42:35 +00007145
Douglas Gregor4c9be892011-02-28 20:01:57 +00007146 NestedNameSpecifierLoc QualifierLoc;
7147 if (Old->getQualifierLoc()) {
7148 QualifierLoc
7149 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7150 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007151 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007152 }
7153
Abramo Bagnara25777432010-08-11 22:01:17 +00007154 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007155 Sema::LookupOrdinaryName);
7156
7157 // Transform all the decls.
7158 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7159 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007160 NamedDecl *InstD = static_cast<NamedDecl*>(
7161 getDerived().TransformDecl(Old->getMemberLoc(),
7162 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007163 if (!InstD) {
7164 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7165 // This can happen because of dependent hiding.
7166 if (isa<UsingShadowDecl>(*I))
7167 continue;
7168 else
John McCallf312b1e2010-08-26 23:41:50 +00007169 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007170 }
John McCall129e2df2009-11-30 22:42:35 +00007171
7172 // Expand using declarations.
7173 if (isa<UsingDecl>(InstD)) {
7174 UsingDecl *UD = cast<UsingDecl>(InstD);
7175 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7176 E = UD->shadow_end(); I != E; ++I)
7177 R.addDecl(*I);
7178 continue;
7179 }
7180
7181 R.addDecl(InstD);
7182 }
7183
7184 R.resolveKind();
7185
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007186 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007187 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007188 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007189 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007190 Old->getMemberLoc(),
7191 Old->getNamingClass()));
7192 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007193 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007194
Douglas Gregor66c45152010-04-27 16:10:10 +00007195 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007196 }
Sean Huntc3021132010-05-05 15:23:54 +00007197
John McCall129e2df2009-11-30 22:42:35 +00007198 TemplateArgumentListInfo TransArgs;
7199 if (Old->hasExplicitTemplateArgs()) {
7200 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7201 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007202 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7203 Old->getNumTemplateArgs(),
7204 TransArgs))
7205 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007206 }
John McCallc2233c52010-01-15 08:34:02 +00007207
7208 // FIXME: to do this check properly, we will need to preserve the
7209 // first-qualifier-in-scope here, just in case we had a dependent
7210 // base (and therefore couldn't do the check) and a
7211 // nested-name-qualifier (and therefore could do the lookup).
7212 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007213
John McCall9ae2f072010-08-23 23:25:46 +00007214 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007215 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007216 Old->getOperatorLoc(),
7217 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007218 QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00007219 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007220 R,
7221 (Old->hasExplicitTemplateArgs()
7222 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007223}
7224
7225template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007226ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007227TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7228 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7229 if (SubExpr.isInvalid())
7230 return ExprError();
7231
7232 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007233 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007234
7235 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7236}
7237
7238template<typename Derived>
7239ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007240TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007241 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7242 if (Pattern.isInvalid())
7243 return ExprError();
7244
7245 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7246 return SemaRef.Owned(E);
7247
Douglas Gregor67fd1252011-01-14 21:20:45 +00007248 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7249 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007250}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007251
7252template<typename Derived>
7253ExprResult
7254TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7255 // If E is not value-dependent, then nothing will change when we transform it.
7256 // Note: This is an instantiation-centric view.
7257 if (!E->isValueDependent())
7258 return SemaRef.Owned(E);
7259
7260 // Note: None of the implementations of TryExpandParameterPacks can ever
7261 // produce a diagnostic when given only a single unexpanded parameter pack,
7262 // so
7263 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7264 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007265 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007266 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007267 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7268 &Unexpanded, 1,
Douglas Gregord3731192011-01-10 07:32:04 +00007269 ShouldExpand, RetainExpansion,
7270 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007271 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007272
Douglas Gregord3731192011-01-10 07:32:04 +00007273 if (!ShouldExpand || RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007274 return SemaRef.Owned(E);
7275
7276 // We now know the length of the parameter pack, so build a new expression
7277 // that stores that length.
7278 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7279 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00007280 *NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007281}
7282
Douglas Gregorbe230c32011-01-03 17:17:50 +00007283template<typename Derived>
7284ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007285TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7286 SubstNonTypeTemplateParmPackExpr *E) {
7287 // Default behavior is to do nothing with this transformation.
7288 return SemaRef.Owned(E);
7289}
7290
7291template<typename Derived>
7292ExprResult
John McCall454feb92009-12-08 09:21:05 +00007293TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007294 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007295}
7296
Mike Stump1eb44332009-09-09 15:08:12 +00007297template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007298ExprResult
John McCall454feb92009-12-08 09:21:05 +00007299TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007300 TypeSourceInfo *EncodedTypeInfo
7301 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7302 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007303 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007304
Douglas Gregorb98b1992009-08-11 05:31:07 +00007305 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007306 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007307 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007308
7309 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007310 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007311 E->getRParenLoc());
7312}
Mike Stump1eb44332009-09-09 15:08:12 +00007313
Douglas Gregorb98b1992009-08-11 05:31:07 +00007314template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007315ExprResult
John McCall454feb92009-12-08 09:21:05 +00007316TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007317 // Transform arguments.
7318 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007319 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007320 Args.reserve(E->getNumArgs());
7321 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7322 &ArgChanged))
7323 return ExprError();
7324
Douglas Gregor92e986e2010-04-22 16:44:27 +00007325 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7326 // Class message: transform the receiver type.
7327 TypeSourceInfo *ReceiverTypeInfo
7328 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7329 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007330 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007331
Douglas Gregor92e986e2010-04-22 16:44:27 +00007332 // If nothing changed, just retain the existing message send.
7333 if (!getDerived().AlwaysRebuild() &&
7334 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007335 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007336
7337 // Build a new class message send.
7338 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7339 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007340 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007341 E->getMethodDecl(),
7342 E->getLeftLoc(),
7343 move_arg(Args),
7344 E->getRightLoc());
7345 }
7346
7347 // Instance message: transform the receiver
7348 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7349 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007350 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007351 = getDerived().TransformExpr(E->getInstanceReceiver());
7352 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007353 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007354
7355 // If nothing changed, just retain the existing message send.
7356 if (!getDerived().AlwaysRebuild() &&
7357 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007358 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007359
Douglas Gregor92e986e2010-04-22 16:44:27 +00007360 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00007361 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007362 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007363 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007364 E->getMethodDecl(),
7365 E->getLeftLoc(),
7366 move_arg(Args),
7367 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007368}
7369
Mike Stump1eb44332009-09-09 15:08:12 +00007370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007371ExprResult
John McCall454feb92009-12-08 09:21:05 +00007372TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007373 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007374}
7375
Mike Stump1eb44332009-09-09 15:08:12 +00007376template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007377ExprResult
John McCall454feb92009-12-08 09:21:05 +00007378TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007379 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007380}
7381
Mike Stump1eb44332009-09-09 15:08:12 +00007382template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007383ExprResult
John McCall454feb92009-12-08 09:21:05 +00007384TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007385 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007386 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007387 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007388 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007389
7390 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007391
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007392 // If nothing changed, just retain the existing expression.
7393 if (!getDerived().AlwaysRebuild() &&
7394 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007395 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007396
John McCall9ae2f072010-08-23 23:25:46 +00007397 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007398 E->getLocation(),
7399 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007400}
7401
Mike Stump1eb44332009-09-09 15:08:12 +00007402template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007403ExprResult
John McCall454feb92009-12-08 09:21:05 +00007404TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00007405 // 'super' and types never change. Property never changes. Just
7406 // retain the existing expression.
7407 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00007408 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00007409
Douglas Gregore3303542010-04-26 20:47:02 +00007410 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007411 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00007412 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007413 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007414
Douglas Gregore3303542010-04-26 20:47:02 +00007415 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007416
Douglas Gregore3303542010-04-26 20:47:02 +00007417 // If nothing changed, just retain the existing expression.
7418 if (!getDerived().AlwaysRebuild() &&
7419 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007420 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007421
John McCall12f78a62010-12-02 01:19:52 +00007422 if (E->isExplicitProperty())
7423 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7424 E->getExplicitProperty(),
7425 E->getLocation());
7426
7427 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7428 E->getType(),
7429 E->getImplicitPropertyGetter(),
7430 E->getImplicitPropertySetter(),
7431 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007432}
7433
Mike Stump1eb44332009-09-09 15:08:12 +00007434template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007435ExprResult
John McCall454feb92009-12-08 09:21:05 +00007436TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007437 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007438 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007439 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007440 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007441
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007442 // If nothing changed, just retain the existing expression.
7443 if (!getDerived().AlwaysRebuild() &&
7444 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007445 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007446
John McCall9ae2f072010-08-23 23:25:46 +00007447 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007448 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007449}
7450
Mike Stump1eb44332009-09-09 15:08:12 +00007451template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007452ExprResult
John McCall454feb92009-12-08 09:21:05 +00007453TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007454 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007455 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007456 SubExprs.reserve(E->getNumSubExprs());
7457 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7458 SubExprs, &ArgumentChanged))
7459 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007460
Douglas Gregorb98b1992009-08-11 05:31:07 +00007461 if (!getDerived().AlwaysRebuild() &&
7462 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007463 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007464
Douglas Gregorb98b1992009-08-11 05:31:07 +00007465 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7466 move_arg(SubExprs),
7467 E->getRParenLoc());
7468}
7469
Mike Stump1eb44332009-09-09 15:08:12 +00007470template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007471ExprResult
John McCall454feb92009-12-08 09:21:05 +00007472TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00007473 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007474
John McCallc6ac9c32011-02-04 18:33:18 +00007475 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7476 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7477
7478 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7479 llvm::SmallVector<ParmVarDecl*, 4> params;
7480 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007481
7482 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00007483 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7484 oldBlock->param_begin(),
7485 oldBlock->param_size(),
7486 0, paramTypes, &params))
Douglas Gregora779d9c2011-01-19 21:32:01 +00007487 return true;
John McCallc6ac9c32011-02-04 18:33:18 +00007488
7489 const FunctionType *exprFunctionType = E->getFunctionType();
7490 QualType exprResultType = exprFunctionType->getResultType();
7491 if (!exprResultType.isNull()) {
7492 if (!exprResultType->isDependentType())
7493 blockScope->ReturnType = exprResultType;
7494 else if (exprResultType != getSema().Context.DependentTy)
7495 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007496 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00007497
7498 // If the return type has not been determined yet, leave it as a dependent
7499 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00007500 if (blockScope->ReturnType.isNull())
7501 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007502
7503 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00007504 if (blockScope->ReturnType->isObjCObjectType()) {
7505 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00007506 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00007507 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007508 return ExprError();
7509 }
John McCall711c52b2011-01-05 12:14:39 +00007510
John McCallc6ac9c32011-02-04 18:33:18 +00007511 QualType functionType = getDerived().RebuildFunctionProtoType(
7512 blockScope->ReturnType,
7513 paramTypes.data(),
7514 paramTypes.size(),
7515 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00007516 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00007517 exprFunctionType->getExtInfo());
7518 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00007519
7520 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00007521 if (!params.empty())
7522 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregora779d9c2011-01-19 21:32:01 +00007523
7524 // If the return type wasn't explicitly set, it will have been marked as a
7525 // dependent type (DependentTy); clear out the return type setting so
7526 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00007527 if (blockScope->ReturnType == getSema().Context.DependentTy)
7528 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00007529
John McCall711c52b2011-01-05 12:14:39 +00007530 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00007531 StmtResult body = getDerived().TransformStmt(E->getBody());
7532 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00007533 return ExprError();
7534
John McCallc6ac9c32011-02-04 18:33:18 +00007535#ifndef NDEBUG
7536 // In builds with assertions, make sure that we captured everything we
7537 // captured before.
7538
7539 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7540
7541 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7542 e = oldBlock->capture_end(); i != e; ++i) {
John McCall6b5a61b2011-02-07 10:33:21 +00007543 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00007544
7545 // Ignore parameter packs.
7546 if (isa<ParmVarDecl>(oldCapture) &&
7547 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7548 continue;
7549
7550 VarDecl *newCapture =
7551 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7552 oldCapture));
John McCall6b5a61b2011-02-07 10:33:21 +00007553 assert(blockScope->CaptureMap.count(newCapture));
John McCallc6ac9c32011-02-04 18:33:18 +00007554 }
7555#endif
7556
7557 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7558 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007559}
7560
Mike Stump1eb44332009-09-09 15:08:12 +00007561template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007562ExprResult
John McCall454feb92009-12-08 09:21:05 +00007563TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007564 ValueDecl *ND
7565 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7566 E->getDecl()));
7567 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00007568 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00007569
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007570 if (!getDerived().AlwaysRebuild() &&
7571 ND == E->getDecl()) {
7572 // Mark it referenced in the new context regardless.
7573 // FIXME: this is a bit instantiation-specific.
7574 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7575
John McCall3fa5cae2010-10-26 07:05:15 +00007576 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007577 }
7578
Abramo Bagnara25777432010-08-11 22:01:17 +00007579 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00007580 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00007581 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007582}
Mike Stump1eb44332009-09-09 15:08:12 +00007583
Douglas Gregorb98b1992009-08-11 05:31:07 +00007584//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00007585// Type reconstruction
7586//===----------------------------------------------------------------------===//
7587
Mike Stump1eb44332009-09-09 15:08:12 +00007588template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007589QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7590 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007591 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007592 getDerived().getBaseEntity());
7593}
7594
Mike Stump1eb44332009-09-09 15:08:12 +00007595template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007596QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7597 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007598 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007599 getDerived().getBaseEntity());
7600}
7601
Mike Stump1eb44332009-09-09 15:08:12 +00007602template<typename Derived>
7603QualType
John McCall85737a72009-10-30 00:06:24 +00007604TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7605 bool WrittenAsLValue,
7606 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007607 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00007608 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007609}
7610
7611template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007612QualType
John McCall85737a72009-10-30 00:06:24 +00007613TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7614 QualType ClassType,
7615 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007616 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00007617 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007618}
7619
7620template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007621QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00007622TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7623 ArrayType::ArraySizeModifier SizeMod,
7624 const llvm::APInt *Size,
7625 Expr *SizeExpr,
7626 unsigned IndexTypeQuals,
7627 SourceRange BracketsRange) {
7628 if (SizeExpr || !Size)
7629 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7630 IndexTypeQuals, BracketsRange,
7631 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00007632
7633 QualType Types[] = {
7634 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7635 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7636 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00007637 };
7638 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7639 QualType SizeType;
7640 for (unsigned I = 0; I != NumTypes; ++I)
7641 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7642 SizeType = Types[I];
7643 break;
7644 }
Mike Stump1eb44332009-09-09 15:08:12 +00007645
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007646 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7647 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00007648 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007649 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00007650 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007651}
Mike Stump1eb44332009-09-09 15:08:12 +00007652
Douglas Gregor577f75a2009-08-04 16:50:30 +00007653template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007654QualType
7655TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007656 ArrayType::ArraySizeModifier SizeMod,
7657 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00007658 unsigned IndexTypeQuals,
7659 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007660 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00007661 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007662}
7663
7664template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007665QualType
Mike Stump1eb44332009-09-09 15:08:12 +00007666TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007667 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00007668 unsigned IndexTypeQuals,
7669 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007670 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00007671 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007672}
Mike Stump1eb44332009-09-09 15:08:12 +00007673
Douglas Gregor577f75a2009-08-04 16:50:30 +00007674template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007675QualType
7676TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007677 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007678 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007679 unsigned IndexTypeQuals,
7680 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007681 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007682 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007683 IndexTypeQuals, BracketsRange);
7684}
7685
7686template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007687QualType
7688TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007689 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007690 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007691 unsigned IndexTypeQuals,
7692 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007693 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007694 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007695 IndexTypeQuals, BracketsRange);
7696}
7697
7698template<typename Derived>
7699QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00007700 unsigned NumElements,
7701 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00007702 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00007703 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007704}
Mike Stump1eb44332009-09-09 15:08:12 +00007705
Douglas Gregor577f75a2009-08-04 16:50:30 +00007706template<typename Derived>
7707QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7708 unsigned NumElements,
7709 SourceLocation AttributeLoc) {
7710 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7711 NumElements, true);
7712 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007713 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7714 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00007715 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007716}
Mike Stump1eb44332009-09-09 15:08:12 +00007717
Douglas Gregor577f75a2009-08-04 16:50:30 +00007718template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007719QualType
7720TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00007721 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007722 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00007723 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007724}
Mike Stump1eb44332009-09-09 15:08:12 +00007725
Douglas Gregor577f75a2009-08-04 16:50:30 +00007726template<typename Derived>
7727QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00007728 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007729 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00007730 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00007731 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00007732 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00007733 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00007734 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00007735 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007736 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00007737 getDerived().getBaseEntity(),
7738 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007739}
Mike Stump1eb44332009-09-09 15:08:12 +00007740
Douglas Gregor577f75a2009-08-04 16:50:30 +00007741template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00007742QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7743 return SemaRef.Context.getFunctionNoProtoType(T);
7744}
7745
7746template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00007747QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7748 assert(D && "no decl found");
7749 if (D->isInvalidDecl()) return QualType();
7750
Douglas Gregor92e986e2010-04-22 16:44:27 +00007751 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00007752 TypeDecl *Ty;
7753 if (isa<UsingDecl>(D)) {
7754 UsingDecl *Using = cast<UsingDecl>(D);
7755 assert(Using->isTypeName() &&
7756 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7757
7758 // A valid resolved using typename decl points to exactly one type decl.
7759 assert(++Using->shadow_begin() == Using->shadow_end());
7760 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00007761
John McCalled976492009-12-04 22:46:56 +00007762 } else {
7763 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7764 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7765 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7766 }
7767
7768 return SemaRef.Context.getTypeDeclType(Ty);
7769}
7770
7771template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007772QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7773 SourceLocation Loc) {
7774 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007775}
7776
7777template<typename Derived>
7778QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7779 return SemaRef.Context.getTypeOfType(Underlying);
7780}
7781
7782template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007783QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7784 SourceLocation Loc) {
7785 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007786}
7787
7788template<typename Derived>
7789QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00007790 TemplateName Template,
7791 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00007792 const TemplateArgumentListInfo &TemplateArgs) {
7793 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007794}
Mike Stump1eb44332009-09-09 15:08:12 +00007795
Douglas Gregordcee1a12009-08-06 05:28:30 +00007796template<typename Derived>
7797NestedNameSpecifier *
7798TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7799 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00007800 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007801 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00007802 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00007803 CXXScopeSpec SS;
7804 // FIXME: The source location information is all wrong.
Douglas Gregorc34348a2011-02-24 17:54:50 +00007805 SS.MakeTrivial(SemaRef.Context, Prefix, Range);
Douglas Gregor2e4c34a2011-02-24 00:17:56 +00007806 if (SemaRef.BuildCXXNestedNameSpecifier(0, II, /*FIXME:*/Range.getBegin(),
7807 /*FIXME:*/Range.getEnd(),
7808 ObjectType, false,
7809 SS, FirstQualifierInScope,
7810 false))
7811 return 0;
7812
7813 return SS.getScopeRep();
Douglas Gregordcee1a12009-08-06 05:28:30 +00007814}
7815
7816template<typename Derived>
7817NestedNameSpecifier *
7818TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7819 SourceRange Range,
7820 NamespaceDecl *NS) {
7821 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7822}
7823
7824template<typename Derived>
7825NestedNameSpecifier *
7826TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7827 SourceRange Range,
Douglas Gregor14aba762011-02-24 02:36:08 +00007828 NamespaceAliasDecl *Alias) {
7829 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, Alias);
7830}
7831
7832template<typename Derived>
7833NestedNameSpecifier *
7834TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7835 SourceRange Range,
Douglas Gregordcee1a12009-08-06 05:28:30 +00007836 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00007837 QualType T) {
7838 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00007839 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00007840 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00007841 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7842 T.getTypePtr());
7843 }
Mike Stump1eb44332009-09-09 15:08:12 +00007844
Douglas Gregordcee1a12009-08-06 05:28:30 +00007845 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7846 return 0;
7847}
Mike Stump1eb44332009-09-09 15:08:12 +00007848
Douglas Gregord1067e52009-08-06 06:41:21 +00007849template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007850TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007851TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7852 bool TemplateKW,
7853 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00007854 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00007855 Template);
7856}
7857
7858template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007859TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007860TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007861 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007862 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +00007863 QualType ObjectType,
7864 NamedDecl *FirstQualifierInScope) {
Douglas Gregord1067e52009-08-06 06:41:21 +00007865 CXXScopeSpec SS;
Douglas Gregorc34348a2011-02-24 17:54:50 +00007866 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Douglas Gregor014e88d2009-11-03 23:16:33 +00007867 UnqualifiedId Name;
7868 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00007869 Sema::TemplateTy Template;
7870 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7871 /*FIXME:*/getDerived().getBaseLocation(),
7872 SS,
7873 Name,
John McCallb3d87482010-08-24 05:47:05 +00007874 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007875 /*EnteringContext=*/false,
7876 Template);
John McCall43fed0d2010-11-12 08:19:04 +00007877 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00007878}
Mike Stump1eb44332009-09-09 15:08:12 +00007879
Douglas Gregorb98b1992009-08-11 05:31:07 +00007880template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007881TemplateName
7882TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7883 OverloadedOperatorKind Operator,
7884 QualType ObjectType) {
7885 CXXScopeSpec SS;
Douglas Gregorc34348a2011-02-24 17:54:50 +00007886 SS.MakeTrivial(SemaRef.Context, Qualifier, SourceRange(getDerived().getBaseLocation()));
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007887 UnqualifiedId Name;
7888 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7889 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7890 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00007891 Sema::TemplateTy Template;
7892 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007893 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007894 SS,
7895 Name,
John McCallb3d87482010-08-24 05:47:05 +00007896 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007897 /*EnteringContext=*/false,
7898 Template);
7899 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007900}
Sean Huntc3021132010-05-05 15:23:54 +00007901
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007902template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007903ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007904TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7905 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007906 Expr *OrigCallee,
7907 Expr *First,
7908 Expr *Second) {
7909 Expr *Callee = OrigCallee->IgnoreParenCasts();
7910 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00007911
Douglas Gregorb98b1992009-08-11 05:31:07 +00007912 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00007913 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00007914 if (!First->getType()->isOverloadableType() &&
7915 !Second->getType()->isOverloadableType())
7916 return getSema().CreateBuiltinArraySubscriptExpr(First,
7917 Callee->getLocStart(),
7918 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00007919 } else if (Op == OO_Arrow) {
7920 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00007921 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7922 } else if (Second == 0 || isPostIncDec) {
7923 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007924 // The argument is not of overloadable type, so try to create a
7925 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00007926 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007927 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00007928
John McCall9ae2f072010-08-23 23:25:46 +00007929 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007930 }
7931 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007932 if (!First->getType()->isOverloadableType() &&
7933 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007934 // Neither of the arguments is an overloadable type, so try to
7935 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00007936 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007937 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00007938 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007939 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007940 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007941
Douglas Gregorb98b1992009-08-11 05:31:07 +00007942 return move(Result);
7943 }
7944 }
Mike Stump1eb44332009-09-09 15:08:12 +00007945
7946 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00007947 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00007948 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00007949
John McCall9ae2f072010-08-23 23:25:46 +00007950 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00007951 assert(ULE->requiresADL());
7952
7953 // FIXME: Do we have to check
7954 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00007955 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00007956 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007957 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00007958 }
Mike Stump1eb44332009-09-09 15:08:12 +00007959
Douglas Gregorb98b1992009-08-11 05:31:07 +00007960 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00007961 Expr *Args[2] = { First, Second };
7962 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00007963
Douglas Gregorb98b1992009-08-11 05:31:07 +00007964 // Create the overloaded operator invocation for unary operators.
7965 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00007966 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007967 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00007968 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007969 }
Mike Stump1eb44332009-09-09 15:08:12 +00007970
Sebastian Redlf322ed62009-10-29 20:17:01 +00007971 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00007972 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00007973 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007974 First,
7975 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00007976
Douglas Gregorb98b1992009-08-11 05:31:07 +00007977 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00007978 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007979 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00007980 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7981 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007982 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007983
Mike Stump1eb44332009-09-09 15:08:12 +00007984 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007985}
Mike Stump1eb44332009-09-09 15:08:12 +00007986
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007987template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007988ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00007989TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007990 SourceLocation OperatorLoc,
7991 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007992 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007993 TypeSourceInfo *ScopeType,
7994 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007995 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007996 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00007997 QualType BaseType = Base->getType();
7998 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007999 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008000 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008001 !BaseType->getAs<PointerType>()->getPointeeType()
8002 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008003 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008004 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008005 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008006 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008007 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008008 /*FIXME?*/true);
8009 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008010
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008011 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008012 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8013 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8014 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8015 NameInfo.setNamedTypeInfo(DestroyedType);
8016
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008017 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008018
John McCall9ae2f072010-08-23 23:25:46 +00008019 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008020 OperatorLoc, isArrow,
8021 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008022 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008023 /*TemplateArgs*/ 0);
8024}
8025
Douglas Gregor577f75a2009-08-04 16:50:30 +00008026} // end namespace clang
8027
8028#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H