blob: 6b25d33bbca85e0c251de866055dc00c98a077fe [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 Gregorfd4ffeb2011-03-02 18:07:45 +0000410 /// \param SS The nested-name-specifier that qualifies the template
411 /// name. This nested-name-specifier must already have been transformed.
412 ///
413 /// \param Name The template name to transform.
414 ///
415 /// \param NameLoc The source location of the template name.
416 ///
417 /// \param ObjectType If we're translating a template name within a member
418 /// access expression, this is the type of the object whose member template
419 /// is being referenced.
420 ///
421 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
422 /// also refers to a name within the current (lexical) scope, this is the
423 /// declaration it refers to.
424 ///
425 /// By default, transforms the template name by transforming the declarations
426 /// and nested-name-specifiers that occur within the template name.
427 /// Subclasses may override this function to provide alternate behavior.
428 TemplateName TransformTemplateName(CXXScopeSpec &SS,
429 TemplateName Name,
430 SourceLocation NameLoc,
431 QualType ObjectType = QualType(),
432 NamedDecl *FirstQualifierInScope = 0);
433
Douglas Gregor577f75a2009-08-04 16:50:30 +0000434 /// \brief Transform the given template argument.
435 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000436 /// By default, this operation transforms the type, expression, or
437 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000438 /// new template argument from the transformed result. Subclasses may
439 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000440 ///
441 /// Returns true if there was an error.
442 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
443 TemplateArgumentLoc &Output);
444
Douglas Gregorfcc12532010-12-20 17:31:10 +0000445 /// \brief Transform the given set of template arguments.
446 ///
447 /// By default, this operation transforms all of the template arguments
448 /// in the input set using \c TransformTemplateArgument(), and appends
449 /// the transformed arguments to the output list.
450 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000451 /// Note that this overload of \c TransformTemplateArguments() is merely
452 /// a convenience function. Subclasses that wish to override this behavior
453 /// should override the iterator-based member template version.
454 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000455 /// \param Inputs The set of template arguments to be transformed.
456 ///
457 /// \param NumInputs The number of template arguments in \p Inputs.
458 ///
459 /// \param Outputs The set of transformed template arguments output by this
460 /// routine.
461 ///
462 /// Returns true if an error occurred.
463 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
464 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000465 TemplateArgumentListInfo &Outputs) {
466 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
467 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000468
469 /// \brief Transform the given set of template arguments.
470 ///
471 /// By default, this operation transforms all of the template arguments
472 /// in the input set using \c TransformTemplateArgument(), and appends
473 /// the transformed arguments to the output list.
474 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000475 /// \param First An iterator to the first template argument.
476 ///
477 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000478 ///
479 /// \param Outputs The set of transformed template arguments output by this
480 /// routine.
481 ///
482 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000483 template<typename InputIterator>
484 bool TransformTemplateArguments(InputIterator First,
485 InputIterator Last,
486 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000487
John McCall833ca992009-10-29 08:12:44 +0000488 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
489 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
490 TemplateArgumentLoc &ArgLoc);
491
John McCalla93c9342009-12-07 02:54:59 +0000492 /// \brief Fakes up a TypeSourceInfo for a type.
493 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
494 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000495 getDerived().getBaseLocation());
496 }
Mike Stump1eb44332009-09-09 15:08:12 +0000497
John McCalla2becad2009-10-21 00:40:46 +0000498#define ABSTRACT_TYPELOC(CLASS, PARENT)
499#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000500 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000501#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000502
John McCall43fed0d2010-11-12 08:19:04 +0000503 QualType
504 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
505 TemplateSpecializationTypeLoc TL,
506 TemplateName Template);
507
508 QualType
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
510 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregora88f09f2011-02-28 17:23:35 +0000511 TemplateName Template);
512
513 QualType
514 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
515 DependentTemplateSpecializationTypeLoc TL,
John McCall43fed0d2010-11-12 08:19:04 +0000516 NestedNameSpecifier *Prefix);
517
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000518 QualType
519 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
520 DependentTemplateSpecializationTypeLoc TL,
521 NestedNameSpecifierLoc QualifierLoc);
522
John McCall21ef0fa2010-03-11 09:03:00 +0000523 /// \brief Transforms the parameters of a function type into the
524 /// given vectors.
525 ///
526 /// The result vectors should be kept in sync; null entries in the
527 /// variables vector are acceptable.
528 ///
529 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000530 bool TransformFunctionTypeParams(SourceLocation Loc,
531 ParmVarDecl **Params, unsigned NumParams,
532 const QualType *ParamTypes,
John McCall21ef0fa2010-03-11 09:03:00 +0000533 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregora009b592011-01-07 00:20:55 +0000534 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000535
536 /// \brief Transforms a single function-type parameter. Return null
537 /// on error.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000538 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
539 llvm::Optional<unsigned> NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +0000540
John McCall43fed0d2010-11-12 08:19:04 +0000541 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000542
John McCall60d7b3a2010-08-24 06:29:42 +0000543 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
544 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000545
Douglas Gregor43959a92009-08-20 07:17:43 +0000546#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000547 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000548#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000549 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000550#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000551#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000552
Douglas Gregor577f75a2009-08-04 16:50:30 +0000553 /// \brief Build a new pointer type given its pointee type.
554 ///
555 /// By default, performs semantic analysis when building the pointer type.
556 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000557 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000558
559 /// \brief Build a new block pointer type given its pointee type.
560 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000561 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000562 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000563 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000564
John McCall85737a72009-10-30 00:06:24 +0000565 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000566 ///
John McCall85737a72009-10-30 00:06:24 +0000567 /// By default, performs semantic analysis when building the
568 /// reference type. Subclasses may override this routine to provide
569 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000570 ///
John McCall85737a72009-10-30 00:06:24 +0000571 /// \param LValue whether the type was written with an lvalue sigil
572 /// or an rvalue sigil.
573 QualType RebuildReferenceType(QualType ReferentType,
574 bool LValue,
575 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000576
Douglas Gregor577f75a2009-08-04 16:50:30 +0000577 /// \brief Build a new member pointer type given the pointee type and the
578 /// class type it refers into.
579 ///
580 /// By default, performs semantic analysis when building the member pointer
581 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000582 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
583 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000584
Douglas Gregor577f75a2009-08-04 16:50:30 +0000585 /// \brief Build a new array type given the element type, size
586 /// modifier, size of the array (if known), size expression, and index type
587 /// qualifiers.
588 ///
589 /// By default, performs semantic analysis when building the array type.
590 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000591 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000592 QualType RebuildArrayType(QualType ElementType,
593 ArrayType::ArraySizeModifier SizeMod,
594 const llvm::APInt *Size,
595 Expr *SizeExpr,
596 unsigned IndexTypeQuals,
597 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000598
Douglas Gregor577f75a2009-08-04 16:50:30 +0000599 /// \brief Build a new constant array type given the element type, size
600 /// modifier, (known) size of the array, and index type qualifiers.
601 ///
602 /// By default, performs semantic analysis when building the array type.
603 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000604 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000605 ArrayType::ArraySizeModifier SizeMod,
606 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000607 unsigned IndexTypeQuals,
608 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000609
Douglas Gregor577f75a2009-08-04 16:50:30 +0000610 /// \brief Build a new incomplete array type given the element type, size
611 /// modifier, and index type qualifiers.
612 ///
613 /// By default, performs semantic analysis when building the array type.
614 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000615 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000616 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000617 unsigned IndexTypeQuals,
618 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000619
Mike Stump1eb44332009-09-09 15:08:12 +0000620 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621 /// size modifier, size expression, and index type qualifiers.
622 ///
623 /// By default, performs semantic analysis when building the array type.
624 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000625 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000626 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000627 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000628 unsigned IndexTypeQuals,
629 SourceRange BracketsRange);
630
Mike Stump1eb44332009-09-09 15:08:12 +0000631 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000632 /// size modifier, size expression, and index type qualifiers.
633 ///
634 /// By default, performs semantic analysis when building the array type.
635 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000636 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000637 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000638 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000639 unsigned IndexTypeQuals,
640 SourceRange BracketsRange);
641
642 /// \brief Build a new vector type given the element type and
643 /// number of elements.
644 ///
645 /// By default, performs semantic analysis when building the vector type.
646 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000647 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000648 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000649
Douglas Gregor577f75a2009-08-04 16:50:30 +0000650 /// \brief Build a new extended vector type given the element type and
651 /// number of elements.
652 ///
653 /// By default, performs semantic analysis when building the vector type.
654 /// Subclasses may override this routine to provide different behavior.
655 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
656 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000657
658 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000659 /// given the element type and number of elements.
660 ///
661 /// By default, performs semantic analysis when building the vector type.
662 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000663 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000664 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000665 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000666
Douglas Gregor577f75a2009-08-04 16:50:30 +0000667 /// \brief Build a new function type.
668 ///
669 /// By default, performs semantic analysis when building the function type.
670 /// Subclasses may override this routine to provide different behavior.
671 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000672 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000673 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000674 bool Variadic, unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000675 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000676 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000677
John McCalla2becad2009-10-21 00:40:46 +0000678 /// \brief Build a new unprototyped function type.
679 QualType RebuildFunctionNoProtoType(QualType ResultType);
680
John McCalled976492009-12-04 22:46:56 +0000681 /// \brief Rebuild an unresolved typename type, given the decl that
682 /// the UnresolvedUsingTypenameDecl was transformed to.
683 QualType RebuildUnresolvedUsingType(Decl *D);
684
Douglas Gregor577f75a2009-08-04 16:50:30 +0000685 /// \brief Build a new typedef type.
686 QualType RebuildTypedefType(TypedefDecl *Typedef) {
687 return SemaRef.Context.getTypeDeclType(Typedef);
688 }
689
690 /// \brief Build a new class/struct/union type.
691 QualType RebuildRecordType(RecordDecl *Record) {
692 return SemaRef.Context.getTypeDeclType(Record);
693 }
694
695 /// \brief Build a new Enum type.
696 QualType RebuildEnumType(EnumDecl *Enum) {
697 return SemaRef.Context.getTypeDeclType(Enum);
698 }
John McCall7da24312009-09-05 00:15:47 +0000699
Mike Stump1eb44332009-09-09 15:08:12 +0000700 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000701 ///
702 /// By default, performs semantic analysis when building the typeof type.
703 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000704 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000705
Mike Stump1eb44332009-09-09 15:08:12 +0000706 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000707 ///
708 /// By default, builds a new TypeOfType with the given underlying type.
709 QualType RebuildTypeOfType(QualType Underlying);
710
Mike Stump1eb44332009-09-09 15:08:12 +0000711 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000712 ///
713 /// By default, performs semantic analysis when building the decltype type.
714 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000715 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000716
Richard Smith34b41d92011-02-20 03:19:35 +0000717 /// \brief Build a new C++0x auto type.
718 ///
719 /// By default, builds a new AutoType with the given deduced type.
720 QualType RebuildAutoType(QualType Deduced) {
721 return SemaRef.Context.getAutoType(Deduced);
722 }
723
Douglas Gregor577f75a2009-08-04 16:50:30 +0000724 /// \brief Build a new template specialization type.
725 ///
726 /// By default, performs semantic analysis when building the template
727 /// specialization type. Subclasses may override this routine to provide
728 /// different behavior.
729 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000730 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000731 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000732
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000733 /// \brief Build a new parenthesized type.
734 ///
735 /// By default, builds a new ParenType type from the inner type.
736 /// Subclasses may override this routine to provide different behavior.
737 QualType RebuildParenType(QualType InnerType) {
738 return SemaRef.Context.getParenType(InnerType);
739 }
740
Douglas Gregor577f75a2009-08-04 16:50:30 +0000741 /// \brief Build a new qualified name type.
742 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000743 /// By default, builds a new ElaboratedType type from the keyword,
744 /// the nested-name-specifier and the named type.
745 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000746 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
747 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000748 NestedNameSpecifierLoc QualifierLoc,
749 QualType Named) {
750 return SemaRef.Context.getElaboratedType(Keyword,
751 QualifierLoc.getNestedNameSpecifier(),
752 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000753 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000754
755 /// \brief Build a new typename type that refers to a template-id.
756 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000757 /// By default, builds a new DependentNameType type from the
758 /// nested-name-specifier and the given type. Subclasses may override
759 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000760 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000761 ElaboratedTypeKeyword Keyword,
762 NestedNameSpecifierLoc QualifierLoc,
763 const IdentifierInfo *Name,
764 SourceLocation NameLoc,
765 const TemplateArgumentListInfo &Args) {
766 // Rebuild the template name.
767 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000768 CXXScopeSpec SS;
769 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000770 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000771 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000772
773 if (InstName.isNull())
774 return QualType();
775
776 // If it's still dependent, make a dependent specialization.
777 if (InstName.getAsDependentTemplateName())
778 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
779 QualifierLoc.getNestedNameSpecifier(),
780 Name,
781 Args);
782
783 // Otherwise, make an elaborated type wrapping a non-dependent
784 // specialization.
785 QualType T =
786 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
787 if (T.isNull()) return QualType();
788
789 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
790 return T;
791
792 return SemaRef.Context.getElaboratedType(Keyword,
793 QualifierLoc.getNestedNameSpecifier(),
794 T);
795 }
796
Douglas Gregor577f75a2009-08-04 16:50:30 +0000797 /// \brief Build a new typename type that refers to an identifier.
798 ///
799 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000800 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000801 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000802 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000803 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000804 NestedNameSpecifierLoc QualifierLoc,
805 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000806 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000807 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000808 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000809
Douglas Gregor2494dd02011-03-01 01:34:45 +0000810 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000811 // If the name is still dependent, just build a new dependent name type.
812 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000813 return SemaRef.Context.getDependentNameType(Keyword,
814 QualifierLoc.getNestedNameSpecifier(),
815 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000816 }
817
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000818 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000819 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000820 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000821
822 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
823
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000824 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000825 // into a non-dependent elaborated-type-specifier. Find the tag we're
826 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000827 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000828 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
829 if (!DC)
830 return QualType();
831
John McCall56138762010-05-27 06:40:31 +0000832 if (SemaRef.RequireCompleteDeclContext(SS, DC))
833 return QualType();
834
Douglas Gregor40336422010-03-31 22:19:08 +0000835 TagDecl *Tag = 0;
836 SemaRef.LookupQualifiedName(Result, DC);
837 switch (Result.getResultKind()) {
838 case LookupResult::NotFound:
839 case LookupResult::NotFoundInCurrentInstantiation:
840 break;
Sean Huntc3021132010-05-05 15:23:54 +0000841
Douglas Gregor40336422010-03-31 22:19:08 +0000842 case LookupResult::Found:
843 Tag = Result.getAsSingle<TagDecl>();
844 break;
Sean Huntc3021132010-05-05 15:23:54 +0000845
Douglas Gregor40336422010-03-31 22:19:08 +0000846 case LookupResult::FoundOverloaded:
847 case LookupResult::FoundUnresolvedValue:
848 llvm_unreachable("Tag lookup cannot find non-tags");
849 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000850
Douglas Gregor40336422010-03-31 22:19:08 +0000851 case LookupResult::Ambiguous:
852 // Let the LookupResult structure handle ambiguities.
853 return QualType();
854 }
855
856 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000857 // Check where the name exists but isn't a tag type and use that to emit
858 // better diagnostics.
859 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
860 SemaRef.LookupQualifiedName(Result, DC);
861 switch (Result.getResultKind()) {
862 case LookupResult::Found:
863 case LookupResult::FoundOverloaded:
864 case LookupResult::FoundUnresolvedValue: {
865 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
866 unsigned Kind = 0;
867 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
868 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
869 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
870 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
871 break;
872 }
873 default:
874 // FIXME: Would be nice to highlight just the source range.
875 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
876 << Kind << Id << DC;
877 break;
878 }
Douglas Gregor40336422010-03-31 22:19:08 +0000879 return QualType();
880 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000881
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000882 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
883 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000884 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
885 return QualType();
886 }
887
888 // Build the elaborated-type-specifier type.
889 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000890 return SemaRef.Context.getElaboratedType(Keyword,
891 QualifierLoc.getNestedNameSpecifier(),
892 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000893 }
Mike Stump1eb44332009-09-09 15:08:12 +0000894
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000895 /// \brief Build a new pack expansion type.
896 ///
897 /// By default, builds a new PackExpansionType type from the given pattern.
898 /// Subclasses may override this routine to provide different behavior.
899 QualType RebuildPackExpansionType(QualType Pattern,
900 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000901 SourceLocation EllipsisLoc,
902 llvm::Optional<unsigned> NumExpansions) {
903 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
904 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000905 }
906
Douglas Gregordcee1a12009-08-06 05:28:30 +0000907 /// \brief Build a new nested-name-specifier given the prefix and an
908 /// identifier that names the next step in the nested-name-specifier.
909 ///
910 /// By default, performs semantic analysis when building the new
911 /// nested-name-specifier. Subclasses may override this routine to provide
912 /// different behavior.
913 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
914 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000915 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000916 QualType ObjectType,
917 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000918
919 /// \brief Build a new nested-name-specifier given the prefix and the
920 /// namespace named in the next step in the nested-name-specifier.
921 ///
922 /// By default, performs semantic analysis when building the new
923 /// nested-name-specifier. Subclasses may override this routine to provide
924 /// different behavior.
925 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
926 SourceRange Range,
927 NamespaceDecl *NS);
928
929 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor14aba762011-02-24 02:36:08 +0000930 /// namespace alias named in the next step in the nested-name-specifier.
931 ///
932 /// By default, performs semantic analysis when building the new
933 /// nested-name-specifier. Subclasses may override this routine to provide
934 /// different behavior.
935 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
936 SourceRange Range,
937 NamespaceAliasDecl *Alias);
938
939 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000940 /// type named in the next step in the nested-name-specifier.
941 ///
942 /// By default, performs semantic analysis when building the new
943 /// nested-name-specifier. Subclasses may override this routine to provide
944 /// different behavior.
945 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
946 SourceRange Range,
947 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000948 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000949
950 /// \brief Build a new template name given a nested name specifier, a flag
951 /// indicating whether the "template" keyword was provided, and the template
952 /// that the template name refers to.
953 ///
954 /// By default, builds the new template name directly. Subclasses may override
955 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000956 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000957 bool TemplateKW,
958 TemplateDecl *Template);
959
Douglas Gregord1067e52009-08-06 06:41:21 +0000960 /// \brief Build a new template name given a nested name specifier and the
961 /// name that is referred to as a template.
962 ///
963 /// By default, performs semantic analysis to determine whether the name can
964 /// be resolved to a specific template, then builds the appropriate kind of
965 /// template name. Subclasses may override this routine to provide different
966 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000967 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
968 const IdentifierInfo &Name,
969 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000970 QualType ObjectType,
971 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000972
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000973 /// \brief Build a new template name given a nested name specifier and the
974 /// overloaded operator name that is referred to as a template.
975 ///
976 /// By default, performs semantic analysis to determine whether the name can
977 /// be resolved to a specific template, then builds the appropriate kind of
978 /// template name. Subclasses may override this routine to provide different
979 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000980 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000981 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000982 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000983 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000984
985 /// \brief Build a new template name given a template template parameter pack
986 /// and the
987 ///
988 /// By default, performs semantic analysis to determine whether the name can
989 /// be resolved to a specific template, then builds the appropriate kind of
990 /// template name. Subclasses may override this routine to provide different
991 /// behavior.
992 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
993 const TemplateArgument &ArgPack) {
994 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
995 }
996
Douglas Gregor43959a92009-08-20 07:17:43 +0000997 /// \brief Build a new compound statement.
998 ///
999 /// By default, performs semantic analysis to build the new statement.
1000 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001001 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001002 MultiStmtArg Statements,
1003 SourceLocation RBraceLoc,
1004 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001005 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001006 IsStmtExpr);
1007 }
1008
1009 /// \brief Build a new case statement.
1010 ///
1011 /// By default, performs semantic analysis to build the new statement.
1012 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001013 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001014 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001016 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001017 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001018 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001019 ColonLoc);
1020 }
Mike Stump1eb44332009-09-09 15:08:12 +00001021
Douglas Gregor43959a92009-08-20 07:17:43 +00001022 /// \brief Attach the body to a new case statement.
1023 ///
1024 /// By default, performs semantic analysis to build the new statement.
1025 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001026 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001027 getSema().ActOnCaseStmtBody(S, Body);
1028 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001029 }
Mike Stump1eb44332009-09-09 15:08:12 +00001030
Douglas Gregor43959a92009-08-20 07:17:43 +00001031 /// \brief Build a new default statement.
1032 ///
1033 /// By default, performs semantic analysis to build the new statement.
1034 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001035 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001036 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001037 Stmt *SubStmt) {
1038 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001039 /*CurScope=*/0);
1040 }
Mike Stump1eb44332009-09-09 15:08:12 +00001041
Douglas Gregor43959a92009-08-20 07:17:43 +00001042 /// \brief Build a new label statement.
1043 ///
1044 /// By default, performs semantic analysis to build the new statement.
1045 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001046 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1047 SourceLocation ColonLoc, Stmt *SubStmt) {
1048 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001049 }
Mike Stump1eb44332009-09-09 15:08:12 +00001050
Douglas Gregor43959a92009-08-20 07:17:43 +00001051 /// \brief Build a new "if" statement.
1052 ///
1053 /// By default, performs semantic analysis to build the new statement.
1054 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001055 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001056 VarDecl *CondVar, Stmt *Then,
1057 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001058 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001059 }
Mike Stump1eb44332009-09-09 15:08:12 +00001060
Douglas Gregor43959a92009-08-20 07:17:43 +00001061 /// \brief Start building a new switch statement.
1062 ///
1063 /// By default, performs semantic analysis to build the new statement.
1064 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001065 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001066 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001067 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001068 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001069 }
Mike Stump1eb44332009-09-09 15:08:12 +00001070
Douglas Gregor43959a92009-08-20 07:17:43 +00001071 /// \brief Attach the body to the switch statement.
1072 ///
1073 /// By default, performs semantic analysis to build the new statement.
1074 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001075 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001076 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001077 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001078 }
1079
1080 /// \brief Build a new while statement.
1081 ///
1082 /// By default, performs semantic analysis to build the new statement.
1083 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001084 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1085 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001086 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001087 }
Mike Stump1eb44332009-09-09 15:08:12 +00001088
Douglas Gregor43959a92009-08-20 07:17:43 +00001089 /// \brief Build a new do-while statement.
1090 ///
1091 /// By default, performs semantic analysis to build the new statement.
1092 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001093 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001094 SourceLocation WhileLoc, SourceLocation LParenLoc,
1095 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001096 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1097 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001098 }
1099
1100 /// \brief Build a new for statement.
1101 ///
1102 /// By default, performs semantic analysis to build the new statement.
1103 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001104 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1105 Stmt *Init, Sema::FullExprArg Cond,
1106 VarDecl *CondVar, Sema::FullExprArg Inc,
1107 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001108 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001109 CondVar, Inc, RParenLoc, Body);
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 goto statement.
1113 ///
1114 /// By default, performs semantic analysis to build the new statement.
1115 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001116 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1117 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001118 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001119 }
1120
1121 /// \brief Build a new indirect goto statement.
1122 ///
1123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001125 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001126 SourceLocation StarLoc,
1127 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001128 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001129 }
Mike Stump1eb44332009-09-09 15:08:12 +00001130
Douglas Gregor43959a92009-08-20 07:17:43 +00001131 /// \brief Build a new return statement.
1132 ///
1133 /// By default, performs semantic analysis to build the new statement.
1134 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001135 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001136 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001137 }
Mike Stump1eb44332009-09-09 15:08:12 +00001138
Douglas Gregor43959a92009-08-20 07:17:43 +00001139 /// \brief Build a new declaration statement.
1140 ///
1141 /// By default, performs semantic analysis to build the new statement.
1142 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001143 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001144 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001145 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001146 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1147 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001148 }
Mike Stump1eb44332009-09-09 15:08:12 +00001149
Anders Carlsson703e3942010-01-24 05:50:09 +00001150 /// \brief Build a new inline asm statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001154 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001155 bool IsSimple,
1156 bool IsVolatile,
1157 unsigned NumOutputs,
1158 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001159 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001160 MultiExprArg Constraints,
1161 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001162 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001163 MultiExprArg Clobbers,
1164 SourceLocation RParenLoc,
1165 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001166 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001167 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001168 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001169 RParenLoc, MSAsm);
1170 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001171
1172 /// \brief Build a new Objective-C @try statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001176 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001177 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001178 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001179 Stmt *Finally) {
1180 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1181 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001182 }
1183
Douglas Gregorbe270a02010-04-26 17:57:08 +00001184 /// \brief Rebuild an Objective-C exception declaration.
1185 ///
1186 /// By default, performs semantic analysis to build the new declaration.
1187 /// Subclasses may override this routine to provide different behavior.
1188 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1189 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +00001190 return getSema().BuildObjCExceptionDecl(TInfo, T,
1191 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00001192 ExceptionDecl->getLocation());
1193 }
Sean Huntc3021132010-05-05 15:23:54 +00001194
Douglas Gregorbe270a02010-04-26 17:57:08 +00001195 /// \brief Build a new Objective-C @catch statement.
1196 ///
1197 /// By default, performs semantic analysis to build the new statement.
1198 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001199 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001200 SourceLocation RParenLoc,
1201 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001202 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001203 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001204 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001205 }
Sean Huntc3021132010-05-05 15:23:54 +00001206
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001207 /// \brief Build a new Objective-C @finally statement.
1208 ///
1209 /// By default, performs semantic analysis to build the new statement.
1210 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001211 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001212 Stmt *Body) {
1213 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001214 }
Sean Huntc3021132010-05-05 15:23:54 +00001215
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001216 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001217 ///
1218 /// By default, performs semantic analysis to build the new statement.
1219 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001220 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001221 Expr *Operand) {
1222 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001223 }
Sean Huntc3021132010-05-05 15:23:54 +00001224
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001225 /// \brief Build a new Objective-C @synchronized statement.
1226 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001229 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001230 Expr *Object,
1231 Stmt *Body) {
1232 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1233 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001234 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001235
1236 /// \brief Build a new Objective-C fast enumeration statement.
1237 ///
1238 /// By default, performs semantic analysis to build the new statement.
1239 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001240 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001241 SourceLocation LParenLoc,
1242 Stmt *Element,
1243 Expr *Collection,
1244 SourceLocation RParenLoc,
1245 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001246 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001247 Element,
1248 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001249 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001250 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001251 }
Sean Huntc3021132010-05-05 15:23:54 +00001252
Douglas Gregor43959a92009-08-20 07:17:43 +00001253 /// \brief Build a new C++ exception declaration.
1254 ///
1255 /// By default, performs semantic analysis to build the new decaration.
1256 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor83cb9422010-09-09 17:09:21 +00001257 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001258 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +00001259 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +00001260 SourceLocation Loc) {
1261 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001262 }
1263
1264 /// \brief Build a new C++ catch statement.
1265 ///
1266 /// By default, performs semantic analysis to build the new statement.
1267 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001268 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001269 VarDecl *ExceptionDecl,
1270 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001271 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1272 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001273 }
Mike Stump1eb44332009-09-09 15:08:12 +00001274
Douglas Gregor43959a92009-08-20 07:17:43 +00001275 /// \brief Build a new C++ try statement.
1276 ///
1277 /// By default, performs semantic analysis to build the new statement.
1278 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001279 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001280 Stmt *TryBlock,
1281 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001282 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001283 }
Mike Stump1eb44332009-09-09 15:08:12 +00001284
Douglas Gregorb98b1992009-08-11 05:31:07 +00001285 /// \brief Build a new expression that references a declaration.
1286 ///
1287 /// 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 RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001290 LookupResult &R,
1291 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001292 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1293 }
1294
1295
1296 /// \brief Build a new expression that references a declaration.
1297 ///
1298 /// By default, performs semantic analysis to build the new expression.
1299 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001300 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001301 ValueDecl *VD,
1302 const DeclarationNameInfo &NameInfo,
1303 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001304 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001305 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001306
1307 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001308
1309 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001310 }
Mike Stump1eb44332009-09-09 15:08:12 +00001311
Douglas Gregorb98b1992009-08-11 05:31:07 +00001312 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001313 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001314 /// By default, performs semantic analysis to build the new expression.
1315 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001316 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001317 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001318 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001319 }
1320
Douglas Gregora71d8192009-09-04 17:36:40 +00001321 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001322 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001323 /// By default, performs semantic analysis to build the new expression.
1324 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001325 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001326 SourceLocation OperatorLoc,
1327 bool isArrow,
1328 CXXScopeSpec &SS,
1329 TypeSourceInfo *ScopeType,
1330 SourceLocation CCLoc,
1331 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001332 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001333
Douglas Gregorb98b1992009-08-11 05:31:07 +00001334 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001335 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001336 /// By default, performs semantic analysis to build the new expression.
1337 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001338 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001339 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001340 Expr *SubExpr) {
1341 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001342 }
Mike Stump1eb44332009-09-09 15:08:12 +00001343
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001344 /// \brief Build a new builtin offsetof expression.
1345 ///
1346 /// By default, performs semantic analysis to build the new expression.
1347 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001348 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001349 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001350 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001351 unsigned NumComponents,
1352 SourceLocation RParenLoc) {
1353 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1354 NumComponents, RParenLoc);
1355 }
Sean Huntc3021132010-05-05 15:23:54 +00001356
Douglas Gregorb98b1992009-08-11 05:31:07 +00001357 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001358 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001359 /// By default, performs semantic analysis to build the new expression.
1360 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001361 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001362 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001363 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001364 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001365 }
1366
Mike Stump1eb44332009-09-09 15:08:12 +00001367 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001368 /// argument.
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 RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001373 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001374 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001375 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001376 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001377 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001378
Douglas Gregorb98b1992009-08-11 05:31:07 +00001379 return move(Result);
1380 }
Mike Stump1eb44332009-09-09 15:08:12 +00001381
Douglas Gregorb98b1992009-08-11 05:31:07 +00001382 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001383 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001384 /// By default, performs semantic analysis to build the new expression.
1385 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001386 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001387 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001388 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001389 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001390 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1391 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001392 RBracketLoc);
1393 }
1394
1395 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001396 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001397 /// By default, performs semantic analysis to build the new expression.
1398 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001399 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001401 SourceLocation RParenLoc,
1402 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001403 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001404 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001405 }
1406
1407 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001408 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 /// By default, performs semantic analysis to build the new expression.
1410 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001411 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001412 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001413 NestedNameSpecifierLoc QualifierLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001414 const DeclarationNameInfo &MemberNameInfo,
1415 ValueDecl *Member,
1416 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001417 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001418 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001419 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001420 // We have a reference to an unnamed field. This is always the
1421 // base of an anonymous struct/union member access, i.e. the
1422 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001423 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001424 assert(Member->getType()->isRecordType() &&
1425 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001426
Douglas Gregor40d96a62011-02-28 21:54:11 +00001427 if (getSema().PerformObjectMemberConversion(Base,
1428 QualifierLoc.getNestedNameSpecifier(),
John McCall6bb80172010-03-30 21:47:33 +00001429 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001430 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001431
John McCallf89e55a2010-11-18 06:31:45 +00001432 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001433 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001434 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001435 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001436 cast<FieldDecl>(Member)->getType(),
1437 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001438 return getSema().Owned(ME);
1439 }
Mike Stump1eb44332009-09-09 15:08:12 +00001440
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001441 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001442 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001443
John McCall9ae2f072010-08-23 23:25:46 +00001444 getSema().DefaultFunctionArrayConversion(Base);
1445 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001446
John McCall6bb80172010-03-30 21:47:33 +00001447 // FIXME: this involves duplicating earlier analysis in a lot of
1448 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001449 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001450 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001451 R.resolveKind();
1452
John McCall9ae2f072010-08-23 23:25:46 +00001453 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001454 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001455 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 }
Mike Stump1eb44332009-09-09 15:08:12 +00001457
Douglas Gregorb98b1992009-08-11 05:31:07 +00001458 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001459 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001460 /// By default, performs semantic analysis to build the new expression.
1461 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001462 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001463 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001464 Expr *LHS, Expr *RHS) {
1465 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001466 }
1467
1468 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001469 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 /// By default, performs semantic analysis to build the new expression.
1471 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001472 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001473 SourceLocation QuestionLoc,
1474 Expr *LHS,
1475 SourceLocation ColonLoc,
1476 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001477 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1478 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001479 }
1480
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001482 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 /// By default, performs semantic analysis to build the new expression.
1484 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001485 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001486 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001488 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001489 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001490 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001491 }
Mike Stump1eb44332009-09-09 15:08:12 +00001492
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001494 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001497 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001498 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001499 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001500 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001501 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001502 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 }
Mike Stump1eb44332009-09-09 15:08:12 +00001504
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001506 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 /// By default, performs semantic analysis to build the new expression.
1508 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001509 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 SourceLocation OpLoc,
1511 SourceLocation AccessorLoc,
1512 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001513
John McCall129e2df2009-11-30 22:42:35 +00001514 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001515 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001516 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001517 OpLoc, /*IsArrow*/ false,
1518 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001519 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001520 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001521 }
Mike Stump1eb44332009-09-09 15:08:12 +00001522
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001524 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001527 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001528 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001529 SourceLocation RBraceLoc,
1530 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001531 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001532 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1533 if (Result.isInvalid() || ResultTy->isDependentType())
1534 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001535
Douglas Gregore48319a2009-11-09 17:16:50 +00001536 // Patch in the result type we were given, which may have been computed
1537 // when the initial InitListExpr was built.
1538 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1539 ILE->setType(ResultTy);
1540 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001541 }
Mike Stump1eb44332009-09-09 15:08:12 +00001542
Douglas Gregorb98b1992009-08-11 05:31:07 +00001543 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001544 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001545 /// By default, performs semantic analysis to build the new expression.
1546 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001547 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001548 MultiExprArg ArrayExprs,
1549 SourceLocation EqualOrColonLoc,
1550 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001551 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001552 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001553 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001554 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001556 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001557
Douglas Gregorb98b1992009-08-11 05:31:07 +00001558 ArrayExprs.release();
1559 return move(Result);
1560 }
Mike Stump1eb44332009-09-09 15:08:12 +00001561
Douglas Gregorb98b1992009-08-11 05:31:07 +00001562 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001563 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001564 /// By default, builds the implicit value initialization without performing
1565 /// any semantic analysis. Subclasses may override this routine to provide
1566 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001567 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001568 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1569 }
Mike Stump1eb44332009-09-09 15:08:12 +00001570
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001572 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001575 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001576 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001577 SourceLocation RParenLoc) {
1578 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001579 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001580 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 }
1582
1583 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001584 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 /// By default, performs semantic analysis to build the new expression.
1586 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001587 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001588 MultiExprArg SubExprs,
1589 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001590 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001591 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 }
Mike Stump1eb44332009-09-09 15:08:12 +00001593
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001595 ///
1596 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 /// rather than attempting to map the label statement itself.
1598 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001599 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001600 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001601 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 }
Mike Stump1eb44332009-09-09 15:08:12 +00001603
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001605 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 /// By default, performs semantic analysis to build the new expression.
1607 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001608 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001609 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001610 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001611 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 }
Mike Stump1eb44332009-09-09 15:08:12 +00001613
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 /// \brief Build a new __builtin_choose_expr expression.
1615 ///
1616 /// By default, performs semantic analysis to build the new expression.
1617 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001618 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001619 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 SourceLocation RParenLoc) {
1621 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001622 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001623 RParenLoc);
1624 }
Mike Stump1eb44332009-09-09 15:08:12 +00001625
Douglas Gregorb98b1992009-08-11 05:31:07 +00001626 /// \brief Build a new overloaded operator call expression.
1627 ///
1628 /// By default, performs semantic analysis to build the new expression.
1629 /// The semantic analysis provides the behavior of template instantiation,
1630 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001631 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 /// argument-dependent lookup, etc. Subclasses may override this routine to
1633 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001634 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001636 Expr *Callee,
1637 Expr *First,
1638 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001639
1640 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 /// reinterpret_cast.
1642 ///
1643 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001644 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001646 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647 Stmt::StmtClass Class,
1648 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001649 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 SourceLocation RAngleLoc,
1651 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001652 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 SourceLocation RParenLoc) {
1654 switch (Class) {
1655 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001656 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001657 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001658 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659
1660 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001661 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001662 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001663 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001664
Douglas Gregorb98b1992009-08-11 05:31:07 +00001665 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001666 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001667 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001668 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001670
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001672 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001673 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001674 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001675
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 default:
1677 assert(false && "Invalid C++ named cast");
1678 break;
1679 }
Mike Stump1eb44332009-09-09 15:08:12 +00001680
John McCallf312b1e2010-08-26 23:41:50 +00001681 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001682 }
Mike Stump1eb44332009-09-09 15:08:12 +00001683
Douglas Gregorb98b1992009-08-11 05:31:07 +00001684 /// \brief Build a new C++ static_cast expression.
1685 ///
1686 /// By default, performs semantic analysis to build the new expression.
1687 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001688 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001689 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001690 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 SourceLocation RAngleLoc,
1692 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001693 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001695 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001696 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001697 SourceRange(LAngleLoc, RAngleLoc),
1698 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 }
1700
1701 /// \brief Build a new C++ dynamic_cast expression.
1702 ///
1703 /// By default, performs semantic analysis to build the new expression.
1704 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001705 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001707 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 SourceLocation RAngleLoc,
1709 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001710 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001712 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001713 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001714 SourceRange(LAngleLoc, RAngleLoc),
1715 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 }
1717
1718 /// \brief Build a new C++ reinterpret_cast expression.
1719 ///
1720 /// By default, performs semantic analysis to build the new expression.
1721 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001722 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001724 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 SourceLocation RAngleLoc,
1726 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001727 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001728 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001729 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001730 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001731 SourceRange(LAngleLoc, RAngleLoc),
1732 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001733 }
1734
1735 /// \brief Build a new C++ const_cast expression.
1736 ///
1737 /// By default, performs semantic analysis to build the new expression.
1738 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001739 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001740 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001741 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 SourceLocation RAngleLoc,
1743 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001744 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001746 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001747 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001748 SourceRange(LAngleLoc, RAngleLoc),
1749 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 }
Mike Stump1eb44332009-09-09 15:08:12 +00001751
Douglas Gregorb98b1992009-08-11 05:31:07 +00001752 /// \brief Build a new C++ functional-style cast expression.
1753 ///
1754 /// By default, performs semantic analysis to build the new expression.
1755 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001756 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1757 SourceLocation LParenLoc,
1758 Expr *Sub,
1759 SourceLocation RParenLoc) {
1760 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001761 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 RParenLoc);
1763 }
Mike Stump1eb44332009-09-09 15:08:12 +00001764
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 /// \brief Build a new C++ typeid(type) expression.
1766 ///
1767 /// By default, performs semantic analysis to build the new expression.
1768 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001769 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001770 SourceLocation TypeidLoc,
1771 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001772 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001773 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001774 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 }
Mike Stump1eb44332009-09-09 15:08:12 +00001776
Francois Pichet01b7c302010-09-08 12:20:18 +00001777
Douglas Gregorb98b1992009-08-11 05:31:07 +00001778 /// \brief Build a new C++ typeid(expr) expression.
1779 ///
1780 /// By default, performs semantic analysis to build the new expression.
1781 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001782 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001783 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001784 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001786 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001787 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001788 }
1789
Francois Pichet01b7c302010-09-08 12:20:18 +00001790 /// \brief Build a new C++ __uuidof(type) expression.
1791 ///
1792 /// By default, performs semantic analysis to build the new expression.
1793 /// Subclasses may override this routine to provide different behavior.
1794 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1795 SourceLocation TypeidLoc,
1796 TypeSourceInfo *Operand,
1797 SourceLocation RParenLoc) {
1798 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1799 RParenLoc);
1800 }
1801
1802 /// \brief Build a new C++ __uuidof(expr) expression.
1803 ///
1804 /// By default, performs semantic analysis to build the new expression.
1805 /// Subclasses may override this routine to provide different behavior.
1806 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1807 SourceLocation TypeidLoc,
1808 Expr *Operand,
1809 SourceLocation RParenLoc) {
1810 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1811 RParenLoc);
1812 }
1813
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 /// \brief Build a new C++ "this" expression.
1815 ///
1816 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001817 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001818 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001819 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001820 QualType ThisType,
1821 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001822 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001823 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1824 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001825 }
1826
1827 /// \brief Build a new C++ throw expression.
1828 ///
1829 /// By default, performs semantic analysis to build the new expression.
1830 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001831 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001832 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001833 }
1834
1835 /// \brief Build a new C++ default-argument expression.
1836 ///
1837 /// By default, builds a new default-argument expression, which does not
1838 /// require any semantic analysis. Subclasses may override this routine to
1839 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001840 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001841 ParmVarDecl *Param) {
1842 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1843 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001844 }
1845
1846 /// \brief Build a new C++ zero-initialization expression.
1847 ///
1848 /// By default, performs semantic analysis to build the new expression.
1849 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001850 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1851 SourceLocation LParenLoc,
1852 SourceLocation RParenLoc) {
1853 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001854 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001855 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001856 }
Mike Stump1eb44332009-09-09 15:08:12 +00001857
Douglas Gregorb98b1992009-08-11 05:31:07 +00001858 /// \brief Build a new C++ "new" expression.
1859 ///
1860 /// By default, performs semantic analysis to build the new expression.
1861 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001862 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001863 bool UseGlobal,
1864 SourceLocation PlacementLParen,
1865 MultiExprArg PlacementArgs,
1866 SourceLocation PlacementRParen,
1867 SourceRange TypeIdParens,
1868 QualType AllocatedType,
1869 TypeSourceInfo *AllocatedTypeInfo,
1870 Expr *ArraySize,
1871 SourceLocation ConstructorLParen,
1872 MultiExprArg ConstructorArgs,
1873 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001874 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001875 PlacementLParen,
1876 move(PlacementArgs),
1877 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001878 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001879 AllocatedType,
1880 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001881 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001882 ConstructorLParen,
1883 move(ConstructorArgs),
1884 ConstructorRParen);
1885 }
Mike Stump1eb44332009-09-09 15:08:12 +00001886
Douglas Gregorb98b1992009-08-11 05:31:07 +00001887 /// \brief Build a new C++ "delete" expression.
1888 ///
1889 /// By default, performs semantic analysis to build the new expression.
1890 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001891 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 bool IsGlobalDelete,
1893 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001894 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001895 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001896 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 }
Mike Stump1eb44332009-09-09 15:08:12 +00001898
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 /// \brief Build a new unary type trait expression.
1900 ///
1901 /// By default, performs semantic analysis to build the new expression.
1902 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001903 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001904 SourceLocation StartLoc,
1905 TypeSourceInfo *T,
1906 SourceLocation RParenLoc) {
1907 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001908 }
1909
Francois Pichet6ad6f282010-12-07 00:08:36 +00001910 /// \brief Build a new binary type trait expression.
1911 ///
1912 /// By default, performs semantic analysis to build the new expression.
1913 /// Subclasses may override this routine to provide different behavior.
1914 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1915 SourceLocation StartLoc,
1916 TypeSourceInfo *LhsT,
1917 TypeSourceInfo *RhsT,
1918 SourceLocation RParenLoc) {
1919 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1920 }
1921
Mike Stump1eb44332009-09-09 15:08:12 +00001922 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001923 /// expression.
1924 ///
1925 /// By default, performs semantic analysis to build the new expression.
1926 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001927 ExprResult RebuildDependentScopeDeclRefExpr(
1928 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001929 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001930 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001931 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001932 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00001933
1934 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001935 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001936 *TemplateArgs);
1937
Abramo Bagnara25777432010-08-11 22:01:17 +00001938 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001939 }
1940
1941 /// \brief Build a new template-id expression.
1942 ///
1943 /// By default, performs semantic analysis to build the new expression.
1944 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001945 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001946 LookupResult &R,
1947 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001948 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001949 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001950 }
1951
1952 /// \brief Build a new object-construction expression.
1953 ///
1954 /// By default, performs semantic analysis to build the new expression.
1955 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001956 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001957 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001958 CXXConstructorDecl *Constructor,
1959 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001960 MultiExprArg Args,
1961 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00001962 CXXConstructExpr::ConstructionKind ConstructKind,
1963 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00001964 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001965 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001966 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001967 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001968
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001969 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001970 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00001971 RequiresZeroInit, ConstructKind,
1972 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 }
1974
1975 /// \brief Build a new object-construction expression.
1976 ///
1977 /// By default, performs semantic analysis to build the new expression.
1978 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001979 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1980 SourceLocation LParenLoc,
1981 MultiExprArg Args,
1982 SourceLocation RParenLoc) {
1983 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001984 LParenLoc,
1985 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001986 RParenLoc);
1987 }
1988
1989 /// \brief Build a new object-construction expression.
1990 ///
1991 /// By default, performs semantic analysis to build the new expression.
1992 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001993 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1994 SourceLocation LParenLoc,
1995 MultiExprArg Args,
1996 SourceLocation RParenLoc) {
1997 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001998 LParenLoc,
1999 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002000 RParenLoc);
2001 }
Mike Stump1eb44332009-09-09 15:08:12 +00002002
Douglas Gregorb98b1992009-08-11 05:31:07 +00002003 /// \brief Build a new member reference expression.
2004 ///
2005 /// By default, performs semantic analysis to build the new expression.
2006 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002007 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002008 QualType BaseType,
2009 bool IsArrow,
2010 SourceLocation OperatorLoc,
2011 NestedNameSpecifierLoc QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00002012 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002013 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002014 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002015 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002016 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002017
John McCall9ae2f072010-08-23 23:25:46 +00002018 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002019 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00002020 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002021 MemberNameInfo,
2022 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002023 }
2024
John McCall129e2df2009-11-30 22:42:35 +00002025 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002026 ///
2027 /// By default, performs semantic analysis to build the new expression.
2028 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002029 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00002030 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00002031 SourceLocation OperatorLoc,
2032 bool IsArrow,
Douglas Gregor4c9be892011-02-28 20:01:57 +00002033 NestedNameSpecifierLoc QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00002034 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00002035 LookupResult &R,
2036 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002037 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002038 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002039
John McCall9ae2f072010-08-23 23:25:46 +00002040 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002041 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00002042 SS, FirstQualifierInScope,
2043 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002044 }
Mike Stump1eb44332009-09-09 15:08:12 +00002045
Sebastian Redl2e156222010-09-10 20:55:43 +00002046 /// \brief Build a new noexcept expression.
2047 ///
2048 /// By default, performs semantic analysis to build the new expression.
2049 /// Subclasses may override this routine to provide different behavior.
2050 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2051 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2052 }
2053
Douglas Gregoree8aff02011-01-04 17:33:58 +00002054 /// \brief Build a new expression to compute the length of a parameter pack.
2055 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2056 SourceLocation PackLoc,
2057 SourceLocation RParenLoc,
2058 unsigned Length) {
2059 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2060 OperatorLoc, Pack, PackLoc,
2061 RParenLoc, Length);
2062 }
2063
Douglas Gregorb98b1992009-08-11 05:31:07 +00002064 /// \brief Build a new Objective-C @encode expression.
2065 ///
2066 /// By default, performs semantic analysis to build the new expression.
2067 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002068 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002069 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002070 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002071 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002072 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002073 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002074
Douglas Gregor92e986e2010-04-22 16:44:27 +00002075 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002076 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002077 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002078 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002079 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002080 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002081 MultiExprArg Args,
2082 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002083 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2084 ReceiverTypeInfo->getType(),
2085 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002086 Sel, Method, LBracLoc, SelectorLoc,
2087 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002088 }
2089
2090 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002091 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002092 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002093 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002094 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002095 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002096 MultiExprArg Args,
2097 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002098 return SemaRef.BuildInstanceMessage(Receiver,
2099 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002100 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002101 Sel, Method, LBracLoc, SelectorLoc,
2102 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002103 }
2104
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002105 /// \brief Build a new Objective-C ivar reference expression.
2106 ///
2107 /// By default, performs semantic analysis to build the new expression.
2108 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002109 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002110 SourceLocation IvarLoc,
2111 bool IsArrow, bool IsFreeIvar) {
2112 // FIXME: We lose track of the IsFreeIvar bit.
2113 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002114 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002115 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2116 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002117 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002118 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002119 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002120 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002121 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002122 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002123
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002124 if (Result.get())
2125 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002126
John McCall9ae2f072010-08-23 23:25:46 +00002127 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002128 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002129 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002130 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002131 /*TemplateArgs=*/0);
2132 }
Douglas Gregore3303542010-04-26 20:47:02 +00002133
2134 /// \brief Build a new Objective-C property reference expression.
2135 ///
2136 /// By default, performs semantic analysis to build the new expression.
2137 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002138 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002139 ObjCPropertyDecl *Property,
2140 SourceLocation PropertyLoc) {
2141 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002142 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00002143 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2144 Sema::LookupMemberName);
2145 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002146 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002147 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002148 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00002149 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002150 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002151
Douglas Gregore3303542010-04-26 20:47:02 +00002152 if (Result.get())
2153 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002154
John McCall9ae2f072010-08-23 23:25:46 +00002155 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002156 /*FIXME:*/PropertyLoc, IsArrow,
2157 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002158 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002159 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002160 /*TemplateArgs=*/0);
2161 }
Sean Huntc3021132010-05-05 15:23:54 +00002162
John McCall12f78a62010-12-02 01:19:52 +00002163 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002164 ///
2165 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002166 /// Subclasses may override this routine to provide different behavior.
2167 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2168 ObjCMethodDecl *Getter,
2169 ObjCMethodDecl *Setter,
2170 SourceLocation PropertyLoc) {
2171 // Since these expressions can only be value-dependent, we do not
2172 // need to perform semantic analysis again.
2173 return Owned(
2174 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2175 VK_LValue, OK_ObjCProperty,
2176 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002177 }
2178
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002179 /// \brief Build a new Objective-C "isa" expression.
2180 ///
2181 /// By default, performs semantic analysis to build the new expression.
2182 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002183 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002184 bool IsArrow) {
2185 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002186 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002187 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2188 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002189 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002190 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002191 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002192 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002193 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002194
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002195 if (Result.get())
2196 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002197
John McCall9ae2f072010-08-23 23:25:46 +00002198 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002199 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002200 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002201 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002202 /*TemplateArgs=*/0);
2203 }
Sean Huntc3021132010-05-05 15:23:54 +00002204
Douglas Gregorb98b1992009-08-11 05:31:07 +00002205 /// \brief Build a new shuffle vector expression.
2206 ///
2207 /// By default, performs semantic analysis to build the new expression.
2208 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002209 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002210 MultiExprArg SubExprs,
2211 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002212 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002213 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002214 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2215 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2216 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2217 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002218
Douglas Gregorb98b1992009-08-11 05:31:07 +00002219 // Build a reference to the __builtin_shufflevector builtin
2220 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00002221 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00002222 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCallf89e55a2010-11-18 06:31:45 +00002223 VK_LValue, BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002224 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00002225
2226 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002227 unsigned NumSubExprs = SubExprs.size();
2228 Expr **Subs = (Expr **)SubExprs.release();
2229 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2230 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002231 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002232 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002233 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00002234 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00002235
Douglas Gregorb98b1992009-08-11 05:31:07 +00002236 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00002237 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002238 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002239 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002240
Douglas Gregorb98b1992009-08-11 05:31:07 +00002241 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00002242 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002243 }
John McCall43fed0d2010-11-12 08:19:04 +00002244
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002245 /// \brief Build a new template argument pack expansion.
2246 ///
2247 /// By default, performs semantic analysis to build a new pack expansion
2248 /// for a template argument. Subclasses may override this routine to provide
2249 /// different behavior.
2250 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002251 SourceLocation EllipsisLoc,
2252 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002253 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002254 case TemplateArgument::Expression: {
2255 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002256 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2257 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002258 if (Result.isInvalid())
2259 return TemplateArgumentLoc();
2260
2261 return TemplateArgumentLoc(Result.get(), Result.get());
2262 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002263
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002264 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002265 return TemplateArgumentLoc(TemplateArgument(
2266 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002267 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002268 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002269 Pattern.getTemplateNameLoc(),
2270 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002271
2272 case TemplateArgument::Null:
2273 case TemplateArgument::Integral:
2274 case TemplateArgument::Declaration:
2275 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002276 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002277 llvm_unreachable("Pack expansion pattern has no parameter packs");
2278
2279 case TemplateArgument::Type:
2280 if (TypeSourceInfo *Expansion
2281 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002282 EllipsisLoc,
2283 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002284 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2285 Expansion);
2286 break;
2287 }
2288
2289 return TemplateArgumentLoc();
2290 }
2291
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002292 /// \brief Build a new expression pack expansion.
2293 ///
2294 /// By default, performs semantic analysis to build a new pack expansion
2295 /// for an expression. Subclasses may override this routine to provide
2296 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002297 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2298 llvm::Optional<unsigned> NumExpansions) {
2299 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002300 }
2301
John McCall43fed0d2010-11-12 08:19:04 +00002302private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002303 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2304 QualType ObjectType,
2305 NamedDecl *FirstQualifierInScope,
2306 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002307
2308 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2309 QualType ObjectType,
2310 NamedDecl *FirstQualifierInScope,
2311 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002312};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002313
Douglas Gregor43959a92009-08-20 07:17:43 +00002314template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002315StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002316 if (!S)
2317 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002318
Douglas Gregor43959a92009-08-20 07:17:43 +00002319 switch (S->getStmtClass()) {
2320 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002321
Douglas Gregor43959a92009-08-20 07:17:43 +00002322 // Transform individual statement nodes
2323#define STMT(Node, Parent) \
2324 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002325#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002326#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002327#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002328
Douglas Gregor43959a92009-08-20 07:17:43 +00002329 // Transform expressions by calling TransformExpr.
2330#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002331#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002332#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002333#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002334 {
John McCall60d7b3a2010-08-24 06:29:42 +00002335 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002336 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002337 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002338
John McCall9ae2f072010-08-23 23:25:46 +00002339 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002340 }
Mike Stump1eb44332009-09-09 15:08:12 +00002341 }
2342
John McCall3fa5cae2010-10-26 07:05:15 +00002343 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002344}
Mike Stump1eb44332009-09-09 15:08:12 +00002345
2346
Douglas Gregor670444e2009-08-04 22:27:00 +00002347template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002348ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002349 if (!E)
2350 return SemaRef.Owned(E);
2351
2352 switch (E->getStmtClass()) {
2353 case Stmt::NoStmtClass: break;
2354#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002355#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002356#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002357 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002358#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002359 }
2360
John McCall3fa5cae2010-10-26 07:05:15 +00002361 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002362}
2363
2364template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002365bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2366 unsigned NumInputs,
2367 bool IsCall,
2368 llvm::SmallVectorImpl<Expr *> &Outputs,
2369 bool *ArgChanged) {
2370 for (unsigned I = 0; I != NumInputs; ++I) {
2371 // If requested, drop call arguments that need to be dropped.
2372 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2373 if (ArgChanged)
2374 *ArgChanged = true;
2375
2376 break;
2377 }
2378
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002379 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2380 Expr *Pattern = Expansion->getPattern();
2381
2382 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2383 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2384 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2385
2386 // Determine whether the set of unexpanded parameter packs can and should
2387 // be expanded.
2388 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002389 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002390 llvm::Optional<unsigned> OrigNumExpansions
2391 = Expansion->getNumExpansions();
2392 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002393 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2394 Pattern->getSourceRange(),
2395 Unexpanded.data(),
2396 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002397 Expand, RetainExpansion,
2398 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002399 return true;
2400
2401 if (!Expand) {
2402 // The transform has determined that we should perform a simple
2403 // transformation on the pack expansion, producing another pack
2404 // expansion.
2405 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2406 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2407 if (OutPattern.isInvalid())
2408 return true;
2409
2410 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002411 Expansion->getEllipsisLoc(),
2412 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002413 if (Out.isInvalid())
2414 return true;
2415
2416 if (ArgChanged)
2417 *ArgChanged = true;
2418 Outputs.push_back(Out.get());
2419 continue;
2420 }
2421
2422 // The transform has determined that we should perform an elementwise
2423 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002424 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002425 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2426 ExprResult Out = getDerived().TransformExpr(Pattern);
2427 if (Out.isInvalid())
2428 return true;
2429
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002430 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002431 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2432 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002433 if (Out.isInvalid())
2434 return true;
2435 }
2436
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002437 if (ArgChanged)
2438 *ArgChanged = true;
2439 Outputs.push_back(Out.get());
2440 }
2441
2442 continue;
2443 }
2444
Douglas Gregoraa165f82011-01-03 19:04:46 +00002445 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2446 if (Result.isInvalid())
2447 return true;
2448
2449 if (Result.get() != Inputs[I] && ArgChanged)
2450 *ArgChanged = true;
2451
2452 Outputs.push_back(Result.get());
2453 }
2454
2455 return false;
2456}
2457
2458template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002459NestedNameSpecifier *
2460TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002461 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002462 QualType ObjectType,
2463 NamedDecl *FirstQualifierInScope) {
John McCall43fed0d2010-11-12 08:19:04 +00002464 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump1eb44332009-09-09 15:08:12 +00002465
Douglas Gregor43959a92009-08-20 07:17:43 +00002466 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002467 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002468 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002469 ObjectType,
2470 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002471 if (!Prefix)
2472 return 0;
2473 }
Mike Stump1eb44332009-09-09 15:08:12 +00002474
Douglas Gregordcee1a12009-08-06 05:28:30 +00002475 switch (NNS->getKind()) {
2476 case NestedNameSpecifier::Identifier:
John McCall43fed0d2010-11-12 08:19:04 +00002477 if (Prefix) {
2478 // The object type and qualifier-in-scope really apply to the
2479 // leftmost entity.
2480 ObjectType = QualType();
2481 FirstQualifierInScope = 0;
2482 }
2483
Mike Stump1eb44332009-09-09 15:08:12 +00002484 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002485 "Identifier nested-name-specifier with no prefix or object type");
2486 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2487 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002488 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002489
2490 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002491 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002492 ObjectType,
2493 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002494
Douglas Gregordcee1a12009-08-06 05:28:30 +00002495 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002496 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002497 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002498 getDerived().TransformDecl(Range.getBegin(),
2499 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002500 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002501 Prefix == NNS->getPrefix() &&
2502 NS == NNS->getAsNamespace())
2503 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002504
Douglas Gregordcee1a12009-08-06 05:28:30 +00002505 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2506 }
Mike Stump1eb44332009-09-09 15:08:12 +00002507
Douglas Gregor14aba762011-02-24 02:36:08 +00002508 case NestedNameSpecifier::NamespaceAlias: {
2509 NamespaceAliasDecl *Alias
2510 = cast_or_null<NamespaceAliasDecl>(
2511 getDerived().TransformDecl(Range.getBegin(),
2512 NNS->getAsNamespaceAlias()));
2513 if (!getDerived().AlwaysRebuild() &&
2514 Prefix == NNS->getPrefix() &&
2515 Alias == NNS->getAsNamespaceAlias())
2516 return NNS;
2517
2518 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, Alias);
2519 }
2520
Douglas Gregordcee1a12009-08-06 05:28:30 +00002521 case NestedNameSpecifier::Global:
2522 // There is no meaningful transformation that one could perform on the
2523 // global scope.
2524 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002525
Douglas Gregordcee1a12009-08-06 05:28:30 +00002526 case NestedNameSpecifier::TypeSpecWithTemplate:
2527 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002528 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorb71d8212011-03-02 18:32:08 +00002529 CXXScopeSpec SS;
2530 SS.MakeTrivial(SemaRef.Context, Prefix, Range);
2531
2532 TypeSourceInfo *TSInfo
2533 = SemaRef.Context.getTrivialTypeSourceInfo(QualType(NNS->getAsType(), 0),
2534 Range.getEnd());
2535 TSInfo = TransformTypeInObjectScope(TSInfo,
2536 ObjectType,
2537 FirstQualifierInScope,
2538 SS);
2539 if (!TSInfo)
Douglas Gregord1067e52009-08-06 06:41:21 +00002540 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002541
Douglas Gregorb71d8212011-03-02 18:32:08 +00002542 QualType T = TSInfo->getType();
Douglas Gregordcee1a12009-08-06 05:28:30 +00002543 if (!getDerived().AlwaysRebuild() &&
2544 Prefix == NNS->getPrefix() &&
2545 T == QualType(NNS->getAsType(), 0))
2546 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002547
2548 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2549 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002550 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002551 }
2552 }
Mike Stump1eb44332009-09-09 15:08:12 +00002553
Douglas Gregordcee1a12009-08-06 05:28:30 +00002554 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002555 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002556}
2557
2558template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002559NestedNameSpecifierLoc
2560TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2561 NestedNameSpecifierLoc NNS,
2562 QualType ObjectType,
2563 NamedDecl *FirstQualifierInScope) {
2564 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2565 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2566 Qualifier = Qualifier.getPrefix())
2567 Qualifiers.push_back(Qualifier);
2568
2569 CXXScopeSpec SS;
2570 while (!Qualifiers.empty()) {
2571 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2572 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2573
2574 switch (QNNS->getKind()) {
2575 case NestedNameSpecifier::Identifier:
2576 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2577 *QNNS->getAsIdentifier(),
2578 Q.getLocalBeginLoc(),
2579 Q.getLocalEndLoc(),
2580 ObjectType, false, SS,
2581 FirstQualifierInScope, false))
2582 return NestedNameSpecifierLoc();
2583
2584 break;
2585
2586 case NestedNameSpecifier::Namespace: {
2587 NamespaceDecl *NS
2588 = cast_or_null<NamespaceDecl>(
2589 getDerived().TransformDecl(
2590 Q.getLocalBeginLoc(),
2591 QNNS->getAsNamespace()));
2592 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2593 break;
2594 }
2595
2596 case NestedNameSpecifier::NamespaceAlias: {
2597 NamespaceAliasDecl *Alias
2598 = cast_or_null<NamespaceAliasDecl>(
2599 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2600 QNNS->getAsNamespaceAlias()));
2601 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2602 Q.getLocalEndLoc());
2603 break;
2604 }
2605
2606 case NestedNameSpecifier::Global:
2607 // There is no meaningful transformation that one could perform on the
2608 // global scope.
2609 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2610 break;
2611
2612 case NestedNameSpecifier::TypeSpecWithTemplate:
2613 case NestedNameSpecifier::TypeSpec: {
2614 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2615 FirstQualifierInScope, SS);
2616
2617 if (!TL)
2618 return NestedNameSpecifierLoc();
2619
2620 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2621 (SemaRef.getLangOptions().CPlusPlus0x &&
2622 TL.getType()->isEnumeralType())) {
2623 assert(!TL.getType().hasLocalQualifiers() &&
2624 "Can't get cv-qualifiers here");
2625 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2626 Q.getLocalEndLoc());
2627 break;
2628 }
2629
2630 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2631 << TL.getType() << SS.getRange();
2632 return NestedNameSpecifierLoc();
2633 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002634 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002635
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002636 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002637 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002638 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002639 }
2640
2641 // Don't rebuild the nested-name-specifier if we don't have to.
2642 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2643 !getDerived().AlwaysRebuild())
2644 return NNS;
2645
2646 // If we can re-use the source-location data from the original
2647 // nested-name-specifier, do so.
2648 if (SS.location_size() == NNS.getDataLength() &&
2649 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2650 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2651
2652 // Allocate new nested-name-specifier location information.
2653 return SS.getWithLocInContext(SemaRef.Context);
2654}
2655
2656template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002657DeclarationNameInfo
2658TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002659::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002660 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002661 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002662 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002663
2664 switch (Name.getNameKind()) {
2665 case DeclarationName::Identifier:
2666 case DeclarationName::ObjCZeroArgSelector:
2667 case DeclarationName::ObjCOneArgSelector:
2668 case DeclarationName::ObjCMultiArgSelector:
2669 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002670 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002671 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002672 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002673
Douglas Gregor81499bb2009-09-03 22:13:48 +00002674 case DeclarationName::CXXConstructorName:
2675 case DeclarationName::CXXDestructorName:
2676 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002677 TypeSourceInfo *NewTInfo;
2678 CanQualType NewCanTy;
2679 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002680 NewTInfo = getDerived().TransformType(OldTInfo);
2681 if (!NewTInfo)
2682 return DeclarationNameInfo();
2683 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002684 }
2685 else {
2686 NewTInfo = 0;
2687 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002688 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002689 if (NewT.isNull())
2690 return DeclarationNameInfo();
2691 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2692 }
Mike Stump1eb44332009-09-09 15:08:12 +00002693
Abramo Bagnara25777432010-08-11 22:01:17 +00002694 DeclarationName NewName
2695 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2696 NewCanTy);
2697 DeclarationNameInfo NewNameInfo(NameInfo);
2698 NewNameInfo.setName(NewName);
2699 NewNameInfo.setNamedTypeInfo(NewTInfo);
2700 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002701 }
Mike Stump1eb44332009-09-09 15:08:12 +00002702 }
2703
Abramo Bagnara25777432010-08-11 22:01:17 +00002704 assert(0 && "Unknown name kind.");
2705 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002706}
2707
2708template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002709TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002710TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2711 TemplateName Name,
2712 SourceLocation NameLoc,
2713 QualType ObjectType,
2714 NamedDecl *FirstQualifierInScope) {
2715 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2716 TemplateDecl *Template = QTN->getTemplateDecl();
2717 assert(Template && "qualified template name must refer to a template");
2718
2719 TemplateDecl *TransTemplate
2720 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2721 Template));
2722 if (!TransTemplate)
2723 return TemplateName();
2724
2725 if (!getDerived().AlwaysRebuild() &&
2726 SS.getScopeRep() == QTN->getQualifier() &&
2727 TransTemplate == Template)
2728 return Name;
2729
2730 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2731 TransTemplate);
2732 }
2733
2734 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2735 if (SS.getScopeRep()) {
2736 // These apply to the scope specifier, not the template.
2737 ObjectType = QualType();
2738 FirstQualifierInScope = 0;
2739 }
2740
2741 if (!getDerived().AlwaysRebuild() &&
2742 SS.getScopeRep() == DTN->getQualifier() &&
2743 ObjectType.isNull())
2744 return Name;
2745
2746 if (DTN->isIdentifier()) {
2747 return getDerived().RebuildTemplateName(SS,
2748 *DTN->getIdentifier(),
2749 NameLoc,
2750 ObjectType,
2751 FirstQualifierInScope);
2752 }
2753
2754 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2755 ObjectType);
2756 }
2757
2758 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2759 TemplateDecl *TransTemplate
2760 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2761 Template));
2762 if (!TransTemplate)
2763 return TemplateName();
2764
2765 if (!getDerived().AlwaysRebuild() &&
2766 TransTemplate == Template)
2767 return Name;
2768
2769 return TemplateName(TransTemplate);
2770 }
2771
2772 if (SubstTemplateTemplateParmPackStorage *SubstPack
2773 = Name.getAsSubstTemplateTemplateParmPack()) {
2774 TemplateTemplateParmDecl *TransParam
2775 = cast_or_null<TemplateTemplateParmDecl>(
2776 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2777 if (!TransParam)
2778 return TemplateName();
2779
2780 if (!getDerived().AlwaysRebuild() &&
2781 TransParam == SubstPack->getParameterPack())
2782 return Name;
2783
2784 return getDerived().RebuildTemplateName(TransParam,
2785 SubstPack->getArgumentPack());
2786 }
2787
2788 // These should be getting filtered out before they reach the AST.
2789 llvm_unreachable("overloaded function decl survived to here");
2790 return TemplateName();
2791}
2792
2793template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002794void TreeTransform<Derived>::InventTemplateArgumentLoc(
2795 const TemplateArgument &Arg,
2796 TemplateArgumentLoc &Output) {
2797 SourceLocation Loc = getDerived().getBaseLocation();
2798 switch (Arg.getKind()) {
2799 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002800 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002801 break;
2802
2803 case TemplateArgument::Type:
2804 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002805 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002806
John McCall833ca992009-10-29 08:12:44 +00002807 break;
2808
Douglas Gregor788cd062009-11-11 01:00:40 +00002809 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002810 case TemplateArgument::TemplateExpansion: {
2811 NestedNameSpecifierLocBuilder Builder;
2812 TemplateName Template = Arg.getAsTemplate();
2813 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2814 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2815 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2816 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2817
2818 if (Arg.getKind() == TemplateArgument::Template)
2819 Output = TemplateArgumentLoc(Arg,
2820 Builder.getWithLocInContext(SemaRef.Context),
2821 Loc);
2822 else
2823 Output = TemplateArgumentLoc(Arg,
2824 Builder.getWithLocInContext(SemaRef.Context),
2825 Loc, Loc);
2826
Douglas Gregor788cd062009-11-11 01:00:40 +00002827 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002828 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002829
John McCall833ca992009-10-29 08:12:44 +00002830 case TemplateArgument::Expression:
2831 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2832 break;
2833
2834 case TemplateArgument::Declaration:
2835 case TemplateArgument::Integral:
2836 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002837 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002838 break;
2839 }
2840}
2841
2842template<typename Derived>
2843bool TreeTransform<Derived>::TransformTemplateArgument(
2844 const TemplateArgumentLoc &Input,
2845 TemplateArgumentLoc &Output) {
2846 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002847 switch (Arg.getKind()) {
2848 case TemplateArgument::Null:
2849 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002850 Output = Input;
2851 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002852
Douglas Gregor670444e2009-08-04 22:27:00 +00002853 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002854 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002855 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002856 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002857
2858 DI = getDerived().TransformType(DI);
2859 if (!DI) return true;
2860
2861 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2862 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002863 }
Mike Stump1eb44332009-09-09 15:08:12 +00002864
Douglas Gregor670444e2009-08-04 22:27:00 +00002865 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002866 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002867 DeclarationName Name;
2868 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2869 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002870 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002871 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002872 if (!D) return true;
2873
John McCall828bff22009-10-29 18:45:58 +00002874 Expr *SourceExpr = Input.getSourceDeclExpression();
2875 if (SourceExpr) {
2876 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002877 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002878 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002879 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002880 }
2881
2882 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002883 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002884 }
Mike Stump1eb44332009-09-09 15:08:12 +00002885
Douglas Gregor788cd062009-11-11 01:00:40 +00002886 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002887 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2888 if (QualifierLoc) {
2889 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2890 if (!QualifierLoc)
2891 return true;
2892 }
2893
Douglas Gregor1d752d72011-03-02 18:46:51 +00002894 CXXScopeSpec SS;
2895 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002896 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002897 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2898 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002899 if (Template.isNull())
2900 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002901
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002902 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002903 Input.getTemplateNameLoc());
2904 return false;
2905 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002906
2907 case TemplateArgument::TemplateExpansion:
2908 llvm_unreachable("Caller should expand pack expansions");
2909
Douglas Gregor670444e2009-08-04 22:27:00 +00002910 case TemplateArgument::Expression: {
2911 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002912 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002913 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002914
John McCall833ca992009-10-29 08:12:44 +00002915 Expr *InputExpr = Input.getSourceExpression();
2916 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2917
John McCall60d7b3a2010-08-24 06:29:42 +00002918 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002919 = getDerived().TransformExpr(InputExpr);
2920 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002921 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002922 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002923 }
Mike Stump1eb44332009-09-09 15:08:12 +00002924
Douglas Gregor670444e2009-08-04 22:27:00 +00002925 case TemplateArgument::Pack: {
2926 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2927 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002928 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002929 AEnd = Arg.pack_end();
2930 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002931
John McCall833ca992009-10-29 08:12:44 +00002932 // FIXME: preserve source information here when we start
2933 // caring about parameter packs.
2934
John McCall828bff22009-10-29 18:45:58 +00002935 TemplateArgumentLoc InputArg;
2936 TemplateArgumentLoc OutputArg;
2937 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2938 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002939 return true;
2940
John McCall828bff22009-10-29 18:45:58 +00002941 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002942 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002943
2944 TemplateArgument *TransformedArgsPtr
2945 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2946 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2947 TransformedArgsPtr);
2948 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2949 TransformedArgs.size()),
2950 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002951 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002952 }
2953 }
Mike Stump1eb44332009-09-09 15:08:12 +00002954
Douglas Gregor670444e2009-08-04 22:27:00 +00002955 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002956 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002957}
2958
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002959/// \brief Iterator adaptor that invents template argument location information
2960/// for each of the template arguments in its underlying iterator.
2961template<typename Derived, typename InputIterator>
2962class TemplateArgumentLocInventIterator {
2963 TreeTransform<Derived> &Self;
2964 InputIterator Iter;
2965
2966public:
2967 typedef TemplateArgumentLoc value_type;
2968 typedef TemplateArgumentLoc reference;
2969 typedef typename std::iterator_traits<InputIterator>::difference_type
2970 difference_type;
2971 typedef std::input_iterator_tag iterator_category;
2972
2973 class pointer {
2974 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002975
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002976 public:
2977 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2978
2979 const TemplateArgumentLoc *operator->() const { return &Arg; }
2980 };
2981
2982 TemplateArgumentLocInventIterator() { }
2983
2984 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2985 InputIterator Iter)
2986 : Self(Self), Iter(Iter) { }
2987
2988 TemplateArgumentLocInventIterator &operator++() {
2989 ++Iter;
2990 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002991 }
2992
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002993 TemplateArgumentLocInventIterator operator++(int) {
2994 TemplateArgumentLocInventIterator Old(*this);
2995 ++(*this);
2996 return Old;
2997 }
2998
2999 reference operator*() const {
3000 TemplateArgumentLoc Result;
3001 Self.InventTemplateArgumentLoc(*Iter, Result);
3002 return Result;
3003 }
3004
3005 pointer operator->() const { return pointer(**this); }
3006
3007 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3008 const TemplateArgumentLocInventIterator &Y) {
3009 return X.Iter == Y.Iter;
3010 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003011
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003012 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3013 const TemplateArgumentLocInventIterator &Y) {
3014 return X.Iter != Y.Iter;
3015 }
3016};
3017
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003018template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003019template<typename InputIterator>
3020bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3021 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003022 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003023 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003024 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003025 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003026
3027 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3028 // Unpack argument packs, which we translate them into separate
3029 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003030 // FIXME: We could do much better if we could guarantee that the
3031 // TemplateArgumentLocInfo for the pack expansion would be usable for
3032 // all of the template arguments in the argument pack.
3033 typedef TemplateArgumentLocInventIterator<Derived,
3034 TemplateArgument::pack_iterator>
3035 PackLocIterator;
3036 if (TransformTemplateArguments(PackLocIterator(*this,
3037 In.getArgument().pack_begin()),
3038 PackLocIterator(*this,
3039 In.getArgument().pack_end()),
3040 Outputs))
3041 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003042
3043 continue;
3044 }
3045
3046 if (In.getArgument().isPackExpansion()) {
3047 // We have a pack expansion, for which we will be substituting into
3048 // the pattern.
3049 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003050 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003051 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003052 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3053 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003054
3055 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3056 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3057 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3058
3059 // Determine whether the set of unexpanded parameter packs can and should
3060 // be expanded.
3061 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003062 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003063 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003064 if (getDerived().TryExpandParameterPacks(Ellipsis,
3065 Pattern.getSourceRange(),
3066 Unexpanded.data(),
3067 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003068 Expand,
3069 RetainExpansion,
3070 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003071 return true;
3072
3073 if (!Expand) {
3074 // The transform has determined that we should perform a simple
3075 // transformation on the pack expansion, producing another pack
3076 // expansion.
3077 TemplateArgumentLoc OutPattern;
3078 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3079 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3080 return true;
3081
Douglas Gregorcded4f62011-01-14 17:04:44 +00003082 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3083 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003084 if (Out.getArgument().isNull())
3085 return true;
3086
3087 Outputs.addArgument(Out);
3088 continue;
3089 }
3090
3091 // The transform has determined that we should perform an elementwise
3092 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003093 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003094 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3095
3096 if (getDerived().TransformTemplateArgument(Pattern, Out))
3097 return true;
3098
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003099 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003100 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3101 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003102 if (Out.getArgument().isNull())
3103 return true;
3104 }
3105
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003106 Outputs.addArgument(Out);
3107 }
3108
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003109 // If we're supposed to retain a pack expansion, do so by temporarily
3110 // forgetting the partially-substituted parameter pack.
3111 if (RetainExpansion) {
3112 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3113
3114 if (getDerived().TransformTemplateArgument(Pattern, Out))
3115 return true;
3116
Douglas Gregorcded4f62011-01-14 17:04:44 +00003117 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3118 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003119 if (Out.getArgument().isNull())
3120 return true;
3121
3122 Outputs.addArgument(Out);
3123 }
Douglas Gregord3731192011-01-10 07:32:04 +00003124
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003125 continue;
3126 }
3127
3128 // The simple case:
3129 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003130 return true;
3131
3132 Outputs.addArgument(Out);
3133 }
3134
3135 return false;
3136
3137}
3138
Douglas Gregor577f75a2009-08-04 16:50:30 +00003139//===----------------------------------------------------------------------===//
3140// Type transformation
3141//===----------------------------------------------------------------------===//
3142
3143template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003144QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003145 if (getDerived().AlreadyTransformed(T))
3146 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003147
John McCalla2becad2009-10-21 00:40:46 +00003148 // Temporary workaround. All of these transformations should
3149 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003150 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3151 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003152
John McCall43fed0d2010-11-12 08:19:04 +00003153 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003154
John McCalla2becad2009-10-21 00:40:46 +00003155 if (!NewDI)
3156 return QualType();
3157
3158 return NewDI->getType();
3159}
3160
3161template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003162TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00003163 if (getDerived().AlreadyTransformed(DI->getType()))
3164 return DI;
3165
3166 TypeLocBuilder TLB;
3167
3168 TypeLoc TL = DI->getTypeLoc();
3169 TLB.reserve(TL.getFullDataSize());
3170
John McCall43fed0d2010-11-12 08:19:04 +00003171 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003172 if (Result.isNull())
3173 return 0;
3174
John McCalla93c9342009-12-07 02:54:59 +00003175 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003176}
3177
3178template<typename Derived>
3179QualType
John McCall43fed0d2010-11-12 08:19:04 +00003180TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003181 switch (T.getTypeLocClass()) {
3182#define ABSTRACT_TYPELOC(CLASS, PARENT)
3183#define TYPELOC(CLASS, PARENT) \
3184 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003185 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003186#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003187 }
Mike Stump1eb44332009-09-09 15:08:12 +00003188
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003189 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003190 return QualType();
3191}
3192
3193/// FIXME: By default, this routine adds type qualifiers only to types
3194/// that can have qualifiers, and silently suppresses those qualifiers
3195/// that are not permitted (e.g., qualifiers on reference or function
3196/// types). This is the right thing for template instantiation, but
3197/// probably not for other clients.
3198template<typename Derived>
3199QualType
3200TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003201 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003202 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003203
John McCall43fed0d2010-11-12 08:19:04 +00003204 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003205 if (Result.isNull())
3206 return QualType();
3207
3208 // Silently suppress qualifiers if the result type can't be qualified.
3209 // FIXME: this is the right thing for template instantiation, but
3210 // probably not for other clients.
3211 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003212 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003213
John McCall28654742010-06-05 06:41:15 +00003214 if (!Quals.empty()) {
3215 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3216 TLB.push<QualifiedTypeLoc>(Result);
3217 // No location information to preserve.
3218 }
John McCalla2becad2009-10-21 00:40:46 +00003219
3220 return Result;
3221}
3222
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003223template<typename Derived>
3224TypeLoc
3225TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3226 QualType ObjectType,
3227 NamedDecl *UnqualLookup,
3228 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003229 QualType T = TL.getType();
3230 if (getDerived().AlreadyTransformed(T))
3231 return TL;
3232
3233 TypeLocBuilder TLB;
3234 QualType Result;
3235
3236 if (isa<TemplateSpecializationType>(T)) {
3237 TemplateSpecializationTypeLoc SpecTL
3238 = cast<TemplateSpecializationTypeLoc>(TL);
3239
3240 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003241 getDerived().TransformTemplateName(SS,
3242 SpecTL.getTypePtr()->getTemplateName(),
3243 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003244 ObjectType, UnqualLookup);
3245 if (Template.isNull())
3246 return TypeLoc();
3247
3248 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3249 Template);
3250 } else if (isa<DependentTemplateSpecializationType>(T)) {
3251 DependentTemplateSpecializationTypeLoc SpecTL
3252 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3253
Douglas Gregora88f09f2011-02-28 17:23:35 +00003254 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003255 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003256 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003257 SpecTL.getNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003258 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003259 if (Template.isNull())
3260 return TypeLoc();
3261
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003262 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003263 SpecTL,
3264 Template);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003265 } else {
3266 // Nothing special needs to be done for these.
3267 Result = getDerived().TransformType(TLB, TL);
3268 }
3269
3270 if (Result.isNull())
3271 return TypeLoc();
3272
3273 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3274}
3275
Douglas Gregorb71d8212011-03-02 18:32:08 +00003276template<typename Derived>
3277TypeSourceInfo *
3278TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3279 QualType ObjectType,
3280 NamedDecl *UnqualLookup,
3281 CXXScopeSpec &SS) {
3282 // FIXME: Painfully copy-paste from the above!
3283
3284 QualType T = TSInfo->getType();
3285 if (getDerived().AlreadyTransformed(T))
3286 return TSInfo;
3287
3288 TypeLocBuilder TLB;
3289 QualType Result;
3290
3291 TypeLoc TL = TSInfo->getTypeLoc();
3292 if (isa<TemplateSpecializationType>(T)) {
3293 TemplateSpecializationTypeLoc SpecTL
3294 = cast<TemplateSpecializationTypeLoc>(TL);
3295
3296 TemplateName Template
3297 = getDerived().TransformTemplateName(SS,
3298 SpecTL.getTypePtr()->getTemplateName(),
3299 SpecTL.getTemplateNameLoc(),
3300 ObjectType, UnqualLookup);
3301 if (Template.isNull())
3302 return 0;
3303
3304 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3305 Template);
3306 } else if (isa<DependentTemplateSpecializationType>(T)) {
3307 DependentTemplateSpecializationTypeLoc SpecTL
3308 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3309
3310 TemplateName Template
3311 = getDerived().RebuildTemplateName(SS,
3312 *SpecTL.getTypePtr()->getIdentifier(),
3313 SpecTL.getNameLoc(),
3314 ObjectType, UnqualLookup);
3315 if (Template.isNull())
3316 return 0;
3317
3318 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3319 SpecTL,
3320 Template);
3321 } else {
3322 // Nothing special needs to be done for these.
3323 Result = getDerived().TransformType(TLB, TL);
3324 }
3325
3326 if (Result.isNull())
3327 return 0;
3328
3329 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3330}
3331
John McCalla2becad2009-10-21 00:40:46 +00003332template <class TyLoc> static inline
3333QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3334 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3335 NewT.setNameLoc(T.getNameLoc());
3336 return T.getType();
3337}
3338
John McCalla2becad2009-10-21 00:40:46 +00003339template<typename Derived>
3340QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003341 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003342 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3343 NewT.setBuiltinLoc(T.getBuiltinLoc());
3344 if (T.needsExtraLocalData())
3345 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3346 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003347}
Mike Stump1eb44332009-09-09 15:08:12 +00003348
Douglas Gregor577f75a2009-08-04 16:50:30 +00003349template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003350QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003351 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003352 // FIXME: recurse?
3353 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003354}
Mike Stump1eb44332009-09-09 15:08:12 +00003355
Douglas Gregor577f75a2009-08-04 16:50:30 +00003356template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003357QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003358 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003359 QualType PointeeType
3360 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003361 if (PointeeType.isNull())
3362 return QualType();
3363
3364 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003365 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003366 // A dependent pointer type 'T *' has is being transformed such
3367 // that an Objective-C class type is being replaced for 'T'. The
3368 // resulting pointer type is an ObjCObjectPointerType, not a
3369 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003370 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003371
John McCallc12c5bb2010-05-15 11:32:37 +00003372 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3373 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003374 return Result;
3375 }
John McCall43fed0d2010-11-12 08:19:04 +00003376
Douglas Gregor92e986e2010-04-22 16:44:27 +00003377 if (getDerived().AlwaysRebuild() ||
3378 PointeeType != TL.getPointeeLoc().getType()) {
3379 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3380 if (Result.isNull())
3381 return QualType();
3382 }
Sean Huntc3021132010-05-05 15:23:54 +00003383
Douglas Gregor92e986e2010-04-22 16:44:27 +00003384 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3385 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003386 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003387}
Mike Stump1eb44332009-09-09 15:08:12 +00003388
3389template<typename Derived>
3390QualType
John McCalla2becad2009-10-21 00:40:46 +00003391TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003392 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003393 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003394 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3395 if (PointeeType.isNull())
3396 return QualType();
3397
3398 QualType Result = TL.getType();
3399 if (getDerived().AlwaysRebuild() ||
3400 PointeeType != TL.getPointeeLoc().getType()) {
3401 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003402 TL.getSigilLoc());
3403 if (Result.isNull())
3404 return QualType();
3405 }
3406
Douglas Gregor39968ad2010-04-22 16:50:51 +00003407 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003408 NewT.setSigilLoc(TL.getSigilLoc());
3409 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003410}
3411
John McCall85737a72009-10-30 00:06:24 +00003412/// Transforms a reference type. Note that somewhat paradoxically we
3413/// don't care whether the type itself is an l-value type or an r-value
3414/// type; we only care if the type was *written* as an l-value type
3415/// or an r-value type.
3416template<typename Derived>
3417QualType
3418TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003419 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003420 const ReferenceType *T = TL.getTypePtr();
3421
3422 // Note that this works with the pointee-as-written.
3423 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3424 if (PointeeType.isNull())
3425 return QualType();
3426
3427 QualType Result = TL.getType();
3428 if (getDerived().AlwaysRebuild() ||
3429 PointeeType != T->getPointeeTypeAsWritten()) {
3430 Result = getDerived().RebuildReferenceType(PointeeType,
3431 T->isSpelledAsLValue(),
3432 TL.getSigilLoc());
3433 if (Result.isNull())
3434 return QualType();
3435 }
3436
3437 // r-value references can be rebuilt as l-value references.
3438 ReferenceTypeLoc NewTL;
3439 if (isa<LValueReferenceType>(Result))
3440 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3441 else
3442 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3443 NewTL.setSigilLoc(TL.getSigilLoc());
3444
3445 return Result;
3446}
3447
Mike Stump1eb44332009-09-09 15:08:12 +00003448template<typename Derived>
3449QualType
John McCalla2becad2009-10-21 00:40:46 +00003450TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003451 LValueReferenceTypeLoc TL) {
3452 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003453}
3454
Mike Stump1eb44332009-09-09 15:08:12 +00003455template<typename Derived>
3456QualType
John McCalla2becad2009-10-21 00:40:46 +00003457TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003458 RValueReferenceTypeLoc TL) {
3459 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003460}
Mike Stump1eb44332009-09-09 15:08:12 +00003461
Douglas Gregor577f75a2009-08-04 16:50:30 +00003462template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003463QualType
John McCalla2becad2009-10-21 00:40:46 +00003464TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003465 MemberPointerTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003466 const MemberPointerType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003467
3468 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003469 if (PointeeType.isNull())
3470 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003471
John McCalla2becad2009-10-21 00:40:46 +00003472 // TODO: preserve source information for this.
3473 QualType ClassType
3474 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003475 if (ClassType.isNull())
3476 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003477
John McCalla2becad2009-10-21 00:40:46 +00003478 QualType Result = TL.getType();
3479 if (getDerived().AlwaysRebuild() ||
3480 PointeeType != T->getPointeeType() ||
3481 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00003482 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3483 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003484 if (Result.isNull())
3485 return QualType();
3486 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003487
John McCalla2becad2009-10-21 00:40:46 +00003488 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3489 NewTL.setSigilLoc(TL.getSigilLoc());
3490
3491 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003492}
3493
Mike Stump1eb44332009-09-09 15:08:12 +00003494template<typename Derived>
3495QualType
John McCalla2becad2009-10-21 00:40:46 +00003496TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003497 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003498 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003499 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003500 if (ElementType.isNull())
3501 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003502
John McCalla2becad2009-10-21 00:40:46 +00003503 QualType Result = TL.getType();
3504 if (getDerived().AlwaysRebuild() ||
3505 ElementType != T->getElementType()) {
3506 Result = getDerived().RebuildConstantArrayType(ElementType,
3507 T->getSizeModifier(),
3508 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003509 T->getIndexTypeCVRQualifiers(),
3510 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003511 if (Result.isNull())
3512 return QualType();
3513 }
Sean Huntc3021132010-05-05 15:23:54 +00003514
John McCalla2becad2009-10-21 00:40:46 +00003515 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3516 NewTL.setLBracketLoc(TL.getLBracketLoc());
3517 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003518
John McCalla2becad2009-10-21 00:40:46 +00003519 Expr *Size = TL.getSizeExpr();
3520 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003521 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003522 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3523 }
3524 NewTL.setSizeExpr(Size);
3525
3526 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003527}
Mike Stump1eb44332009-09-09 15:08:12 +00003528
Douglas Gregor577f75a2009-08-04 16:50:30 +00003529template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003530QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003531 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003532 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003533 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003534 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003535 if (ElementType.isNull())
3536 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003537
John McCalla2becad2009-10-21 00:40:46 +00003538 QualType Result = TL.getType();
3539 if (getDerived().AlwaysRebuild() ||
3540 ElementType != T->getElementType()) {
3541 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003542 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003543 T->getIndexTypeCVRQualifiers(),
3544 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003545 if (Result.isNull())
3546 return QualType();
3547 }
Sean Huntc3021132010-05-05 15:23:54 +00003548
John McCalla2becad2009-10-21 00:40:46 +00003549 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3550 NewTL.setLBracketLoc(TL.getLBracketLoc());
3551 NewTL.setRBracketLoc(TL.getRBracketLoc());
3552 NewTL.setSizeExpr(0);
3553
3554 return Result;
3555}
3556
3557template<typename Derived>
3558QualType
3559TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003560 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003561 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003562 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3563 if (ElementType.isNull())
3564 return QualType();
3565
3566 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003567 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003568
John McCall60d7b3a2010-08-24 06:29:42 +00003569 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003570 = getDerived().TransformExpr(T->getSizeExpr());
3571 if (SizeResult.isInvalid())
3572 return QualType();
3573
John McCall9ae2f072010-08-23 23:25:46 +00003574 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003575
3576 QualType Result = TL.getType();
3577 if (getDerived().AlwaysRebuild() ||
3578 ElementType != T->getElementType() ||
3579 Size != T->getSizeExpr()) {
3580 Result = getDerived().RebuildVariableArrayType(ElementType,
3581 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003582 Size,
John McCalla2becad2009-10-21 00:40:46 +00003583 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003584 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003585 if (Result.isNull())
3586 return QualType();
3587 }
Sean Huntc3021132010-05-05 15:23:54 +00003588
John McCalla2becad2009-10-21 00:40:46 +00003589 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3590 NewTL.setLBracketLoc(TL.getLBracketLoc());
3591 NewTL.setRBracketLoc(TL.getRBracketLoc());
3592 NewTL.setSizeExpr(Size);
3593
3594 return Result;
3595}
3596
3597template<typename Derived>
3598QualType
3599TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003600 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003601 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003602 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3603 if (ElementType.isNull())
3604 return QualType();
3605
3606 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003607 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003608
John McCall3b657512011-01-19 10:06:00 +00003609 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3610 Expr *origSize = TL.getSizeExpr();
3611 if (!origSize) origSize = T->getSizeExpr();
3612
3613 ExprResult sizeResult
3614 = getDerived().TransformExpr(origSize);
3615 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003616 return QualType();
3617
John McCall3b657512011-01-19 10:06:00 +00003618 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003619
3620 QualType Result = TL.getType();
3621 if (getDerived().AlwaysRebuild() ||
3622 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003623 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003624 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3625 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003626 size,
John McCalla2becad2009-10-21 00:40:46 +00003627 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003628 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003629 if (Result.isNull())
3630 return QualType();
3631 }
John McCalla2becad2009-10-21 00:40:46 +00003632
3633 // We might have any sort of array type now, but fortunately they
3634 // all have the same location layout.
3635 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3636 NewTL.setLBracketLoc(TL.getLBracketLoc());
3637 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003638 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003639
3640 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003641}
Mike Stump1eb44332009-09-09 15:08:12 +00003642
3643template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003644QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003645 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003646 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003647 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003648
3649 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003650 QualType ElementType = getDerived().TransformType(T->getElementType());
3651 if (ElementType.isNull())
3652 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003653
Douglas Gregor670444e2009-08-04 22:27:00 +00003654 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003655 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003656
John McCall60d7b3a2010-08-24 06:29:42 +00003657 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003658 if (Size.isInvalid())
3659 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003660
John McCalla2becad2009-10-21 00:40:46 +00003661 QualType Result = TL.getType();
3662 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003663 ElementType != T->getElementType() ||
3664 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003665 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003666 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003667 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003668 if (Result.isNull())
3669 return QualType();
3670 }
John McCalla2becad2009-10-21 00:40:46 +00003671
3672 // Result might be dependent or not.
3673 if (isa<DependentSizedExtVectorType>(Result)) {
3674 DependentSizedExtVectorTypeLoc NewTL
3675 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3676 NewTL.setNameLoc(TL.getNameLoc());
3677 } else {
3678 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3679 NewTL.setNameLoc(TL.getNameLoc());
3680 }
3681
3682 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003683}
Mike Stump1eb44332009-09-09 15:08:12 +00003684
3685template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003686QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003687 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003688 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003689 QualType ElementType = getDerived().TransformType(T->getElementType());
3690 if (ElementType.isNull())
3691 return QualType();
3692
John McCalla2becad2009-10-21 00:40:46 +00003693 QualType Result = TL.getType();
3694 if (getDerived().AlwaysRebuild() ||
3695 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003696 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003697 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003698 if (Result.isNull())
3699 return QualType();
3700 }
Sean Huntc3021132010-05-05 15:23:54 +00003701
John McCalla2becad2009-10-21 00:40:46 +00003702 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3703 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003704
John McCalla2becad2009-10-21 00:40:46 +00003705 return Result;
3706}
3707
3708template<typename Derived>
3709QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003710 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003711 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003712 QualType ElementType = getDerived().TransformType(T->getElementType());
3713 if (ElementType.isNull())
3714 return QualType();
3715
3716 QualType Result = TL.getType();
3717 if (getDerived().AlwaysRebuild() ||
3718 ElementType != T->getElementType()) {
3719 Result = getDerived().RebuildExtVectorType(ElementType,
3720 T->getNumElements(),
3721 /*FIXME*/ SourceLocation());
3722 if (Result.isNull())
3723 return QualType();
3724 }
Sean Huntc3021132010-05-05 15:23:54 +00003725
John McCalla2becad2009-10-21 00:40:46 +00003726 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3727 NewTL.setNameLoc(TL.getNameLoc());
3728
3729 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003730}
Mike Stump1eb44332009-09-09 15:08:12 +00003731
3732template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003733ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003734TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3735 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003736 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003737 TypeSourceInfo *NewDI = 0;
3738
3739 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3740 // If we're substituting into a pack expansion type and we know the
3741 TypeLoc OldTL = OldDI->getTypeLoc();
3742 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3743
3744 TypeLocBuilder TLB;
3745 TypeLoc NewTL = OldDI->getTypeLoc();
3746 TLB.reserve(NewTL.getFullDataSize());
3747
3748 QualType Result = getDerived().TransformType(TLB,
3749 OldExpansionTL.getPatternLoc());
3750 if (Result.isNull())
3751 return 0;
3752
3753 Result = RebuildPackExpansionType(Result,
3754 OldExpansionTL.getPatternLoc().getSourceRange(),
3755 OldExpansionTL.getEllipsisLoc(),
3756 NumExpansions);
3757 if (Result.isNull())
3758 return 0;
3759
3760 PackExpansionTypeLoc NewExpansionTL
3761 = TLB.push<PackExpansionTypeLoc>(Result);
3762 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3763 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3764 } else
3765 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003766 if (!NewDI)
3767 return 0;
3768
3769 if (NewDI == OldDI)
3770 return OldParm;
3771 else
3772 return ParmVarDecl::Create(SemaRef.Context,
3773 OldParm->getDeclContext(),
3774 OldParm->getLocation(),
3775 OldParm->getIdentifier(),
3776 NewDI->getType(),
3777 NewDI,
3778 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00003779 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00003780 /* DefArg */ NULL);
3781}
3782
3783template<typename Derived>
3784bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003785 TransformFunctionTypeParams(SourceLocation Loc,
3786 ParmVarDecl **Params, unsigned NumParams,
3787 const QualType *ParamTypes,
3788 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3789 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3790 for (unsigned i = 0; i != NumParams; ++i) {
3791 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003792 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003793 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003794 if (OldParm->isParameterPack()) {
3795 // We have a function parameter pack that may need to be expanded.
3796 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003797
Douglas Gregor603cfb42011-01-05 23:12:31 +00003798 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003799 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3800 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3801 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3802 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003803 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3804
Douglas Gregor603cfb42011-01-05 23:12:31 +00003805 // Determine whether we should expand the parameter packs.
3806 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003807 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003808 llvm::Optional<unsigned> OrigNumExpansions
3809 = ExpansionTL.getTypePtr()->getNumExpansions();
3810 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003811 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3812 Pattern.getSourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003813 Unexpanded.data(),
3814 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003815 ShouldExpand,
3816 RetainExpansion,
3817 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003818 return true;
3819 }
3820
3821 if (ShouldExpand) {
3822 // Expand the function parameter pack into multiple, separate
3823 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003824 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003825 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003826 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3827 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003828 = getDerived().TransformFunctionTypeParam(OldParm,
3829 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003830 if (!NewParm)
3831 return true;
3832
Douglas Gregora009b592011-01-07 00:20:55 +00003833 OutParamTypes.push_back(NewParm->getType());
3834 if (PVars)
3835 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003836 }
Douglas Gregord3731192011-01-10 07:32:04 +00003837
3838 // If we're supposed to retain a pack expansion, do so by temporarily
3839 // forgetting the partially-substituted parameter pack.
3840 if (RetainExpansion) {
3841 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3842 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003843 = getDerived().TransformFunctionTypeParam(OldParm,
3844 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003845 if (!NewParm)
3846 return true;
3847
3848 OutParamTypes.push_back(NewParm->getType());
3849 if (PVars)
3850 PVars->push_back(NewParm);
3851 }
3852
Douglas Gregor603cfb42011-01-05 23:12:31 +00003853 // We're done with the pack expansion.
3854 continue;
3855 }
3856
3857 // We'll substitute the parameter now without expanding the pack
3858 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003859 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3860 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3861 NumExpansions);
3862 } else {
3863 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3864 llvm::Optional<unsigned>());
Douglas Gregor603cfb42011-01-05 23:12:31 +00003865 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003866
John McCall21ef0fa2010-03-11 09:03:00 +00003867 if (!NewParm)
3868 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003869
Douglas Gregora009b592011-01-07 00:20:55 +00003870 OutParamTypes.push_back(NewParm->getType());
3871 if (PVars)
3872 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003873 continue;
3874 }
John McCall21ef0fa2010-03-11 09:03:00 +00003875
3876 // Deal with the possibility that we don't have a parameter
3877 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003878 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003879 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003880 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003881 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003882 if (const PackExpansionType *Expansion
3883 = dyn_cast<PackExpansionType>(OldType)) {
3884 // We have a function parameter pack that may need to be expanded.
3885 QualType Pattern = Expansion->getPattern();
3886 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3887 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3888
3889 // Determine whether we should expand the parameter packs.
3890 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003891 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003892 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003893 Unexpanded.data(),
3894 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003895 ShouldExpand,
3896 RetainExpansion,
3897 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003898 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003899 }
3900
3901 if (ShouldExpand) {
3902 // Expand the function parameter pack into multiple, separate
3903 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003904 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003905 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3906 QualType NewType = getDerived().TransformType(Pattern);
3907 if (NewType.isNull())
3908 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003909
Douglas Gregora009b592011-01-07 00:20:55 +00003910 OutParamTypes.push_back(NewType);
3911 if (PVars)
3912 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003913 }
3914
3915 // We're done with the pack expansion.
3916 continue;
3917 }
3918
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003919 // If we're supposed to retain a pack expansion, do so by temporarily
3920 // forgetting the partially-substituted parameter pack.
3921 if (RetainExpansion) {
3922 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3923 QualType NewType = getDerived().TransformType(Pattern);
3924 if (NewType.isNull())
3925 return true;
3926
3927 OutParamTypes.push_back(NewType);
3928 if (PVars)
3929 PVars->push_back(0);
3930 }
Douglas Gregord3731192011-01-10 07:32:04 +00003931
Douglas Gregor603cfb42011-01-05 23:12:31 +00003932 // We'll substitute the parameter now without expanding the pack
3933 // expansion.
3934 OldType = Expansion->getPattern();
3935 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003936 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3937 NewType = getDerived().TransformType(OldType);
3938 } else {
3939 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003940 }
3941
Douglas Gregor603cfb42011-01-05 23:12:31 +00003942 if (NewType.isNull())
3943 return true;
3944
3945 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00003946 NewType = getSema().Context.getPackExpansionType(NewType,
3947 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003948
Douglas Gregora009b592011-01-07 00:20:55 +00003949 OutParamTypes.push_back(NewType);
3950 if (PVars)
3951 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00003952 }
3953
3954 return false;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003955 }
John McCall21ef0fa2010-03-11 09:03:00 +00003956
3957template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003958QualType
John McCalla2becad2009-10-21 00:40:46 +00003959TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003960 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003961 // Transform the parameters and return type.
3962 //
3963 // We instantiate in source order, with the return type first followed by
3964 // the parameters, because users tend to expect this (even if they shouldn't
3965 // rely on it!).
3966 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003967 // When the function has a trailing return type, we instantiate the
3968 // parameters before the return type, since the return type can then refer
3969 // to the parameters themselves (via decltype, sizeof, etc.).
3970 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003971 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003972 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00003973 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003974
Douglas Gregordab60ad2010-10-01 18:44:50 +00003975 QualType ResultType;
3976
3977 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00003978 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3979 TL.getParmArray(),
3980 TL.getNumArgs(),
3981 TL.getTypePtr()->arg_type_begin(),
3982 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003983 return QualType();
3984
3985 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3986 if (ResultType.isNull())
3987 return QualType();
3988 }
3989 else {
3990 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3991 if (ResultType.isNull())
3992 return QualType();
3993
Douglas Gregora009b592011-01-07 00:20:55 +00003994 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3995 TL.getParmArray(),
3996 TL.getNumArgs(),
3997 TL.getTypePtr()->arg_type_begin(),
3998 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003999 return QualType();
4000 }
4001
John McCalla2becad2009-10-21 00:40:46 +00004002 QualType Result = TL.getType();
4003 if (getDerived().AlwaysRebuild() ||
4004 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004005 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004006 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4007 Result = getDerived().RebuildFunctionProtoType(ResultType,
4008 ParamTypes.data(),
4009 ParamTypes.size(),
4010 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004011 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004012 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004013 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004014 if (Result.isNull())
4015 return QualType();
4016 }
Mike Stump1eb44332009-09-09 15:08:12 +00004017
John McCalla2becad2009-10-21 00:40:46 +00004018 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4019 NewTL.setLParenLoc(TL.getLParenLoc());
4020 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004021 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004022 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4023 NewTL.setArg(i, ParamDecls[i]);
4024
4025 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004026}
Mike Stump1eb44332009-09-09 15:08:12 +00004027
Douglas Gregor577f75a2009-08-04 16:50:30 +00004028template<typename Derived>
4029QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004030 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004031 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004032 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004033 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4034 if (ResultType.isNull())
4035 return QualType();
4036
4037 QualType Result = TL.getType();
4038 if (getDerived().AlwaysRebuild() ||
4039 ResultType != T->getResultType())
4040 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4041
4042 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4043 NewTL.setLParenLoc(TL.getLParenLoc());
4044 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004045 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004046
4047 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004048}
Mike Stump1eb44332009-09-09 15:08:12 +00004049
John McCalled976492009-12-04 22:46:56 +00004050template<typename Derived> QualType
4051TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004052 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004053 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004054 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004055 if (!D)
4056 return QualType();
4057
4058 QualType Result = TL.getType();
4059 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4060 Result = getDerived().RebuildUnresolvedUsingType(D);
4061 if (Result.isNull())
4062 return QualType();
4063 }
4064
4065 // We might get an arbitrary type spec type back. We should at
4066 // least always get a type spec type, though.
4067 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4068 NewTL.setNameLoc(TL.getNameLoc());
4069
4070 return Result;
4071}
4072
Douglas Gregor577f75a2009-08-04 16:50:30 +00004073template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004074QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004075 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004076 const TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004077 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004078 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4079 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004080 if (!Typedef)
4081 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004082
John McCalla2becad2009-10-21 00:40:46 +00004083 QualType Result = TL.getType();
4084 if (getDerived().AlwaysRebuild() ||
4085 Typedef != T->getDecl()) {
4086 Result = getDerived().RebuildTypedefType(Typedef);
4087 if (Result.isNull())
4088 return QualType();
4089 }
Mike Stump1eb44332009-09-09 15:08:12 +00004090
John McCalla2becad2009-10-21 00:40:46 +00004091 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4092 NewTL.setNameLoc(TL.getNameLoc());
4093
4094 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004095}
Mike Stump1eb44332009-09-09 15:08:12 +00004096
Douglas Gregor577f75a2009-08-04 16:50:30 +00004097template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004098QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004099 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004100 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004101 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004102
John McCall60d7b3a2010-08-24 06:29:42 +00004103 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004104 if (E.isInvalid())
4105 return QualType();
4106
John McCalla2becad2009-10-21 00:40:46 +00004107 QualType Result = TL.getType();
4108 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004109 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004110 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004111 if (Result.isNull())
4112 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004113 }
John McCalla2becad2009-10-21 00:40:46 +00004114 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004115
John McCalla2becad2009-10-21 00:40:46 +00004116 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004117 NewTL.setTypeofLoc(TL.getTypeofLoc());
4118 NewTL.setLParenLoc(TL.getLParenLoc());
4119 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004120
4121 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004122}
Mike Stump1eb44332009-09-09 15:08:12 +00004123
4124template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004125QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004126 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004127 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4128 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4129 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004130 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004131
John McCalla2becad2009-10-21 00:40:46 +00004132 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004133 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4134 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004135 if (Result.isNull())
4136 return QualType();
4137 }
Mike Stump1eb44332009-09-09 15:08:12 +00004138
John McCalla2becad2009-10-21 00:40:46 +00004139 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004140 NewTL.setTypeofLoc(TL.getTypeofLoc());
4141 NewTL.setLParenLoc(TL.getLParenLoc());
4142 NewTL.setRParenLoc(TL.getRParenLoc());
4143 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004144
4145 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004146}
Mike Stump1eb44332009-09-09 15:08:12 +00004147
4148template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004149QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004150 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004151 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004152
Douglas Gregor670444e2009-08-04 22:27:00 +00004153 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004154 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004155
John McCall60d7b3a2010-08-24 06:29:42 +00004156 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004157 if (E.isInvalid())
4158 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004159
John McCalla2becad2009-10-21 00:40:46 +00004160 QualType Result = TL.getType();
4161 if (getDerived().AlwaysRebuild() ||
4162 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004163 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004164 if (Result.isNull())
4165 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004166 }
John McCalla2becad2009-10-21 00:40:46 +00004167 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004168
John McCalla2becad2009-10-21 00:40:46 +00004169 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4170 NewTL.setNameLoc(TL.getNameLoc());
4171
4172 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004173}
4174
4175template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004176QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4177 AutoTypeLoc TL) {
4178 const AutoType *T = TL.getTypePtr();
4179 QualType OldDeduced = T->getDeducedType();
4180 QualType NewDeduced;
4181 if (!OldDeduced.isNull()) {
4182 NewDeduced = getDerived().TransformType(OldDeduced);
4183 if (NewDeduced.isNull())
4184 return QualType();
4185 }
4186
4187 QualType Result = TL.getType();
4188 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4189 Result = getDerived().RebuildAutoType(NewDeduced);
4190 if (Result.isNull())
4191 return QualType();
4192 }
4193
4194 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4195 NewTL.setNameLoc(TL.getNameLoc());
4196
4197 return Result;
4198}
4199
4200template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004201QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004202 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004203 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004204 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004205 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4206 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004207 if (!Record)
4208 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004209
John McCalla2becad2009-10-21 00:40:46 +00004210 QualType Result = TL.getType();
4211 if (getDerived().AlwaysRebuild() ||
4212 Record != T->getDecl()) {
4213 Result = getDerived().RebuildRecordType(Record);
4214 if (Result.isNull())
4215 return QualType();
4216 }
Mike Stump1eb44332009-09-09 15:08:12 +00004217
John McCalla2becad2009-10-21 00:40:46 +00004218 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4219 NewTL.setNameLoc(TL.getNameLoc());
4220
4221 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004222}
Mike Stump1eb44332009-09-09 15:08:12 +00004223
4224template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004225QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004226 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004227 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004228 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004229 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4230 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004231 if (!Enum)
4232 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004233
John McCalla2becad2009-10-21 00:40:46 +00004234 QualType Result = TL.getType();
4235 if (getDerived().AlwaysRebuild() ||
4236 Enum != T->getDecl()) {
4237 Result = getDerived().RebuildEnumType(Enum);
4238 if (Result.isNull())
4239 return QualType();
4240 }
Mike Stump1eb44332009-09-09 15:08:12 +00004241
John McCalla2becad2009-10-21 00:40:46 +00004242 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4243 NewTL.setNameLoc(TL.getNameLoc());
4244
4245 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004246}
John McCall7da24312009-09-05 00:15:47 +00004247
John McCall3cb0ebd2010-03-10 03:28:59 +00004248template<typename Derived>
4249QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4250 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004251 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004252 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4253 TL.getTypePtr()->getDecl());
4254 if (!D) return QualType();
4255
4256 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4257 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4258 return T;
4259}
4260
Douglas Gregor577f75a2009-08-04 16:50:30 +00004261template<typename Derived>
4262QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004263 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004264 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004265 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004266}
4267
Mike Stump1eb44332009-09-09 15:08:12 +00004268template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004269QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004270 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004271 SubstTemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004272 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00004273}
4274
4275template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004276QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4277 TypeLocBuilder &TLB,
4278 SubstTemplateTypeParmPackTypeLoc TL) {
4279 return TransformTypeSpecType(TLB, TL);
4280}
4281
4282template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004283QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004284 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004285 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004286 const TemplateSpecializationType *T = TL.getTypePtr();
4287
Douglas Gregor1d752d72011-03-02 18:46:51 +00004288 // The nested-name-specifier never matters in a TemplateSpecializationType,
4289 // because we can't have a dependent nested-name-specifier anyway.
4290 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004291 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004292 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4293 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004294 if (Template.isNull())
4295 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004296
John McCall43fed0d2010-11-12 08:19:04 +00004297 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4298}
4299
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004300namespace {
4301 /// \brief Simple iterator that traverses the template arguments in a
4302 /// container that provides a \c getArgLoc() member function.
4303 ///
4304 /// This iterator is intended to be used with the iterator form of
4305 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4306 template<typename ArgLocContainer>
4307 class TemplateArgumentLocContainerIterator {
4308 ArgLocContainer *Container;
4309 unsigned Index;
4310
4311 public:
4312 typedef TemplateArgumentLoc value_type;
4313 typedef TemplateArgumentLoc reference;
4314 typedef int difference_type;
4315 typedef std::input_iterator_tag iterator_category;
4316
4317 class pointer {
4318 TemplateArgumentLoc Arg;
4319
4320 public:
4321 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4322
4323 const TemplateArgumentLoc *operator->() const {
4324 return &Arg;
4325 }
4326 };
4327
4328
4329 TemplateArgumentLocContainerIterator() {}
4330
4331 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4332 unsigned Index)
4333 : Container(&Container), Index(Index) { }
4334
4335 TemplateArgumentLocContainerIterator &operator++() {
4336 ++Index;
4337 return *this;
4338 }
4339
4340 TemplateArgumentLocContainerIterator operator++(int) {
4341 TemplateArgumentLocContainerIterator Old(*this);
4342 ++(*this);
4343 return Old;
4344 }
4345
4346 TemplateArgumentLoc operator*() const {
4347 return Container->getArgLoc(Index);
4348 }
4349
4350 pointer operator->() const {
4351 return pointer(Container->getArgLoc(Index));
4352 }
4353
4354 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004355 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004356 return X.Container == Y.Container && X.Index == Y.Index;
4357 }
4358
4359 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004360 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004361 return !(X == Y);
4362 }
4363 };
4364}
4365
4366
John McCall43fed0d2010-11-12 08:19:04 +00004367template <typename Derived>
4368QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4369 TypeLocBuilder &TLB,
4370 TemplateSpecializationTypeLoc TL,
4371 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004372 TemplateArgumentListInfo NewTemplateArgs;
4373 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4374 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004375 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4376 ArgIterator;
4377 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4378 ArgIterator(TL, TL.getNumArgs()),
4379 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004380 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004381
John McCall833ca992009-10-29 08:12:44 +00004382 // FIXME: maybe don't rebuild if all the template arguments are the same.
4383
4384 QualType Result =
4385 getDerived().RebuildTemplateSpecializationType(Template,
4386 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004387 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004388
4389 if (!Result.isNull()) {
4390 TemplateSpecializationTypeLoc NewTL
4391 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4392 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4393 NewTL.setLAngleLoc(TL.getLAngleLoc());
4394 NewTL.setRAngleLoc(TL.getRAngleLoc());
4395 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4396 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004397 }
Mike Stump1eb44332009-09-09 15:08:12 +00004398
John McCall833ca992009-10-29 08:12:44 +00004399 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004400}
Mike Stump1eb44332009-09-09 15:08:12 +00004401
Douglas Gregora88f09f2011-02-28 17:23:35 +00004402template <typename Derived>
4403QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4404 TypeLocBuilder &TLB,
4405 DependentTemplateSpecializationTypeLoc TL,
4406 TemplateName Template) {
4407 TemplateArgumentListInfo NewTemplateArgs;
4408 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4409 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4410 typedef TemplateArgumentLocContainerIterator<
4411 DependentTemplateSpecializationTypeLoc> ArgIterator;
4412 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4413 ArgIterator(TL, TL.getNumArgs()),
4414 NewTemplateArgs))
4415 return QualType();
4416
4417 // FIXME: maybe don't rebuild if all the template arguments are the same.
4418
4419 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4420 QualType Result
4421 = getSema().Context.getDependentTemplateSpecializationType(
4422 TL.getTypePtr()->getKeyword(),
4423 DTN->getQualifier(),
4424 DTN->getIdentifier(),
4425 NewTemplateArgs);
4426
4427 DependentTemplateSpecializationTypeLoc NewTL
4428 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4429 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004430
4431 // FIXME: Poor nested-name-specifier source-location information.
4432 CXXScopeSpec SS;
4433 SS.MakeTrivial(SemaRef.Context,
4434 DTN->getQualifier(), TL.getQualifierLoc().getSourceRange());
4435 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregora88f09f2011-02-28 17:23:35 +00004436 NewTL.setNameLoc(TL.getNameLoc());
4437 NewTL.setLAngleLoc(TL.getLAngleLoc());
4438 NewTL.setRAngleLoc(TL.getRAngleLoc());
4439 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4440 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4441 return Result;
4442 }
4443
4444 QualType Result
4445 = getDerived().RebuildTemplateSpecializationType(Template,
4446 TL.getNameLoc(),
4447 NewTemplateArgs);
4448
4449 if (!Result.isNull()) {
4450 /// FIXME: Wrap this in an elaborated-type-specifier?
4451 TemplateSpecializationTypeLoc NewTL
4452 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4453 NewTL.setTemplateNameLoc(TL.getNameLoc());
4454 NewTL.setLAngleLoc(TL.getLAngleLoc());
4455 NewTL.setRAngleLoc(TL.getRAngleLoc());
4456 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4457 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4458 }
4459
4460 return Result;
4461}
4462
Mike Stump1eb44332009-09-09 15:08:12 +00004463template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004464QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004465TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004466 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004467 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004468
Douglas Gregor9e876872011-03-01 18:12:44 +00004469 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004470 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004471 if (TL.getQualifierLoc()) {
4472 QualifierLoc
4473 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4474 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004475 return QualType();
4476 }
Mike Stump1eb44332009-09-09 15:08:12 +00004477
John McCall43fed0d2010-11-12 08:19:04 +00004478 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4479 if (NamedT.isNull())
4480 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004481
John McCalla2becad2009-10-21 00:40:46 +00004482 QualType Result = TL.getType();
4483 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004484 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004485 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004486 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004487 T->getKeyword(),
4488 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004489 if (Result.isNull())
4490 return QualType();
4491 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004492
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004493 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004494 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004495 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004496 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004497}
Mike Stump1eb44332009-09-09 15:08:12 +00004498
4499template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004500QualType TreeTransform<Derived>::TransformAttributedType(
4501 TypeLocBuilder &TLB,
4502 AttributedTypeLoc TL) {
4503 const AttributedType *oldType = TL.getTypePtr();
4504 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4505 if (modifiedType.isNull())
4506 return QualType();
4507
4508 QualType result = TL.getType();
4509
4510 // FIXME: dependent operand expressions?
4511 if (getDerived().AlwaysRebuild() ||
4512 modifiedType != oldType->getModifiedType()) {
4513 // TODO: this is really lame; we should really be rebuilding the
4514 // equivalent type from first principles.
4515 QualType equivalentType
4516 = getDerived().TransformType(oldType->getEquivalentType());
4517 if (equivalentType.isNull())
4518 return QualType();
4519 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4520 modifiedType,
4521 equivalentType);
4522 }
4523
4524 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4525 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4526 if (TL.hasAttrOperand())
4527 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4528 if (TL.hasAttrExprOperand())
4529 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4530 else if (TL.hasAttrEnumOperand())
4531 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4532
4533 return result;
4534}
4535
4536template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004537QualType
4538TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4539 ParenTypeLoc TL) {
4540 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4541 if (Inner.isNull())
4542 return QualType();
4543
4544 QualType Result = TL.getType();
4545 if (getDerived().AlwaysRebuild() ||
4546 Inner != TL.getInnerLoc().getType()) {
4547 Result = getDerived().RebuildParenType(Inner);
4548 if (Result.isNull())
4549 return QualType();
4550 }
4551
4552 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4553 NewTL.setLParenLoc(TL.getLParenLoc());
4554 NewTL.setRParenLoc(TL.getRParenLoc());
4555 return Result;
4556}
4557
4558template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004559QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004560 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004561 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004562
Douglas Gregor2494dd02011-03-01 01:34:45 +00004563 NestedNameSpecifierLoc QualifierLoc
4564 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4565 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004566 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004567
John McCall33500952010-06-11 00:33:02 +00004568 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004569 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCall33500952010-06-11 00:33:02 +00004570 TL.getKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004571 QualifierLoc,
4572 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004573 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004574 if (Result.isNull())
4575 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004576
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004577 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4578 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004579 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4580
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004581 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4582 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004583 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004584 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004585 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4586 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004587 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004588 NewTL.setNameLoc(TL.getNameLoc());
4589 }
John McCalla2becad2009-10-21 00:40:46 +00004590 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004591}
Mike Stump1eb44332009-09-09 15:08:12 +00004592
Douglas Gregor577f75a2009-08-04 16:50:30 +00004593template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004594QualType TreeTransform<Derived>::
4595 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004596 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004597 NestedNameSpecifierLoc QualifierLoc;
4598 if (TL.getQualifierLoc()) {
4599 QualifierLoc
4600 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4601 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004602 return QualType();
4603 }
4604
John McCall43fed0d2010-11-12 08:19:04 +00004605 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004606 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004607}
4608
4609template<typename Derived>
4610QualType TreeTransform<Derived>::
4611 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4612 DependentTemplateSpecializationTypeLoc TL,
4613 NestedNameSpecifier *NNS) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004614 // FIXME: This routine needs to go away.
John McCallf4c73712011-01-19 06:33:43 +00004615 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall43fed0d2010-11-12 08:19:04 +00004616
John McCall33500952010-06-11 00:33:02 +00004617 TemplateArgumentListInfo NewTemplateArgs;
4618 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4619 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00004620
4621 // FIXME: Nested-name-specifier source location info!
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004622 typedef TemplateArgumentLocContainerIterator<
4623 DependentTemplateSpecializationTypeLoc> ArgIterator;
4624 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4625 ArgIterator(TL, TL.getNumArgs()),
4626 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004627 return QualType();
John McCall33500952010-06-11 00:33:02 +00004628
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00004629 CXXScopeSpec SS;
4630 SS.MakeTrivial(SemaRef.Context, NNS,
4631 TL.getQualifierLoc().getSourceRange());
Douglas Gregor1efb6c72010-09-08 23:56:00 +00004632 QualType Result
4633 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00004634 SS.getWithLocInContext(SemaRef.Context),
Douglas Gregor1efb6c72010-09-08 23:56:00 +00004635 T->getIdentifier(),
4636 TL.getNameLoc(),
4637 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00004638 if (Result.isNull())
4639 return QualType();
4640
4641 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4642 QualType NamedT = ElabT->getNamedType();
4643
4644 // Copy information relevant to the template specialization.
4645 TemplateSpecializationTypeLoc NamedTL
4646 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4647 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4648 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4649 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4650 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4651
4652 // Copy information relevant to the elaborated type.
4653 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4654 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004655
4656 // FIXME: DependentTemplateSpecializationType needs better source-location
4657 // info.
4658 NestedNameSpecifierLocBuilder Builder;
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004659 Builder.MakeTrivial(SemaRef.Context,
4660 NNS, TL.getQualifierLoc().getSourceRange());
Douglas Gregor9e876872011-03-01 18:12:44 +00004661 NewTL.setQualifierLoc(Builder.getWithLocInContext(SemaRef.Context));
John McCall33500952010-06-11 00:33:02 +00004662 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00004663 TypeLoc NewTL(Result, TL.getOpaqueData());
4664 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00004665 }
4666 return Result;
4667}
4668
4669template<typename Derived>
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004670QualType TreeTransform<Derived>::
4671TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4672 DependentTemplateSpecializationTypeLoc TL,
4673 NestedNameSpecifierLoc QualifierLoc) {
4674 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4675
4676 TemplateArgumentListInfo NewTemplateArgs;
4677 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4678 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4679
4680 typedef TemplateArgumentLocContainerIterator<
4681 DependentTemplateSpecializationTypeLoc> ArgIterator;
4682 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4683 ArgIterator(TL, TL.getNumArgs()),
4684 NewTemplateArgs))
4685 return QualType();
4686
4687 QualType Result
4688 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4689 QualifierLoc,
4690 T->getIdentifier(),
4691 TL.getNameLoc(),
4692 NewTemplateArgs);
4693 if (Result.isNull())
4694 return QualType();
4695
4696 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4697 QualType NamedT = ElabT->getNamedType();
4698
4699 // Copy information relevant to the template specialization.
4700 TemplateSpecializationTypeLoc NamedTL
4701 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4702 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4703 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4704 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4705 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4706
4707 // Copy information relevant to the elaborated type.
4708 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4709 NewTL.setKeywordLoc(TL.getKeywordLoc());
4710 NewTL.setQualifierLoc(QualifierLoc);
4711 } else {
4712 TypeLoc NewTL(Result, TL.getOpaqueData());
4713 TLB.pushFullCopy(NewTL);
4714 }
4715 return Result;
4716}
4717
4718template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004719QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4720 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004721 QualType Pattern
4722 = getDerived().TransformType(TLB, TL.getPatternLoc());
4723 if (Pattern.isNull())
4724 return QualType();
4725
4726 QualType Result = TL.getType();
4727 if (getDerived().AlwaysRebuild() ||
4728 Pattern != TL.getPatternLoc().getType()) {
4729 Result = getDerived().RebuildPackExpansionType(Pattern,
4730 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004731 TL.getEllipsisLoc(),
4732 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004733 if (Result.isNull())
4734 return QualType();
4735 }
4736
4737 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4738 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4739 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004740}
4741
4742template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004743QualType
4744TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004745 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004746 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004747 TLB.pushFullCopy(TL);
4748 return TL.getType();
4749}
4750
4751template<typename Derived>
4752QualType
4753TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004754 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004755 // ObjCObjectType is never dependent.
4756 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004757 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004758}
Mike Stump1eb44332009-09-09 15:08:12 +00004759
4760template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004761QualType
4762TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004763 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004764 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004765 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004766 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004767}
4768
Douglas Gregor577f75a2009-08-04 16:50:30 +00004769//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004770// Statement transformation
4771//===----------------------------------------------------------------------===//
4772template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004773StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004774TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004775 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004776}
4777
4778template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004779StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004780TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4781 return getDerived().TransformCompoundStmt(S, false);
4782}
4783
4784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004785StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004786TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004787 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004788 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004789 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004790 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004791 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4792 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004793 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004794 if (Result.isInvalid()) {
4795 // Immediately fail if this was a DeclStmt, since it's very
4796 // likely that this will cause problems for future statements.
4797 if (isa<DeclStmt>(*B))
4798 return StmtError();
4799
4800 // Otherwise, just keep processing substatements and fail later.
4801 SubStmtInvalid = true;
4802 continue;
4803 }
Mike Stump1eb44332009-09-09 15:08:12 +00004804
Douglas Gregor43959a92009-08-20 07:17:43 +00004805 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4806 Statements.push_back(Result.takeAs<Stmt>());
4807 }
Mike Stump1eb44332009-09-09 15:08:12 +00004808
John McCall7114cba2010-08-27 19:56:05 +00004809 if (SubStmtInvalid)
4810 return StmtError();
4811
Douglas Gregor43959a92009-08-20 07:17:43 +00004812 if (!getDerived().AlwaysRebuild() &&
4813 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004814 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004815
4816 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4817 move_arg(Statements),
4818 S->getRBracLoc(),
4819 IsStmtExpr);
4820}
Mike Stump1eb44332009-09-09 15:08:12 +00004821
Douglas Gregor43959a92009-08-20 07:17:43 +00004822template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004823StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004824TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004825 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004826 {
4827 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004828 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004829
Eli Friedman264c1f82009-11-19 03:14:00 +00004830 // Transform the left-hand case value.
4831 LHS = getDerived().TransformExpr(S->getLHS());
4832 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004833 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004834
Eli Friedman264c1f82009-11-19 03:14:00 +00004835 // Transform the right-hand case value (for the GNU case-range extension).
4836 RHS = getDerived().TransformExpr(S->getRHS());
4837 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004838 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004839 }
Mike Stump1eb44332009-09-09 15:08:12 +00004840
Douglas Gregor43959a92009-08-20 07:17:43 +00004841 // Build the case statement.
4842 // Case statements are always rebuilt so that they will attached to their
4843 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004844 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004845 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004846 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004847 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004848 S->getColonLoc());
4849 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004850 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004851
Douglas Gregor43959a92009-08-20 07:17:43 +00004852 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004853 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004854 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004855 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004856
Douglas Gregor43959a92009-08-20 07:17:43 +00004857 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004858 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004859}
4860
4861template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004862StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004863TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004864 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00004865 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004866 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004867 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004868
Douglas Gregor43959a92009-08-20 07:17:43 +00004869 // Default statements are always rebuilt
4870 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004871 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004872}
Mike Stump1eb44332009-09-09 15:08:12 +00004873
Douglas Gregor43959a92009-08-20 07:17:43 +00004874template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004875StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004876TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004877 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004878 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004879 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004880
Chris Lattner57ad3782011-02-17 20:34:02 +00004881 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4882 S->getDecl());
4883 if (!LD)
4884 return StmtError();
4885
4886
Douglas Gregor43959a92009-08-20 07:17:43 +00004887 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00004888 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00004889 cast<LabelDecl>(LD), SourceLocation(),
4890 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004891}
Mike Stump1eb44332009-09-09 15:08:12 +00004892
Douglas Gregor43959a92009-08-20 07:17:43 +00004893template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004894StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004895TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004896 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004897 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004898 VarDecl *ConditionVar = 0;
4899 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004900 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004901 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004902 getDerived().TransformDefinition(
4903 S->getConditionVariable()->getLocation(),
4904 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004905 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004906 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004907 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004908 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004909
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004910 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004911 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004912
4913 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004914 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004915 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4916 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004917 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004918 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004919
John McCall9ae2f072010-08-23 23:25:46 +00004920 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004921 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004922 }
Sean Huntc3021132010-05-05 15:23:54 +00004923
John McCall9ae2f072010-08-23 23:25:46 +00004924 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4925 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004926 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004927
Douglas Gregor43959a92009-08-20 07:17:43 +00004928 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004929 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00004930 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004931 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004932
Douglas Gregor43959a92009-08-20 07:17:43 +00004933 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004934 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00004935 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004936 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004937
Douglas Gregor43959a92009-08-20 07:17:43 +00004938 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004939 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004940 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004941 Then.get() == S->getThen() &&
4942 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00004943 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004944
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004945 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00004946 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00004947 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004948}
4949
4950template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004951StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004952TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004953 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00004954 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00004955 VarDecl *ConditionVar = 0;
4956 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004957 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00004958 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004959 getDerived().TransformDefinition(
4960 S->getConditionVariable()->getLocation(),
4961 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00004962 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004963 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004964 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00004965 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004966
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004967 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004968 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004969 }
Mike Stump1eb44332009-09-09 15:08:12 +00004970
Douglas Gregor43959a92009-08-20 07:17:43 +00004971 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004972 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00004973 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00004974 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00004975 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004976 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004977
Douglas Gregor43959a92009-08-20 07:17:43 +00004978 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004979 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004980 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004981 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004982
Douglas Gregor43959a92009-08-20 07:17:43 +00004983 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00004984 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4985 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004986}
Mike Stump1eb44332009-09-09 15:08:12 +00004987
Douglas Gregor43959a92009-08-20 07:17:43 +00004988template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004989StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004990TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004991 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004992 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00004993 VarDecl *ConditionVar = 0;
4994 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004995 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00004996 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004997 getDerived().TransformDefinition(
4998 S->getConditionVariable()->getLocation(),
4999 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005000 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005001 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005002 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005003 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005004
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005005 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005006 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005007
5008 if (S->getCond()) {
5009 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005010 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5011 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005012 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005013 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005014 Cond = CondE;
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 body
John McCall60d7b3a2010-08-24 06:29:42 +00005023 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005024 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005025 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005026
Douglas Gregor43959a92009-08-20 07:17:43 +00005027 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005028 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005029 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005030 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005031 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005032
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005033 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005034 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005035}
Mike Stump1eb44332009-09-09 15:08:12 +00005036
Douglas Gregor43959a92009-08-20 07:17:43 +00005037template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005038StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005039TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005040 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005041 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005042 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005043 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005044
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005045 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005046 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005047 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005048 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005049
Douglas Gregor43959a92009-08-20 07:17:43 +00005050 if (!getDerived().AlwaysRebuild() &&
5051 Cond.get() == S->getCond() &&
5052 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005053 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005054
John McCall9ae2f072010-08-23 23:25:46 +00005055 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5056 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005057 S->getRParenLoc());
5058}
Mike Stump1eb44332009-09-09 15:08:12 +00005059
Douglas Gregor43959a92009-08-20 07:17:43 +00005060template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005061StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005062TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005063 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005064 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005065 if (Init.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 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005069 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005070 VarDecl *ConditionVar = 0;
5071 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005072 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005073 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005074 getDerived().TransformDefinition(
5075 S->getConditionVariable()->getLocation(),
5076 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005077 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005078 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005079 } else {
5080 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005081
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005082 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005083 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005084
5085 if (S->getCond()) {
5086 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005087 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5088 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005089 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005090 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005091
John McCall9ae2f072010-08-23 23:25:46 +00005092 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005093 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005094 }
Mike Stump1eb44332009-09-09 15:08:12 +00005095
John McCall9ae2f072010-08-23 23:25:46 +00005096 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5097 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005098 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005099
Douglas Gregor43959a92009-08-20 07:17:43 +00005100 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005101 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005102 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005103 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005104
John McCall9ae2f072010-08-23 23:25:46 +00005105 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5106 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005107 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005108
Douglas Gregor43959a92009-08-20 07:17:43 +00005109 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005110 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005111 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005112 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005113
Douglas Gregor43959a92009-08-20 07:17:43 +00005114 if (!getDerived().AlwaysRebuild() &&
5115 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005116 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005117 Inc.get() == S->getInc() &&
5118 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005119 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005120
Douglas Gregor43959a92009-08-20 07:17:43 +00005121 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005122 Init.get(), FullCond, ConditionVar,
5123 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005124}
5125
5126template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005127StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005128TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005129 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5130 S->getLabel());
5131 if (!LD)
5132 return StmtError();
5133
Douglas Gregor43959a92009-08-20 07:17:43 +00005134 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005135 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005136 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005137}
5138
5139template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005140StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005141TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005142 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005143 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005144 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005145
Douglas Gregor43959a92009-08-20 07:17:43 +00005146 if (!getDerived().AlwaysRebuild() &&
5147 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005148 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005149
5150 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005151 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005152}
5153
5154template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005155StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005156TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005157 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005158}
Mike Stump1eb44332009-09-09 15:08:12 +00005159
Douglas Gregor43959a92009-08-20 07:17:43 +00005160template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005161StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005162TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005163 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005164}
Mike Stump1eb44332009-09-09 15:08:12 +00005165
Douglas Gregor43959a92009-08-20 07:17:43 +00005166template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005167StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005168TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005169 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005170 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005171 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005172
Mike Stump1eb44332009-09-09 15:08:12 +00005173 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005174 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005175 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005176}
Mike Stump1eb44332009-09-09 15:08:12 +00005177
Douglas Gregor43959a92009-08-20 07:17:43 +00005178template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005179StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005180TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005181 bool DeclChanged = false;
5182 llvm::SmallVector<Decl *, 4> Decls;
5183 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5184 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005185 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5186 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005187 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005188 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005189
Douglas Gregor43959a92009-08-20 07:17:43 +00005190 if (Transformed != *D)
5191 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005192
Douglas Gregor43959a92009-08-20 07:17:43 +00005193 Decls.push_back(Transformed);
5194 }
Mike Stump1eb44332009-09-09 15:08:12 +00005195
Douglas Gregor43959a92009-08-20 07:17:43 +00005196 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005197 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005198
5199 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005200 S->getStartLoc(), S->getEndLoc());
5201}
Mike Stump1eb44332009-09-09 15:08:12 +00005202
Douglas Gregor43959a92009-08-20 07:17:43 +00005203template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005204StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005205TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005206
John McCallca0408f2010-08-23 06:44:23 +00005207 ASTOwningVector<Expr*> Constraints(getSema());
5208 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005209 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005210
John McCall60d7b3a2010-08-24 06:29:42 +00005211 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005212 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005213
5214 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005215
Anders Carlsson703e3942010-01-24 05:50:09 +00005216 // Go through the outputs.
5217 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005218 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005219
Anders Carlsson703e3942010-01-24 05:50:09 +00005220 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005221 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005222
Anders Carlsson703e3942010-01-24 05:50:09 +00005223 // Transform the output expr.
5224 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005225 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005226 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005227 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005228
Anders Carlsson703e3942010-01-24 05:50:09 +00005229 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005230
John McCall9ae2f072010-08-23 23:25:46 +00005231 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005232 }
Sean Huntc3021132010-05-05 15:23:54 +00005233
Anders Carlsson703e3942010-01-24 05:50:09 +00005234 // Go through the inputs.
5235 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005236 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005237
Anders Carlsson703e3942010-01-24 05:50:09 +00005238 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005239 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005240
Anders Carlsson703e3942010-01-24 05:50:09 +00005241 // Transform the input expr.
5242 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005243 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005244 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005245 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005246
Anders Carlsson703e3942010-01-24 05:50:09 +00005247 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005248
John McCall9ae2f072010-08-23 23:25:46 +00005249 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005250 }
Sean Huntc3021132010-05-05 15:23:54 +00005251
Anders Carlsson703e3942010-01-24 05:50:09 +00005252 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005253 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005254
5255 // Go through the clobbers.
5256 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005257 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005258
5259 // No need to transform the asm string literal.
5260 AsmString = SemaRef.Owned(S->getAsmString());
5261
5262 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5263 S->isSimple(),
5264 S->isVolatile(),
5265 S->getNumOutputs(),
5266 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005267 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005268 move_arg(Constraints),
5269 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005270 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005271 move_arg(Clobbers),
5272 S->getRParenLoc(),
5273 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005274}
5275
5276
5277template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005278StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005279TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005280 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005281 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005282 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005283 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005284
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005285 // Transform the @catch statements (if present).
5286 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005287 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005288 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005289 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005290 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005291 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005292 if (Catch.get() != S->getCatchStmt(I))
5293 AnyCatchChanged = true;
5294 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005295 }
Sean Huntc3021132010-05-05 15:23:54 +00005296
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005297 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005298 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005299 if (S->getFinallyStmt()) {
5300 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5301 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005302 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005303 }
5304
5305 // If nothing changed, just retain this statement.
5306 if (!getDerived().AlwaysRebuild() &&
5307 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005308 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005309 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005310 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005311
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005312 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005313 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5314 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005315}
Mike Stump1eb44332009-09-09 15:08:12 +00005316
Douglas Gregor43959a92009-08-20 07:17:43 +00005317template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005318StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005319TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005320 // Transform the @catch parameter, if there is one.
5321 VarDecl *Var = 0;
5322 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5323 TypeSourceInfo *TSInfo = 0;
5324 if (FromVar->getTypeSourceInfo()) {
5325 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5326 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005327 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005328 }
Sean Huntc3021132010-05-05 15:23:54 +00005329
Douglas Gregorbe270a02010-04-26 17:57:08 +00005330 QualType T;
5331 if (TSInfo)
5332 T = TSInfo->getType();
5333 else {
5334 T = getDerived().TransformType(FromVar->getType());
5335 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005336 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005337 }
Sean Huntc3021132010-05-05 15:23:54 +00005338
Douglas Gregorbe270a02010-04-26 17:57:08 +00005339 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5340 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005341 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005342 }
Sean Huntc3021132010-05-05 15:23:54 +00005343
John McCall60d7b3a2010-08-24 06:29:42 +00005344 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005345 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005346 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005347
5348 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005349 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005350 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005351}
Mike Stump1eb44332009-09-09 15:08:12 +00005352
Douglas Gregor43959a92009-08-20 07:17:43 +00005353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005354StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005355TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005356 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005357 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005358 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005359 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005360
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005361 // If nothing changed, just retain this statement.
5362 if (!getDerived().AlwaysRebuild() &&
5363 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005364 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005365
5366 // Build a new statement.
5367 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005368 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005369}
Mike Stump1eb44332009-09-09 15:08:12 +00005370
Douglas Gregor43959a92009-08-20 07:17:43 +00005371template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005372StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005373TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005374 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005375 if (S->getThrowExpr()) {
5376 Operand = getDerived().TransformExpr(S->getThrowExpr());
5377 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005378 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005379 }
Sean Huntc3021132010-05-05 15:23:54 +00005380
Douglas Gregord1377b22010-04-22 21:44:01 +00005381 if (!getDerived().AlwaysRebuild() &&
5382 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005383 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005384
John McCall9ae2f072010-08-23 23:25:46 +00005385 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005386}
Mike Stump1eb44332009-09-09 15:08:12 +00005387
Douglas Gregor43959a92009-08-20 07:17:43 +00005388template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005389StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005390TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005391 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005392 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005393 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005394 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005395 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005396
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005397 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005398 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005399 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005400 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005401
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005402 // If nothing change, just retain the current statement.
5403 if (!getDerived().AlwaysRebuild() &&
5404 Object.get() == S->getSynchExpr() &&
5405 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005406 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005407
5408 // Build a new statement.
5409 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005410 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005411}
5412
5413template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005414StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005415TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005416 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005417 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005418 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005419 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005420 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005421
Douglas Gregorc3203e72010-04-22 23:10:45 +00005422 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005423 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005424 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005425 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005426
Douglas Gregorc3203e72010-04-22 23:10:45 +00005427 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005428 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005429 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005430 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005431
Douglas Gregorc3203e72010-04-22 23:10:45 +00005432 // If nothing changed, just retain this statement.
5433 if (!getDerived().AlwaysRebuild() &&
5434 Element.get() == S->getElement() &&
5435 Collection.get() == S->getCollection() &&
5436 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005437 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005438
Douglas Gregorc3203e72010-04-22 23:10:45 +00005439 // Build a new statement.
5440 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5441 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005442 Element.get(),
5443 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005444 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005445 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005446}
5447
5448
5449template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005450StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005451TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5452 // Transform the exception declaration, if any.
5453 VarDecl *Var = 0;
5454 if (S->getExceptionDecl()) {
5455 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005456 TypeSourceInfo *T = getDerived().TransformType(
5457 ExceptionDecl->getTypeSourceInfo());
5458 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005459 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005460
Douglas Gregor83cb9422010-09-09 17:09:21 +00005461 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00005462 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00005463 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00005464 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005465 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005466 }
Mike Stump1eb44332009-09-09 15:08:12 +00005467
Douglas Gregor43959a92009-08-20 07:17:43 +00005468 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005469 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005470 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005471 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005472
Douglas Gregor43959a92009-08-20 07:17:43 +00005473 if (!getDerived().AlwaysRebuild() &&
5474 !Var &&
5475 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005476 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005477
5478 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5479 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005480 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005481}
Mike Stump1eb44332009-09-09 15:08:12 +00005482
Douglas Gregor43959a92009-08-20 07:17:43 +00005483template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005484StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005485TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5486 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005487 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005488 = getDerived().TransformCompoundStmt(S->getTryBlock());
5489 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005490 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005491
Douglas Gregor43959a92009-08-20 07:17:43 +00005492 // Transform the handlers.
5493 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005494 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005495 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005496 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005497 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5498 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005499 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005500
Douglas Gregor43959a92009-08-20 07:17:43 +00005501 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5502 Handlers.push_back(Handler.takeAs<Stmt>());
5503 }
Mike Stump1eb44332009-09-09 15:08:12 +00005504
Douglas Gregor43959a92009-08-20 07:17:43 +00005505 if (!getDerived().AlwaysRebuild() &&
5506 TryBlock.get() == S->getTryBlock() &&
5507 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005508 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005509
John McCall9ae2f072010-08-23 23:25:46 +00005510 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005511 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005512}
Mike Stump1eb44332009-09-09 15:08:12 +00005513
Douglas Gregor43959a92009-08-20 07:17:43 +00005514//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005515// Expression transformation
5516//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005517template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005518ExprResult
John McCall454feb92009-12-08 09:21:05 +00005519TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005520 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005521}
Mike Stump1eb44332009-09-09 15:08:12 +00005522
5523template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005524ExprResult
John McCall454feb92009-12-08 09:21:05 +00005525TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005526 NestedNameSpecifierLoc QualifierLoc;
5527 if (E->getQualifierLoc()) {
5528 QualifierLoc
5529 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5530 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005531 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005532 }
John McCalldbd872f2009-12-08 09:08:17 +00005533
5534 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005535 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5536 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005537 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005538 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005539
John McCallec8045d2010-08-17 21:27:17 +00005540 DeclarationNameInfo NameInfo = E->getNameInfo();
5541 if (NameInfo.getName()) {
5542 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5543 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005544 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005545 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005546
5547 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005548 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005549 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005550 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005551 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005552
5553 // Mark it referenced in the new context regardless.
5554 // FIXME: this is a bit instantiation-specific.
5555 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5556
John McCall3fa5cae2010-10-26 07:05:15 +00005557 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005558 }
John McCalldbd872f2009-12-08 09:08:17 +00005559
5560 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005561 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005562 TemplateArgs = &TransArgs;
5563 TransArgs.setLAngleLoc(E->getLAngleLoc());
5564 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005565 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5566 E->getNumTemplateArgs(),
5567 TransArgs))
5568 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005569 }
5570
Douglas Gregor40d96a62011-02-28 21:54:11 +00005571 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5572 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005573}
Mike Stump1eb44332009-09-09 15:08:12 +00005574
Douglas Gregorb98b1992009-08-11 05:31:07 +00005575template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005576ExprResult
John McCall454feb92009-12-08 09:21:05 +00005577TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005578 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005579}
Mike Stump1eb44332009-09-09 15:08:12 +00005580
Douglas Gregorb98b1992009-08-11 05:31:07 +00005581template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005582ExprResult
John McCall454feb92009-12-08 09:21:05 +00005583TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005584 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005585}
Mike Stump1eb44332009-09-09 15:08:12 +00005586
Douglas Gregorb98b1992009-08-11 05:31:07 +00005587template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005588ExprResult
John McCall454feb92009-12-08 09:21:05 +00005589TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005590 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005591}
Mike Stump1eb44332009-09-09 15:08:12 +00005592
Douglas Gregorb98b1992009-08-11 05:31:07 +00005593template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005594ExprResult
John McCall454feb92009-12-08 09:21:05 +00005595TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005596 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005597}
Mike Stump1eb44332009-09-09 15:08:12 +00005598
Douglas Gregorb98b1992009-08-11 05:31:07 +00005599template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005600ExprResult
John McCall454feb92009-12-08 09:21:05 +00005601TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005602 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005603}
5604
5605template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005606ExprResult
John McCall454feb92009-12-08 09:21:05 +00005607TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005608 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005609 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005610 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005611
Douglas Gregorb98b1992009-08-11 05:31:07 +00005612 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005613 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005614
John McCall9ae2f072010-08-23 23:25:46 +00005615 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005616 E->getRParen());
5617}
5618
Mike Stump1eb44332009-09-09 15:08:12 +00005619template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005620ExprResult
John McCall454feb92009-12-08 09:21:05 +00005621TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005622 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005623 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005624 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005625
Douglas Gregorb98b1992009-08-11 05:31:07 +00005626 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005627 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005628
Douglas Gregorb98b1992009-08-11 05:31:07 +00005629 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5630 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005631 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005632}
Mike Stump1eb44332009-09-09 15:08:12 +00005633
Douglas Gregorb98b1992009-08-11 05:31:07 +00005634template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005635ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005636TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5637 // Transform the type.
5638 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5639 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005640 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005641
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005642 // Transform all of the components into components similar to what the
5643 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005644 // FIXME: It would be slightly more efficient in the non-dependent case to
5645 // just map FieldDecls, rather than requiring the rebuilder to look for
5646 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005647 // template code that we don't care.
5648 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005649 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005650 typedef OffsetOfExpr::OffsetOfNode Node;
5651 llvm::SmallVector<Component, 4> Components;
5652 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5653 const Node &ON = E->getComponent(I);
5654 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005655 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005656 Comp.LocStart = ON.getRange().getBegin();
5657 Comp.LocEnd = ON.getRange().getEnd();
5658 switch (ON.getKind()) {
5659 case Node::Array: {
5660 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005661 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005662 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005663 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005664
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005665 ExprChanged = ExprChanged || Index.get() != FromIndex;
5666 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005667 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005668 break;
5669 }
Sean Huntc3021132010-05-05 15:23:54 +00005670
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005671 case Node::Field:
5672 case Node::Identifier:
5673 Comp.isBrackets = false;
5674 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005675 if (!Comp.U.IdentInfo)
5676 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005677
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005678 break;
Sean Huntc3021132010-05-05 15:23:54 +00005679
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005680 case Node::Base:
5681 // Will be recomputed during the rebuild.
5682 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005683 }
Sean Huntc3021132010-05-05 15:23:54 +00005684
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005685 Components.push_back(Comp);
5686 }
Sean Huntc3021132010-05-05 15:23:54 +00005687
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005688 // If nothing changed, retain the existing expression.
5689 if (!getDerived().AlwaysRebuild() &&
5690 Type == E->getTypeSourceInfo() &&
5691 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005692 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00005693
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005694 // Build a new offsetof expression.
5695 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5696 Components.data(), Components.size(),
5697 E->getRParenLoc());
5698}
5699
5700template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005701ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00005702TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5703 assert(getDerived().AlreadyTransformed(E->getType()) &&
5704 "opaque value expression requires transformation");
5705 return SemaRef.Owned(E);
5706}
5707
5708template<typename Derived>
5709ExprResult
John McCall454feb92009-12-08 09:21:05 +00005710TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005711 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00005712 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00005713
John McCalla93c9342009-12-07 02:54:59 +00005714 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00005715 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005716 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005717
John McCall5ab75172009-11-04 07:28:41 +00005718 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00005719 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005720
John McCall5ab75172009-11-04 07:28:41 +00005721 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005722 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005723 E->getSourceRange());
5724 }
Mike Stump1eb44332009-09-09 15:08:12 +00005725
John McCall60d7b3a2010-08-24 06:29:42 +00005726 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00005727 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005728 // C++0x [expr.sizeof]p1:
5729 // The operand is either an expression, which is an unevaluated operand
5730 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00005731 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005732
Douglas Gregorb98b1992009-08-11 05:31:07 +00005733 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5734 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005735 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005736
Douglas Gregorb98b1992009-08-11 05:31:07 +00005737 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005738 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005739 }
Mike Stump1eb44332009-09-09 15:08:12 +00005740
John McCall9ae2f072010-08-23 23:25:46 +00005741 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005742 E->isSizeOf(),
5743 E->getSourceRange());
5744}
Mike Stump1eb44332009-09-09 15:08:12 +00005745
Douglas Gregorb98b1992009-08-11 05:31:07 +00005746template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005747ExprResult
John McCall454feb92009-12-08 09:21:05 +00005748TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005749 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005750 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005751 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005752
John McCall60d7b3a2010-08-24 06:29:42 +00005753 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005754 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005755 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005756
5757
Douglas Gregorb98b1992009-08-11 05:31:07 +00005758 if (!getDerived().AlwaysRebuild() &&
5759 LHS.get() == E->getLHS() &&
5760 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005761 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005762
John McCall9ae2f072010-08-23 23:25:46 +00005763 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005764 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005765 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005766 E->getRBracketLoc());
5767}
Mike Stump1eb44332009-09-09 15:08:12 +00005768
5769template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005770ExprResult
John McCall454feb92009-12-08 09:21:05 +00005771TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005772 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00005773 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005774 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005775 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005776
5777 // Transform arguments.
5778 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005779 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005780 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5781 &ArgChanged))
5782 return ExprError();
5783
Douglas Gregorb98b1992009-08-11 05:31:07 +00005784 if (!getDerived().AlwaysRebuild() &&
5785 Callee.get() == E->getCallee() &&
5786 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005787 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005788
Douglas Gregorb98b1992009-08-11 05:31:07 +00005789 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00005790 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005791 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00005792 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005793 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005794 E->getRParenLoc());
5795}
Mike Stump1eb44332009-09-09 15:08:12 +00005796
5797template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005798ExprResult
John McCall454feb92009-12-08 09:21:05 +00005799TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005800 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005801 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005802 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005803
Douglas Gregor40d96a62011-02-28 21:54:11 +00005804 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005805 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005806 QualifierLoc
5807 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5808
5809 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005810 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005811 }
Mike Stump1eb44332009-09-09 15:08:12 +00005812
Eli Friedmanf595cc42009-12-04 06:40:45 +00005813 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005814 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5815 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005816 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00005817 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005818
John McCall6bb80172010-03-30 21:47:33 +00005819 NamedDecl *FoundDecl = E->getFoundDecl();
5820 if (FoundDecl == E->getMemberDecl()) {
5821 FoundDecl = Member;
5822 } else {
5823 FoundDecl = cast_or_null<NamedDecl>(
5824 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5825 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00005826 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00005827 }
5828
Douglas Gregorb98b1992009-08-11 05:31:07 +00005829 if (!getDerived().AlwaysRebuild() &&
5830 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005831 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005832 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00005833 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00005834 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00005835
Anders Carlsson1f240322009-12-22 05:24:09 +00005836 // Mark it referenced in the new context regardless.
5837 // FIXME: this is a bit instantiation-specific.
5838 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00005839 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00005840 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005841
John McCalld5532b62009-11-23 01:53:49 +00005842 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00005843 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00005844 TransArgs.setLAngleLoc(E->getLAngleLoc());
5845 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005846 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5847 E->getNumTemplateArgs(),
5848 TransArgs))
5849 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005850 }
Sean Huntc3021132010-05-05 15:23:54 +00005851
Douglas Gregorb98b1992009-08-11 05:31:07 +00005852 // FIXME: Bogus source location for the operator
5853 SourceLocation FakeOperatorLoc
5854 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5855
John McCallc2233c52010-01-15 08:34:02 +00005856 // FIXME: to do this check properly, we will need to preserve the
5857 // first-qualifier-in-scope here, just in case we had a dependent
5858 // base (and therefore couldn't do the check) and a
5859 // nested-name-qualifier (and therefore could do the lookup).
5860 NamedDecl *FirstQualifierInScope = 0;
5861
John McCall9ae2f072010-08-23 23:25:46 +00005862 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005863 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00005864 QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00005865 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005866 Member,
John McCall6bb80172010-03-30 21:47:33 +00005867 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00005868 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00005869 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00005870 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005871}
Mike Stump1eb44332009-09-09 15:08:12 +00005872
Douglas Gregorb98b1992009-08-11 05:31:07 +00005873template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005874ExprResult
John McCall454feb92009-12-08 09:21:05 +00005875TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005876 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005877 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005878 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005879
John McCall60d7b3a2010-08-24 06:29:42 +00005880 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005881 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005882 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005883
Douglas Gregorb98b1992009-08-11 05:31:07 +00005884 if (!getDerived().AlwaysRebuild() &&
5885 LHS.get() == E->getLHS() &&
5886 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005887 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005888
Douglas Gregorb98b1992009-08-11 05:31:07 +00005889 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005890 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005891}
5892
Mike Stump1eb44332009-09-09 15:08:12 +00005893template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005894ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005895TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00005896 CompoundAssignOperator *E) {
5897 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005898}
Mike Stump1eb44332009-09-09 15:08:12 +00005899
Douglas Gregorb98b1992009-08-11 05:31:07 +00005900template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00005901ExprResult TreeTransform<Derived>::
5902TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5903 // Just rebuild the common and RHS expressions and see whether we
5904 // get any changes.
5905
5906 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5907 if (commonExpr.isInvalid())
5908 return ExprError();
5909
5910 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5911 if (rhs.isInvalid())
5912 return ExprError();
5913
5914 if (!getDerived().AlwaysRebuild() &&
5915 commonExpr.get() == e->getCommon() &&
5916 rhs.get() == e->getFalseExpr())
5917 return SemaRef.Owned(e);
5918
5919 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5920 e->getQuestionLoc(),
5921 0,
5922 e->getColonLoc(),
5923 rhs.get());
5924}
5925
5926template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005927ExprResult
John McCall454feb92009-12-08 09:21:05 +00005928TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005929 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005930 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005931 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005932
John McCall60d7b3a2010-08-24 06:29:42 +00005933 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005934 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005935 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005936
John McCall60d7b3a2010-08-24 06:29:42 +00005937 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005938 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005939 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005940
Douglas Gregorb98b1992009-08-11 05:31:07 +00005941 if (!getDerived().AlwaysRebuild() &&
5942 Cond.get() == E->getCond() &&
5943 LHS.get() == E->getLHS() &&
5944 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005945 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005946
John McCall9ae2f072010-08-23 23:25:46 +00005947 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005948 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005949 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005950 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005951 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005952}
Mike Stump1eb44332009-09-09 15:08:12 +00005953
5954template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005955ExprResult
John McCall454feb92009-12-08 09:21:05 +00005956TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005957 // Implicit casts are eliminated during transformation, since they
5958 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00005959 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005960}
Mike Stump1eb44332009-09-09 15:08:12 +00005961
Douglas Gregorb98b1992009-08-11 05:31:07 +00005962template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005963ExprResult
John McCall454feb92009-12-08 09:21:05 +00005964TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005965 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5966 if (!Type)
5967 return ExprError();
5968
John McCall60d7b3a2010-08-24 06:29:42 +00005969 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005970 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005971 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005972 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005973
Douglas Gregorb98b1992009-08-11 05:31:07 +00005974 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005975 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005976 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005977 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005978
John McCall9d125032010-01-15 18:39:57 +00005979 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005980 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005981 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005982 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005983}
Mike Stump1eb44332009-09-09 15:08:12 +00005984
Douglas Gregorb98b1992009-08-11 05:31:07 +00005985template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005986ExprResult
John McCall454feb92009-12-08 09:21:05 +00005987TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00005988 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5989 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5990 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005991 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005992
John McCall60d7b3a2010-08-24 06:29:42 +00005993 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005994 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005995 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005996
Douglas Gregorb98b1992009-08-11 05:31:07 +00005997 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00005998 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005999 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00006000 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006001
John McCall1d7d8d62010-01-19 22:33:45 +00006002 // Note: the expression type doesn't necessarily match the
6003 // type-as-written, but that's okay, because it should always be
6004 // derivable from the initializer.
6005
John McCall42f56b52010-01-18 19:35:47 +00006006 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006007 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006008 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006009}
Mike Stump1eb44332009-09-09 15:08:12 +00006010
Douglas Gregorb98b1992009-08-11 05:31:07 +00006011template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006012ExprResult
John McCall454feb92009-12-08 09:21:05 +00006013TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006014 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006015 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006016 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006017
Douglas Gregorb98b1992009-08-11 05:31:07 +00006018 if (!getDerived().AlwaysRebuild() &&
6019 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006020 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006021
Douglas Gregorb98b1992009-08-11 05:31:07 +00006022 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006023 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006024 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006025 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006026 E->getAccessorLoc(),
6027 E->getAccessor());
6028}
Mike Stump1eb44332009-09-09 15:08:12 +00006029
Douglas Gregorb98b1992009-08-11 05:31:07 +00006030template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006031ExprResult
John McCall454feb92009-12-08 09:21:05 +00006032TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006033 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006034
John McCallca0408f2010-08-23 06:44:23 +00006035 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006036 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6037 Inits, &InitChanged))
6038 return ExprError();
6039
Douglas Gregorb98b1992009-08-11 05:31:07 +00006040 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006041 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006042
Douglas Gregorb98b1992009-08-11 05:31:07 +00006043 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006044 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006045}
Mike Stump1eb44332009-09-09 15:08:12 +00006046
Douglas Gregorb98b1992009-08-11 05:31:07 +00006047template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006048ExprResult
John McCall454feb92009-12-08 09:21:05 +00006049TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006050 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006051
Douglas Gregor43959a92009-08-20 07:17:43 +00006052 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006053 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006054 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006055 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006056
Douglas Gregor43959a92009-08-20 07:17:43 +00006057 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006058 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006059 bool ExprChanged = false;
6060 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6061 DEnd = E->designators_end();
6062 D != DEnd; ++D) {
6063 if (D->isFieldDesignator()) {
6064 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6065 D->getDotLoc(),
6066 D->getFieldLoc()));
6067 continue;
6068 }
Mike Stump1eb44332009-09-09 15:08:12 +00006069
Douglas Gregorb98b1992009-08-11 05:31:07 +00006070 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006071 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006072 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006073 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006074
6075 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006076 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006077
Douglas Gregorb98b1992009-08-11 05:31:07 +00006078 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6079 ArrayExprs.push_back(Index.release());
6080 continue;
6081 }
Mike Stump1eb44332009-09-09 15:08:12 +00006082
Douglas Gregorb98b1992009-08-11 05:31:07 +00006083 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006084 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006085 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6086 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006087 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006088
John McCall60d7b3a2010-08-24 06:29:42 +00006089 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006090 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006091 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006092
6093 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006094 End.get(),
6095 D->getLBracketLoc(),
6096 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006097
Douglas Gregorb98b1992009-08-11 05:31:07 +00006098 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6099 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006100
Douglas Gregorb98b1992009-08-11 05:31:07 +00006101 ArrayExprs.push_back(Start.release());
6102 ArrayExprs.push_back(End.release());
6103 }
Mike Stump1eb44332009-09-09 15:08:12 +00006104
Douglas Gregorb98b1992009-08-11 05:31:07 +00006105 if (!getDerived().AlwaysRebuild() &&
6106 Init.get() == E->getInit() &&
6107 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006108 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006109
Douglas Gregorb98b1992009-08-11 05:31:07 +00006110 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6111 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006112 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006113}
Mike Stump1eb44332009-09-09 15:08:12 +00006114
Douglas Gregorb98b1992009-08-11 05:31:07 +00006115template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006116ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006117TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006118 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006119 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006120
Douglas Gregor5557b252009-10-28 00:29:27 +00006121 // FIXME: Will we ever have proper type location here? Will we actually
6122 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006123 QualType T = getDerived().TransformType(E->getType());
6124 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006125 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006126
Douglas Gregorb98b1992009-08-11 05:31:07 +00006127 if (!getDerived().AlwaysRebuild() &&
6128 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006129 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006130
Douglas Gregorb98b1992009-08-11 05:31:07 +00006131 return getDerived().RebuildImplicitValueInitExpr(T);
6132}
Mike Stump1eb44332009-09-09 15:08:12 +00006133
Douglas Gregorb98b1992009-08-11 05:31:07 +00006134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006135ExprResult
John McCall454feb92009-12-08 09:21:05 +00006136TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006137 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6138 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006139 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006140
John McCall60d7b3a2010-08-24 06:29:42 +00006141 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006142 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006143 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006144
Douglas Gregorb98b1992009-08-11 05:31:07 +00006145 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006146 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006147 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006148 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006149
John McCall9ae2f072010-08-23 23:25:46 +00006150 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006151 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006152}
6153
6154template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006155ExprResult
John McCall454feb92009-12-08 09:21:05 +00006156TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006157 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006158 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006159 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6160 &ArgumentChanged))
6161 return ExprError();
6162
Douglas Gregorb98b1992009-08-11 05:31:07 +00006163 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6164 move_arg(Inits),
6165 E->getRParenLoc());
6166}
Mike Stump1eb44332009-09-09 15:08:12 +00006167
Douglas Gregorb98b1992009-08-11 05:31:07 +00006168/// \brief Transform an address-of-label expression.
6169///
6170/// By default, the transformation of an address-of-label expression always
6171/// rebuilds the expression, so that the label identifier can be resolved to
6172/// the corresponding label statement by semantic analysis.
6173template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006174ExprResult
John McCall454feb92009-12-08 09:21:05 +00006175TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006176 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6177 E->getLabel());
6178 if (!LD)
6179 return ExprError();
6180
Douglas Gregorb98b1992009-08-11 05:31:07 +00006181 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006182 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006183}
Mike Stump1eb44332009-09-09 15:08:12 +00006184
6185template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006186ExprResult
John McCall454feb92009-12-08 09:21:05 +00006187TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006188 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006189 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6190 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006191 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006192
Douglas Gregorb98b1992009-08-11 05:31:07 +00006193 if (!getDerived().AlwaysRebuild() &&
6194 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00006195 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006196
6197 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006198 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006199 E->getRParenLoc());
6200}
Mike Stump1eb44332009-09-09 15:08:12 +00006201
Douglas Gregorb98b1992009-08-11 05:31:07 +00006202template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006203ExprResult
John McCall454feb92009-12-08 09:21:05 +00006204TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006205 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006206 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006207 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006208
John McCall60d7b3a2010-08-24 06:29:42 +00006209 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006210 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006211 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006212
John McCall60d7b3a2010-08-24 06:29:42 +00006213 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006214 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006215 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006216
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217 if (!getDerived().AlwaysRebuild() &&
6218 Cond.get() == E->getCond() &&
6219 LHS.get() == E->getLHS() &&
6220 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006221 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006222
Douglas Gregorb98b1992009-08-11 05:31:07 +00006223 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006224 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006225 E->getRParenLoc());
6226}
Mike Stump1eb44332009-09-09 15:08:12 +00006227
Douglas Gregorb98b1992009-08-11 05:31:07 +00006228template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006229ExprResult
John McCall454feb92009-12-08 09:21:05 +00006230TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006231 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006232}
6233
6234template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006235ExprResult
John McCall454feb92009-12-08 09:21:05 +00006236TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006237 switch (E->getOperator()) {
6238 case OO_New:
6239 case OO_Delete:
6240 case OO_Array_New:
6241 case OO_Array_Delete:
6242 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006243 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006244
Douglas Gregor668d6d92009-12-13 20:44:55 +00006245 case OO_Call: {
6246 // This is a call to an object's operator().
6247 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6248
6249 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006250 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006251 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006252 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006253
6254 // FIXME: Poor location information
6255 SourceLocation FakeLParenLoc
6256 = SemaRef.PP.getLocForEndOfToken(
6257 static_cast<Expr *>(Object.get())->getLocEnd());
6258
6259 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006260 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006261 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6262 Args))
6263 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006264
John McCall9ae2f072010-08-23 23:25:46 +00006265 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006266 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006267 E->getLocEnd());
6268 }
6269
6270#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6271 case OO_##Name:
6272#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6273#include "clang/Basic/OperatorKinds.def"
6274 case OO_Subscript:
6275 // Handled below.
6276 break;
6277
6278 case OO_Conditional:
6279 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006280 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006281
6282 case OO_None:
6283 case NUM_OVERLOADED_OPERATORS:
6284 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006285 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006286 }
6287
John McCall60d7b3a2010-08-24 06:29:42 +00006288 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006289 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006290 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006291
John McCall60d7b3a2010-08-24 06:29:42 +00006292 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006293 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006294 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006295
John McCall60d7b3a2010-08-24 06:29:42 +00006296 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006297 if (E->getNumArgs() == 2) {
6298 Second = getDerived().TransformExpr(E->getArg(1));
6299 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006300 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006301 }
Mike Stump1eb44332009-09-09 15:08:12 +00006302
Douglas Gregorb98b1992009-08-11 05:31:07 +00006303 if (!getDerived().AlwaysRebuild() &&
6304 Callee.get() == E->getCallee() &&
6305 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006306 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00006307 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006308
Douglas Gregorb98b1992009-08-11 05:31:07 +00006309 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6310 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006311 Callee.get(),
6312 First.get(),
6313 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006314}
Mike Stump1eb44332009-09-09 15:08:12 +00006315
Douglas Gregorb98b1992009-08-11 05:31:07 +00006316template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006317ExprResult
John McCall454feb92009-12-08 09:21:05 +00006318TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6319 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006320}
Mike Stump1eb44332009-09-09 15:08:12 +00006321
Douglas Gregorb98b1992009-08-11 05:31:07 +00006322template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006323ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006324TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6325 // Transform the callee.
6326 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6327 if (Callee.isInvalid())
6328 return ExprError();
6329
6330 // Transform exec config.
6331 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6332 if (EC.isInvalid())
6333 return ExprError();
6334
6335 // Transform arguments.
6336 bool ArgChanged = false;
6337 ASTOwningVector<Expr*> Args(SemaRef);
6338 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6339 &ArgChanged))
6340 return ExprError();
6341
6342 if (!getDerived().AlwaysRebuild() &&
6343 Callee.get() == E->getCallee() &&
6344 !ArgChanged)
6345 return SemaRef.Owned(E);
6346
6347 // FIXME: Wrong source location information for the '('.
6348 SourceLocation FakeLParenLoc
6349 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6350 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6351 move_arg(Args),
6352 E->getRParenLoc(), EC.get());
6353}
6354
6355template<typename Derived>
6356ExprResult
John McCall454feb92009-12-08 09:21:05 +00006357TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006358 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6359 if (!Type)
6360 return ExprError();
6361
John McCall60d7b3a2010-08-24 06:29:42 +00006362 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006363 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006364 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006365 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006366
Douglas Gregorb98b1992009-08-11 05:31:07 +00006367 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006368 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006369 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006370 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006371
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006373 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006374 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6375 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6376 SourceLocation FakeRParenLoc
6377 = SemaRef.PP.getLocForEndOfToken(
6378 E->getSubExpr()->getSourceRange().getEnd());
6379 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006380 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006381 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006382 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006383 FakeRAngleLoc,
6384 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006385 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006386 FakeRParenLoc);
6387}
Mike Stump1eb44332009-09-09 15:08:12 +00006388
Douglas Gregorb98b1992009-08-11 05:31:07 +00006389template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006390ExprResult
John McCall454feb92009-12-08 09:21:05 +00006391TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6392 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006393}
Mike Stump1eb44332009-09-09 15:08:12 +00006394
6395template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006396ExprResult
John McCall454feb92009-12-08 09:21:05 +00006397TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6398 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006399}
6400
Douglas Gregorb98b1992009-08-11 05:31:07 +00006401template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006402ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006403TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006404 CXXReinterpretCastExpr *E) {
6405 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006406}
Mike Stump1eb44332009-09-09 15:08:12 +00006407
Douglas Gregorb98b1992009-08-11 05:31:07 +00006408template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006409ExprResult
John McCall454feb92009-12-08 09:21:05 +00006410TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6411 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006412}
Mike Stump1eb44332009-09-09 15:08:12 +00006413
Douglas Gregorb98b1992009-08-11 05:31:07 +00006414template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006415ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006416TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006417 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006418 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6419 if (!Type)
6420 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006421
John McCall60d7b3a2010-08-24 06:29:42 +00006422 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006423 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006424 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006425 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006426
Douglas Gregorb98b1992009-08-11 05:31:07 +00006427 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006428 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006429 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006430 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006431
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006432 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006433 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006434 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006435 E->getRParenLoc());
6436}
Mike Stump1eb44332009-09-09 15:08:12 +00006437
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006439ExprResult
John McCall454feb92009-12-08 09:21:05 +00006440TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006441 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006442 TypeSourceInfo *TInfo
6443 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6444 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006445 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006446
Douglas Gregorb98b1992009-08-11 05:31:07 +00006447 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006448 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006449 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006450
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006451 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6452 E->getLocStart(),
6453 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006454 E->getLocEnd());
6455 }
Mike Stump1eb44332009-09-09 15:08:12 +00006456
Douglas Gregorb98b1992009-08-11 05:31:07 +00006457 // We don't know whether the expression is potentially evaluated until
6458 // after we perform semantic analysis, so the expression is potentially
6459 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006460 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006461 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006462
John McCall60d7b3a2010-08-24 06:29:42 +00006463 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006464 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006465 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006466
Douglas Gregorb98b1992009-08-11 05:31:07 +00006467 if (!getDerived().AlwaysRebuild() &&
6468 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006469 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006470
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006471 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6472 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006473 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006474 E->getLocEnd());
6475}
6476
6477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006478ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006479TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6480 if (E->isTypeOperand()) {
6481 TypeSourceInfo *TInfo
6482 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6483 if (!TInfo)
6484 return ExprError();
6485
6486 if (!getDerived().AlwaysRebuild() &&
6487 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006488 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006489
6490 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6491 E->getLocStart(),
6492 TInfo,
6493 E->getLocEnd());
6494 }
6495
6496 // We don't know whether the expression is potentially evaluated until
6497 // after we perform semantic analysis, so the expression is potentially
6498 // potentially evaluated.
6499 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6500
6501 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6502 if (SubExpr.isInvalid())
6503 return ExprError();
6504
6505 if (!getDerived().AlwaysRebuild() &&
6506 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006507 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006508
6509 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6510 E->getLocStart(),
6511 SubExpr.get(),
6512 E->getLocEnd());
6513}
6514
6515template<typename Derived>
6516ExprResult
John McCall454feb92009-12-08 09:21:05 +00006517TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006518 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006519}
Mike Stump1eb44332009-09-09 15:08:12 +00006520
Douglas Gregorb98b1992009-08-11 05:31:07 +00006521template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006522ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006523TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006524 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006525 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526}
Mike Stump1eb44332009-09-09 15:08:12 +00006527
Douglas Gregorb98b1992009-08-11 05:31:07 +00006528template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006529ExprResult
John McCall454feb92009-12-08 09:21:05 +00006530TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006531 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6532 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6533 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00006534
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006535 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006536 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006537
Douglas Gregor828a1972010-01-07 23:12:05 +00006538 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539}
Mike Stump1eb44332009-09-09 15:08:12 +00006540
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006542ExprResult
John McCall454feb92009-12-08 09:21:05 +00006543TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006544 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006545 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006546 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006547
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548 if (!getDerived().AlwaysRebuild() &&
6549 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006550 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551
John McCall9ae2f072010-08-23 23:25:46 +00006552 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006553}
Mike Stump1eb44332009-09-09 15:08:12 +00006554
Douglas Gregorb98b1992009-08-11 05:31:07 +00006555template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006556ExprResult
John McCall454feb92009-12-08 09:21:05 +00006557TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006558 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006559 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6560 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006562 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006563
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006564 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006566 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006567
Douglas Gregor036aed12009-12-23 23:03:06 +00006568 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006569}
Mike Stump1eb44332009-09-09 15:08:12 +00006570
Douglas Gregorb98b1992009-08-11 05:31:07 +00006571template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006572ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006573TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6574 CXXScalarValueInitExpr *E) {
6575 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6576 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006577 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006578
Douglas Gregorb98b1992009-08-11 05:31:07 +00006579 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006580 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006581 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006582
Douglas Gregorab6677e2010-09-08 00:15:04 +00006583 return getDerived().RebuildCXXScalarValueInitExpr(T,
6584 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006585 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006586}
Mike Stump1eb44332009-09-09 15:08:12 +00006587
Douglas Gregorb98b1992009-08-11 05:31:07 +00006588template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006589ExprResult
John McCall454feb92009-12-08 09:21:05 +00006590TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006592 TypeSourceInfo *AllocTypeInfo
6593 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6594 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006595 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006596
Douglas Gregorb98b1992009-08-11 05:31:07 +00006597 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006598 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006599 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006600 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006601
Douglas Gregorb98b1992009-08-11 05:31:07 +00006602 // Transform the placement arguments (if any).
6603 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006604 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006605 if (getDerived().TransformExprs(E->getPlacementArgs(),
6606 E->getNumPlacementArgs(), true,
6607 PlacementArgs, &ArgumentChanged))
6608 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006609
Douglas Gregor43959a92009-08-20 07:17:43 +00006610 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00006611 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006612 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6613 ConstructorArgs, &ArgumentChanged))
6614 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006615
Douglas Gregor1af74512010-02-26 00:38:10 +00006616 // Transform constructor, new operator, and delete operator.
6617 CXXConstructorDecl *Constructor = 0;
6618 if (E->getConstructor()) {
6619 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006620 getDerived().TransformDecl(E->getLocStart(),
6621 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006622 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006623 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006624 }
6625
6626 FunctionDecl *OperatorNew = 0;
6627 if (E->getOperatorNew()) {
6628 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006629 getDerived().TransformDecl(E->getLocStart(),
6630 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006631 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006632 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006633 }
6634
6635 FunctionDecl *OperatorDelete = 0;
6636 if (E->getOperatorDelete()) {
6637 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006638 getDerived().TransformDecl(E->getLocStart(),
6639 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006640 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006641 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006642 }
Sean Huntc3021132010-05-05 15:23:54 +00006643
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006645 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006647 Constructor == E->getConstructor() &&
6648 OperatorNew == E->getOperatorNew() &&
6649 OperatorDelete == E->getOperatorDelete() &&
6650 !ArgumentChanged) {
6651 // Mark any declarations we need as referenced.
6652 // FIXME: instantiation-specific.
6653 if (Constructor)
6654 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6655 if (OperatorNew)
6656 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6657 if (OperatorDelete)
6658 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00006659 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006660 }
Mike Stump1eb44332009-09-09 15:08:12 +00006661
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006662 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006663 if (!ArraySize.get()) {
6664 // If no array size was specified, but the new expression was
6665 // instantiated with an array type (e.g., "new T" where T is
6666 // instantiated with "int[4]"), extract the outer bound from the
6667 // array type as our array size. We do this with constant and
6668 // dependently-sized array types.
6669 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6670 if (!ArrayT) {
6671 // Do nothing
6672 } else if (const ConstantArrayType *ConsArrayT
6673 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00006674 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006675 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6676 ConsArrayT->getSize(),
6677 SemaRef.Context.getSizeType(),
6678 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006679 AllocType = ConsArrayT->getElementType();
6680 } else if (const DependentSizedArrayType *DepArrayT
6681 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6682 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00006683 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006684 AllocType = DepArrayT->getElementType();
6685 }
6686 }
6687 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006688
Douglas Gregorb98b1992009-08-11 05:31:07 +00006689 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6690 E->isGlobalNew(),
6691 /*FIXME:*/E->getLocStart(),
6692 move_arg(PlacementArgs),
6693 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00006694 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006696 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00006697 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698 /*FIXME:*/E->getLocStart(),
6699 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00006700 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701}
Mike Stump1eb44332009-09-09 15:08:12 +00006702
Douglas Gregorb98b1992009-08-11 05:31:07 +00006703template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006704ExprResult
John McCall454feb92009-12-08 09:21:05 +00006705TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006706 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006708 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006709
Douglas Gregor1af74512010-02-26 00:38:10 +00006710 // Transform the delete operator, if known.
6711 FunctionDecl *OperatorDelete = 0;
6712 if (E->getOperatorDelete()) {
6713 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006714 getDerived().TransformDecl(E->getLocStart(),
6715 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006716 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006717 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006718 }
Sean Huntc3021132010-05-05 15:23:54 +00006719
Douglas Gregorb98b1992009-08-11 05:31:07 +00006720 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006721 Operand.get() == E->getArgument() &&
6722 OperatorDelete == E->getOperatorDelete()) {
6723 // Mark any declarations we need as referenced.
6724 // FIXME: instantiation-specific.
6725 if (OperatorDelete)
6726 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00006727
6728 if (!E->getArgument()->isTypeDependent()) {
6729 QualType Destroyed = SemaRef.Context.getBaseElementType(
6730 E->getDestroyedType());
6731 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6732 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6733 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6734 SemaRef.LookupDestructor(Record));
6735 }
6736 }
6737
John McCall3fa5cae2010-10-26 07:05:15 +00006738 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006739 }
Mike Stump1eb44332009-09-09 15:08:12 +00006740
Douglas Gregorb98b1992009-08-11 05:31:07 +00006741 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6742 E->isGlobalDelete(),
6743 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00006744 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745}
Mike Stump1eb44332009-09-09 15:08:12 +00006746
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006748ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00006749TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00006750 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006751 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00006752 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006753 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006754
John McCallb3d87482010-08-24 05:47:05 +00006755 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006756 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006757 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006758 E->getOperatorLoc(),
6759 E->isArrow()? tok::arrow : tok::period,
6760 ObjectTypePtr,
6761 MayBePseudoDestructor);
6762 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006763 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006764
John McCallb3d87482010-08-24 05:47:05 +00006765 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006766 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6767 if (QualifierLoc) {
6768 QualifierLoc
6769 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6770 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00006771 return ExprError();
6772 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006773 CXXScopeSpec SS;
6774 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00006775
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006776 PseudoDestructorTypeStorage Destroyed;
6777 if (E->getDestroyedTypeInfo()) {
6778 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00006779 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00006780 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006781 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006782 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006783 Destroyed = DestroyedTypeInfo;
6784 } else if (ObjectType->isDependentType()) {
6785 // We aren't likely to be able to resolve the identifier down to a type
6786 // now anyway, so just retain the identifier.
6787 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6788 E->getDestroyedTypeLoc());
6789 } else {
6790 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00006791 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006792 *E->getDestroyedTypeIdentifier(),
6793 E->getDestroyedTypeLoc(),
6794 /*Scope=*/0,
6795 SS, ObjectTypePtr,
6796 false);
6797 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006798 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006799
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006800 Destroyed
6801 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6802 E->getDestroyedTypeLoc());
6803 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006804
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006805 TypeSourceInfo *ScopeTypeInfo = 0;
6806 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00006807 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006808 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006809 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00006810 }
Sean Huntc3021132010-05-05 15:23:54 +00006811
John McCall9ae2f072010-08-23 23:25:46 +00006812 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006813 E->getOperatorLoc(),
6814 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006815 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006816 ScopeTypeInfo,
6817 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006818 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006819 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00006820}
Mike Stump1eb44332009-09-09 15:08:12 +00006821
Douglas Gregora71d8192009-09-04 17:36:40 +00006822template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006823ExprResult
John McCallba135432009-11-21 08:51:07 +00006824TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00006825 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00006826 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6827
6828 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6829 Sema::LookupOrdinaryName);
6830
6831 // Transform all the decls.
6832 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6833 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006834 NamedDecl *InstD = static_cast<NamedDecl*>(
6835 getDerived().TransformDecl(Old->getNameLoc(),
6836 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006837 if (!InstD) {
6838 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6839 // This can happen because of dependent hiding.
6840 if (isa<UsingShadowDecl>(*I))
6841 continue;
6842 else
John McCallf312b1e2010-08-26 23:41:50 +00006843 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006844 }
John McCallf7a1a742009-11-24 19:00:30 +00006845
6846 // Expand using declarations.
6847 if (isa<UsingDecl>(InstD)) {
6848 UsingDecl *UD = cast<UsingDecl>(InstD);
6849 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6850 E = UD->shadow_end(); I != E; ++I)
6851 R.addDecl(*I);
6852 continue;
6853 }
6854
6855 R.addDecl(InstD);
6856 }
6857
6858 // Resolve a kind, but don't do any further analysis. If it's
6859 // ambiguous, the callee needs to deal with it.
6860 R.resolveKind();
6861
6862 // Rebuild the nested-name qualifier, if present.
6863 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00006864 if (Old->getQualifierLoc()) {
6865 NestedNameSpecifierLoc QualifierLoc
6866 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6867 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006868 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006869
Douglas Gregor4c9be892011-02-28 20:01:57 +00006870 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00006871 }
6872
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006873 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00006874 CXXRecordDecl *NamingClass
6875 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6876 Old->getNameLoc(),
6877 Old->getNamingClass()));
6878 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006879 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006880
Douglas Gregor66c45152010-04-27 16:10:10 +00006881 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00006882 }
6883
6884 // If we have no template arguments, it's a normal declaration name.
6885 if (!Old->hasExplicitTemplateArgs())
6886 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6887
6888 // If we have template arguments, rebuild them, then rebuild the
6889 // templateid expression.
6890 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006891 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6892 Old->getNumTemplateArgs(),
6893 TransArgs))
6894 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00006895
6896 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6897 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006898}
Mike Stump1eb44332009-09-09 15:08:12 +00006899
Douglas Gregorb98b1992009-08-11 05:31:07 +00006900template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006901ExprResult
John McCall454feb92009-12-08 09:21:05 +00006902TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006903 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6904 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006905 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006906
Douglas Gregorb98b1992009-08-11 05:31:07 +00006907 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006908 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006909 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006910
Mike Stump1eb44332009-09-09 15:08:12 +00006911 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006912 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913 T,
6914 E->getLocEnd());
6915}
Mike Stump1eb44332009-09-09 15:08:12 +00006916
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006918ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00006919TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6920 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6921 if (!LhsT)
6922 return ExprError();
6923
6924 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6925 if (!RhsT)
6926 return ExprError();
6927
6928 if (!getDerived().AlwaysRebuild() &&
6929 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6930 return SemaRef.Owned(E);
6931
6932 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6933 E->getLocStart(),
6934 LhsT, RhsT,
6935 E->getLocEnd());
6936}
6937
6938template<typename Derived>
6939ExprResult
John McCall865d4472009-11-19 22:55:06 +00006940TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006941 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00006942 NestedNameSpecifierLoc QualifierLoc
6943 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6944 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006945 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006946
John McCall43fed0d2010-11-12 08:19:04 +00006947 // TODO: If this is a conversion-function-id, verify that the
6948 // destination type name (if present) resolves the same way after
6949 // instantiation as it did in the local scope.
6950
Abramo Bagnara25777432010-08-11 22:01:17 +00006951 DeclarationNameInfo NameInfo
6952 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6953 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006954 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006955
John McCallf7a1a742009-11-24 19:00:30 +00006956 if (!E->hasExplicitTemplateArgs()) {
6957 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00006958 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006959 // Note: it is sufficient to compare the Name component of NameInfo:
6960 // if name has not changed, DNLoc has not changed either.
6961 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00006962 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006963
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00006964 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006965 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006966 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00006967 }
John McCalld5532b62009-11-23 01:53:49 +00006968
6969 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006970 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6971 E->getNumTemplateArgs(),
6972 TransArgs))
6973 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00006975 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006976 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006977 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006978}
6979
6980template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006981ExprResult
John McCall454feb92009-12-08 09:21:05 +00006982TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00006983 // CXXConstructExprs are always implicit, so when we have a
6984 // 1-argument construction we just transform that argument.
6985 if (E->getNumArgs() == 1 ||
6986 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6987 return getDerived().TransformExpr(E->getArg(0));
6988
Douglas Gregorb98b1992009-08-11 05:31:07 +00006989 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6990
6991 QualType T = getDerived().TransformType(E->getType());
6992 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006993 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006994
6995 CXXConstructorDecl *Constructor
6996 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006997 getDerived().TransformDecl(E->getLocStart(),
6998 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006999 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007000 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007001
Douglas Gregorb98b1992009-08-11 05:31:07 +00007002 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007003 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007004 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7005 &ArgumentChanged))
7006 return ExprError();
7007
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008 if (!getDerived().AlwaysRebuild() &&
7009 T == E->getType() &&
7010 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007011 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007012 // Mark the constructor as referenced.
7013 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00007014 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007015 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007016 }
Mike Stump1eb44332009-09-09 15:08:12 +00007017
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007018 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7019 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007020 move_arg(Args),
7021 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007022 E->getConstructionKind(),
7023 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024}
Mike Stump1eb44332009-09-09 15:08:12 +00007025
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026/// \brief Transform a C++ temporary-binding expression.
7027///
Douglas Gregor51326552009-12-24 18:51:59 +00007028/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7029/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007031ExprResult
John McCall454feb92009-12-08 09:21:05 +00007032TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007033 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007034}
Mike Stump1eb44332009-09-09 15:08:12 +00007035
John McCall4765fa02010-12-06 08:20:24 +00007036/// \brief Transform a C++ expression that contains cleanups that should
7037/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007038///
John McCall4765fa02010-12-06 08:20:24 +00007039/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007040/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007042ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007043TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007044 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045}
Mike Stump1eb44332009-09-09 15:08:12 +00007046
Douglas Gregorb98b1992009-08-11 05:31:07 +00007047template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007048ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007049TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007050 CXXTemporaryObjectExpr *E) {
7051 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7052 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007053 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007054
Douglas Gregorb98b1992009-08-11 05:31:07 +00007055 CXXConstructorDecl *Constructor
7056 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007057 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007058 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007059 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007060 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007061
Douglas Gregorb98b1992009-08-11 05:31:07 +00007062 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007063 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007065 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7066 &ArgumentChanged))
7067 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007068
Douglas Gregorb98b1992009-08-11 05:31:07 +00007069 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007070 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007071 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007072 !ArgumentChanged) {
7073 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00007074 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007075 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007076 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007077
7078 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7079 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007080 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007081 E->getLocEnd());
7082}
Mike Stump1eb44332009-09-09 15:08:12 +00007083
Douglas Gregorb98b1992009-08-11 05:31:07 +00007084template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007085ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007086TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007087 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007088 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7089 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007090 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007091
Douglas Gregorb98b1992009-08-11 05:31:07 +00007092 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007093 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007094 Args.reserve(E->arg_size());
7095 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7096 &ArgumentChanged))
7097 return ExprError();
7098
Douglas Gregorb98b1992009-08-11 05:31:07 +00007099 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007100 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007101 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007102 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007103
Douglas Gregorb98b1992009-08-11 05:31:07 +00007104 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007105 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007106 E->getLParenLoc(),
7107 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007108 E->getRParenLoc());
7109}
Mike Stump1eb44332009-09-09 15:08:12 +00007110
Douglas Gregorb98b1992009-08-11 05:31:07 +00007111template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007112ExprResult
John McCall865d4472009-11-19 22:55:06 +00007113TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007114 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007115 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007116 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007117 Expr *OldBase;
7118 QualType BaseType;
7119 QualType ObjectType;
7120 if (!E->isImplicitAccess()) {
7121 OldBase = E->getBase();
7122 Base = getDerived().TransformExpr(OldBase);
7123 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007124 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007125
John McCallaa81e162009-12-01 22:10:20 +00007126 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007127 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007128 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007129 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007130 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007131 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007132 ObjectTy,
7133 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007134 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007135 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007136
John McCallb3d87482010-08-24 05:47:05 +00007137 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007138 BaseType = ((Expr*) Base.get())->getType();
7139 } else {
7140 OldBase = 0;
7141 BaseType = getDerived().TransformType(E->getBaseType());
7142 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7143 }
Mike Stump1eb44332009-09-09 15:08:12 +00007144
Douglas Gregor6cd21982009-10-20 05:58:46 +00007145 // Transform the first part of the nested-name-specifier that qualifies
7146 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007147 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007148 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007149 E->getFirstQualifierFoundInScope(),
7150 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007151
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007152 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007153 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007154 QualifierLoc
7155 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7156 ObjectType,
7157 FirstQualifierInScope);
7158 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007159 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007160 }
Mike Stump1eb44332009-09-09 15:08:12 +00007161
John McCall43fed0d2010-11-12 08:19:04 +00007162 // TODO: If this is a conversion-function-id, verify that the
7163 // destination type name (if present) resolves the same way after
7164 // instantiation as it did in the local scope.
7165
Abramo Bagnara25777432010-08-11 22:01:17 +00007166 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007167 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007168 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007169 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007170
John McCallaa81e162009-12-01 22:10:20 +00007171 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007172 // This is a reference to a member without an explicitly-specified
7173 // template argument list. Optimize for this common case.
7174 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007175 Base.get() == OldBase &&
7176 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007177 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007178 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007179 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007180 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007181
John McCall9ae2f072010-08-23 23:25:46 +00007182 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007183 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007184 E->isArrow(),
7185 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007186 QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00007187 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007188 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007189 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007190 }
7191
John McCalld5532b62009-11-23 01:53:49 +00007192 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007193 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7194 E->getNumTemplateArgs(),
7195 TransArgs))
7196 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007197
John McCall9ae2f072010-08-23 23:25:46 +00007198 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007199 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007200 E->isArrow(),
7201 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007202 QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007203 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007204 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007205 &TransArgs);
7206}
7207
7208template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007209ExprResult
John McCall454feb92009-12-08 09:21:05 +00007210TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007211 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007212 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007213 QualType BaseType;
7214 if (!Old->isImplicitAccess()) {
7215 Base = getDerived().TransformExpr(Old->getBase());
7216 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007217 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007218 BaseType = ((Expr*) Base.get())->getType();
7219 } else {
7220 BaseType = getDerived().TransformType(Old->getBaseType());
7221 }
John McCall129e2df2009-11-30 22:42:35 +00007222
Douglas Gregor4c9be892011-02-28 20:01:57 +00007223 NestedNameSpecifierLoc QualifierLoc;
7224 if (Old->getQualifierLoc()) {
7225 QualifierLoc
7226 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7227 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007228 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007229 }
7230
Abramo Bagnara25777432010-08-11 22:01:17 +00007231 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007232 Sema::LookupOrdinaryName);
7233
7234 // Transform all the decls.
7235 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7236 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007237 NamedDecl *InstD = static_cast<NamedDecl*>(
7238 getDerived().TransformDecl(Old->getMemberLoc(),
7239 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007240 if (!InstD) {
7241 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7242 // This can happen because of dependent hiding.
7243 if (isa<UsingShadowDecl>(*I))
7244 continue;
7245 else
John McCallf312b1e2010-08-26 23:41:50 +00007246 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007247 }
John McCall129e2df2009-11-30 22:42:35 +00007248
7249 // Expand using declarations.
7250 if (isa<UsingDecl>(InstD)) {
7251 UsingDecl *UD = cast<UsingDecl>(InstD);
7252 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7253 E = UD->shadow_end(); I != E; ++I)
7254 R.addDecl(*I);
7255 continue;
7256 }
7257
7258 R.addDecl(InstD);
7259 }
7260
7261 R.resolveKind();
7262
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007263 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007264 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007265 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007266 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007267 Old->getMemberLoc(),
7268 Old->getNamingClass()));
7269 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007270 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007271
Douglas Gregor66c45152010-04-27 16:10:10 +00007272 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007273 }
Sean Huntc3021132010-05-05 15:23:54 +00007274
John McCall129e2df2009-11-30 22:42:35 +00007275 TemplateArgumentListInfo TransArgs;
7276 if (Old->hasExplicitTemplateArgs()) {
7277 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7278 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007279 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7280 Old->getNumTemplateArgs(),
7281 TransArgs))
7282 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007283 }
John McCallc2233c52010-01-15 08:34:02 +00007284
7285 // FIXME: to do this check properly, we will need to preserve the
7286 // first-qualifier-in-scope here, just in case we had a dependent
7287 // base (and therefore couldn't do the check) and a
7288 // nested-name-qualifier (and therefore could do the lookup).
7289 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007290
John McCall9ae2f072010-08-23 23:25:46 +00007291 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007292 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007293 Old->getOperatorLoc(),
7294 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007295 QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00007296 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007297 R,
7298 (Old->hasExplicitTemplateArgs()
7299 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007300}
7301
7302template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007303ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007304TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7305 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7306 if (SubExpr.isInvalid())
7307 return ExprError();
7308
7309 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007310 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007311
7312 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7313}
7314
7315template<typename Derived>
7316ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007317TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007318 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7319 if (Pattern.isInvalid())
7320 return ExprError();
7321
7322 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7323 return SemaRef.Owned(E);
7324
Douglas Gregor67fd1252011-01-14 21:20:45 +00007325 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7326 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007327}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007328
7329template<typename Derived>
7330ExprResult
7331TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7332 // If E is not value-dependent, then nothing will change when we transform it.
7333 // Note: This is an instantiation-centric view.
7334 if (!E->isValueDependent())
7335 return SemaRef.Owned(E);
7336
7337 // Note: None of the implementations of TryExpandParameterPacks can ever
7338 // produce a diagnostic when given only a single unexpanded parameter pack,
7339 // so
7340 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7341 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007342 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007343 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007344 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7345 &Unexpanded, 1,
Douglas Gregord3731192011-01-10 07:32:04 +00007346 ShouldExpand, RetainExpansion,
7347 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007348 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007349
Douglas Gregord3731192011-01-10 07:32:04 +00007350 if (!ShouldExpand || RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007351 return SemaRef.Owned(E);
7352
7353 // We now know the length of the parameter pack, so build a new expression
7354 // that stores that length.
7355 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7356 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00007357 *NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007358}
7359
Douglas Gregorbe230c32011-01-03 17:17:50 +00007360template<typename Derived>
7361ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007362TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7363 SubstNonTypeTemplateParmPackExpr *E) {
7364 // Default behavior is to do nothing with this transformation.
7365 return SemaRef.Owned(E);
7366}
7367
7368template<typename Derived>
7369ExprResult
John McCall454feb92009-12-08 09:21:05 +00007370TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007371 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007372}
7373
Mike Stump1eb44332009-09-09 15:08:12 +00007374template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007375ExprResult
John McCall454feb92009-12-08 09:21:05 +00007376TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007377 TypeSourceInfo *EncodedTypeInfo
7378 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7379 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007380 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007381
Douglas Gregorb98b1992009-08-11 05:31:07 +00007382 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007383 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007384 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007385
7386 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007387 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007388 E->getRParenLoc());
7389}
Mike Stump1eb44332009-09-09 15:08:12 +00007390
Douglas Gregorb98b1992009-08-11 05:31:07 +00007391template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007392ExprResult
John McCall454feb92009-12-08 09:21:05 +00007393TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007394 // Transform arguments.
7395 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007396 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007397 Args.reserve(E->getNumArgs());
7398 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7399 &ArgChanged))
7400 return ExprError();
7401
Douglas Gregor92e986e2010-04-22 16:44:27 +00007402 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7403 // Class message: transform the receiver type.
7404 TypeSourceInfo *ReceiverTypeInfo
7405 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7406 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007407 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007408
Douglas Gregor92e986e2010-04-22 16:44:27 +00007409 // If nothing changed, just retain the existing message send.
7410 if (!getDerived().AlwaysRebuild() &&
7411 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007412 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007413
7414 // Build a new class message send.
7415 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7416 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007417 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007418 E->getMethodDecl(),
7419 E->getLeftLoc(),
7420 move_arg(Args),
7421 E->getRightLoc());
7422 }
7423
7424 // Instance message: transform the receiver
7425 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7426 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007427 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007428 = getDerived().TransformExpr(E->getInstanceReceiver());
7429 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007430 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007431
7432 // If nothing changed, just retain the existing message send.
7433 if (!getDerived().AlwaysRebuild() &&
7434 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007435 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007436
Douglas Gregor92e986e2010-04-22 16:44:27 +00007437 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00007438 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007439 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007440 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007441 E->getMethodDecl(),
7442 E->getLeftLoc(),
7443 move_arg(Args),
7444 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007445}
7446
Mike Stump1eb44332009-09-09 15:08:12 +00007447template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007448ExprResult
John McCall454feb92009-12-08 09:21:05 +00007449TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007450 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007451}
7452
Mike Stump1eb44332009-09-09 15:08:12 +00007453template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007454ExprResult
John McCall454feb92009-12-08 09:21:05 +00007455TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007456 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007457}
7458
Mike Stump1eb44332009-09-09 15:08:12 +00007459template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007460ExprResult
John McCall454feb92009-12-08 09:21:05 +00007461TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007462 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007463 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007464 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007465 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007466
7467 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007468
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007469 // If nothing changed, just retain the existing expression.
7470 if (!getDerived().AlwaysRebuild() &&
7471 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007472 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007473
John McCall9ae2f072010-08-23 23:25:46 +00007474 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007475 E->getLocation(),
7476 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007477}
7478
Mike Stump1eb44332009-09-09 15:08:12 +00007479template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007480ExprResult
John McCall454feb92009-12-08 09:21:05 +00007481TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00007482 // 'super' and types never change. Property never changes. Just
7483 // retain the existing expression.
7484 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00007485 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00007486
Douglas Gregore3303542010-04-26 20:47:02 +00007487 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007488 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00007489 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007490 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007491
Douglas Gregore3303542010-04-26 20:47:02 +00007492 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007493
Douglas Gregore3303542010-04-26 20:47:02 +00007494 // If nothing changed, just retain the existing expression.
7495 if (!getDerived().AlwaysRebuild() &&
7496 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007497 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007498
John McCall12f78a62010-12-02 01:19:52 +00007499 if (E->isExplicitProperty())
7500 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7501 E->getExplicitProperty(),
7502 E->getLocation());
7503
7504 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7505 E->getType(),
7506 E->getImplicitPropertyGetter(),
7507 E->getImplicitPropertySetter(),
7508 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007509}
7510
Mike Stump1eb44332009-09-09 15:08:12 +00007511template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007512ExprResult
John McCall454feb92009-12-08 09:21:05 +00007513TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007514 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007515 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007516 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007517 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007518
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007519 // If nothing changed, just retain the existing expression.
7520 if (!getDerived().AlwaysRebuild() &&
7521 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007522 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007523
John McCall9ae2f072010-08-23 23:25:46 +00007524 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007525 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007526}
7527
Mike Stump1eb44332009-09-09 15:08:12 +00007528template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007529ExprResult
John McCall454feb92009-12-08 09:21:05 +00007530TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007531 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007532 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007533 SubExprs.reserve(E->getNumSubExprs());
7534 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7535 SubExprs, &ArgumentChanged))
7536 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007537
Douglas Gregorb98b1992009-08-11 05:31:07 +00007538 if (!getDerived().AlwaysRebuild() &&
7539 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007540 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007541
Douglas Gregorb98b1992009-08-11 05:31:07 +00007542 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7543 move_arg(SubExprs),
7544 E->getRParenLoc());
7545}
7546
Mike Stump1eb44332009-09-09 15:08:12 +00007547template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007548ExprResult
John McCall454feb92009-12-08 09:21:05 +00007549TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00007550 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007551
John McCallc6ac9c32011-02-04 18:33:18 +00007552 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7553 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7554
7555 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7556 llvm::SmallVector<ParmVarDecl*, 4> params;
7557 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007558
7559 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00007560 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7561 oldBlock->param_begin(),
7562 oldBlock->param_size(),
7563 0, paramTypes, &params))
Douglas Gregora779d9c2011-01-19 21:32:01 +00007564 return true;
John McCallc6ac9c32011-02-04 18:33:18 +00007565
7566 const FunctionType *exprFunctionType = E->getFunctionType();
7567 QualType exprResultType = exprFunctionType->getResultType();
7568 if (!exprResultType.isNull()) {
7569 if (!exprResultType->isDependentType())
7570 blockScope->ReturnType = exprResultType;
7571 else if (exprResultType != getSema().Context.DependentTy)
7572 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007573 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00007574
7575 // If the return type has not been determined yet, leave it as a dependent
7576 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00007577 if (blockScope->ReturnType.isNull())
7578 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007579
7580 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00007581 if (blockScope->ReturnType->isObjCObjectType()) {
7582 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00007583 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00007584 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007585 return ExprError();
7586 }
John McCall711c52b2011-01-05 12:14:39 +00007587
John McCallc6ac9c32011-02-04 18:33:18 +00007588 QualType functionType = getDerived().RebuildFunctionProtoType(
7589 blockScope->ReturnType,
7590 paramTypes.data(),
7591 paramTypes.size(),
7592 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00007593 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00007594 exprFunctionType->getExtInfo());
7595 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00007596
7597 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00007598 if (!params.empty())
7599 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregora779d9c2011-01-19 21:32:01 +00007600
7601 // If the return type wasn't explicitly set, it will have been marked as a
7602 // dependent type (DependentTy); clear out the return type setting so
7603 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00007604 if (blockScope->ReturnType == getSema().Context.DependentTy)
7605 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00007606
John McCall711c52b2011-01-05 12:14:39 +00007607 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00007608 StmtResult body = getDerived().TransformStmt(E->getBody());
7609 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00007610 return ExprError();
7611
John McCallc6ac9c32011-02-04 18:33:18 +00007612#ifndef NDEBUG
7613 // In builds with assertions, make sure that we captured everything we
7614 // captured before.
7615
7616 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7617
7618 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7619 e = oldBlock->capture_end(); i != e; ++i) {
John McCall6b5a61b2011-02-07 10:33:21 +00007620 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00007621
7622 // Ignore parameter packs.
7623 if (isa<ParmVarDecl>(oldCapture) &&
7624 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7625 continue;
7626
7627 VarDecl *newCapture =
7628 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7629 oldCapture));
John McCall6b5a61b2011-02-07 10:33:21 +00007630 assert(blockScope->CaptureMap.count(newCapture));
John McCallc6ac9c32011-02-04 18:33:18 +00007631 }
7632#endif
7633
7634 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7635 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007636}
7637
Mike Stump1eb44332009-09-09 15:08:12 +00007638template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007639ExprResult
John McCall454feb92009-12-08 09:21:05 +00007640TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007641 ValueDecl *ND
7642 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7643 E->getDecl()));
7644 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00007645 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00007646
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007647 if (!getDerived().AlwaysRebuild() &&
7648 ND == E->getDecl()) {
7649 // Mark it referenced in the new context regardless.
7650 // FIXME: this is a bit instantiation-specific.
7651 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7652
John McCall3fa5cae2010-10-26 07:05:15 +00007653 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007654 }
7655
Abramo Bagnara25777432010-08-11 22:01:17 +00007656 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00007657 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00007658 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007659}
Mike Stump1eb44332009-09-09 15:08:12 +00007660
Douglas Gregorb98b1992009-08-11 05:31:07 +00007661//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00007662// Type reconstruction
7663//===----------------------------------------------------------------------===//
7664
Mike Stump1eb44332009-09-09 15:08:12 +00007665template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007666QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7667 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007668 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007669 getDerived().getBaseEntity());
7670}
7671
Mike Stump1eb44332009-09-09 15:08:12 +00007672template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007673QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7674 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007675 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007676 getDerived().getBaseEntity());
7677}
7678
Mike Stump1eb44332009-09-09 15:08:12 +00007679template<typename Derived>
7680QualType
John McCall85737a72009-10-30 00:06:24 +00007681TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7682 bool WrittenAsLValue,
7683 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007684 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00007685 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007686}
7687
7688template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007689QualType
John McCall85737a72009-10-30 00:06:24 +00007690TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7691 QualType ClassType,
7692 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007693 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00007694 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007695}
7696
7697template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007698QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00007699TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7700 ArrayType::ArraySizeModifier SizeMod,
7701 const llvm::APInt *Size,
7702 Expr *SizeExpr,
7703 unsigned IndexTypeQuals,
7704 SourceRange BracketsRange) {
7705 if (SizeExpr || !Size)
7706 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7707 IndexTypeQuals, BracketsRange,
7708 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00007709
7710 QualType Types[] = {
7711 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7712 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7713 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00007714 };
7715 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7716 QualType SizeType;
7717 for (unsigned I = 0; I != NumTypes; ++I)
7718 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7719 SizeType = Types[I];
7720 break;
7721 }
Mike Stump1eb44332009-09-09 15:08:12 +00007722
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007723 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7724 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00007725 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007726 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00007727 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007728}
Mike Stump1eb44332009-09-09 15:08:12 +00007729
Douglas Gregor577f75a2009-08-04 16:50:30 +00007730template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007731QualType
7732TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007733 ArrayType::ArraySizeModifier SizeMod,
7734 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00007735 unsigned IndexTypeQuals,
7736 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007737 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00007738 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007739}
7740
7741template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007742QualType
Mike Stump1eb44332009-09-09 15:08:12 +00007743TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007744 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00007745 unsigned IndexTypeQuals,
7746 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007747 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00007748 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007749}
Mike Stump1eb44332009-09-09 15:08:12 +00007750
Douglas Gregor577f75a2009-08-04 16:50:30 +00007751template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007752QualType
7753TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007754 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007755 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007756 unsigned IndexTypeQuals,
7757 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007758 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007759 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007760 IndexTypeQuals, BracketsRange);
7761}
7762
7763template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007764QualType
7765TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007766 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007767 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007768 unsigned IndexTypeQuals,
7769 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007770 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007771 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007772 IndexTypeQuals, BracketsRange);
7773}
7774
7775template<typename Derived>
7776QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00007777 unsigned NumElements,
7778 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00007779 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00007780 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007781}
Mike Stump1eb44332009-09-09 15:08:12 +00007782
Douglas Gregor577f75a2009-08-04 16:50:30 +00007783template<typename Derived>
7784QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7785 unsigned NumElements,
7786 SourceLocation AttributeLoc) {
7787 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7788 NumElements, true);
7789 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007790 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7791 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00007792 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007793}
Mike Stump1eb44332009-09-09 15:08:12 +00007794
Douglas Gregor577f75a2009-08-04 16:50:30 +00007795template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007796QualType
7797TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00007798 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007799 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00007800 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007801}
Mike Stump1eb44332009-09-09 15:08:12 +00007802
Douglas Gregor577f75a2009-08-04 16:50:30 +00007803template<typename Derived>
7804QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00007805 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007806 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00007807 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00007808 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00007809 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00007810 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00007811 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00007812 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007813 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00007814 getDerived().getBaseEntity(),
7815 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007816}
Mike Stump1eb44332009-09-09 15:08:12 +00007817
Douglas Gregor577f75a2009-08-04 16:50:30 +00007818template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00007819QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7820 return SemaRef.Context.getFunctionNoProtoType(T);
7821}
7822
7823template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00007824QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7825 assert(D && "no decl found");
7826 if (D->isInvalidDecl()) return QualType();
7827
Douglas Gregor92e986e2010-04-22 16:44:27 +00007828 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00007829 TypeDecl *Ty;
7830 if (isa<UsingDecl>(D)) {
7831 UsingDecl *Using = cast<UsingDecl>(D);
7832 assert(Using->isTypeName() &&
7833 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7834
7835 // A valid resolved using typename decl points to exactly one type decl.
7836 assert(++Using->shadow_begin() == Using->shadow_end());
7837 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00007838
John McCalled976492009-12-04 22:46:56 +00007839 } else {
7840 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7841 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7842 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7843 }
7844
7845 return SemaRef.Context.getTypeDeclType(Ty);
7846}
7847
7848template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007849QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7850 SourceLocation Loc) {
7851 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007852}
7853
7854template<typename Derived>
7855QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7856 return SemaRef.Context.getTypeOfType(Underlying);
7857}
7858
7859template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007860QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7861 SourceLocation Loc) {
7862 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007863}
7864
7865template<typename Derived>
7866QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00007867 TemplateName Template,
7868 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00007869 const TemplateArgumentListInfo &TemplateArgs) {
7870 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007871}
Mike Stump1eb44332009-09-09 15:08:12 +00007872
Douglas Gregordcee1a12009-08-06 05:28:30 +00007873template<typename Derived>
7874NestedNameSpecifier *
7875TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7876 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00007877 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007878 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00007879 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00007880 CXXScopeSpec SS;
7881 // FIXME: The source location information is all wrong.
Douglas Gregorc34348a2011-02-24 17:54:50 +00007882 SS.MakeTrivial(SemaRef.Context, Prefix, Range);
Douglas Gregor2e4c34a2011-02-24 00:17:56 +00007883 if (SemaRef.BuildCXXNestedNameSpecifier(0, II, /*FIXME:*/Range.getBegin(),
7884 /*FIXME:*/Range.getEnd(),
7885 ObjectType, false,
7886 SS, FirstQualifierInScope,
7887 false))
7888 return 0;
7889
7890 return SS.getScopeRep();
Douglas Gregordcee1a12009-08-06 05:28:30 +00007891}
7892
7893template<typename Derived>
7894NestedNameSpecifier *
7895TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7896 SourceRange Range,
7897 NamespaceDecl *NS) {
7898 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7899}
7900
7901template<typename Derived>
7902NestedNameSpecifier *
7903TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7904 SourceRange Range,
Douglas Gregor14aba762011-02-24 02:36:08 +00007905 NamespaceAliasDecl *Alias) {
7906 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, Alias);
7907}
7908
7909template<typename Derived>
7910NestedNameSpecifier *
7911TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7912 SourceRange Range,
Douglas Gregordcee1a12009-08-06 05:28:30 +00007913 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00007914 QualType T) {
7915 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00007916 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00007917 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00007918 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7919 T.getTypePtr());
7920 }
Mike Stump1eb44332009-09-09 15:08:12 +00007921
Douglas Gregordcee1a12009-08-06 05:28:30 +00007922 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7923 return 0;
7924}
Mike Stump1eb44332009-09-09 15:08:12 +00007925
Douglas Gregord1067e52009-08-06 06:41:21 +00007926template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007927TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007928TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00007929 bool TemplateKW,
7930 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007931 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00007932 Template);
7933}
7934
7935template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007936TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007937TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
7938 const IdentifierInfo &Name,
7939 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00007940 QualType ObjectType,
7941 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007942 UnqualifiedId TemplateName;
7943 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00007944 Sema::TemplateTy Template;
7945 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007946 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007947 SS,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007948 TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00007949 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007950 /*EnteringContext=*/false,
7951 Template);
John McCall43fed0d2010-11-12 08:19:04 +00007952 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00007953}
Mike Stump1eb44332009-09-09 15:08:12 +00007954
Douglas Gregorb98b1992009-08-11 05:31:07 +00007955template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007956TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007957TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007958 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007959 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007960 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007961 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007962 // FIXME: Bogus location information.
7963 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
7964 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00007965 Sema::TemplateTy Template;
7966 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007967 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007968 SS,
7969 Name,
John McCallb3d87482010-08-24 05:47:05 +00007970 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007971 /*EnteringContext=*/false,
7972 Template);
7973 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007974}
Sean Huntc3021132010-05-05 15:23:54 +00007975
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007976template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007977ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007978TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7979 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007980 Expr *OrigCallee,
7981 Expr *First,
7982 Expr *Second) {
7983 Expr *Callee = OrigCallee->IgnoreParenCasts();
7984 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00007985
Douglas Gregorb98b1992009-08-11 05:31:07 +00007986 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00007987 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00007988 if (!First->getType()->isOverloadableType() &&
7989 !Second->getType()->isOverloadableType())
7990 return getSema().CreateBuiltinArraySubscriptExpr(First,
7991 Callee->getLocStart(),
7992 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00007993 } else if (Op == OO_Arrow) {
7994 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00007995 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7996 } else if (Second == 0 || isPostIncDec) {
7997 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007998 // The argument is not of overloadable type, so try to create a
7999 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008000 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008001 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008002
John McCall9ae2f072010-08-23 23:25:46 +00008003 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008004 }
8005 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008006 if (!First->getType()->isOverloadableType() &&
8007 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008008 // Neither of the arguments is an overloadable type, so try to
8009 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008010 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008011 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008012 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008013 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008014 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008015
Douglas Gregorb98b1992009-08-11 05:31:07 +00008016 return move(Result);
8017 }
8018 }
Mike Stump1eb44332009-09-09 15:08:12 +00008019
8020 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008021 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008022 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008023
John McCall9ae2f072010-08-23 23:25:46 +00008024 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008025 assert(ULE->requiresADL());
8026
8027 // FIXME: Do we have to check
8028 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008029 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008030 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008031 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008032 }
Mike Stump1eb44332009-09-09 15:08:12 +00008033
Douglas Gregorb98b1992009-08-11 05:31:07 +00008034 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008035 Expr *Args[2] = { First, Second };
8036 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008037
Douglas Gregorb98b1992009-08-11 05:31:07 +00008038 // Create the overloaded operator invocation for unary operators.
8039 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008040 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008041 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008042 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008043 }
Mike Stump1eb44332009-09-09 15:08:12 +00008044
Sebastian Redlf322ed62009-10-29 20:17:01 +00008045 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00008046 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00008047 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008048 First,
8049 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00008050
Douglas Gregorb98b1992009-08-11 05:31:07 +00008051 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008052 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008053 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008054 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8055 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008056 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008057
Mike Stump1eb44332009-09-09 15:08:12 +00008058 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008059}
Mike Stump1eb44332009-09-09 15:08:12 +00008060
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008062ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008063TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008064 SourceLocation OperatorLoc,
8065 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008066 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008067 TypeSourceInfo *ScopeType,
8068 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008069 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008070 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008071 QualType BaseType = Base->getType();
8072 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008073 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008074 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008075 !BaseType->getAs<PointerType>()->getPointeeType()
8076 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008077 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008078 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008079 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008080 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008081 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008082 /*FIXME?*/true);
8083 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008084
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008085 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008086 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8087 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8088 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8089 NameInfo.setNamedTypeInfo(DestroyedType);
8090
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008091 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008092
John McCall9ae2f072010-08-23 23:25:46 +00008093 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008094 OperatorLoc, isArrow,
8095 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008096 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008097 /*TemplateArgs*/ 0);
8098}
8099
Douglas Gregor577f75a2009-08-04 16:50:30 +00008100} // end namespace clang
8101
8102#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H