blob: 82bfe6fa7063739b1b021c8ef3492e4265c7766e [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall2d887082010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000036#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCall781472f2010-08-25 08:40:02 +000040using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000041
Douglas Gregor577f75a2009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump1eb44332009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump1eb44332009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
101
102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
106
107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000114
Douglas Gregordfca6f52012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
119
Mike Stump1eb44332009-09-09 15:08:12 +0000120public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000123
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 }
131
John McCall60d7b3a2010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000134
Douglas Gregor577f75a2009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000138
Douglas Gregor577f75a2009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
144 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Douglas Gregor577f75a2009-08-04 16:50:30 +0000146 /// \brief Returns the location of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
148 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000149 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000150 /// provide an alternative implementation that provides better location
151 /// information.
152 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000153
Douglas Gregor577f75a2009-08-04 16:50:30 +0000154 /// \brief Returns the name of the entity being transformed, if that
155 /// information was not available elsewhere in the AST.
156 ///
157 /// By default, returns an empty name. Subclasses can provide an alternative
158 /// implementation with a more precise name.
159 DeclarationName getBaseEntity() { return DeclarationName(); }
160
Douglas Gregorb98b1992009-08-11 05:31:07 +0000161 /// \brief Sets the "base" location and entity when that
162 /// information is known based on another transformation.
163 ///
164 /// By default, the source location and entity are ignored. Subclasses can
165 /// override this function to provide a customized implementation.
166 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000167
Douglas Gregorb98b1992009-08-11 05:31:07 +0000168 /// \brief RAII object that temporarily sets the base location and entity
169 /// used for reporting diagnostics in types.
170 class TemporaryBase {
171 TreeTransform &Self;
172 SourceLocation OldLocation;
173 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000174
Douglas Gregorb98b1992009-08-11 05:31:07 +0000175 public:
176 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000177 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 OldLocation = Self.getDerived().getBaseLocation();
179 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregorae201f72011-01-25 17:51:48 +0000180
181 if (Location.isValid())
182 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000183 }
Mike Stump1eb44332009-09-09 15:08:12 +0000184
Douglas Gregorb98b1992009-08-11 05:31:07 +0000185 ~TemporaryBase() {
186 Self.getDerived().setBase(OldLocation, OldEntity);
187 }
188 };
Mike Stump1eb44332009-09-09 15:08:12 +0000189
190 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000191 /// transformed.
192 ///
193 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000194 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000195 /// not change. For example, template instantiation need not traverse
196 /// non-dependent types.
197 bool AlreadyTransformed(QualType T) {
198 return T.isNull();
199 }
200
Douglas Gregor6eef5192009-12-14 19:27:10 +0000201 /// \brief Determine whether the given call argument should be dropped, e.g.,
202 /// because it is a default argument.
203 ///
204 /// Subclasses can provide an alternative implementation of this routine to
205 /// determine which kinds of call arguments get dropped. By default,
206 /// CXXDefaultArgument nodes are dropped (prior to transformation).
207 bool DropCallArgument(Expr *E) {
208 return E->isDefaultArgument();
209 }
Sean Huntc3021132010-05-05 15:23:54 +0000210
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000211 /// \brief Determine whether we should expand a pack expansion with the
212 /// given set of parameter packs into separate arguments by repeatedly
213 /// transforming the pattern.
214 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000215 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000216 /// Subclasses can override this routine to provide different behavior.
217 ///
218 /// \param EllipsisLoc The location of the ellipsis that identifies the
219 /// pack expansion.
220 ///
221 /// \param PatternRange The source range that covers the entire pattern of
222 /// the pack expansion.
223 ///
224 /// \param Unexpanded The set of unexpanded parameter packs within the
225 /// pattern.
226 ///
227 /// \param NumUnexpanded The number of unexpanded parameter packs in
228 /// \p Unexpanded.
229 ///
230 /// \param ShouldExpand Will be set to \c true if the transformer should
231 /// expand the corresponding pack expansions into separate arguments. When
232 /// set, \c NumExpansions must also be set.
233 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000234 /// \param RetainExpansion Whether the caller should add an unexpanded
235 /// pack expansion after all of the expanded arguments. This is used
236 /// when extending explicitly-specified template argument packs per
237 /// C++0x [temp.arg.explicit]p9.
238 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000239 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000240 /// the expanded form of the corresponding pack expansion. This is both an
241 /// input and an output parameter, which can be set by the caller if the
242 /// number of expansions is known a priori (e.g., due to a prior substitution)
243 /// and will be set by the callee when the number of expansions is known.
244 /// The callee must set this value when \c ShouldExpand is \c true; it may
245 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000246 ///
247 /// \returns true if an error occurred (e.g., because the parameter packs
248 /// are to be instantiated with arguments of different lengths), false
249 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
250 /// must be set.
251 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
252 SourceRange PatternRange,
David Blaikiea71f9d02011-09-22 02:34:54 +0000253 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000254 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000255 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000256 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000257 ShouldExpand = false;
258 return false;
259 }
260
Douglas Gregord3731192011-01-10 07:32:04 +0000261 /// \brief "Forget" about the partially-substituted pack template argument,
262 /// when performing an instantiation that must preserve the parameter pack
263 /// use.
264 ///
265 /// This routine is meant to be overridden by the template instantiator.
266 TemplateArgument ForgetPartiallySubstitutedPack() {
267 return TemplateArgument();
268 }
269
270 /// \brief "Remember" the partially-substituted pack template argument
271 /// after performing an instantiation that must preserve the parameter pack
272 /// use.
273 ///
274 /// This routine is meant to be overridden by the template instantiator.
275 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
276
Douglas Gregor12c9c002011-01-07 16:43:16 +0000277 /// \brief Note to the derived class when a function parameter pack is
278 /// being expanded.
279 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
280
Douglas Gregor577f75a2009-08-04 16:50:30 +0000281 /// \brief Transforms the given type into another type.
282 ///
John McCalla2becad2009-10-21 00:40:46 +0000283 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000284 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000285 /// function. This is expensive, but we don't mind, because
286 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000287 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000288 ///
289 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000290 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000291
John McCalla2becad2009-10-21 00:40:46 +0000292 /// \brief Transforms the given type-with-location into a new
293 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000294 ///
John McCalla2becad2009-10-21 00:40:46 +0000295 /// By default, this routine transforms a type by delegating to the
296 /// appropriate TransformXXXType to build a new type. Subclasses
297 /// may override this function (to take over all type
298 /// transformations) or some set of the TransformXXXType functions
299 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000300 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000301
302 /// \brief Transform the given type-with-location into a new
303 /// type, collecting location information in the given builder
304 /// as necessary.
305 ///
John McCall43fed0d2010-11-12 08:19:04 +0000306 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000307
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000308 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000309 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000310 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000311 /// appropriate TransformXXXStmt function to transform a specific kind of
312 /// statement or the TransformExpr() function to transform an expression.
313 /// Subclasses may override this function to transform statements using some
314 /// other mechanism.
315 ///
316 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000317 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000318
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000319 /// \brief Transform the given expression.
320 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000321 /// By default, this routine transforms an expression by delegating to the
322 /// appropriate TransformXXXExpr function to build a new expression.
323 /// Subclasses may override this function to transform expressions using some
324 /// other mechanism.
325 ///
326 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000327 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000328
Douglas Gregoraa165f82011-01-03 19:04:46 +0000329 /// \brief Transform the given list of expressions.
330 ///
331 /// This routine transforms a list of expressions by invoking
332 /// \c TransformExpr() for each subexpression. However, it also provides
333 /// support for variadic templates by expanding any pack expansions (if the
334 /// derived class permits such expansion) along the way. When pack expansions
335 /// are present, the number of outputs may not equal the number of inputs.
336 ///
337 /// \param Inputs The set of expressions to be transformed.
338 ///
339 /// \param NumInputs The number of expressions in \c Inputs.
340 ///
341 /// \param IsCall If \c true, then this transform is being performed on
342 /// function-call arguments, and any arguments that should be dropped, will
343 /// be.
344 ///
345 /// \param Outputs The transformed input expressions will be added to this
346 /// vector.
347 ///
348 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
349 /// due to transformation.
350 ///
351 /// \returns true if an error occurred, false otherwise.
352 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000353 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000354 bool *ArgChanged = 0);
355
Douglas Gregor577f75a2009-08-04 16:50:30 +0000356 /// \brief Transform the given declaration, which is referenced from a type
357 /// or expression.
358 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000359 /// By default, acts as the identity function on declarations, unless the
360 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000361 /// may override this function to provide alternate behavior.
Douglas Gregordfca6f52012-02-13 22:00:16 +0000362 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
363 llvm::DenseMap<Decl *, Decl *>::iterator Known
364 = TransformedLocalDecls.find(D);
365 if (Known != TransformedLocalDecls.end())
366 return Known->second;
367
368 return D;
369 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000370
Douglas Gregordfca6f52012-02-13 22:00:16 +0000371 /// \brief Transform the attributes associated with the given declaration and
372 /// place them on the new declaration.
373 ///
374 /// By default, this operation does nothing. Subclasses may override this
375 /// behavior to transform attributes.
376 void transformAttrs(Decl *Old, Decl *New) { }
377
378 /// \brief Note that a local declaration has been transformed by this
379 /// transformer.
380 ///
381 /// Local declarations are typically transformed via a call to
382 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
383 /// the transformer itself has to transform the declarations. This routine
384 /// can be overridden by a subclass that keeps track of such mappings.
385 void transformedLocalDecl(Decl *Old, Decl *New) {
386 TransformedLocalDecls[Old] = New;
387 }
388
Douglas Gregor43959a92009-08-20 07:17:43 +0000389 /// \brief Transform the definition of the given declaration.
390 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000391 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000392 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000393 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
394 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000395 }
Mike Stump1eb44332009-09-09 15:08:12 +0000396
Douglas Gregor6cd21982009-10-20 05:58:46 +0000397 /// \brief Transform the given declaration, which was the first part of a
398 /// nested-name-specifier in a member access expression.
399 ///
Sean Huntc3021132010-05-05 15:23:54 +0000400 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000401 /// identifier in a nested-name-specifier of a member access expression, e.g.,
402 /// the \c T in \c x->T::member
403 ///
404 /// By default, invokes TransformDecl() to transform the declaration.
405 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000406 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
407 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000408 }
Sean Huntc3021132010-05-05 15:23:54 +0000409
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000410 /// \brief Transform the given nested-name-specifier with source-location
411 /// information.
412 ///
413 /// By default, transforms all of the types and declarations within the
414 /// nested-name-specifier. Subclasses may override this function to provide
415 /// alternate behavior.
416 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
417 NestedNameSpecifierLoc NNS,
418 QualType ObjectType = QualType(),
419 NamedDecl *FirstQualifierInScope = 0);
420
Douglas Gregor81499bb2009-09-03 22:13:48 +0000421 /// \brief Transform the given declaration name.
422 ///
423 /// By default, transforms the types of conversion function, constructor,
424 /// and destructor names and then (if needed) rebuilds the declaration name.
425 /// Identifiers and selectors are returned unmodified. Sublcasses may
426 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000427 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000428 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000429
Douglas Gregor577f75a2009-08-04 16:50:30 +0000430 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000431 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000432 /// \param SS The nested-name-specifier that qualifies the template
433 /// name. This nested-name-specifier must already have been transformed.
434 ///
435 /// \param Name The template name to transform.
436 ///
437 /// \param NameLoc The source location of the template name.
438 ///
439 /// \param ObjectType If we're translating a template name within a member
440 /// access expression, this is the type of the object whose member template
441 /// is being referenced.
442 ///
443 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
444 /// also refers to a name within the current (lexical) scope, this is the
445 /// declaration it refers to.
446 ///
447 /// By default, transforms the template name by transforming the declarations
448 /// and nested-name-specifiers that occur within the template name.
449 /// Subclasses may override this function to provide alternate behavior.
450 TemplateName TransformTemplateName(CXXScopeSpec &SS,
451 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000452 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000453 QualType ObjectType = QualType(),
454 NamedDecl *FirstQualifierInScope = 0);
455
Douglas Gregor577f75a2009-08-04 16:50:30 +0000456 /// \brief Transform the given template argument.
457 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000458 /// By default, this operation transforms the type, expression, or
459 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000460 /// new template argument from the transformed result. Subclasses may
461 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000462 ///
463 /// Returns true if there was an error.
464 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
465 TemplateArgumentLoc &Output);
466
Douglas Gregorfcc12532010-12-20 17:31:10 +0000467 /// \brief Transform the given set of template arguments.
468 ///
469 /// By default, this operation transforms all of the template arguments
470 /// in the input set using \c TransformTemplateArgument(), and appends
471 /// the transformed arguments to the output list.
472 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000473 /// Note that this overload of \c TransformTemplateArguments() is merely
474 /// a convenience function. Subclasses that wish to override this behavior
475 /// should override the iterator-based member template version.
476 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000477 /// \param Inputs The set of template arguments to be transformed.
478 ///
479 /// \param NumInputs The number of template arguments in \p Inputs.
480 ///
481 /// \param Outputs The set of transformed template arguments output by this
482 /// routine.
483 ///
484 /// Returns true if an error occurred.
485 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
486 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000487 TemplateArgumentListInfo &Outputs) {
488 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
489 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000490
491 /// \brief Transform the given set of template arguments.
492 ///
493 /// By default, this operation transforms all of the template arguments
494 /// in the input set using \c TransformTemplateArgument(), and appends
495 /// the transformed arguments to the output list.
496 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000497 /// \param First An iterator to the first template argument.
498 ///
499 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000500 ///
501 /// \param Outputs The set of transformed template arguments output by this
502 /// routine.
503 ///
504 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000505 template<typename InputIterator>
506 bool TransformTemplateArguments(InputIterator First,
507 InputIterator Last,
508 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000509
John McCall833ca992009-10-29 08:12:44 +0000510 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
511 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
512 TemplateArgumentLoc &ArgLoc);
513
John McCalla93c9342009-12-07 02:54:59 +0000514 /// \brief Fakes up a TypeSourceInfo for a type.
515 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
516 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000517 getDerived().getBaseLocation());
518 }
Mike Stump1eb44332009-09-09 15:08:12 +0000519
John McCalla2becad2009-10-21 00:40:46 +0000520#define ABSTRACT_TYPELOC(CLASS, PARENT)
521#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000522 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000523#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000524
John Wiegley28bbe4b2011-04-28 01:08:34 +0000525 StmtResult
526 TransformSEHHandler(Stmt *Handler);
527
John McCall43fed0d2010-11-12 08:19:04 +0000528 QualType
529 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
530 TemplateSpecializationTypeLoc TL,
531 TemplateName Template);
532
533 QualType
534 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
535 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000536 TemplateName Template,
537 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000538
539 QualType
540 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000541 DependentTemplateSpecializationTypeLoc TL,
542 NestedNameSpecifierLoc QualifierLoc);
543
John McCall21ef0fa2010-03-11 09:03:00 +0000544 /// \brief Transforms the parameters of a function type into the
545 /// given vectors.
546 ///
547 /// The result vectors should be kept in sync; null entries in the
548 /// variables vector are acceptable.
549 ///
550 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000551 bool TransformFunctionTypeParams(SourceLocation Loc,
552 ParmVarDecl **Params, unsigned NumParams,
553 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000554 SmallVectorImpl<QualType> &PTypes,
555 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000556
557 /// \brief Transforms a single function-type parameter. Return null
558 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000559 ///
560 /// \param indexAdjustment - A number to add to the parameter's
561 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000562 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000563 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000564 llvm::Optional<unsigned> NumExpansions,
565 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000566
John McCall43fed0d2010-11-12 08:19:04 +0000567 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000568
John McCall60d7b3a2010-08-24 06:29:42 +0000569 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
570 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000571
Douglas Gregor43959a92009-08-20 07:17:43 +0000572#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000573 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000574#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000575 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000576#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000577#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000578
Douglas Gregor577f75a2009-08-04 16:50:30 +0000579 /// \brief Build a new pointer type given its pointee type.
580 ///
581 /// By default, performs semantic analysis when building the pointer type.
582 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000583 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000584
585 /// \brief Build a new block pointer type given its pointee type.
586 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000587 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000588 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000589 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000590
John McCall85737a72009-10-30 00:06:24 +0000591 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000592 ///
John McCall85737a72009-10-30 00:06:24 +0000593 /// By default, performs semantic analysis when building the
594 /// reference type. Subclasses may override this routine to provide
595 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000596 ///
John McCall85737a72009-10-30 00:06:24 +0000597 /// \param LValue whether the type was written with an lvalue sigil
598 /// or an rvalue sigil.
599 QualType RebuildReferenceType(QualType ReferentType,
600 bool LValue,
601 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000602
Douglas Gregor577f75a2009-08-04 16:50:30 +0000603 /// \brief Build a new member pointer type given the pointee type and the
604 /// class type it refers into.
605 ///
606 /// By default, performs semantic analysis when building the member pointer
607 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000608 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
609 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000610
Douglas Gregor577f75a2009-08-04 16:50:30 +0000611 /// \brief Build a new array type given the element type, size
612 /// modifier, size of the array (if known), size expression, and index type
613 /// qualifiers.
614 ///
615 /// By default, performs semantic analysis when building the array type.
616 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000617 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000618 QualType RebuildArrayType(QualType ElementType,
619 ArrayType::ArraySizeModifier SizeMod,
620 const llvm::APInt *Size,
621 Expr *SizeExpr,
622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000624
Douglas Gregor577f75a2009-08-04 16:50:30 +0000625 /// \brief Build a new constant array type given the element type, size
626 /// modifier, (known) size of the array, and index type qualifiers.
627 ///
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000630 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
632 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000635
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 /// \brief Build a new incomplete array type given the element type, size
637 /// modifier, and index type qualifiers.
638 ///
639 /// By default, performs semantic analysis when building the array type.
640 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000641 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000642 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000643 unsigned IndexTypeQuals,
644 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000645
Mike Stump1eb44332009-09-09 15:08:12 +0000646 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000647 /// size modifier, size expression, and index type qualifiers.
648 ///
649 /// By default, performs semantic analysis when building the array type.
650 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000651 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000652 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000653 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 unsigned IndexTypeQuals,
655 SourceRange BracketsRange);
656
Mike Stump1eb44332009-09-09 15:08:12 +0000657 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000658 /// size modifier, size expression, and index type qualifiers.
659 ///
660 /// By default, performs semantic analysis when building the array type.
661 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000662 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000664 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000665 unsigned IndexTypeQuals,
666 SourceRange BracketsRange);
667
668 /// \brief Build a new vector type given the element type and
669 /// number of elements.
670 ///
671 /// By default, performs semantic analysis when building the vector type.
672 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000673 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000674 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000675
Douglas Gregor577f75a2009-08-04 16:50:30 +0000676 /// \brief Build a new extended vector type given the element type and
677 /// number of elements.
678 ///
679 /// By default, performs semantic analysis when building the vector type.
680 /// Subclasses may override this routine to provide different behavior.
681 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
682 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000683
684 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000685 /// given the element type and number of elements.
686 ///
687 /// By default, performs semantic analysis when building the vector type.
688 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000689 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000690 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000691 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000692
Douglas Gregor577f75a2009-08-04 16:50:30 +0000693 /// \brief Build a new function type.
694 ///
695 /// By default, performs semantic analysis when building the function type.
696 /// Subclasses may override this routine to provide different behavior.
697 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000698 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000699 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000700 bool Variadic, bool HasTrailingReturn,
701 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000702 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000703 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000704
John McCalla2becad2009-10-21 00:40:46 +0000705 /// \brief Build a new unprototyped function type.
706 QualType RebuildFunctionNoProtoType(QualType ResultType);
707
John McCalled976492009-12-04 22:46:56 +0000708 /// \brief Rebuild an unresolved typename type, given the decl that
709 /// the UnresolvedUsingTypenameDecl was transformed to.
710 QualType RebuildUnresolvedUsingType(Decl *D);
711
Douglas Gregor577f75a2009-08-04 16:50:30 +0000712 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000713 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000714 return SemaRef.Context.getTypeDeclType(Typedef);
715 }
716
717 /// \brief Build a new class/struct/union type.
718 QualType RebuildRecordType(RecordDecl *Record) {
719 return SemaRef.Context.getTypeDeclType(Record);
720 }
721
722 /// \brief Build a new Enum type.
723 QualType RebuildEnumType(EnumDecl *Enum) {
724 return SemaRef.Context.getTypeDeclType(Enum);
725 }
John McCall7da24312009-09-05 00:15:47 +0000726
Mike Stump1eb44332009-09-09 15:08:12 +0000727 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000728 ///
729 /// By default, performs semantic analysis when building the typeof type.
730 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000731 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000732
Mike Stump1eb44332009-09-09 15:08:12 +0000733 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000734 ///
735 /// By default, builds a new TypeOfType with the given underlying type.
736 QualType RebuildTypeOfType(QualType Underlying);
737
Sean Huntca63c202011-05-24 22:41:36 +0000738 /// \brief Build a new unary transform type.
739 QualType RebuildUnaryTransformType(QualType BaseType,
740 UnaryTransformType::UTTKind UKind,
741 SourceLocation Loc);
742
Mike Stump1eb44332009-09-09 15:08:12 +0000743 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000744 ///
745 /// By default, performs semantic analysis when building the decltype type.
746 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000747 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000748
Richard Smith34b41d92011-02-20 03:19:35 +0000749 /// \brief Build a new C++0x auto type.
750 ///
751 /// By default, builds a new AutoType with the given deduced type.
752 QualType RebuildAutoType(QualType Deduced) {
753 return SemaRef.Context.getAutoType(Deduced);
754 }
755
Douglas Gregor577f75a2009-08-04 16:50:30 +0000756 /// \brief Build a new template specialization type.
757 ///
758 /// By default, performs semantic analysis when building the template
759 /// specialization type. Subclasses may override this routine to provide
760 /// different behavior.
761 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000762 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000763 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000764
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000765 /// \brief Build a new parenthesized type.
766 ///
767 /// By default, builds a new ParenType type from the inner type.
768 /// Subclasses may override this routine to provide different behavior.
769 QualType RebuildParenType(QualType InnerType) {
770 return SemaRef.Context.getParenType(InnerType);
771 }
772
Douglas Gregor577f75a2009-08-04 16:50:30 +0000773 /// \brief Build a new qualified name type.
774 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000775 /// By default, builds a new ElaboratedType type from the keyword,
776 /// the nested-name-specifier and the named type.
777 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000778 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
779 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000780 NestedNameSpecifierLoc QualifierLoc,
781 QualType Named) {
782 return SemaRef.Context.getElaboratedType(Keyword,
783 QualifierLoc.getNestedNameSpecifier(),
784 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000785 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000786
787 /// \brief Build a new typename type that refers to a template-id.
788 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000789 /// By default, builds a new DependentNameType type from the
790 /// nested-name-specifier and the given type. Subclasses may override
791 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000792 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000793 ElaboratedTypeKeyword Keyword,
794 NestedNameSpecifierLoc QualifierLoc,
795 const IdentifierInfo *Name,
796 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000797 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000798 // Rebuild the template name.
799 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000800 CXXScopeSpec SS;
801 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000802 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000803 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000804
805 if (InstName.isNull())
806 return QualType();
807
808 // If it's still dependent, make a dependent specialization.
809 if (InstName.getAsDependentTemplateName())
810 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
811 QualifierLoc.getNestedNameSpecifier(),
812 Name,
813 Args);
814
815 // Otherwise, make an elaborated type wrapping a non-dependent
816 // specialization.
817 QualType T =
818 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
819 if (T.isNull()) return QualType();
820
821 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
822 return T;
823
824 return SemaRef.Context.getElaboratedType(Keyword,
825 QualifierLoc.getNestedNameSpecifier(),
826 T);
827 }
828
Douglas Gregor577f75a2009-08-04 16:50:30 +0000829 /// \brief Build a new typename type that refers to an identifier.
830 ///
831 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000832 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000833 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000834 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000835 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000836 NestedNameSpecifierLoc QualifierLoc,
837 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000838 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000839 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000840 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000841
Douglas Gregor2494dd02011-03-01 01:34:45 +0000842 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000843 // If the name is still dependent, just build a new dependent name type.
844 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000845 return SemaRef.Context.getDependentNameType(Keyword,
846 QualifierLoc.getNestedNameSpecifier(),
847 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000848 }
849
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000850 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000851 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000852 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000853
854 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
855
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000856 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000857 // into a non-dependent elaborated-type-specifier. Find the tag we're
858 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000859 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000860 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
861 if (!DC)
862 return QualType();
863
John McCall56138762010-05-27 06:40:31 +0000864 if (SemaRef.RequireCompleteDeclContext(SS, DC))
865 return QualType();
866
Douglas Gregor40336422010-03-31 22:19:08 +0000867 TagDecl *Tag = 0;
868 SemaRef.LookupQualifiedName(Result, DC);
869 switch (Result.getResultKind()) {
870 case LookupResult::NotFound:
871 case LookupResult::NotFoundInCurrentInstantiation:
872 break;
Sean Huntc3021132010-05-05 15:23:54 +0000873
Douglas Gregor40336422010-03-31 22:19:08 +0000874 case LookupResult::Found:
875 Tag = Result.getAsSingle<TagDecl>();
876 break;
Sean Huntc3021132010-05-05 15:23:54 +0000877
Douglas Gregor40336422010-03-31 22:19:08 +0000878 case LookupResult::FoundOverloaded:
879 case LookupResult::FoundUnresolvedValue:
880 llvm_unreachable("Tag lookup cannot find non-tags");
Sean Huntc3021132010-05-05 15:23:54 +0000881
Douglas Gregor40336422010-03-31 22:19:08 +0000882 case LookupResult::Ambiguous:
883 // Let the LookupResult structure handle ambiguities.
884 return QualType();
885 }
886
887 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000888 // Check where the name exists but isn't a tag type and use that to emit
889 // better diagnostics.
890 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
891 SemaRef.LookupQualifiedName(Result, DC);
892 switch (Result.getResultKind()) {
893 case LookupResult::Found:
894 case LookupResult::FoundOverloaded:
895 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000896 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000897 unsigned Kind = 0;
898 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000899 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
900 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000901 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
902 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
903 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000904 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000905 default:
906 // FIXME: Would be nice to highlight just the source range.
907 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
908 << Kind << Id << DC;
909 break;
910 }
Douglas Gregor40336422010-03-31 22:19:08 +0000911 return QualType();
912 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000913
Richard Trieubbf34c02011-06-10 03:11:26 +0000914 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
915 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000916 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000917 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
918 return QualType();
919 }
920
921 // Build the elaborated-type-specifier type.
922 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000923 return SemaRef.Context.getElaboratedType(Keyword,
924 QualifierLoc.getNestedNameSpecifier(),
925 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000926 }
Mike Stump1eb44332009-09-09 15:08:12 +0000927
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000928 /// \brief Build a new pack expansion type.
929 ///
930 /// By default, builds a new PackExpansionType type from the given pattern.
931 /// Subclasses may override this routine to provide different behavior.
932 QualType RebuildPackExpansionType(QualType Pattern,
933 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000934 SourceLocation EllipsisLoc,
935 llvm::Optional<unsigned> NumExpansions) {
936 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
937 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000938 }
939
Eli Friedmanb001de72011-10-06 23:00:33 +0000940 /// \brief Build a new atomic type given its value type.
941 ///
942 /// By default, performs semantic analysis when building the atomic type.
943 /// Subclasses may override this routine to provide different behavior.
944 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
945
Douglas Gregord1067e52009-08-06 06:41:21 +0000946 /// \brief Build a new template name given a nested name specifier, a flag
947 /// indicating whether the "template" keyword was provided, and the template
948 /// that the template name refers to.
949 ///
950 /// By default, builds the new template name directly. Subclasses may override
951 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000952 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000953 bool TemplateKW,
954 TemplateDecl *Template);
955
Douglas Gregord1067e52009-08-06 06:41:21 +0000956 /// \brief Build a new template name given a nested name specifier and the
957 /// name that is referred to as a template.
958 ///
959 /// By default, performs semantic analysis to determine whether the name can
960 /// be resolved to a specific template, then builds the appropriate kind of
961 /// template name. Subclasses may override this routine to provide different
962 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000963 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
964 const IdentifierInfo &Name,
965 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000966 QualType ObjectType,
967 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000968
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000969 /// \brief Build a new template name given a nested name specifier and the
970 /// overloaded operator name that is referred to as a template.
971 ///
972 /// By default, performs semantic analysis to determine whether the name can
973 /// be resolved to a specific template, then builds the appropriate kind of
974 /// template name. Subclasses may override this routine to provide different
975 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000976 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000977 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000978 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000979 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000980
981 /// \brief Build a new template name given a template template parameter pack
982 /// and the
983 ///
984 /// By default, performs semantic analysis to determine whether the name can
985 /// be resolved to a specific template, then builds the appropriate kind of
986 /// template name. Subclasses may override this routine to provide different
987 /// behavior.
988 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
989 const TemplateArgument &ArgPack) {
990 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
991 }
992
Douglas Gregor43959a92009-08-20 07:17:43 +0000993 /// \brief Build a new compound statement.
994 ///
995 /// By default, performs semantic analysis to build the new statement.
996 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000997 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000998 MultiStmtArg Statements,
999 SourceLocation RBraceLoc,
1000 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001001 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001002 IsStmtExpr);
1003 }
1004
1005 /// \brief Build a new case statement.
1006 ///
1007 /// By default, performs semantic analysis to build the new statement.
1008 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001009 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001010 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001011 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001012 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001013 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001014 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 ColonLoc);
1016 }
Mike Stump1eb44332009-09-09 15:08:12 +00001017
Douglas Gregor43959a92009-08-20 07:17:43 +00001018 /// \brief Attach the body to a new case statement.
1019 ///
1020 /// By default, performs semantic analysis to build the new statement.
1021 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001022 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001023 getSema().ActOnCaseStmtBody(S, Body);
1024 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001025 }
Mike Stump1eb44332009-09-09 15:08:12 +00001026
Douglas Gregor43959a92009-08-20 07:17:43 +00001027 /// \brief Build a new default statement.
1028 ///
1029 /// By default, performs semantic analysis to build the new statement.
1030 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001031 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001033 Stmt *SubStmt) {
1034 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 /*CurScope=*/0);
1036 }
Mike Stump1eb44332009-09-09 15:08:12 +00001037
Douglas Gregor43959a92009-08-20 07:17:43 +00001038 /// \brief Build a new label statement.
1039 ///
1040 /// By default, performs semantic analysis to build the new statement.
1041 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001042 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1043 SourceLocation ColonLoc, Stmt *SubStmt) {
1044 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001045 }
Mike Stump1eb44332009-09-09 15:08:12 +00001046
Douglas Gregor43959a92009-08-20 07:17:43 +00001047 /// \brief Build a new "if" statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001051 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001052 VarDecl *CondVar, Stmt *Then,
1053 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001054 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 }
Mike Stump1eb44332009-09-09 15:08:12 +00001056
Douglas Gregor43959a92009-08-20 07:17:43 +00001057 /// \brief Start building a new switch statement.
1058 ///
1059 /// By default, performs semantic analysis to build the new statement.
1060 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001061 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001062 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001063 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001064 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001065 }
Mike Stump1eb44332009-09-09 15:08:12 +00001066
Douglas Gregor43959a92009-08-20 07:17:43 +00001067 /// \brief Attach the body to the switch statement.
1068 ///
1069 /// By default, performs semantic analysis to build the new statement.
1070 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001071 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001072 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001073 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001074 }
1075
1076 /// \brief Build a new while statement.
1077 ///
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001080 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1081 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001082 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001083 }
Mike Stump1eb44332009-09-09 15:08:12 +00001084
Douglas Gregor43959a92009-08-20 07:17:43 +00001085 /// \brief Build a new do-while statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001089 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001090 SourceLocation WhileLoc, SourceLocation LParenLoc,
1091 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001092 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1093 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 }
1095
1096 /// \brief Build a new for statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001100 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1101 Stmt *Init, Sema::FullExprArg Cond,
1102 VarDecl *CondVar, Sema::FullExprArg Inc,
1103 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001104 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001105 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001106 }
Mike Stump1eb44332009-09-09 15:08:12 +00001107
Douglas Gregor43959a92009-08-20 07:17:43 +00001108 /// \brief Build a new goto statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001112 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1113 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001114 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001115 }
1116
1117 /// \brief Build a new indirect goto statement.
1118 ///
1119 /// By default, performs semantic analysis to build the new statement.
1120 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001121 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001122 SourceLocation StarLoc,
1123 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001124 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001125 }
Mike Stump1eb44332009-09-09 15:08:12 +00001126
Douglas Gregor43959a92009-08-20 07:17:43 +00001127 /// \brief Build a new return statement.
1128 ///
1129 /// By default, performs semantic analysis to build the new statement.
1130 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001131 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001132 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001133 }
Mike Stump1eb44332009-09-09 15:08:12 +00001134
Douglas Gregor43959a92009-08-20 07:17:43 +00001135 /// \brief Build a new declaration statement.
1136 ///
1137 /// By default, performs semantic analysis to build the new statement.
1138 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001139 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001140 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001141 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001142 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1143 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001144 }
Mike Stump1eb44332009-09-09 15:08:12 +00001145
Anders Carlsson703e3942010-01-24 05:50:09 +00001146 /// \brief Build a new inline asm statement.
1147 ///
1148 /// By default, performs semantic analysis to build the new statement.
1149 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001150 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001151 bool IsSimple,
1152 bool IsVolatile,
1153 unsigned NumOutputs,
1154 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001155 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001156 MultiExprArg Constraints,
1157 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001158 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001159 MultiExprArg Clobbers,
1160 SourceLocation RParenLoc,
1161 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001162 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001163 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001164 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001165 RParenLoc, MSAsm);
1166 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001167
1168 /// \brief Build a new Objective-C @try statement.
1169 ///
1170 /// By default, performs semantic analysis to build the new statement.
1171 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001172 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001173 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001174 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001175 Stmt *Finally) {
1176 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1177 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001178 }
1179
Douglas Gregorbe270a02010-04-26 17:57:08 +00001180 /// \brief Rebuild an Objective-C exception declaration.
1181 ///
1182 /// By default, performs semantic analysis to build the new declaration.
1183 /// Subclasses may override this routine to provide different behavior.
1184 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1185 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001186 return getSema().BuildObjCExceptionDecl(TInfo, T,
1187 ExceptionDecl->getInnerLocStart(),
1188 ExceptionDecl->getLocation(),
1189 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001190 }
Sean Huntc3021132010-05-05 15:23:54 +00001191
Douglas Gregorbe270a02010-04-26 17:57:08 +00001192 /// \brief Build a new Objective-C @catch statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001196 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001197 SourceLocation RParenLoc,
1198 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001199 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001200 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001201 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001202 }
Sean Huntc3021132010-05-05 15:23:54 +00001203
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001204 /// \brief Build a new Objective-C @finally statement.
1205 ///
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001208 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001209 Stmt *Body) {
1210 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001211 }
Sean Huntc3021132010-05-05 15:23:54 +00001212
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001213 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001214 ///
1215 /// By default, performs semantic analysis to build the new statement.
1216 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001217 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001218 Expr *Operand) {
1219 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001220 }
Sean Huntc3021132010-05-05 15:23:54 +00001221
John McCall07524032011-07-27 21:50:02 +00001222 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
1226 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1227 Expr *object) {
1228 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1229 }
1230
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001231 /// \brief Build a new Objective-C @synchronized statement.
1232 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001233 /// By default, performs semantic analysis to build the new statement.
1234 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001235 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001236 Expr *Object, Stmt *Body) {
1237 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001238 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001239
John McCallf85e1932011-06-15 23:02:42 +00001240 /// \brief Build a new Objective-C @autoreleasepool statement.
1241 ///
1242 /// By default, performs semantic analysis to build the new statement.
1243 /// Subclasses may override this routine to provide different behavior.
1244 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1245 Stmt *Body) {
1246 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1247 }
John McCall990567c2011-07-27 01:07:15 +00001248
1249 /// \brief Build the collection operand to a new Objective-C fast
1250 /// enumeration statement.
1251 ///
1252 /// By default, performs semantic analysis to build the new statement.
1253 /// Subclasses may override this routine to provide different behavior.
1254 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1255 Expr *collection) {
1256 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1257 }
John McCallf85e1932011-06-15 23:02:42 +00001258
Douglas Gregorc3203e72010-04-22 23:10:45 +00001259 /// \brief Build a new Objective-C fast enumeration statement.
1260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001263 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001264 SourceLocation LParenLoc,
1265 Stmt *Element,
1266 Expr *Collection,
1267 SourceLocation RParenLoc,
1268 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001269 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001270 Element,
1271 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001272 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001273 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001274 }
Sean Huntc3021132010-05-05 15:23:54 +00001275
Douglas Gregor43959a92009-08-20 07:17:43 +00001276 /// \brief Build a new C++ exception declaration.
1277 ///
1278 /// By default, performs semantic analysis to build the new decaration.
1279 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001280 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001281 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001282 SourceLocation StartLoc,
1283 SourceLocation IdLoc,
1284 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001285 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1286 StartLoc, IdLoc, Id);
1287 if (Var)
1288 getSema().CurContext->addDecl(Var);
1289 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001290 }
1291
1292 /// \brief Build a new C++ catch statement.
1293 ///
1294 /// By default, performs semantic analysis to build the new statement.
1295 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001296 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001297 VarDecl *ExceptionDecl,
1298 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001299 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1300 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001301 }
Mike Stump1eb44332009-09-09 15:08:12 +00001302
Douglas Gregor43959a92009-08-20 07:17:43 +00001303 /// \brief Build a new C++ try statement.
1304 ///
1305 /// By default, performs semantic analysis to build the new statement.
1306 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001307 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001308 Stmt *TryBlock,
1309 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001310 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001311 }
Mike Stump1eb44332009-09-09 15:08:12 +00001312
Richard Smithad762fc2011-04-14 22:09:26 +00001313 /// \brief Build a new C++0x range-based for statement.
1314 ///
1315 /// By default, performs semantic analysis to build the new statement.
1316 /// Subclasses may override this routine to provide different behavior.
1317 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1318 SourceLocation ColonLoc,
1319 Stmt *Range, Stmt *BeginEnd,
1320 Expr *Cond, Expr *Inc,
1321 Stmt *LoopVar,
1322 SourceLocation RParenLoc) {
1323 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1324 Cond, Inc, LoopVar, RParenLoc);
1325 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001326
1327 /// \brief Build a new C++0x range-based for statement.
1328 ///
1329 /// By default, performs semantic analysis to build the new statement.
1330 /// Subclasses may override this routine to provide different behavior.
1331 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1332 bool IsIfExists,
1333 NestedNameSpecifierLoc QualifierLoc,
1334 DeclarationNameInfo NameInfo,
1335 Stmt *Nested) {
1336 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1337 QualifierLoc, NameInfo, Nested);
1338 }
1339
Richard Smithad762fc2011-04-14 22:09:26 +00001340 /// \brief Attach body to a C++0x range-based for statement.
1341 ///
1342 /// By default, performs semantic analysis to finish the new statement.
1343 /// Subclasses may override this routine to provide different behavior.
1344 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1345 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1346 }
1347
John Wiegley28bbe4b2011-04-28 01:08:34 +00001348 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1349 SourceLocation TryLoc,
1350 Stmt *TryBlock,
1351 Stmt *Handler) {
1352 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1353 }
1354
1355 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1356 Expr *FilterExpr,
1357 Stmt *Block) {
1358 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1359 }
1360
1361 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1362 Stmt *Block) {
1363 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1364 }
1365
Douglas Gregorb98b1992009-08-11 05:31:07 +00001366 /// \brief Build a new expression that references a declaration.
1367 ///
1368 /// By default, performs semantic analysis to build the new expression.
1369 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001370 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001371 LookupResult &R,
1372 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001373 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1374 }
1375
1376
1377 /// \brief Build a new expression that references a declaration.
1378 ///
1379 /// By default, performs semantic analysis to build the new expression.
1380 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001381 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001382 ValueDecl *VD,
1383 const DeclarationNameInfo &NameInfo,
1384 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001385 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001386 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001387
1388 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001389
1390 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001391 }
Mike Stump1eb44332009-09-09 15:08:12 +00001392
Douglas Gregorb98b1992009-08-11 05:31:07 +00001393 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001394 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001395 /// By default, performs semantic analysis to build the new expression.
1396 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001397 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001398 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001399 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 }
1401
Douglas Gregora71d8192009-09-04 17:36:40 +00001402 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001403 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001406 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001407 SourceLocation OperatorLoc,
1408 bool isArrow,
1409 CXXScopeSpec &SS,
1410 TypeSourceInfo *ScopeType,
1411 SourceLocation CCLoc,
1412 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001413 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001414
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001416 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 /// By default, performs semantic analysis to build the new expression.
1418 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001419 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001420 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001421 Expr *SubExpr) {
1422 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001423 }
Mike Stump1eb44332009-09-09 15:08:12 +00001424
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001425 /// \brief Build a new builtin offsetof expression.
1426 ///
1427 /// By default, performs semantic analysis to build the new expression.
1428 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001429 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001430 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001431 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001432 unsigned NumComponents,
1433 SourceLocation RParenLoc) {
1434 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1435 NumComponents, RParenLoc);
1436 }
Sean Huntc3021132010-05-05 15:23:54 +00001437
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001438 /// \brief Build a new sizeof, alignof or vec_step expression with a
1439 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001440 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001441 /// By default, performs semantic analysis to build the new expression.
1442 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001443 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1444 SourceLocation OpLoc,
1445 UnaryExprOrTypeTrait ExprKind,
1446 SourceRange R) {
1447 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001448 }
1449
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001450 /// \brief Build a new sizeof, alignof or vec step expression with an
1451 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001452 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001453 /// By default, performs semantic analysis to build the new expression.
1454 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001455 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1456 UnaryExprOrTypeTrait ExprKind,
1457 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001458 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001459 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001460 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001461 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001462
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 return move(Result);
1464 }
Mike Stump1eb44332009-09-09 15:08:12 +00001465
Douglas Gregorb98b1992009-08-11 05:31:07 +00001466 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001467 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001468 /// By default, performs semantic analysis to build the new expression.
1469 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001470 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001472 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001474 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1475 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001476 RBracketLoc);
1477 }
1478
1479 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001480 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 /// By default, performs semantic analysis to build the new expression.
1482 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001483 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001485 SourceLocation RParenLoc,
1486 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001487 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001488 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 }
1490
1491 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001492 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001495 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001496 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001497 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001498 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001499 const DeclarationNameInfo &MemberNameInfo,
1500 ValueDecl *Member,
1501 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001502 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001503 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001504 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1505 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001506 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001507 // We have a reference to an unnamed field. This is always the
1508 // base of an anonymous struct/union member access, i.e. the
1509 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001510 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001511 assert(Member->getType()->isRecordType() &&
1512 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001513
Richard Smith9138b4e2011-10-26 19:06:56 +00001514 BaseResult =
1515 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001516 QualifierLoc.getNestedNameSpecifier(),
1517 FoundDecl, Member);
1518 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001519 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001520 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001521 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001522 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001523 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001524 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001525 cast<FieldDecl>(Member)->getType(),
1526 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001527 return getSema().Owned(ME);
1528 }
Mike Stump1eb44332009-09-09 15:08:12 +00001529
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001530 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001531 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001532
John Wiegley429bb272011-04-08 18:41:53 +00001533 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001534 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001535
John McCall6bb80172010-03-30 21:47:33 +00001536 // FIXME: this involves duplicating earlier analysis in a lot of
1537 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001538 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001539 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001540 R.resolveKind();
1541
John McCall9ae2f072010-08-23 23:25:46 +00001542 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001543 SS, TemplateKWLoc,
1544 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001545 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001546 }
Mike Stump1eb44332009-09-09 15:08:12 +00001547
Douglas Gregorb98b1992009-08-11 05:31:07 +00001548 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001549 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001550 /// By default, performs semantic analysis to build the new expression.
1551 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001552 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001553 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001554 Expr *LHS, Expr *RHS) {
1555 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001556 }
1557
1558 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001559 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001562 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001563 SourceLocation QuestionLoc,
1564 Expr *LHS,
1565 SourceLocation ColonLoc,
1566 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001567 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1568 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 }
1570
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 /// \brief Build a new C-style cast 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 RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001576 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001578 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001579 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001580 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 }
Mike Stump1eb44332009-09-09 15:08:12 +00001582
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 /// \brief Build a new compound literal expression.
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 RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001588 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001590 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001591 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001592 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 }
Mike Stump1eb44332009-09-09 15:08:12 +00001594
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001596 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001599 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 SourceLocation OpLoc,
1601 SourceLocation AccessorLoc,
1602 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001603
John McCall129e2df2009-11-30 22:42:35 +00001604 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001605 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001606 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001607 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001608 SS, SourceLocation(),
1609 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001610 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001611 /* TemplateArgs */ 0);
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 initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001615 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 /// 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 RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001619 MultiExprArg Inits,
1620 SourceLocation RBraceLoc,
1621 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001622 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001623 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1624 if (Result.isInvalid() || ResultTy->isDependentType())
1625 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001626
Douglas Gregore48319a2009-11-09 17:16:50 +00001627 // Patch in the result type we were given, which may have been computed
1628 // when the initial InitListExpr was built.
1629 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1630 ILE->setType(ResultTy);
1631 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 }
Mike Stump1eb44332009-09-09 15:08:12 +00001633
Douglas Gregorb98b1992009-08-11 05:31:07 +00001634 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001635 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 /// By default, performs semantic analysis to build the new expression.
1637 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001638 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 MultiExprArg ArrayExprs,
1640 SourceLocation EqualOrColonLoc,
1641 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001642 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001643 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001645 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001647 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001648
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 ArrayExprs.release();
1650 return move(Result);
1651 }
Mike Stump1eb44332009-09-09 15:08:12 +00001652
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001654 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 /// By default, builds the implicit value initialization without performing
1656 /// any semantic analysis. Subclasses may override this routine to provide
1657 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001658 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1660 }
Mike Stump1eb44332009-09-09 15:08:12 +00001661
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001663 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 /// By default, performs semantic analysis to build the new expression.
1665 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001666 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001667 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001668 SourceLocation RParenLoc) {
1669 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001670 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001671 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 }
1673
1674 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001675 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 /// By default, performs semantic analysis to build the new expression.
1677 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001678 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001679 MultiExprArg SubExprs,
1680 SourceLocation RParenLoc) {
1681 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
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 address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001685 ///
1686 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 /// rather than attempting to map the label statement itself.
1688 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001689 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001690 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001691 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001692 }
Mike Stump1eb44332009-09-09 15:08:12 +00001693
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001695 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 /// By default, performs semantic analysis to build the new expression.
1697 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001698 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001699 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001701 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001702 }
Mike Stump1eb44332009-09-09 15:08:12 +00001703
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 /// \brief Build a new __builtin_choose_expr expression.
1705 ///
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001708 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001709 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 SourceLocation RParenLoc) {
1711 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001712 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 RParenLoc);
1714 }
Mike Stump1eb44332009-09-09 15:08:12 +00001715
Peter Collingbournef111d932011-04-15 00:35:48 +00001716 /// \brief Build a new generic selection expression.
1717 ///
1718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
1720 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1721 SourceLocation DefaultLoc,
1722 SourceLocation RParenLoc,
1723 Expr *ControllingExpr,
1724 TypeSourceInfo **Types,
1725 Expr **Exprs,
1726 unsigned NumAssocs) {
1727 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1728 ControllingExpr, Types, Exprs,
1729 NumAssocs);
1730 }
1731
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 /// \brief Build a new overloaded operator call expression.
1733 ///
1734 /// By default, performs semantic analysis to build the new expression.
1735 /// The semantic analysis provides the behavior of template instantiation,
1736 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001737 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 /// argument-dependent lookup, etc. Subclasses may override this routine to
1739 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001740 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001742 Expr *Callee,
1743 Expr *First,
1744 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001745
1746 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001747 /// reinterpret_cast.
1748 ///
1749 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001750 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001751 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001752 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 Stmt::StmtClass Class,
1754 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001755 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 SourceLocation RAngleLoc,
1757 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001758 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 SourceLocation RParenLoc) {
1760 switch (Class) {
1761 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001762 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001763 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001764 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765
1766 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001767 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001768 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001769 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001770
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001772 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001773 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001774 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001776
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001778 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001779 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001780 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001781
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001783 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 }
Mike Stump1eb44332009-09-09 15:08:12 +00001786
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 /// \brief Build a new C++ static_cast expression.
1788 ///
1789 /// By default, performs semantic analysis to build the new expression.
1790 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001791 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001793 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 SourceLocation RAngleLoc,
1795 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001796 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001798 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001799 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001800 SourceRange(LAngleLoc, RAngleLoc),
1801 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001802 }
1803
1804 /// \brief Build a new C++ dynamic_cast expression.
1805 ///
1806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001808 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001810 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 SourceLocation RAngleLoc,
1812 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001813 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001815 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001816 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001817 SourceRange(LAngleLoc, RAngleLoc),
1818 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 }
1820
1821 /// \brief Build a new C++ reinterpret_cast expression.
1822 ///
1823 /// By default, performs semantic analysis to build the new expression.
1824 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001825 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001827 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 SourceLocation RAngleLoc,
1829 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001830 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001832 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001833 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001834 SourceRange(LAngleLoc, RAngleLoc),
1835 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 }
1837
1838 /// \brief Build a new C++ const_cast expression.
1839 ///
1840 /// By default, performs semantic analysis to build the new expression.
1841 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001842 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001843 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001844 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 SourceLocation RAngleLoc,
1846 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001847 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001848 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001849 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001850 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001851 SourceRange(LAngleLoc, RAngleLoc),
1852 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 }
Mike Stump1eb44332009-09-09 15:08:12 +00001854
Douglas Gregorb98b1992009-08-11 05:31:07 +00001855 /// \brief Build a new C++ functional-style cast expression.
1856 ///
1857 /// By default, performs semantic analysis to build the new expression.
1858 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001859 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1860 SourceLocation LParenLoc,
1861 Expr *Sub,
1862 SourceLocation RParenLoc) {
1863 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001864 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001865 RParenLoc);
1866 }
Mike Stump1eb44332009-09-09 15:08:12 +00001867
Douglas Gregorb98b1992009-08-11 05:31:07 +00001868 /// \brief Build a new C++ typeid(type) expression.
1869 ///
1870 /// By default, performs semantic analysis to build the new expression.
1871 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001872 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001873 SourceLocation TypeidLoc,
1874 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001875 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001876 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001877 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001878 }
Mike Stump1eb44332009-09-09 15:08:12 +00001879
Francois Pichet01b7c302010-09-08 12:20:18 +00001880
Douglas Gregorb98b1992009-08-11 05:31:07 +00001881 /// \brief Build a new C++ typeid(expr) expression.
1882 ///
1883 /// By default, performs semantic analysis to build the new expression.
1884 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001885 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001886 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001887 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001888 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001889 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001890 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001891 }
1892
Francois Pichet01b7c302010-09-08 12:20:18 +00001893 /// \brief Build a new C++ __uuidof(type) expression.
1894 ///
1895 /// By default, performs semantic analysis to build the new expression.
1896 /// Subclasses may override this routine to provide different behavior.
1897 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1898 SourceLocation TypeidLoc,
1899 TypeSourceInfo *Operand,
1900 SourceLocation RParenLoc) {
1901 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1902 RParenLoc);
1903 }
1904
1905 /// \brief Build a new C++ __uuidof(expr) expression.
1906 ///
1907 /// By default, performs semantic analysis to build the new expression.
1908 /// Subclasses may override this routine to provide different behavior.
1909 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1910 SourceLocation TypeidLoc,
1911 Expr *Operand,
1912 SourceLocation RParenLoc) {
1913 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1914 RParenLoc);
1915 }
1916
Douglas Gregorb98b1992009-08-11 05:31:07 +00001917 /// \brief Build a new C++ "this" expression.
1918 ///
1919 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001920 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001921 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001922 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001923 QualType ThisType,
1924 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001925 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001926 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001927 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1928 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001929 }
1930
1931 /// \brief Build a new C++ throw expression.
1932 ///
1933 /// By default, performs semantic analysis to build the new expression.
1934 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001935 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1936 bool IsThrownVariableInScope) {
1937 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 }
1939
1940 /// \brief Build a new C++ default-argument expression.
1941 ///
1942 /// By default, builds a new default-argument expression, which does not
1943 /// require any semantic analysis. Subclasses may override this routine to
1944 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001945 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001946 ParmVarDecl *Param) {
1947 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1948 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001949 }
1950
1951 /// \brief Build a new C++ zero-initialization expression.
1952 ///
1953 /// By default, performs semantic analysis to build the new expression.
1954 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001955 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1956 SourceLocation LParenLoc,
1957 SourceLocation RParenLoc) {
1958 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001959 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001960 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001961 }
Mike Stump1eb44332009-09-09 15:08:12 +00001962
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 /// \brief Build a new C++ "new" expression.
1964 ///
1965 /// By default, performs semantic analysis to build the new expression.
1966 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001967 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001968 bool UseGlobal,
1969 SourceLocation PlacementLParen,
1970 MultiExprArg PlacementArgs,
1971 SourceLocation PlacementRParen,
1972 SourceRange TypeIdParens,
1973 QualType AllocatedType,
1974 TypeSourceInfo *AllocatedTypeInfo,
1975 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001976 SourceRange DirectInitRange,
1977 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001978 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001979 PlacementLParen,
1980 move(PlacementArgs),
1981 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001982 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001983 AllocatedType,
1984 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001985 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001986 DirectInitRange,
1987 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001988 }
Mike Stump1eb44332009-09-09 15:08:12 +00001989
Douglas Gregorb98b1992009-08-11 05:31:07 +00001990 /// \brief Build a new C++ "delete" expression.
1991 ///
1992 /// By default, performs semantic analysis to build the new expression.
1993 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001994 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001995 bool IsGlobalDelete,
1996 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001997 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001998 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001999 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002000 }
Mike Stump1eb44332009-09-09 15:08:12 +00002001
Douglas Gregorb98b1992009-08-11 05:31:07 +00002002 /// \brief Build a new unary type trait expression.
2003 ///
2004 /// By default, performs semantic analysis to build the new expression.
2005 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002006 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002007 SourceLocation StartLoc,
2008 TypeSourceInfo *T,
2009 SourceLocation RParenLoc) {
2010 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002011 }
2012
Francois Pichet6ad6f282010-12-07 00:08:36 +00002013 /// \brief Build a new binary type trait expression.
2014 ///
2015 /// By default, performs semantic analysis to build the new expression.
2016 /// Subclasses may override this routine to provide different behavior.
2017 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2018 SourceLocation StartLoc,
2019 TypeSourceInfo *LhsT,
2020 TypeSourceInfo *RhsT,
2021 SourceLocation RParenLoc) {
2022 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2023 }
2024
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002025 /// \brief Build a new type trait expression.
2026 ///
2027 /// By default, performs semantic analysis to build the new expression.
2028 /// Subclasses may override this routine to provide different behavior.
2029 ExprResult RebuildTypeTrait(TypeTrait Trait,
2030 SourceLocation StartLoc,
2031 ArrayRef<TypeSourceInfo *> Args,
2032 SourceLocation RParenLoc) {
2033 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2034 }
2035
John Wiegley21ff2e52011-04-28 00:16:57 +00002036 /// \brief Build a new array type trait expression.
2037 ///
2038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
2040 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2041 SourceLocation StartLoc,
2042 TypeSourceInfo *TSInfo,
2043 Expr *DimExpr,
2044 SourceLocation RParenLoc) {
2045 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2046 }
2047
John Wiegley55262202011-04-25 06:54:41 +00002048 /// \brief Build a new expression trait expression.
2049 ///
2050 /// By default, performs semantic analysis to build the new expression.
2051 /// Subclasses may override this routine to provide different behavior.
2052 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2053 SourceLocation StartLoc,
2054 Expr *Queried,
2055 SourceLocation RParenLoc) {
2056 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2057 }
2058
Mike Stump1eb44332009-09-09 15:08:12 +00002059 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002060 /// expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002064 ExprResult RebuildDependentScopeDeclRefExpr(
2065 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002066 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002067 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002068 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002069 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002070 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002071
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002072 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002073 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002074 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002075
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002076 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002077 }
2078
2079 /// \brief Build a new template-id expression.
2080 ///
2081 /// By default, performs semantic analysis to build the new expression.
2082 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002083 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002084 SourceLocation TemplateKWLoc,
2085 LookupResult &R,
2086 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002087 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002088 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2089 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002090 }
2091
2092 /// \brief Build a new object-construction expression.
2093 ///
2094 /// By default, performs semantic analysis to build the new expression.
2095 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002096 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002097 SourceLocation Loc,
2098 CXXConstructorDecl *Constructor,
2099 bool IsElidable,
2100 MultiExprArg Args,
2101 bool HadMultipleCandidates,
2102 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002103 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002104 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002105 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002106 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002107 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002108 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002109
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002110 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002111 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002112 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002113 RequiresZeroInit, ConstructKind,
2114 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002115 }
2116
2117 /// \brief Build a new object-construction expression.
2118 ///
2119 /// By default, performs semantic analysis to build the new expression.
2120 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002121 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2122 SourceLocation LParenLoc,
2123 MultiExprArg Args,
2124 SourceLocation RParenLoc) {
2125 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002126 LParenLoc,
2127 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002128 RParenLoc);
2129 }
2130
2131 /// \brief Build a new object-construction expression.
2132 ///
2133 /// By default, performs semantic analysis to build the new expression.
2134 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002135 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2136 SourceLocation LParenLoc,
2137 MultiExprArg Args,
2138 SourceLocation RParenLoc) {
2139 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002140 LParenLoc,
2141 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002142 RParenLoc);
2143 }
Mike Stump1eb44332009-09-09 15:08:12 +00002144
Douglas Gregorb98b1992009-08-11 05:31:07 +00002145 /// \brief Build a new member reference expression.
2146 ///
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002149 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002150 QualType BaseType,
2151 bool IsArrow,
2152 SourceLocation OperatorLoc,
2153 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002154 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002155 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002156 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002157 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002158 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002159 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002160
John McCall9ae2f072010-08-23 23:25:46 +00002161 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002162 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002163 SS, TemplateKWLoc,
2164 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002165 MemberNameInfo,
2166 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002167 }
2168
John McCall129e2df2009-11-30 22:42:35 +00002169 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002170 ///
2171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002173 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2174 SourceLocation OperatorLoc,
2175 bool IsArrow,
2176 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002177 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002178 NamedDecl *FirstQualifierInScope,
2179 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002180 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002181 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002182 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002183
John McCall9ae2f072010-08-23 23:25:46 +00002184 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002185 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002186 SS, TemplateKWLoc,
2187 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002188 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002189 }
Mike Stump1eb44332009-09-09 15:08:12 +00002190
Sebastian Redl2e156222010-09-10 20:55:43 +00002191 /// \brief Build a new noexcept expression.
2192 ///
2193 /// By default, performs semantic analysis to build the new expression.
2194 /// Subclasses may override this routine to provide different behavior.
2195 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2196 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2197 }
2198
Douglas Gregoree8aff02011-01-04 17:33:58 +00002199 /// \brief Build a new expression to compute the length of a parameter pack.
2200 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2201 SourceLocation PackLoc,
2202 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002203 llvm::Optional<unsigned> Length) {
2204 if (Length)
2205 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2206 OperatorLoc, Pack, PackLoc,
2207 RParenLoc, *Length);
2208
Douglas Gregoree8aff02011-01-04 17:33:58 +00002209 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2210 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002211 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002212 }
2213
Douglas Gregorb98b1992009-08-11 05:31:07 +00002214 /// \brief Build a new Objective-C @encode expression.
2215 ///
2216 /// By default, performs semantic analysis to build the new expression.
2217 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002218 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002219 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002220 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002221 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002222 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002223 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002224
Douglas Gregor92e986e2010-04-22 16:44:27 +00002225 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002226 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002227 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002228 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002229 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002230 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002231 MultiExprArg Args,
2232 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002233 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2234 ReceiverTypeInfo->getType(),
2235 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002236 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002237 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002238 }
2239
2240 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002241 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002242 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002243 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002244 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002245 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002246 MultiExprArg Args,
2247 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002248 return SemaRef.BuildInstanceMessage(Receiver,
2249 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002250 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002251 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002252 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002253 }
2254
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002255 /// \brief Build a new Objective-C ivar reference expression.
2256 ///
2257 /// By default, performs semantic analysis to build the new expression.
2258 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002259 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002260 SourceLocation IvarLoc,
2261 bool IsArrow, bool IsFreeIvar) {
2262 // FIXME: We lose track of the IsFreeIvar bit.
2263 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002264 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002265 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2266 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002267 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002268 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002269 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002270 false);
John Wiegley429bb272011-04-08 18:41:53 +00002271 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002272 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002273
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002274 if (Result.get())
2275 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002276
John Wiegley429bb272011-04-08 18:41:53 +00002277 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002278 /*FIXME:*/IvarLoc, IsArrow,
2279 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002280 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002281 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002282 /*TemplateArgs=*/0);
2283 }
Douglas Gregore3303542010-04-26 20:47:02 +00002284
2285 /// \brief Build a new Objective-C property reference expression.
2286 ///
2287 /// By default, performs semantic analysis to build the new expression.
2288 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002289 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002290 ObjCPropertyDecl *Property,
2291 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002292 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002293 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002294 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2295 Sema::LookupMemberName);
2296 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002297 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002298 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002299 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002300 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002301 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002302
Douglas Gregore3303542010-04-26 20:47:02 +00002303 if (Result.get())
2304 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002305
John Wiegley429bb272011-04-08 18:41:53 +00002306 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002307 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002308 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002309 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002310 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002311 /*TemplateArgs=*/0);
2312 }
Sean Huntc3021132010-05-05 15:23:54 +00002313
John McCall12f78a62010-12-02 01:19:52 +00002314 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002315 ///
2316 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002317 /// Subclasses may override this routine to provide different behavior.
2318 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2319 ObjCMethodDecl *Getter,
2320 ObjCMethodDecl *Setter,
2321 SourceLocation PropertyLoc) {
2322 // Since these expressions can only be value-dependent, we do not
2323 // need to perform semantic analysis again.
2324 return Owned(
2325 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2326 VK_LValue, OK_ObjCProperty,
2327 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002328 }
2329
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002330 /// \brief Build a new Objective-C "isa" expression.
2331 ///
2332 /// By default, performs semantic analysis to build the new expression.
2333 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002334 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002335 bool IsArrow) {
2336 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002337 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002338 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2339 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002340 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002341 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002342 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002343 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002344 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002345
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002346 if (Result.get())
2347 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002348
John Wiegley429bb272011-04-08 18:41:53 +00002349 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002350 /*FIXME:*/IsaLoc, IsArrow,
2351 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002352 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002353 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002354 /*TemplateArgs=*/0);
2355 }
Sean Huntc3021132010-05-05 15:23:54 +00002356
Douglas Gregorb98b1992009-08-11 05:31:07 +00002357 /// \brief Build a new shuffle vector expression.
2358 ///
2359 /// By default, performs semantic analysis to build the new expression.
2360 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002361 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002362 MultiExprArg SubExprs,
2363 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002364 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002365 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002366 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2367 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2368 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2369 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002370
Douglas Gregorb98b1992009-08-11 05:31:07 +00002371 // Build a reference to the __builtin_shufflevector builtin
2372 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002373 ExprResult Callee
2374 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2375 VK_LValue, BuiltinLoc));
2376 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2377 if (Callee.isInvalid())
2378 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002379
2380 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002381 unsigned NumSubExprs = SubExprs.size();
2382 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002383 ExprResult TheCall = SemaRef.Owned(
2384 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002385 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002386 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002387 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002388 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002389
Douglas Gregorb98b1992009-08-11 05:31:07 +00002390 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002391 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002392 }
John McCall43fed0d2010-11-12 08:19:04 +00002393
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002394 /// \brief Build a new template argument pack expansion.
2395 ///
2396 /// By default, performs semantic analysis to build a new pack expansion
2397 /// for a template argument. Subclasses may override this routine to provide
2398 /// different behavior.
2399 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002400 SourceLocation EllipsisLoc,
2401 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002402 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002403 case TemplateArgument::Expression: {
2404 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002405 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2406 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002407 if (Result.isInvalid())
2408 return TemplateArgumentLoc();
2409
2410 return TemplateArgumentLoc(Result.get(), Result.get());
2411 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002412
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002413 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002414 return TemplateArgumentLoc(TemplateArgument(
2415 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002416 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002417 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002418 Pattern.getTemplateNameLoc(),
2419 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002420
2421 case TemplateArgument::Null:
2422 case TemplateArgument::Integral:
2423 case TemplateArgument::Declaration:
2424 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002425 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002426 llvm_unreachable("Pack expansion pattern has no parameter packs");
2427
2428 case TemplateArgument::Type:
2429 if (TypeSourceInfo *Expansion
2430 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002431 EllipsisLoc,
2432 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002433 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2434 Expansion);
2435 break;
2436 }
2437
2438 return TemplateArgumentLoc();
2439 }
2440
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002441 /// \brief Build a new expression pack expansion.
2442 ///
2443 /// By default, performs semantic analysis to build a new pack expansion
2444 /// for an expression. Subclasses may override this routine to provide
2445 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002446 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2447 llvm::Optional<unsigned> NumExpansions) {
2448 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002449 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002450
2451 /// \brief Build a new atomic operation expression.
2452 ///
2453 /// By default, performs semantic analysis to build the new expression.
2454 /// Subclasses may override this routine to provide different behavior.
2455 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2456 MultiExprArg SubExprs,
2457 QualType RetTy,
2458 AtomicExpr::AtomicOp Op,
2459 SourceLocation RParenLoc) {
2460 // Just create the expression; there is not any interesting semantic
2461 // analysis here because we can't actually build an AtomicExpr until
2462 // we are sure it is semantically sound.
2463 unsigned NumSubExprs = SubExprs.size();
2464 Expr **Subs = (Expr **)SubExprs.release();
2465 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2466 NumSubExprs, RetTy, Op,
2467 RParenLoc);
2468 }
2469
John McCall43fed0d2010-11-12 08:19:04 +00002470private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002471 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2472 QualType ObjectType,
2473 NamedDecl *FirstQualifierInScope,
2474 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002475
2476 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2477 QualType ObjectType,
2478 NamedDecl *FirstQualifierInScope,
2479 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002480};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002481
Douglas Gregor43959a92009-08-20 07:17:43 +00002482template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002483StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002484 if (!S)
2485 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002486
Douglas Gregor43959a92009-08-20 07:17:43 +00002487 switch (S->getStmtClass()) {
2488 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002489
Douglas Gregor43959a92009-08-20 07:17:43 +00002490 // Transform individual statement nodes
2491#define STMT(Node, Parent) \
2492 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002493#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002494#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002495#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002496
Douglas Gregor43959a92009-08-20 07:17:43 +00002497 // Transform expressions by calling TransformExpr.
2498#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002499#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002500#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002501#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002502 {
John McCall60d7b3a2010-08-24 06:29:42 +00002503 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002504 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002505 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002506
John McCall9ae2f072010-08-23 23:25:46 +00002507 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002508 }
Mike Stump1eb44332009-09-09 15:08:12 +00002509 }
2510
John McCall3fa5cae2010-10-26 07:05:15 +00002511 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002512}
Mike Stump1eb44332009-09-09 15:08:12 +00002513
2514
Douglas Gregor670444e2009-08-04 22:27:00 +00002515template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002516ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002517 if (!E)
2518 return SemaRef.Owned(E);
2519
2520 switch (E->getStmtClass()) {
2521 case Stmt::NoStmtClass: break;
2522#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002523#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002524#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002525 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002526#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002527 }
2528
John McCall3fa5cae2010-10-26 07:05:15 +00002529 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002530}
2531
2532template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002533bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2534 unsigned NumInputs,
2535 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002536 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002537 bool *ArgChanged) {
2538 for (unsigned I = 0; I != NumInputs; ++I) {
2539 // If requested, drop call arguments that need to be dropped.
2540 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2541 if (ArgChanged)
2542 *ArgChanged = true;
2543
2544 break;
2545 }
2546
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002547 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2548 Expr *Pattern = Expansion->getPattern();
2549
Chris Lattner686775d2011-07-20 06:58:45 +00002550 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002551 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2552 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2553
2554 // Determine whether the set of unexpanded parameter packs can and should
2555 // be expanded.
2556 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002557 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002558 llvm::Optional<unsigned> OrigNumExpansions
2559 = Expansion->getNumExpansions();
2560 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002561 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2562 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002563 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002564 Expand, RetainExpansion,
2565 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002566 return true;
2567
2568 if (!Expand) {
2569 // The transform has determined that we should perform a simple
2570 // transformation on the pack expansion, producing another pack
2571 // expansion.
2572 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2573 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2574 if (OutPattern.isInvalid())
2575 return true;
2576
2577 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002578 Expansion->getEllipsisLoc(),
2579 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002580 if (Out.isInvalid())
2581 return true;
2582
2583 if (ArgChanged)
2584 *ArgChanged = true;
2585 Outputs.push_back(Out.get());
2586 continue;
2587 }
John McCallc8fc90a2011-07-06 07:30:07 +00002588
2589 // Record right away that the argument was changed. This needs
2590 // to happen even if the array expands to nothing.
2591 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002592
2593 // The transform has determined that we should perform an elementwise
2594 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002595 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002596 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2597 ExprResult Out = getDerived().TransformExpr(Pattern);
2598 if (Out.isInvalid())
2599 return true;
2600
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002601 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002602 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2603 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002604 if (Out.isInvalid())
2605 return true;
2606 }
2607
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002608 Outputs.push_back(Out.get());
2609 }
2610
2611 continue;
2612 }
2613
Douglas Gregoraa165f82011-01-03 19:04:46 +00002614 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2615 if (Result.isInvalid())
2616 return true;
2617
2618 if (Result.get() != Inputs[I] && ArgChanged)
2619 *ArgChanged = true;
2620
2621 Outputs.push_back(Result.get());
2622 }
2623
2624 return false;
2625}
2626
2627template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002628NestedNameSpecifierLoc
2629TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2630 NestedNameSpecifierLoc NNS,
2631 QualType ObjectType,
2632 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002633 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002634 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2635 Qualifier = Qualifier.getPrefix())
2636 Qualifiers.push_back(Qualifier);
2637
2638 CXXScopeSpec SS;
2639 while (!Qualifiers.empty()) {
2640 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2641 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2642
2643 switch (QNNS->getKind()) {
2644 case NestedNameSpecifier::Identifier:
2645 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2646 *QNNS->getAsIdentifier(),
2647 Q.getLocalBeginLoc(),
2648 Q.getLocalEndLoc(),
2649 ObjectType, false, SS,
2650 FirstQualifierInScope, false))
2651 return NestedNameSpecifierLoc();
2652
2653 break;
2654
2655 case NestedNameSpecifier::Namespace: {
2656 NamespaceDecl *NS
2657 = cast_or_null<NamespaceDecl>(
2658 getDerived().TransformDecl(
2659 Q.getLocalBeginLoc(),
2660 QNNS->getAsNamespace()));
2661 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2662 break;
2663 }
2664
2665 case NestedNameSpecifier::NamespaceAlias: {
2666 NamespaceAliasDecl *Alias
2667 = cast_or_null<NamespaceAliasDecl>(
2668 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2669 QNNS->getAsNamespaceAlias()));
2670 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2671 Q.getLocalEndLoc());
2672 break;
2673 }
2674
2675 case NestedNameSpecifier::Global:
2676 // There is no meaningful transformation that one could perform on the
2677 // global scope.
2678 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2679 break;
2680
2681 case NestedNameSpecifier::TypeSpecWithTemplate:
2682 case NestedNameSpecifier::TypeSpec: {
2683 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2684 FirstQualifierInScope, SS);
2685
2686 if (!TL)
2687 return NestedNameSpecifierLoc();
2688
2689 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2690 (SemaRef.getLangOptions().CPlusPlus0x &&
2691 TL.getType()->isEnumeralType())) {
2692 assert(!TL.getType().hasLocalQualifiers() &&
2693 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002694 if (TL.getType()->isEnumeralType())
2695 SemaRef.Diag(TL.getBeginLoc(),
2696 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002697 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2698 Q.getLocalEndLoc());
2699 break;
2700 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002701 // If the nested-name-specifier is an invalid type def, don't emit an
2702 // error because a previous error should have already been emitted.
2703 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2704 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2705 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2706 << TL.getType() << SS.getRange();
2707 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002708 return NestedNameSpecifierLoc();
2709 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002710 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002711
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002712 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002713 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002714 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002715 }
2716
2717 // Don't rebuild the nested-name-specifier if we don't have to.
2718 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2719 !getDerived().AlwaysRebuild())
2720 return NNS;
2721
2722 // If we can re-use the source-location data from the original
2723 // nested-name-specifier, do so.
2724 if (SS.location_size() == NNS.getDataLength() &&
2725 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2726 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2727
2728 // Allocate new nested-name-specifier location information.
2729 return SS.getWithLocInContext(SemaRef.Context);
2730}
2731
2732template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002733DeclarationNameInfo
2734TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002735::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002736 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002737 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002738 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002739
2740 switch (Name.getNameKind()) {
2741 case DeclarationName::Identifier:
2742 case DeclarationName::ObjCZeroArgSelector:
2743 case DeclarationName::ObjCOneArgSelector:
2744 case DeclarationName::ObjCMultiArgSelector:
2745 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002746 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002747 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002748 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002749
Douglas Gregor81499bb2009-09-03 22:13:48 +00002750 case DeclarationName::CXXConstructorName:
2751 case DeclarationName::CXXDestructorName:
2752 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002753 TypeSourceInfo *NewTInfo;
2754 CanQualType NewCanTy;
2755 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002756 NewTInfo = getDerived().TransformType(OldTInfo);
2757 if (!NewTInfo)
2758 return DeclarationNameInfo();
2759 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002760 }
2761 else {
2762 NewTInfo = 0;
2763 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002764 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002765 if (NewT.isNull())
2766 return DeclarationNameInfo();
2767 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2768 }
Mike Stump1eb44332009-09-09 15:08:12 +00002769
Abramo Bagnara25777432010-08-11 22:01:17 +00002770 DeclarationName NewName
2771 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2772 NewCanTy);
2773 DeclarationNameInfo NewNameInfo(NameInfo);
2774 NewNameInfo.setName(NewName);
2775 NewNameInfo.setNamedTypeInfo(NewTInfo);
2776 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002777 }
Mike Stump1eb44332009-09-09 15:08:12 +00002778 }
2779
David Blaikieb219cfc2011-09-23 05:06:16 +00002780 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002781}
2782
2783template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002784TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002785TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2786 TemplateName Name,
2787 SourceLocation NameLoc,
2788 QualType ObjectType,
2789 NamedDecl *FirstQualifierInScope) {
2790 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2791 TemplateDecl *Template = QTN->getTemplateDecl();
2792 assert(Template && "qualified template name must refer to a template");
2793
2794 TemplateDecl *TransTemplate
2795 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2796 Template));
2797 if (!TransTemplate)
2798 return TemplateName();
2799
2800 if (!getDerived().AlwaysRebuild() &&
2801 SS.getScopeRep() == QTN->getQualifier() &&
2802 TransTemplate == Template)
2803 return Name;
2804
2805 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2806 TransTemplate);
2807 }
2808
2809 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2810 if (SS.getScopeRep()) {
2811 // These apply to the scope specifier, not the template.
2812 ObjectType = QualType();
2813 FirstQualifierInScope = 0;
2814 }
2815
2816 if (!getDerived().AlwaysRebuild() &&
2817 SS.getScopeRep() == DTN->getQualifier() &&
2818 ObjectType.isNull())
2819 return Name;
2820
2821 if (DTN->isIdentifier()) {
2822 return getDerived().RebuildTemplateName(SS,
2823 *DTN->getIdentifier(),
2824 NameLoc,
2825 ObjectType,
2826 FirstQualifierInScope);
2827 }
2828
2829 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2830 ObjectType);
2831 }
2832
2833 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2834 TemplateDecl *TransTemplate
2835 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2836 Template));
2837 if (!TransTemplate)
2838 return TemplateName();
2839
2840 if (!getDerived().AlwaysRebuild() &&
2841 TransTemplate == Template)
2842 return Name;
2843
2844 return TemplateName(TransTemplate);
2845 }
2846
2847 if (SubstTemplateTemplateParmPackStorage *SubstPack
2848 = Name.getAsSubstTemplateTemplateParmPack()) {
2849 TemplateTemplateParmDecl *TransParam
2850 = cast_or_null<TemplateTemplateParmDecl>(
2851 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2852 if (!TransParam)
2853 return TemplateName();
2854
2855 if (!getDerived().AlwaysRebuild() &&
2856 TransParam == SubstPack->getParameterPack())
2857 return Name;
2858
2859 return getDerived().RebuildTemplateName(TransParam,
2860 SubstPack->getArgumentPack());
2861 }
2862
2863 // These should be getting filtered out before they reach the AST.
2864 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002865}
2866
2867template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002868void TreeTransform<Derived>::InventTemplateArgumentLoc(
2869 const TemplateArgument &Arg,
2870 TemplateArgumentLoc &Output) {
2871 SourceLocation Loc = getDerived().getBaseLocation();
2872 switch (Arg.getKind()) {
2873 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002874 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002875 break;
2876
2877 case TemplateArgument::Type:
2878 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002879 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002880
John McCall833ca992009-10-29 08:12:44 +00002881 break;
2882
Douglas Gregor788cd062009-11-11 01:00:40 +00002883 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002884 case TemplateArgument::TemplateExpansion: {
2885 NestedNameSpecifierLocBuilder Builder;
2886 TemplateName Template = Arg.getAsTemplate();
2887 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2888 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2889 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2890 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2891
2892 if (Arg.getKind() == TemplateArgument::Template)
2893 Output = TemplateArgumentLoc(Arg,
2894 Builder.getWithLocInContext(SemaRef.Context),
2895 Loc);
2896 else
2897 Output = TemplateArgumentLoc(Arg,
2898 Builder.getWithLocInContext(SemaRef.Context),
2899 Loc, Loc);
2900
Douglas Gregor788cd062009-11-11 01:00:40 +00002901 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002902 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002903
John McCall833ca992009-10-29 08:12:44 +00002904 case TemplateArgument::Expression:
2905 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2906 break;
2907
2908 case TemplateArgument::Declaration:
2909 case TemplateArgument::Integral:
2910 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002911 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002912 break;
2913 }
2914}
2915
2916template<typename Derived>
2917bool TreeTransform<Derived>::TransformTemplateArgument(
2918 const TemplateArgumentLoc &Input,
2919 TemplateArgumentLoc &Output) {
2920 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002921 switch (Arg.getKind()) {
2922 case TemplateArgument::Null:
2923 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002924 Output = Input;
2925 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002926
Douglas Gregor670444e2009-08-04 22:27:00 +00002927 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002928 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002929 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002930 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002931
2932 DI = getDerived().TransformType(DI);
2933 if (!DI) return true;
2934
2935 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2936 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002937 }
Mike Stump1eb44332009-09-09 15:08:12 +00002938
Douglas Gregor670444e2009-08-04 22:27:00 +00002939 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002940 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002941 DeclarationName Name;
2942 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2943 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002944 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002945 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002946 if (!D) return true;
2947
John McCall828bff22009-10-29 18:45:58 +00002948 Expr *SourceExpr = Input.getSourceDeclExpression();
2949 if (SourceExpr) {
2950 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002951 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002952 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00002953 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00002954 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002955 }
2956
2957 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002958 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002959 }
Mike Stump1eb44332009-09-09 15:08:12 +00002960
Douglas Gregor788cd062009-11-11 01:00:40 +00002961 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002962 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2963 if (QualifierLoc) {
2964 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2965 if (!QualifierLoc)
2966 return true;
2967 }
2968
Douglas Gregor1d752d72011-03-02 18:46:51 +00002969 CXXScopeSpec SS;
2970 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002971 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002972 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2973 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002974 if (Template.isNull())
2975 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002976
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002977 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002978 Input.getTemplateNameLoc());
2979 return false;
2980 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002981
2982 case TemplateArgument::TemplateExpansion:
2983 llvm_unreachable("Caller should expand pack expansions");
2984
Douglas Gregor670444e2009-08-04 22:27:00 +00002985 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00002986 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00002987 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002988 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002989
John McCall833ca992009-10-29 08:12:44 +00002990 Expr *InputExpr = Input.getSourceExpression();
2991 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2992
Chris Lattner223de242011-04-25 20:37:58 +00002993 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00002994 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00002995 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002996 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002997 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002998 }
Mike Stump1eb44332009-09-09 15:08:12 +00002999
Douglas Gregor670444e2009-08-04 22:27:00 +00003000 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003001 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003002 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003003 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003004 AEnd = Arg.pack_end();
3005 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003006
John McCall833ca992009-10-29 08:12:44 +00003007 // FIXME: preserve source information here when we start
3008 // caring about parameter packs.
3009
John McCall828bff22009-10-29 18:45:58 +00003010 TemplateArgumentLoc InputArg;
3011 TemplateArgumentLoc OutputArg;
3012 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3013 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003014 return true;
3015
John McCall828bff22009-10-29 18:45:58 +00003016 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003017 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003018
3019 TemplateArgument *TransformedArgsPtr
3020 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3021 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3022 TransformedArgsPtr);
3023 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3024 TransformedArgs.size()),
3025 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003026 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003027 }
3028 }
Mike Stump1eb44332009-09-09 15:08:12 +00003029
Douglas Gregor670444e2009-08-04 22:27:00 +00003030 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003031 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003032}
3033
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003034/// \brief Iterator adaptor that invents template argument location information
3035/// for each of the template arguments in its underlying iterator.
3036template<typename Derived, typename InputIterator>
3037class TemplateArgumentLocInventIterator {
3038 TreeTransform<Derived> &Self;
3039 InputIterator Iter;
3040
3041public:
3042 typedef TemplateArgumentLoc value_type;
3043 typedef TemplateArgumentLoc reference;
3044 typedef typename std::iterator_traits<InputIterator>::difference_type
3045 difference_type;
3046 typedef std::input_iterator_tag iterator_category;
3047
3048 class pointer {
3049 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003050
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003051 public:
3052 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3053
3054 const TemplateArgumentLoc *operator->() const { return &Arg; }
3055 };
3056
3057 TemplateArgumentLocInventIterator() { }
3058
3059 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3060 InputIterator Iter)
3061 : Self(Self), Iter(Iter) { }
3062
3063 TemplateArgumentLocInventIterator &operator++() {
3064 ++Iter;
3065 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003066 }
3067
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003068 TemplateArgumentLocInventIterator operator++(int) {
3069 TemplateArgumentLocInventIterator Old(*this);
3070 ++(*this);
3071 return Old;
3072 }
3073
3074 reference operator*() const {
3075 TemplateArgumentLoc Result;
3076 Self.InventTemplateArgumentLoc(*Iter, Result);
3077 return Result;
3078 }
3079
3080 pointer operator->() const { return pointer(**this); }
3081
3082 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3083 const TemplateArgumentLocInventIterator &Y) {
3084 return X.Iter == Y.Iter;
3085 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003086
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003087 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3088 const TemplateArgumentLocInventIterator &Y) {
3089 return X.Iter != Y.Iter;
3090 }
3091};
3092
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003093template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003094template<typename InputIterator>
3095bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3096 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003097 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003098 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003099 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003100 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003101
3102 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3103 // Unpack argument packs, which we translate them into separate
3104 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003105 // FIXME: We could do much better if we could guarantee that the
3106 // TemplateArgumentLocInfo for the pack expansion would be usable for
3107 // all of the template arguments in the argument pack.
3108 typedef TemplateArgumentLocInventIterator<Derived,
3109 TemplateArgument::pack_iterator>
3110 PackLocIterator;
3111 if (TransformTemplateArguments(PackLocIterator(*this,
3112 In.getArgument().pack_begin()),
3113 PackLocIterator(*this,
3114 In.getArgument().pack_end()),
3115 Outputs))
3116 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003117
3118 continue;
3119 }
3120
3121 if (In.getArgument().isPackExpansion()) {
3122 // We have a pack expansion, for which we will be substituting into
3123 // the pattern.
3124 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003125 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003126 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003127 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3128 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003129
Chris Lattner686775d2011-07-20 06:58:45 +00003130 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003131 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3132 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3133
3134 // Determine whether the set of unexpanded parameter packs can and should
3135 // be expanded.
3136 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003137 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003138 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003139 if (getDerived().TryExpandParameterPacks(Ellipsis,
3140 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003141 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003142 Expand,
3143 RetainExpansion,
3144 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003145 return true;
3146
3147 if (!Expand) {
3148 // The transform has determined that we should perform a simple
3149 // transformation on the pack expansion, producing another pack
3150 // expansion.
3151 TemplateArgumentLoc OutPattern;
3152 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3153 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3154 return true;
3155
Douglas Gregorcded4f62011-01-14 17:04:44 +00003156 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3157 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003158 if (Out.getArgument().isNull())
3159 return true;
3160
3161 Outputs.addArgument(Out);
3162 continue;
3163 }
3164
3165 // The transform has determined that we should perform an elementwise
3166 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003167 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003168 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3169
3170 if (getDerived().TransformTemplateArgument(Pattern, Out))
3171 return true;
3172
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003173 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003174 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3175 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003176 if (Out.getArgument().isNull())
3177 return true;
3178 }
3179
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003180 Outputs.addArgument(Out);
3181 }
3182
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003183 // If we're supposed to retain a pack expansion, do so by temporarily
3184 // forgetting the partially-substituted parameter pack.
3185 if (RetainExpansion) {
3186 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3187
3188 if (getDerived().TransformTemplateArgument(Pattern, Out))
3189 return true;
3190
Douglas Gregorcded4f62011-01-14 17:04:44 +00003191 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3192 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003193 if (Out.getArgument().isNull())
3194 return true;
3195
3196 Outputs.addArgument(Out);
3197 }
Douglas Gregord3731192011-01-10 07:32:04 +00003198
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003199 continue;
3200 }
3201
3202 // The simple case:
3203 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003204 return true;
3205
3206 Outputs.addArgument(Out);
3207 }
3208
3209 return false;
3210
3211}
3212
Douglas Gregor577f75a2009-08-04 16:50:30 +00003213//===----------------------------------------------------------------------===//
3214// Type transformation
3215//===----------------------------------------------------------------------===//
3216
3217template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003218QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003219 if (getDerived().AlreadyTransformed(T))
3220 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003221
John McCalla2becad2009-10-21 00:40:46 +00003222 // Temporary workaround. All of these transformations should
3223 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003224 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3225 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003226
John McCall43fed0d2010-11-12 08:19:04 +00003227 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003228
John McCalla2becad2009-10-21 00:40:46 +00003229 if (!NewDI)
3230 return QualType();
3231
3232 return NewDI->getType();
3233}
3234
3235template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003236TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003237 // Refine the base location to the type's location.
3238 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3239 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003240 if (getDerived().AlreadyTransformed(DI->getType()))
3241 return DI;
3242
3243 TypeLocBuilder TLB;
3244
3245 TypeLoc TL = DI->getTypeLoc();
3246 TLB.reserve(TL.getFullDataSize());
3247
John McCall43fed0d2010-11-12 08:19:04 +00003248 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003249 if (Result.isNull())
3250 return 0;
3251
John McCalla93c9342009-12-07 02:54:59 +00003252 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003253}
3254
3255template<typename Derived>
3256QualType
John McCall43fed0d2010-11-12 08:19:04 +00003257TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003258 switch (T.getTypeLocClass()) {
3259#define ABSTRACT_TYPELOC(CLASS, PARENT)
3260#define TYPELOC(CLASS, PARENT) \
3261 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003262 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003263#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003264 }
Mike Stump1eb44332009-09-09 15:08:12 +00003265
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003266 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003267}
3268
3269/// FIXME: By default, this routine adds type qualifiers only to types
3270/// that can have qualifiers, and silently suppresses those qualifiers
3271/// that are not permitted (e.g., qualifiers on reference or function
3272/// types). This is the right thing for template instantiation, but
3273/// probably not for other clients.
3274template<typename Derived>
3275QualType
3276TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003277 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003278 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003279
John McCall43fed0d2010-11-12 08:19:04 +00003280 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003281 if (Result.isNull())
3282 return QualType();
3283
3284 // Silently suppress qualifiers if the result type can't be qualified.
3285 // FIXME: this is the right thing for template instantiation, but
3286 // probably not for other clients.
3287 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003288 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003289
John McCallf85e1932011-06-15 23:02:42 +00003290 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003291 // resulting type.
3292 if (Quals.hasObjCLifetime()) {
3293 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3294 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003295 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003296 // Objective-C ARC:
3297 // A lifetime qualifier applied to a substituted template parameter
3298 // overrides the lifetime qualifier from the template argument.
3299 if (const SubstTemplateTypeParmType *SubstTypeParam
3300 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3301 QualType Replacement = SubstTypeParam->getReplacementType();
3302 Qualifiers Qs = Replacement.getQualifiers();
3303 Qs.removeObjCLifetime();
3304 Replacement
3305 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3306 Qs);
3307 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3308 SubstTypeParam->getReplacedParameter(),
3309 Replacement);
3310 TLB.TypeWasModifiedSafely(Result);
3311 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003312 // Otherwise, complain about the addition of a qualifier to an
3313 // already-qualified type.
3314 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003315 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003316 << Result << R;
3317
Douglas Gregore559ca12011-06-17 22:11:49 +00003318 Quals.removeObjCLifetime();
3319 }
3320 }
3321 }
John McCall28654742010-06-05 06:41:15 +00003322 if (!Quals.empty()) {
3323 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3324 TLB.push<QualifiedTypeLoc>(Result);
3325 // No location information to preserve.
3326 }
John McCalla2becad2009-10-21 00:40:46 +00003327
3328 return Result;
3329}
3330
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003331template<typename Derived>
3332TypeLoc
3333TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3334 QualType ObjectType,
3335 NamedDecl *UnqualLookup,
3336 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003337 QualType T = TL.getType();
3338 if (getDerived().AlreadyTransformed(T))
3339 return TL;
3340
3341 TypeLocBuilder TLB;
3342 QualType Result;
3343
3344 if (isa<TemplateSpecializationType>(T)) {
3345 TemplateSpecializationTypeLoc SpecTL
3346 = cast<TemplateSpecializationTypeLoc>(TL);
3347
3348 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003349 getDerived().TransformTemplateName(SS,
3350 SpecTL.getTypePtr()->getTemplateName(),
3351 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003352 ObjectType, UnqualLookup);
3353 if (Template.isNull())
3354 return TypeLoc();
3355
3356 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3357 Template);
3358 } else if (isa<DependentTemplateSpecializationType>(T)) {
3359 DependentTemplateSpecializationTypeLoc SpecTL
3360 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3361
Douglas Gregora88f09f2011-02-28 17:23:35 +00003362 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003363 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003364 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003365 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003366 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003367 if (Template.isNull())
3368 return TypeLoc();
3369
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003370 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003371 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003372 Template,
3373 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003374 } else {
3375 // Nothing special needs to be done for these.
3376 Result = getDerived().TransformType(TLB, TL);
3377 }
3378
3379 if (Result.isNull())
3380 return TypeLoc();
3381
3382 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3383}
3384
Douglas Gregorb71d8212011-03-02 18:32:08 +00003385template<typename Derived>
3386TypeSourceInfo *
3387TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3388 QualType ObjectType,
3389 NamedDecl *UnqualLookup,
3390 CXXScopeSpec &SS) {
3391 // FIXME: Painfully copy-paste from the above!
3392
3393 QualType T = TSInfo->getType();
3394 if (getDerived().AlreadyTransformed(T))
3395 return TSInfo;
3396
3397 TypeLocBuilder TLB;
3398 QualType Result;
3399
3400 TypeLoc TL = TSInfo->getTypeLoc();
3401 if (isa<TemplateSpecializationType>(T)) {
3402 TemplateSpecializationTypeLoc SpecTL
3403 = cast<TemplateSpecializationTypeLoc>(TL);
3404
3405 TemplateName Template
3406 = getDerived().TransformTemplateName(SS,
3407 SpecTL.getTypePtr()->getTemplateName(),
3408 SpecTL.getTemplateNameLoc(),
3409 ObjectType, UnqualLookup);
3410 if (Template.isNull())
3411 return 0;
3412
3413 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3414 Template);
3415 } else if (isa<DependentTemplateSpecializationType>(T)) {
3416 DependentTemplateSpecializationTypeLoc SpecTL
3417 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3418
3419 TemplateName Template
3420 = getDerived().RebuildTemplateName(SS,
3421 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003422 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003423 ObjectType, UnqualLookup);
3424 if (Template.isNull())
3425 return 0;
3426
3427 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3428 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003429 Template,
3430 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003431 } else {
3432 // Nothing special needs to be done for these.
3433 Result = getDerived().TransformType(TLB, TL);
3434 }
3435
3436 if (Result.isNull())
3437 return 0;
3438
3439 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3440}
3441
John McCalla2becad2009-10-21 00:40:46 +00003442template <class TyLoc> static inline
3443QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3444 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3445 NewT.setNameLoc(T.getNameLoc());
3446 return T.getType();
3447}
3448
John McCalla2becad2009-10-21 00:40:46 +00003449template<typename Derived>
3450QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003451 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003452 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3453 NewT.setBuiltinLoc(T.getBuiltinLoc());
3454 if (T.needsExtraLocalData())
3455 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3456 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003457}
Mike Stump1eb44332009-09-09 15:08:12 +00003458
Douglas Gregor577f75a2009-08-04 16:50:30 +00003459template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003460QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003461 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003462 // FIXME: recurse?
3463 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003464}
Mike Stump1eb44332009-09-09 15:08:12 +00003465
Douglas Gregor577f75a2009-08-04 16:50:30 +00003466template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003467QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003468 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003469 QualType PointeeType
3470 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003471 if (PointeeType.isNull())
3472 return QualType();
3473
3474 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003475 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003476 // A dependent pointer type 'T *' has is being transformed such
3477 // that an Objective-C class type is being replaced for 'T'. The
3478 // resulting pointer type is an ObjCObjectPointerType, not a
3479 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003480 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003481
John McCallc12c5bb2010-05-15 11:32:37 +00003482 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3483 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003484 return Result;
3485 }
John McCall43fed0d2010-11-12 08:19:04 +00003486
Douglas Gregor92e986e2010-04-22 16:44:27 +00003487 if (getDerived().AlwaysRebuild() ||
3488 PointeeType != TL.getPointeeLoc().getType()) {
3489 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3490 if (Result.isNull())
3491 return QualType();
3492 }
John McCallf85e1932011-06-15 23:02:42 +00003493
3494 // Objective-C ARC can add lifetime qualifiers to the type that we're
3495 // pointing to.
3496 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3497
Douglas Gregor92e986e2010-04-22 16:44:27 +00003498 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3499 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003500 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003501}
Mike Stump1eb44332009-09-09 15:08:12 +00003502
3503template<typename Derived>
3504QualType
John McCalla2becad2009-10-21 00:40:46 +00003505TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003506 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003507 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003508 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3509 if (PointeeType.isNull())
3510 return QualType();
3511
3512 QualType Result = TL.getType();
3513 if (getDerived().AlwaysRebuild() ||
3514 PointeeType != TL.getPointeeLoc().getType()) {
3515 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003516 TL.getSigilLoc());
3517 if (Result.isNull())
3518 return QualType();
3519 }
3520
Douglas Gregor39968ad2010-04-22 16:50:51 +00003521 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003522 NewT.setSigilLoc(TL.getSigilLoc());
3523 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003524}
3525
John McCall85737a72009-10-30 00:06:24 +00003526/// Transforms a reference type. Note that somewhat paradoxically we
3527/// don't care whether the type itself is an l-value type or an r-value
3528/// type; we only care if the type was *written* as an l-value type
3529/// or an r-value type.
3530template<typename Derived>
3531QualType
3532TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003533 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003534 const ReferenceType *T = TL.getTypePtr();
3535
3536 // Note that this works with the pointee-as-written.
3537 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3538 if (PointeeType.isNull())
3539 return QualType();
3540
3541 QualType Result = TL.getType();
3542 if (getDerived().AlwaysRebuild() ||
3543 PointeeType != T->getPointeeTypeAsWritten()) {
3544 Result = getDerived().RebuildReferenceType(PointeeType,
3545 T->isSpelledAsLValue(),
3546 TL.getSigilLoc());
3547 if (Result.isNull())
3548 return QualType();
3549 }
3550
John McCallf85e1932011-06-15 23:02:42 +00003551 // Objective-C ARC can add lifetime qualifiers to the type that we're
3552 // referring to.
3553 TLB.TypeWasModifiedSafely(
3554 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3555
John McCall85737a72009-10-30 00:06:24 +00003556 // r-value references can be rebuilt as l-value references.
3557 ReferenceTypeLoc NewTL;
3558 if (isa<LValueReferenceType>(Result))
3559 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3560 else
3561 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3562 NewTL.setSigilLoc(TL.getSigilLoc());
3563
3564 return Result;
3565}
3566
Mike Stump1eb44332009-09-09 15:08:12 +00003567template<typename Derived>
3568QualType
John McCalla2becad2009-10-21 00:40:46 +00003569TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003570 LValueReferenceTypeLoc TL) {
3571 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003572}
3573
Mike Stump1eb44332009-09-09 15:08:12 +00003574template<typename Derived>
3575QualType
John McCalla2becad2009-10-21 00:40:46 +00003576TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003577 RValueReferenceTypeLoc TL) {
3578 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003579}
Mike Stump1eb44332009-09-09 15:08:12 +00003580
Douglas Gregor577f75a2009-08-04 16:50:30 +00003581template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003582QualType
John McCalla2becad2009-10-21 00:40:46 +00003583TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003584 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003585 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003586 if (PointeeType.isNull())
3587 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003588
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003589 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3590 TypeSourceInfo* NewClsTInfo = 0;
3591 if (OldClsTInfo) {
3592 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3593 if (!NewClsTInfo)
3594 return QualType();
3595 }
3596
3597 const MemberPointerType *T = TL.getTypePtr();
3598 QualType OldClsType = QualType(T->getClass(), 0);
3599 QualType NewClsType;
3600 if (NewClsTInfo)
3601 NewClsType = NewClsTInfo->getType();
3602 else {
3603 NewClsType = getDerived().TransformType(OldClsType);
3604 if (NewClsType.isNull())
3605 return QualType();
3606 }
Mike Stump1eb44332009-09-09 15:08:12 +00003607
John McCalla2becad2009-10-21 00:40:46 +00003608 QualType Result = TL.getType();
3609 if (getDerived().AlwaysRebuild() ||
3610 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003611 NewClsType != OldClsType) {
3612 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003613 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003614 if (Result.isNull())
3615 return QualType();
3616 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003617
John McCalla2becad2009-10-21 00:40:46 +00003618 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3619 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003620 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003621
3622 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003623}
3624
Mike Stump1eb44332009-09-09 15:08:12 +00003625template<typename Derived>
3626QualType
John McCalla2becad2009-10-21 00:40:46 +00003627TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003628 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003629 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003630 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003631 if (ElementType.isNull())
3632 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003633
John McCalla2becad2009-10-21 00:40:46 +00003634 QualType Result = TL.getType();
3635 if (getDerived().AlwaysRebuild() ||
3636 ElementType != T->getElementType()) {
3637 Result = getDerived().RebuildConstantArrayType(ElementType,
3638 T->getSizeModifier(),
3639 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003640 T->getIndexTypeCVRQualifiers(),
3641 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003642 if (Result.isNull())
3643 return QualType();
3644 }
Eli Friedman457a3772012-01-25 22:19:07 +00003645
3646 // We might have either a ConstantArrayType or a VariableArrayType now:
3647 // a ConstantArrayType is allowed to have an element type which is a
3648 // VariableArrayType if the type is dependent. Fortunately, all array
3649 // types have the same location layout.
3650 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003651 NewTL.setLBracketLoc(TL.getLBracketLoc());
3652 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003653
John McCalla2becad2009-10-21 00:40:46 +00003654 Expr *Size = TL.getSizeExpr();
3655 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003656 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3657 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003658 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003659 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003660 }
3661 NewTL.setSizeExpr(Size);
3662
3663 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003664}
Mike Stump1eb44332009-09-09 15:08:12 +00003665
Douglas Gregor577f75a2009-08-04 16:50:30 +00003666template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003667QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003668 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003669 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003670 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003671 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003672 if (ElementType.isNull())
3673 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003674
John McCalla2becad2009-10-21 00:40:46 +00003675 QualType Result = TL.getType();
3676 if (getDerived().AlwaysRebuild() ||
3677 ElementType != T->getElementType()) {
3678 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003679 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003680 T->getIndexTypeCVRQualifiers(),
3681 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003682 if (Result.isNull())
3683 return QualType();
3684 }
Sean Huntc3021132010-05-05 15:23:54 +00003685
John McCalla2becad2009-10-21 00:40:46 +00003686 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3687 NewTL.setLBracketLoc(TL.getLBracketLoc());
3688 NewTL.setRBracketLoc(TL.getRBracketLoc());
3689 NewTL.setSizeExpr(0);
3690
3691 return Result;
3692}
3693
3694template<typename Derived>
3695QualType
3696TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003697 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003698 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003699 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3700 if (ElementType.isNull())
3701 return QualType();
3702
John McCall60d7b3a2010-08-24 06:29:42 +00003703 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003704 = getDerived().TransformExpr(T->getSizeExpr());
3705 if (SizeResult.isInvalid())
3706 return QualType();
3707
John McCall9ae2f072010-08-23 23:25:46 +00003708 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003709
3710 QualType Result = TL.getType();
3711 if (getDerived().AlwaysRebuild() ||
3712 ElementType != T->getElementType() ||
3713 Size != T->getSizeExpr()) {
3714 Result = getDerived().RebuildVariableArrayType(ElementType,
3715 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003716 Size,
John McCalla2becad2009-10-21 00:40:46 +00003717 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003718 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003719 if (Result.isNull())
3720 return QualType();
3721 }
Sean Huntc3021132010-05-05 15:23:54 +00003722
John McCalla2becad2009-10-21 00:40:46 +00003723 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3724 NewTL.setLBracketLoc(TL.getLBracketLoc());
3725 NewTL.setRBracketLoc(TL.getRBracketLoc());
3726 NewTL.setSizeExpr(Size);
3727
3728 return Result;
3729}
3730
3731template<typename Derived>
3732QualType
3733TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003734 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003735 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003736 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3737 if (ElementType.isNull())
3738 return QualType();
3739
Richard Smithf6702a32011-12-20 02:08:33 +00003740 // Array bounds are constant expressions.
3741 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3742 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003743
John McCall3b657512011-01-19 10:06:00 +00003744 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3745 Expr *origSize = TL.getSizeExpr();
3746 if (!origSize) origSize = T->getSizeExpr();
3747
3748 ExprResult sizeResult
3749 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003750 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003751 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003752 return QualType();
3753
John McCall3b657512011-01-19 10:06:00 +00003754 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003755
3756 QualType Result = TL.getType();
3757 if (getDerived().AlwaysRebuild() ||
3758 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003759 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003760 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3761 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003762 size,
John McCalla2becad2009-10-21 00:40:46 +00003763 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003764 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003765 if (Result.isNull())
3766 return QualType();
3767 }
John McCalla2becad2009-10-21 00:40:46 +00003768
3769 // We might have any sort of array type now, but fortunately they
3770 // all have the same location layout.
3771 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3772 NewTL.setLBracketLoc(TL.getLBracketLoc());
3773 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003774 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003775
3776 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003777}
Mike Stump1eb44332009-09-09 15:08:12 +00003778
3779template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003780QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003781 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003782 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003783 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003784
3785 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003786 QualType ElementType = getDerived().TransformType(T->getElementType());
3787 if (ElementType.isNull())
3788 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003789
Richard Smithf6702a32011-12-20 02:08:33 +00003790 // Vector sizes are constant expressions.
3791 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3792 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003793
John McCall60d7b3a2010-08-24 06:29:42 +00003794 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003795 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003796 if (Size.isInvalid())
3797 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003798
John McCalla2becad2009-10-21 00:40:46 +00003799 QualType Result = TL.getType();
3800 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003801 ElementType != T->getElementType() ||
3802 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003803 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003804 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003805 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003806 if (Result.isNull())
3807 return QualType();
3808 }
John McCalla2becad2009-10-21 00:40:46 +00003809
3810 // Result might be dependent or not.
3811 if (isa<DependentSizedExtVectorType>(Result)) {
3812 DependentSizedExtVectorTypeLoc NewTL
3813 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3814 NewTL.setNameLoc(TL.getNameLoc());
3815 } else {
3816 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3817 NewTL.setNameLoc(TL.getNameLoc());
3818 }
3819
3820 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003821}
Mike Stump1eb44332009-09-09 15:08:12 +00003822
3823template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003824QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003825 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003826 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003827 QualType ElementType = getDerived().TransformType(T->getElementType());
3828 if (ElementType.isNull())
3829 return QualType();
3830
John McCalla2becad2009-10-21 00:40:46 +00003831 QualType Result = TL.getType();
3832 if (getDerived().AlwaysRebuild() ||
3833 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003834 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003835 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003836 if (Result.isNull())
3837 return QualType();
3838 }
Sean Huntc3021132010-05-05 15:23:54 +00003839
John McCalla2becad2009-10-21 00:40:46 +00003840 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3841 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003842
John McCalla2becad2009-10-21 00:40:46 +00003843 return Result;
3844}
3845
3846template<typename Derived>
3847QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003848 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003849 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003850 QualType ElementType = getDerived().TransformType(T->getElementType());
3851 if (ElementType.isNull())
3852 return QualType();
3853
3854 QualType Result = TL.getType();
3855 if (getDerived().AlwaysRebuild() ||
3856 ElementType != T->getElementType()) {
3857 Result = getDerived().RebuildExtVectorType(ElementType,
3858 T->getNumElements(),
3859 /*FIXME*/ SourceLocation());
3860 if (Result.isNull())
3861 return QualType();
3862 }
Sean Huntc3021132010-05-05 15:23:54 +00003863
John McCalla2becad2009-10-21 00:40:46 +00003864 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3865 NewTL.setNameLoc(TL.getNameLoc());
3866
3867 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003868}
Mike Stump1eb44332009-09-09 15:08:12 +00003869
3870template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003871ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003872TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003873 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003874 llvm::Optional<unsigned> NumExpansions,
3875 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003876 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003877 TypeSourceInfo *NewDI = 0;
3878
3879 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3880 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003881 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003882 TypeLoc OldTL = OldDI->getTypeLoc();
3883 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3884
3885 TypeLocBuilder TLB;
3886 TypeLoc NewTL = OldDI->getTypeLoc();
3887 TLB.reserve(NewTL.getFullDataSize());
3888
3889 QualType Result = getDerived().TransformType(TLB,
3890 OldExpansionTL.getPatternLoc());
3891 if (Result.isNull())
3892 return 0;
3893
3894 Result = RebuildPackExpansionType(Result,
3895 OldExpansionTL.getPatternLoc().getSourceRange(),
3896 OldExpansionTL.getEllipsisLoc(),
3897 NumExpansions);
3898 if (Result.isNull())
3899 return 0;
3900
3901 PackExpansionTypeLoc NewExpansionTL
3902 = TLB.push<PackExpansionTypeLoc>(Result);
3903 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3904 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3905 } else
3906 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003907 if (!NewDI)
3908 return 0;
3909
John McCallfb44de92011-05-01 22:35:37 +00003910 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003911 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003912
3913 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3914 OldParm->getDeclContext(),
3915 OldParm->getInnerLocStart(),
3916 OldParm->getLocation(),
3917 OldParm->getIdentifier(),
3918 NewDI->getType(),
3919 NewDI,
3920 OldParm->getStorageClass(),
3921 OldParm->getStorageClassAsWritten(),
3922 /* DefArg */ NULL);
3923 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3924 OldParm->getFunctionScopeIndex() + indexAdjustment);
3925 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003926}
3927
3928template<typename Derived>
3929bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003930 TransformFunctionTypeParams(SourceLocation Loc,
3931 ParmVarDecl **Params, unsigned NumParams,
3932 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003933 SmallVectorImpl<QualType> &OutParamTypes,
3934 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003935 int indexAdjustment = 0;
3936
Douglas Gregora009b592011-01-07 00:20:55 +00003937 for (unsigned i = 0; i != NumParams; ++i) {
3938 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003939 assert(OldParm->getFunctionScopeIndex() == i);
3940
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003941 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003942 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003943 if (OldParm->isParameterPack()) {
3944 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003945 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003946
Douglas Gregor603cfb42011-01-05 23:12:31 +00003947 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003948 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3949 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3950 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3951 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003952 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3953
Douglas Gregor603cfb42011-01-05 23:12:31 +00003954 // Determine whether we should expand the parameter packs.
3955 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003956 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003957 llvm::Optional<unsigned> OrigNumExpansions
3958 = ExpansionTL.getTypePtr()->getNumExpansions();
3959 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003960 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3961 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003962 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003963 ShouldExpand,
3964 RetainExpansion,
3965 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003966 return true;
3967 }
3968
3969 if (ShouldExpand) {
3970 // Expand the function parameter pack into multiple, separate
3971 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003972 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003973 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003974 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3975 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003976 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003977 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003978 OrigNumExpansions,
3979 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003980 if (!NewParm)
3981 return true;
3982
Douglas Gregora009b592011-01-07 00:20:55 +00003983 OutParamTypes.push_back(NewParm->getType());
3984 if (PVars)
3985 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003986 }
Douglas Gregord3731192011-01-10 07:32:04 +00003987
3988 // If we're supposed to retain a pack expansion, do so by temporarily
3989 // forgetting the partially-substituted parameter pack.
3990 if (RetainExpansion) {
3991 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3992 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003993 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003994 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003995 OrigNumExpansions,
3996 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00003997 if (!NewParm)
3998 return true;
3999
4000 OutParamTypes.push_back(NewParm->getType());
4001 if (PVars)
4002 PVars->push_back(NewParm);
4003 }
4004
John McCallfb44de92011-05-01 22:35:37 +00004005 // The next parameter should have the same adjustment as the
4006 // last thing we pushed, but we post-incremented indexAdjustment
4007 // on every push. Also, if we push nothing, the adjustment should
4008 // go down by one.
4009 indexAdjustment--;
4010
Douglas Gregor603cfb42011-01-05 23:12:31 +00004011 // We're done with the pack expansion.
4012 continue;
4013 }
4014
4015 // We'll substitute the parameter now without expanding the pack
4016 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004017 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4018 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004019 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004020 NumExpansions,
4021 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004022 } else {
4023 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004024 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004025 llvm::Optional<unsigned>(),
4026 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004027 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004028
John McCall21ef0fa2010-03-11 09:03:00 +00004029 if (!NewParm)
4030 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004031
Douglas Gregora009b592011-01-07 00:20:55 +00004032 OutParamTypes.push_back(NewParm->getType());
4033 if (PVars)
4034 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004035 continue;
4036 }
John McCall21ef0fa2010-03-11 09:03:00 +00004037
4038 // Deal with the possibility that we don't have a parameter
4039 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004040 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004041 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004042 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004043 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004044 if (const PackExpansionType *Expansion
4045 = dyn_cast<PackExpansionType>(OldType)) {
4046 // We have a function parameter pack that may need to be expanded.
4047 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004048 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004049 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4050
4051 // Determine whether we should expand the parameter packs.
4052 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004053 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004054 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004055 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004056 ShouldExpand,
4057 RetainExpansion,
4058 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004059 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004060 }
4061
4062 if (ShouldExpand) {
4063 // Expand the function parameter pack into multiple, separate
4064 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004065 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004066 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4067 QualType NewType = getDerived().TransformType(Pattern);
4068 if (NewType.isNull())
4069 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004070
Douglas Gregora009b592011-01-07 00:20:55 +00004071 OutParamTypes.push_back(NewType);
4072 if (PVars)
4073 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004074 }
4075
4076 // We're done with the pack expansion.
4077 continue;
4078 }
4079
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004080 // If we're supposed to retain a pack expansion, do so by temporarily
4081 // forgetting the partially-substituted parameter pack.
4082 if (RetainExpansion) {
4083 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4084 QualType NewType = getDerived().TransformType(Pattern);
4085 if (NewType.isNull())
4086 return true;
4087
4088 OutParamTypes.push_back(NewType);
4089 if (PVars)
4090 PVars->push_back(0);
4091 }
Douglas Gregord3731192011-01-10 07:32:04 +00004092
Douglas Gregor603cfb42011-01-05 23:12:31 +00004093 // We'll substitute the parameter now without expanding the pack
4094 // expansion.
4095 OldType = Expansion->getPattern();
4096 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004097 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4098 NewType = getDerived().TransformType(OldType);
4099 } else {
4100 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004101 }
4102
Douglas Gregor603cfb42011-01-05 23:12:31 +00004103 if (NewType.isNull())
4104 return true;
4105
4106 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004107 NewType = getSema().Context.getPackExpansionType(NewType,
4108 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004109
Douglas Gregora009b592011-01-07 00:20:55 +00004110 OutParamTypes.push_back(NewType);
4111 if (PVars)
4112 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004113 }
4114
John McCallfb44de92011-05-01 22:35:37 +00004115#ifndef NDEBUG
4116 if (PVars) {
4117 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4118 if (ParmVarDecl *parm = (*PVars)[i])
4119 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004120 }
John McCallfb44de92011-05-01 22:35:37 +00004121#endif
4122
4123 return false;
4124}
John McCall21ef0fa2010-03-11 09:03:00 +00004125
4126template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004127QualType
John McCalla2becad2009-10-21 00:40:46 +00004128TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004129 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004130 // Transform the parameters and return type.
4131 //
4132 // We instantiate in source order, with the return type first followed by
4133 // the parameters, because users tend to expect this (even if they shouldn't
4134 // rely on it!).
4135 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004136 // When the function has a trailing return type, we instantiate the
4137 // parameters before the return type, since the return type can then refer
4138 // to the parameters themselves (via decltype, sizeof, etc.).
4139 //
Chris Lattner686775d2011-07-20 06:58:45 +00004140 SmallVector<QualType, 4> ParamTypes;
4141 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004142 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004143
Douglas Gregordab60ad2010-10-01 18:44:50 +00004144 QualType ResultType;
4145
4146 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004147 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4148 TL.getParmArray(),
4149 TL.getNumArgs(),
4150 TL.getTypePtr()->arg_type_begin(),
4151 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004152 return QualType();
4153
4154 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4155 if (ResultType.isNull())
4156 return QualType();
4157 }
4158 else {
4159 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4160 if (ResultType.isNull())
4161 return QualType();
4162
Douglas Gregora009b592011-01-07 00:20:55 +00004163 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4164 TL.getParmArray(),
4165 TL.getNumArgs(),
4166 TL.getTypePtr()->arg_type_begin(),
4167 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004168 return QualType();
4169 }
4170
John McCalla2becad2009-10-21 00:40:46 +00004171 QualType Result = TL.getType();
4172 if (getDerived().AlwaysRebuild() ||
4173 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004174 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004175 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4176 Result = getDerived().RebuildFunctionProtoType(ResultType,
4177 ParamTypes.data(),
4178 ParamTypes.size(),
4179 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004180 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004181 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004182 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004183 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004184 if (Result.isNull())
4185 return QualType();
4186 }
Mike Stump1eb44332009-09-09 15:08:12 +00004187
John McCalla2becad2009-10-21 00:40:46 +00004188 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004189 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4190 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004191 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004192 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4193 NewTL.setArg(i, ParamDecls[i]);
4194
4195 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004196}
Mike Stump1eb44332009-09-09 15:08:12 +00004197
Douglas Gregor577f75a2009-08-04 16:50:30 +00004198template<typename Derived>
4199QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004200 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004201 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004202 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004203 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4204 if (ResultType.isNull())
4205 return QualType();
4206
4207 QualType Result = TL.getType();
4208 if (getDerived().AlwaysRebuild() ||
4209 ResultType != T->getResultType())
4210 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4211
4212 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004213 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4214 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004215 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004216
4217 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004218}
Mike Stump1eb44332009-09-09 15:08:12 +00004219
John McCalled976492009-12-04 22:46:56 +00004220template<typename Derived> QualType
4221TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004222 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004223 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004224 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004225 if (!D)
4226 return QualType();
4227
4228 QualType Result = TL.getType();
4229 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4230 Result = getDerived().RebuildUnresolvedUsingType(D);
4231 if (Result.isNull())
4232 return QualType();
4233 }
4234
4235 // We might get an arbitrary type spec type back. We should at
4236 // least always get a type spec type, though.
4237 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4238 NewTL.setNameLoc(TL.getNameLoc());
4239
4240 return Result;
4241}
4242
Douglas Gregor577f75a2009-08-04 16:50:30 +00004243template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004244QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004245 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004246 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004247 TypedefNameDecl *Typedef
4248 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4249 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004250 if (!Typedef)
4251 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004252
John McCalla2becad2009-10-21 00:40:46 +00004253 QualType Result = TL.getType();
4254 if (getDerived().AlwaysRebuild() ||
4255 Typedef != T->getDecl()) {
4256 Result = getDerived().RebuildTypedefType(Typedef);
4257 if (Result.isNull())
4258 return QualType();
4259 }
Mike Stump1eb44332009-09-09 15:08:12 +00004260
John McCalla2becad2009-10-21 00:40:46 +00004261 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4262 NewTL.setNameLoc(TL.getNameLoc());
4263
4264 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004265}
Mike Stump1eb44332009-09-09 15:08:12 +00004266
Douglas Gregor577f75a2009-08-04 16:50:30 +00004267template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004268QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004269 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004270 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004271 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004272
John McCall60d7b3a2010-08-24 06:29:42 +00004273 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004274 if (E.isInvalid())
4275 return QualType();
4276
John McCalla2becad2009-10-21 00:40:46 +00004277 QualType Result = TL.getType();
4278 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004279 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004280 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004281 if (Result.isNull())
4282 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004283 }
John McCalla2becad2009-10-21 00:40:46 +00004284 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004285
John McCalla2becad2009-10-21 00:40:46 +00004286 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004287 NewTL.setTypeofLoc(TL.getTypeofLoc());
4288 NewTL.setLParenLoc(TL.getLParenLoc());
4289 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004290
4291 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004292}
Mike Stump1eb44332009-09-09 15:08:12 +00004293
4294template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004295QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004296 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004297 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4298 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4299 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004300 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004301
John McCalla2becad2009-10-21 00:40:46 +00004302 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004303 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4304 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004305 if (Result.isNull())
4306 return QualType();
4307 }
Mike Stump1eb44332009-09-09 15:08:12 +00004308
John McCalla2becad2009-10-21 00:40:46 +00004309 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004310 NewTL.setTypeofLoc(TL.getTypeofLoc());
4311 NewTL.setLParenLoc(TL.getLParenLoc());
4312 NewTL.setRParenLoc(TL.getRParenLoc());
4313 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004314
4315 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004316}
Mike Stump1eb44332009-09-09 15:08:12 +00004317
4318template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004319QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004320 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004321 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004322
Douglas Gregor670444e2009-08-04 22:27:00 +00004323 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004324 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4325 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004326
John McCall60d7b3a2010-08-24 06:29:42 +00004327 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004328 if (E.isInvalid())
4329 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004330
Richard Smith76f3f692012-02-22 02:04:18 +00004331 E = getSema().ActOnDecltypeExpression(E.take());
4332 if (E.isInvalid())
4333 return QualType();
4334
John McCalla2becad2009-10-21 00:40:46 +00004335 QualType Result = TL.getType();
4336 if (getDerived().AlwaysRebuild() ||
4337 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004338 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004339 if (Result.isNull())
4340 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004341 }
John McCalla2becad2009-10-21 00:40:46 +00004342 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004343
John McCalla2becad2009-10-21 00:40:46 +00004344 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4345 NewTL.setNameLoc(TL.getNameLoc());
4346
4347 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004348}
4349
4350template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004351QualType TreeTransform<Derived>::TransformUnaryTransformType(
4352 TypeLocBuilder &TLB,
4353 UnaryTransformTypeLoc TL) {
4354 QualType Result = TL.getType();
4355 if (Result->isDependentType()) {
4356 const UnaryTransformType *T = TL.getTypePtr();
4357 QualType NewBase =
4358 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4359 Result = getDerived().RebuildUnaryTransformType(NewBase,
4360 T->getUTTKind(),
4361 TL.getKWLoc());
4362 if (Result.isNull())
4363 return QualType();
4364 }
4365
4366 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4367 NewTL.setKWLoc(TL.getKWLoc());
4368 NewTL.setParensRange(TL.getParensRange());
4369 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4370 return Result;
4371}
4372
4373template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004374QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4375 AutoTypeLoc TL) {
4376 const AutoType *T = TL.getTypePtr();
4377 QualType OldDeduced = T->getDeducedType();
4378 QualType NewDeduced;
4379 if (!OldDeduced.isNull()) {
4380 NewDeduced = getDerived().TransformType(OldDeduced);
4381 if (NewDeduced.isNull())
4382 return QualType();
4383 }
4384
4385 QualType Result = TL.getType();
4386 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4387 Result = getDerived().RebuildAutoType(NewDeduced);
4388 if (Result.isNull())
4389 return QualType();
4390 }
4391
4392 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4393 NewTL.setNameLoc(TL.getNameLoc());
4394
4395 return Result;
4396}
4397
4398template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004399QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004400 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004401 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004402 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004403 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4404 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004405 if (!Record)
4406 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004407
John McCalla2becad2009-10-21 00:40:46 +00004408 QualType Result = TL.getType();
4409 if (getDerived().AlwaysRebuild() ||
4410 Record != T->getDecl()) {
4411 Result = getDerived().RebuildRecordType(Record);
4412 if (Result.isNull())
4413 return QualType();
4414 }
Mike Stump1eb44332009-09-09 15:08:12 +00004415
John McCalla2becad2009-10-21 00:40:46 +00004416 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4417 NewTL.setNameLoc(TL.getNameLoc());
4418
4419 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004420}
Mike Stump1eb44332009-09-09 15:08:12 +00004421
4422template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004423QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004424 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004425 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004426 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004427 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4428 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004429 if (!Enum)
4430 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004431
John McCalla2becad2009-10-21 00:40:46 +00004432 QualType Result = TL.getType();
4433 if (getDerived().AlwaysRebuild() ||
4434 Enum != T->getDecl()) {
4435 Result = getDerived().RebuildEnumType(Enum);
4436 if (Result.isNull())
4437 return QualType();
4438 }
Mike Stump1eb44332009-09-09 15:08:12 +00004439
John McCalla2becad2009-10-21 00:40:46 +00004440 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4441 NewTL.setNameLoc(TL.getNameLoc());
4442
4443 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004444}
John McCall7da24312009-09-05 00:15:47 +00004445
John McCall3cb0ebd2010-03-10 03:28:59 +00004446template<typename Derived>
4447QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4448 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004449 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004450 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4451 TL.getTypePtr()->getDecl());
4452 if (!D) return QualType();
4453
4454 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4455 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4456 return T;
4457}
4458
Douglas Gregor577f75a2009-08-04 16:50:30 +00004459template<typename Derived>
4460QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004461 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004462 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004463 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004464}
4465
Mike Stump1eb44332009-09-09 15:08:12 +00004466template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004467QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004468 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004469 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004470 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4471
4472 // Substitute into the replacement type, which itself might involve something
4473 // that needs to be transformed. This only tends to occur with default
4474 // template arguments of template template parameters.
4475 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4476 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4477 if (Replacement.isNull())
4478 return QualType();
4479
4480 // Always canonicalize the replacement type.
4481 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4482 QualType Result
4483 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4484 Replacement);
4485
4486 // Propagate type-source information.
4487 SubstTemplateTypeParmTypeLoc NewTL
4488 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4489 NewTL.setNameLoc(TL.getNameLoc());
4490 return Result;
4491
John McCall49a832b2009-10-18 09:09:24 +00004492}
4493
4494template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004495QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4496 TypeLocBuilder &TLB,
4497 SubstTemplateTypeParmPackTypeLoc TL) {
4498 return TransformTypeSpecType(TLB, TL);
4499}
4500
4501template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004502QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004503 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004504 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004505 const TemplateSpecializationType *T = TL.getTypePtr();
4506
Douglas Gregor1d752d72011-03-02 18:46:51 +00004507 // The nested-name-specifier never matters in a TemplateSpecializationType,
4508 // because we can't have a dependent nested-name-specifier anyway.
4509 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004510 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004511 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4512 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004513 if (Template.isNull())
4514 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004515
John McCall43fed0d2010-11-12 08:19:04 +00004516 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4517}
4518
Eli Friedmanb001de72011-10-06 23:00:33 +00004519template<typename Derived>
4520QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4521 AtomicTypeLoc TL) {
4522 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4523 if (ValueType.isNull())
4524 return QualType();
4525
4526 QualType Result = TL.getType();
4527 if (getDerived().AlwaysRebuild() ||
4528 ValueType != TL.getValueLoc().getType()) {
4529 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4530 if (Result.isNull())
4531 return QualType();
4532 }
4533
4534 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4535 NewTL.setKWLoc(TL.getKWLoc());
4536 NewTL.setLParenLoc(TL.getLParenLoc());
4537 NewTL.setRParenLoc(TL.getRParenLoc());
4538
4539 return Result;
4540}
4541
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004542namespace {
4543 /// \brief Simple iterator that traverses the template arguments in a
4544 /// container that provides a \c getArgLoc() member function.
4545 ///
4546 /// This iterator is intended to be used with the iterator form of
4547 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4548 template<typename ArgLocContainer>
4549 class TemplateArgumentLocContainerIterator {
4550 ArgLocContainer *Container;
4551 unsigned Index;
4552
4553 public:
4554 typedef TemplateArgumentLoc value_type;
4555 typedef TemplateArgumentLoc reference;
4556 typedef int difference_type;
4557 typedef std::input_iterator_tag iterator_category;
4558
4559 class pointer {
4560 TemplateArgumentLoc Arg;
4561
4562 public:
4563 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4564
4565 const TemplateArgumentLoc *operator->() const {
4566 return &Arg;
4567 }
4568 };
4569
4570
4571 TemplateArgumentLocContainerIterator() {}
4572
4573 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4574 unsigned Index)
4575 : Container(&Container), Index(Index) { }
4576
4577 TemplateArgumentLocContainerIterator &operator++() {
4578 ++Index;
4579 return *this;
4580 }
4581
4582 TemplateArgumentLocContainerIterator operator++(int) {
4583 TemplateArgumentLocContainerIterator Old(*this);
4584 ++(*this);
4585 return Old;
4586 }
4587
4588 TemplateArgumentLoc operator*() const {
4589 return Container->getArgLoc(Index);
4590 }
4591
4592 pointer operator->() const {
4593 return pointer(Container->getArgLoc(Index));
4594 }
4595
4596 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004597 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004598 return X.Container == Y.Container && X.Index == Y.Index;
4599 }
4600
4601 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004602 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004603 return !(X == Y);
4604 }
4605 };
4606}
4607
4608
John McCall43fed0d2010-11-12 08:19:04 +00004609template <typename Derived>
4610QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4611 TypeLocBuilder &TLB,
4612 TemplateSpecializationTypeLoc TL,
4613 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004614 TemplateArgumentListInfo NewTemplateArgs;
4615 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4616 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004617 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4618 ArgIterator;
4619 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4620 ArgIterator(TL, TL.getNumArgs()),
4621 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004622 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004623
John McCall833ca992009-10-29 08:12:44 +00004624 // FIXME: maybe don't rebuild if all the template arguments are the same.
4625
4626 QualType Result =
4627 getDerived().RebuildTemplateSpecializationType(Template,
4628 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004629 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004630
4631 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004632 // Specializations of template template parameters are represented as
4633 // TemplateSpecializationTypes, and substitution of type alias templates
4634 // within a dependent context can transform them into
4635 // DependentTemplateSpecializationTypes.
4636 if (isa<DependentTemplateSpecializationType>(Result)) {
4637 DependentTemplateSpecializationTypeLoc NewTL
4638 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004639 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004640 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004641 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004642 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004643 NewTL.setLAngleLoc(TL.getLAngleLoc());
4644 NewTL.setRAngleLoc(TL.getRAngleLoc());
4645 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4646 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4647 return Result;
4648 }
4649
John McCall833ca992009-10-29 08:12:44 +00004650 TemplateSpecializationTypeLoc NewTL
4651 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004652 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004653 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4654 NewTL.setLAngleLoc(TL.getLAngleLoc());
4655 NewTL.setRAngleLoc(TL.getRAngleLoc());
4656 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4657 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004658 }
Mike Stump1eb44332009-09-09 15:08:12 +00004659
John McCall833ca992009-10-29 08:12:44 +00004660 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004661}
Mike Stump1eb44332009-09-09 15:08:12 +00004662
Douglas Gregora88f09f2011-02-28 17:23:35 +00004663template <typename Derived>
4664QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4665 TypeLocBuilder &TLB,
4666 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004667 TemplateName Template,
4668 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004669 TemplateArgumentListInfo NewTemplateArgs;
4670 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4671 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4672 typedef TemplateArgumentLocContainerIterator<
4673 DependentTemplateSpecializationTypeLoc> ArgIterator;
4674 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4675 ArgIterator(TL, TL.getNumArgs()),
4676 NewTemplateArgs))
4677 return QualType();
4678
4679 // FIXME: maybe don't rebuild if all the template arguments are the same.
4680
4681 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4682 QualType Result
4683 = getSema().Context.getDependentTemplateSpecializationType(
4684 TL.getTypePtr()->getKeyword(),
4685 DTN->getQualifier(),
4686 DTN->getIdentifier(),
4687 NewTemplateArgs);
4688
4689 DependentTemplateSpecializationTypeLoc NewTL
4690 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004691 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004692 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004693 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004694 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004695 NewTL.setLAngleLoc(TL.getLAngleLoc());
4696 NewTL.setRAngleLoc(TL.getRAngleLoc());
4697 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4698 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4699 return Result;
4700 }
4701
4702 QualType Result
4703 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004704 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004705 NewTemplateArgs);
4706
4707 if (!Result.isNull()) {
4708 /// FIXME: Wrap this in an elaborated-type-specifier?
4709 TemplateSpecializationTypeLoc NewTL
4710 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004711 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004712 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004713 NewTL.setLAngleLoc(TL.getLAngleLoc());
4714 NewTL.setRAngleLoc(TL.getRAngleLoc());
4715 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4716 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4717 }
4718
4719 return Result;
4720}
4721
Mike Stump1eb44332009-09-09 15:08:12 +00004722template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004723QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004724TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004725 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004726 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004727
Douglas Gregor9e876872011-03-01 18:12:44 +00004728 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004729 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004730 if (TL.getQualifierLoc()) {
4731 QualifierLoc
4732 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4733 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004734 return QualType();
4735 }
Mike Stump1eb44332009-09-09 15:08:12 +00004736
John McCall43fed0d2010-11-12 08:19:04 +00004737 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4738 if (NamedT.isNull())
4739 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004740
Richard Smith3e4c6c42011-05-05 21:57:07 +00004741 // C++0x [dcl.type.elab]p2:
4742 // If the identifier resolves to a typedef-name or the simple-template-id
4743 // resolves to an alias template specialization, the
4744 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004745 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4746 if (const TemplateSpecializationType *TST =
4747 NamedT->getAs<TemplateSpecializationType>()) {
4748 TemplateName Template = TST->getTemplateName();
4749 if (TypeAliasTemplateDecl *TAT =
4750 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4751 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4752 diag::err_tag_reference_non_tag) << 4;
4753 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4754 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004755 }
4756 }
4757
John McCalla2becad2009-10-21 00:40:46 +00004758 QualType Result = TL.getType();
4759 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004760 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004761 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004762 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004763 T->getKeyword(),
4764 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004765 if (Result.isNull())
4766 return QualType();
4767 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004768
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004769 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004770 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004771 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004772 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004773}
Mike Stump1eb44332009-09-09 15:08:12 +00004774
4775template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004776QualType TreeTransform<Derived>::TransformAttributedType(
4777 TypeLocBuilder &TLB,
4778 AttributedTypeLoc TL) {
4779 const AttributedType *oldType = TL.getTypePtr();
4780 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4781 if (modifiedType.isNull())
4782 return QualType();
4783
4784 QualType result = TL.getType();
4785
4786 // FIXME: dependent operand expressions?
4787 if (getDerived().AlwaysRebuild() ||
4788 modifiedType != oldType->getModifiedType()) {
4789 // TODO: this is really lame; we should really be rebuilding the
4790 // equivalent type from first principles.
4791 QualType equivalentType
4792 = getDerived().TransformType(oldType->getEquivalentType());
4793 if (equivalentType.isNull())
4794 return QualType();
4795 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4796 modifiedType,
4797 equivalentType);
4798 }
4799
4800 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4801 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4802 if (TL.hasAttrOperand())
4803 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4804 if (TL.hasAttrExprOperand())
4805 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4806 else if (TL.hasAttrEnumOperand())
4807 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4808
4809 return result;
4810}
4811
4812template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004813QualType
4814TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4815 ParenTypeLoc TL) {
4816 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4817 if (Inner.isNull())
4818 return QualType();
4819
4820 QualType Result = TL.getType();
4821 if (getDerived().AlwaysRebuild() ||
4822 Inner != TL.getInnerLoc().getType()) {
4823 Result = getDerived().RebuildParenType(Inner);
4824 if (Result.isNull())
4825 return QualType();
4826 }
4827
4828 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4829 NewTL.setLParenLoc(TL.getLParenLoc());
4830 NewTL.setRParenLoc(TL.getRParenLoc());
4831 return Result;
4832}
4833
4834template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004835QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004836 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004837 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004838
Douglas Gregor2494dd02011-03-01 01:34:45 +00004839 NestedNameSpecifierLoc QualifierLoc
4840 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4841 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004842 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004843
John McCall33500952010-06-11 00:33:02 +00004844 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004845 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004846 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004847 QualifierLoc,
4848 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004849 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004850 if (Result.isNull())
4851 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004852
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004853 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4854 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004855 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4856
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004857 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004858 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004859 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004860 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004861 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004862 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004863 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004864 NewTL.setNameLoc(TL.getNameLoc());
4865 }
John McCalla2becad2009-10-21 00:40:46 +00004866 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004867}
Mike Stump1eb44332009-09-09 15:08:12 +00004868
Douglas Gregor577f75a2009-08-04 16:50:30 +00004869template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004870QualType TreeTransform<Derived>::
4871 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004872 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004873 NestedNameSpecifierLoc QualifierLoc;
4874 if (TL.getQualifierLoc()) {
4875 QualifierLoc
4876 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4877 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004878 return QualType();
4879 }
4880
John McCall43fed0d2010-11-12 08:19:04 +00004881 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004882 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004883}
4884
4885template<typename Derived>
4886QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004887TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4888 DependentTemplateSpecializationTypeLoc TL,
4889 NestedNameSpecifierLoc QualifierLoc) {
4890 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4891
4892 TemplateArgumentListInfo NewTemplateArgs;
4893 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4894 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4895
4896 typedef TemplateArgumentLocContainerIterator<
4897 DependentTemplateSpecializationTypeLoc> ArgIterator;
4898 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4899 ArgIterator(TL, TL.getNumArgs()),
4900 NewTemplateArgs))
4901 return QualType();
4902
4903 QualType Result
4904 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4905 QualifierLoc,
4906 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004907 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004908 NewTemplateArgs);
4909 if (Result.isNull())
4910 return QualType();
4911
4912 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4913 QualType NamedT = ElabT->getNamedType();
4914
4915 // Copy information relevant to the template specialization.
4916 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004917 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004918 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004919 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004920 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4921 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004922 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004923 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004924
4925 // Copy information relevant to the elaborated type.
4926 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004927 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004928 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004929 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4930 DependentTemplateSpecializationTypeLoc SpecTL
4931 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004932 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004933 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004934 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004935 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004936 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4937 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004938 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004939 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004940 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004941 TemplateSpecializationTypeLoc SpecTL
4942 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004943 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004944 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004945 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4946 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004947 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004948 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004949 }
4950 return Result;
4951}
4952
4953template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004954QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4955 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004956 QualType Pattern
4957 = getDerived().TransformType(TLB, TL.getPatternLoc());
4958 if (Pattern.isNull())
4959 return QualType();
4960
4961 QualType Result = TL.getType();
4962 if (getDerived().AlwaysRebuild() ||
4963 Pattern != TL.getPatternLoc().getType()) {
4964 Result = getDerived().RebuildPackExpansionType(Pattern,
4965 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004966 TL.getEllipsisLoc(),
4967 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004968 if (Result.isNull())
4969 return QualType();
4970 }
4971
4972 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4973 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4974 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004975}
4976
4977template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004978QualType
4979TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004980 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004981 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004982 TLB.pushFullCopy(TL);
4983 return TL.getType();
4984}
4985
4986template<typename Derived>
4987QualType
4988TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004989 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004990 // ObjCObjectType is never dependent.
4991 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004992 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004993}
Mike Stump1eb44332009-09-09 15:08:12 +00004994
4995template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004996QualType
4997TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004998 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004999 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005000 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005001 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005002}
5003
Douglas Gregor577f75a2009-08-04 16:50:30 +00005004//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005005// Statement transformation
5006//===----------------------------------------------------------------------===//
5007template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005008StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005009TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005010 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005011}
5012
5013template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005014StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005015TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5016 return getDerived().TransformCompoundStmt(S, false);
5017}
5018
5019template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005020StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005021TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005022 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005023 Sema::CompoundScopeRAII CompoundScope(getSema());
5024
John McCall7114cba2010-08-27 19:56:05 +00005025 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005026 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005027 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005028 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5029 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005030 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005031 if (Result.isInvalid()) {
5032 // Immediately fail if this was a DeclStmt, since it's very
5033 // likely that this will cause problems for future statements.
5034 if (isa<DeclStmt>(*B))
5035 return StmtError();
5036
5037 // Otherwise, just keep processing substatements and fail later.
5038 SubStmtInvalid = true;
5039 continue;
5040 }
Mike Stump1eb44332009-09-09 15:08:12 +00005041
Douglas Gregor43959a92009-08-20 07:17:43 +00005042 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5043 Statements.push_back(Result.takeAs<Stmt>());
5044 }
Mike Stump1eb44332009-09-09 15:08:12 +00005045
John McCall7114cba2010-08-27 19:56:05 +00005046 if (SubStmtInvalid)
5047 return StmtError();
5048
Douglas Gregor43959a92009-08-20 07:17:43 +00005049 if (!getDerived().AlwaysRebuild() &&
5050 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005051 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005052
5053 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5054 move_arg(Statements),
5055 S->getRBracLoc(),
5056 IsStmtExpr);
5057}
Mike Stump1eb44332009-09-09 15:08:12 +00005058
Douglas Gregor43959a92009-08-20 07:17:43 +00005059template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005060StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005061TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005062 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005063 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005064 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5065 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005066
Eli Friedman264c1f82009-11-19 03:14:00 +00005067 // Transform the left-hand case value.
5068 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005069 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005070 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005071 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005072
Eli Friedman264c1f82009-11-19 03:14:00 +00005073 // Transform the right-hand case value (for the GNU case-range extension).
5074 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005075 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005076 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005077 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005078 }
Mike Stump1eb44332009-09-09 15:08:12 +00005079
Douglas Gregor43959a92009-08-20 07:17:43 +00005080 // Build the case statement.
5081 // Case statements are always rebuilt so that they will attached to their
5082 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005083 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005084 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005085 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005086 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005087 S->getColonLoc());
5088 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005089 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005090
Douglas Gregor43959a92009-08-20 07:17:43 +00005091 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005092 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005093 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005094 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005095
Douglas Gregor43959a92009-08-20 07:17:43 +00005096 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005097 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005098}
5099
5100template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005101StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005102TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005103 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005104 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005105 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005106 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005107
Douglas Gregor43959a92009-08-20 07:17:43 +00005108 // Default statements are always rebuilt
5109 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005110 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005111}
Mike Stump1eb44332009-09-09 15:08:12 +00005112
Douglas Gregor43959a92009-08-20 07:17:43 +00005113template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005114StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005115TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005116 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005117 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005118 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005119
Chris Lattner57ad3782011-02-17 20:34:02 +00005120 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5121 S->getDecl());
5122 if (!LD)
5123 return StmtError();
5124
5125
Douglas Gregor43959a92009-08-20 07:17:43 +00005126 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005127 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005128 cast<LabelDecl>(LD), SourceLocation(),
5129 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005130}
Mike Stump1eb44332009-09-09 15:08:12 +00005131
Douglas Gregor43959a92009-08-20 07:17:43 +00005132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005133StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005134TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005135 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005136 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005137 VarDecl *ConditionVar = 0;
5138 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005139 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005140 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005141 getDerived().TransformDefinition(
5142 S->getConditionVariable()->getLocation(),
5143 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005144 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005145 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005146 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005147 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005148
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005149 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005150 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005151
5152 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005153 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005154 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5155 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005156 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005157 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005158
John McCall9ae2f072010-08-23 23:25:46 +00005159 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005160 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005161 }
Sean Huntc3021132010-05-05 15:23:54 +00005162
John McCall9ae2f072010-08-23 23:25:46 +00005163 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5164 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005165 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005166
Douglas Gregor43959a92009-08-20 07:17:43 +00005167 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005168 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005169 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005170 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005171
Douglas Gregor43959a92009-08-20 07:17:43 +00005172 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005173 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005174 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005175 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005176
Douglas Gregor43959a92009-08-20 07:17:43 +00005177 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005178 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005179 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005180 Then.get() == S->getThen() &&
5181 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005182 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005183
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005184 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005185 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005186 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005187}
5188
5189template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005190StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005191TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005192 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005193 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005194 VarDecl *ConditionVar = 0;
5195 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005196 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005197 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005198 getDerived().TransformDefinition(
5199 S->getConditionVariable()->getLocation(),
5200 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005201 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005202 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005203 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005204 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005205
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005206 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005207 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005208 }
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Douglas Gregor43959a92009-08-20 07:17:43 +00005210 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005211 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005212 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005213 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005214 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005215 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005216
Douglas Gregor43959a92009-08-20 07:17:43 +00005217 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005218 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005219 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005220 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005221
Douglas Gregor43959a92009-08-20 07:17:43 +00005222 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005223 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5224 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005225}
Mike Stump1eb44332009-09-09 15:08:12 +00005226
Douglas Gregor43959a92009-08-20 07:17:43 +00005227template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005228StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005229TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005230 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005231 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005232 VarDecl *ConditionVar = 0;
5233 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005234 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005235 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005236 getDerived().TransformDefinition(
5237 S->getConditionVariable()->getLocation(),
5238 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005239 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005240 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005241 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005242 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005243
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005244 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005245 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005246
5247 if (S->getCond()) {
5248 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005249 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5250 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005251 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005252 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005253 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005254 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005255 }
Mike Stump1eb44332009-09-09 15:08:12 +00005256
John McCall9ae2f072010-08-23 23:25:46 +00005257 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5258 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005259 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005260
Douglas Gregor43959a92009-08-20 07:17:43 +00005261 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005262 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005263 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005264 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005265
Douglas Gregor43959a92009-08-20 07:17:43 +00005266 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005267 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005268 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005269 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005270 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005271
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005272 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005273 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005274}
Mike Stump1eb44332009-09-09 15:08:12 +00005275
Douglas Gregor43959a92009-08-20 07:17:43 +00005276template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005277StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005278TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005279 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005280 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005281 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005282 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005283
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005284 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005285 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005286 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005287 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005288
Douglas Gregor43959a92009-08-20 07:17:43 +00005289 if (!getDerived().AlwaysRebuild() &&
5290 Cond.get() == S->getCond() &&
5291 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005292 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005293
John McCall9ae2f072010-08-23 23:25:46 +00005294 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5295 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005296 S->getRParenLoc());
5297}
Mike Stump1eb44332009-09-09 15:08:12 +00005298
Douglas Gregor43959a92009-08-20 07:17:43 +00005299template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005300StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005301TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005302 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005303 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005304 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005305 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005306
Douglas Gregor43959a92009-08-20 07:17:43 +00005307 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005308 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005309 VarDecl *ConditionVar = 0;
5310 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005311 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005312 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005313 getDerived().TransformDefinition(
5314 S->getConditionVariable()->getLocation(),
5315 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005316 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005317 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005318 } else {
5319 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005320
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005321 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005322 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005323
5324 if (S->getCond()) {
5325 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005326 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5327 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005328 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005329 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005330
John McCall9ae2f072010-08-23 23:25:46 +00005331 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005332 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005333 }
Mike Stump1eb44332009-09-09 15:08:12 +00005334
John McCall9ae2f072010-08-23 23:25:46 +00005335 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5336 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005337 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005338
Douglas Gregor43959a92009-08-20 07:17:43 +00005339 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005340 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005341 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005342 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005343
John McCall9ae2f072010-08-23 23:25:46 +00005344 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5345 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005346 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005347
Douglas Gregor43959a92009-08-20 07:17:43 +00005348 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005349 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005350 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005351 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005352
Douglas Gregor43959a92009-08-20 07:17:43 +00005353 if (!getDerived().AlwaysRebuild() &&
5354 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005355 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005356 Inc.get() == S->getInc() &&
5357 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005358 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005359
Douglas Gregor43959a92009-08-20 07:17:43 +00005360 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005361 Init.get(), FullCond, ConditionVar,
5362 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005363}
5364
5365template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005366StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005367TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005368 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5369 S->getLabel());
5370 if (!LD)
5371 return StmtError();
5372
Douglas Gregor43959a92009-08-20 07:17:43 +00005373 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005374 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005375 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005376}
5377
5378template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005379StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005380TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005381 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005382 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005383 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005384 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005385
Douglas Gregor43959a92009-08-20 07:17:43 +00005386 if (!getDerived().AlwaysRebuild() &&
5387 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005388 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005389
5390 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005391 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005392}
5393
5394template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005395StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005396TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005397 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005398}
Mike Stump1eb44332009-09-09 15:08:12 +00005399
Douglas Gregor43959a92009-08-20 07:17:43 +00005400template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005401StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005402TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005403 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005404}
Mike Stump1eb44332009-09-09 15:08:12 +00005405
Douglas Gregor43959a92009-08-20 07:17:43 +00005406template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005407StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005408TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005409 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005410 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005411 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005412
Mike Stump1eb44332009-09-09 15:08:12 +00005413 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005415 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005416}
Mike Stump1eb44332009-09-09 15:08:12 +00005417
Douglas Gregor43959a92009-08-20 07:17:43 +00005418template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005419StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005420TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005421 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005422 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005423 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5424 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005425 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5426 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005427 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005428 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005429
Douglas Gregor43959a92009-08-20 07:17:43 +00005430 if (Transformed != *D)
5431 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005432
Douglas Gregor43959a92009-08-20 07:17:43 +00005433 Decls.push_back(Transformed);
5434 }
Mike Stump1eb44332009-09-09 15:08:12 +00005435
Douglas Gregor43959a92009-08-20 07:17:43 +00005436 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005437 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005438
5439 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005440 S->getStartLoc(), S->getEndLoc());
5441}
Mike Stump1eb44332009-09-09 15:08:12 +00005442
Douglas Gregor43959a92009-08-20 07:17:43 +00005443template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005444StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005445TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005446
John McCallca0408f2010-08-23 06:44:23 +00005447 ASTOwningVector<Expr*> Constraints(getSema());
5448 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005449 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005450
John McCall60d7b3a2010-08-24 06:29:42 +00005451 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005452 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005453
5454 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005455
Anders Carlsson703e3942010-01-24 05:50:09 +00005456 // Go through the outputs.
5457 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005458 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005459
Anders Carlsson703e3942010-01-24 05:50:09 +00005460 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005461 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005462
Anders Carlsson703e3942010-01-24 05:50:09 +00005463 // Transform the output expr.
5464 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005465 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005466 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005467 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005468
Anders Carlsson703e3942010-01-24 05:50:09 +00005469 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005470
John McCall9ae2f072010-08-23 23:25:46 +00005471 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005472 }
Sean Huntc3021132010-05-05 15:23:54 +00005473
Anders Carlsson703e3942010-01-24 05:50:09 +00005474 // Go through the inputs.
5475 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005476 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005477
Anders Carlsson703e3942010-01-24 05:50:09 +00005478 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005479 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005480
Anders Carlsson703e3942010-01-24 05:50:09 +00005481 // Transform the input expr.
5482 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005483 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005484 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005485 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005486
Anders Carlsson703e3942010-01-24 05:50:09 +00005487 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005488
John McCall9ae2f072010-08-23 23:25:46 +00005489 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005490 }
Sean Huntc3021132010-05-05 15:23:54 +00005491
Anders Carlsson703e3942010-01-24 05:50:09 +00005492 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005493 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005494
5495 // Go through the clobbers.
5496 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005497 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005498
5499 // No need to transform the asm string literal.
5500 AsmString = SemaRef.Owned(S->getAsmString());
5501
5502 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5503 S->isSimple(),
5504 S->isVolatile(),
5505 S->getNumOutputs(),
5506 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005507 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005508 move_arg(Constraints),
5509 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005510 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005511 move_arg(Clobbers),
5512 S->getRParenLoc(),
5513 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005514}
5515
5516
5517template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005518StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005519TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005520 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005521 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005522 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005523 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005524
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005525 // Transform the @catch statements (if present).
5526 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005527 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005528 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005529 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005530 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005531 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005532 if (Catch.get() != S->getCatchStmt(I))
5533 AnyCatchChanged = true;
5534 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005535 }
Sean Huntc3021132010-05-05 15:23:54 +00005536
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005537 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005538 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005539 if (S->getFinallyStmt()) {
5540 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5541 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005542 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005543 }
5544
5545 // If nothing changed, just retain this statement.
5546 if (!getDerived().AlwaysRebuild() &&
5547 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005548 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005549 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005550 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005551
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005552 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005553 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5554 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005555}
Mike Stump1eb44332009-09-09 15:08:12 +00005556
Douglas Gregor43959a92009-08-20 07:17:43 +00005557template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005558StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005559TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005560 // Transform the @catch parameter, if there is one.
5561 VarDecl *Var = 0;
5562 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5563 TypeSourceInfo *TSInfo = 0;
5564 if (FromVar->getTypeSourceInfo()) {
5565 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5566 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005567 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005568 }
Sean Huntc3021132010-05-05 15:23:54 +00005569
Douglas Gregorbe270a02010-04-26 17:57:08 +00005570 QualType T;
5571 if (TSInfo)
5572 T = TSInfo->getType();
5573 else {
5574 T = getDerived().TransformType(FromVar->getType());
5575 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005576 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005577 }
Sean Huntc3021132010-05-05 15:23:54 +00005578
Douglas Gregorbe270a02010-04-26 17:57:08 +00005579 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5580 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005581 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005582 }
Sean Huntc3021132010-05-05 15:23:54 +00005583
John McCall60d7b3a2010-08-24 06:29:42 +00005584 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005585 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005586 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005587
5588 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005589 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005590 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005591}
Mike Stump1eb44332009-09-09 15:08:12 +00005592
Douglas Gregor43959a92009-08-20 07:17:43 +00005593template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005594StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005595TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005596 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005597 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005598 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005599 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005600
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005601 // If nothing changed, just retain this statement.
5602 if (!getDerived().AlwaysRebuild() &&
5603 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005604 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005605
5606 // Build a new statement.
5607 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005608 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005609}
Mike Stump1eb44332009-09-09 15:08:12 +00005610
Douglas Gregor43959a92009-08-20 07:17:43 +00005611template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005612StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005613TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005614 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005615 if (S->getThrowExpr()) {
5616 Operand = getDerived().TransformExpr(S->getThrowExpr());
5617 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005618 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005619 }
Sean Huntc3021132010-05-05 15:23:54 +00005620
Douglas Gregord1377b22010-04-22 21:44:01 +00005621 if (!getDerived().AlwaysRebuild() &&
5622 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005623 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005624
John McCall9ae2f072010-08-23 23:25:46 +00005625 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005626}
Mike Stump1eb44332009-09-09 15:08:12 +00005627
Douglas Gregor43959a92009-08-20 07:17:43 +00005628template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005629StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005630TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005631 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005632 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005633 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005634 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005635 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005636 Object =
5637 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5638 Object.get());
5639 if (Object.isInvalid())
5640 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005641
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005642 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005643 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005644 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005645 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005646
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005647 // If nothing change, just retain the current statement.
5648 if (!getDerived().AlwaysRebuild() &&
5649 Object.get() == S->getSynchExpr() &&
5650 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005651 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005652
5653 // Build a new statement.
5654 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005655 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005656}
5657
5658template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005659StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005660TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5661 ObjCAutoreleasePoolStmt *S) {
5662 // Transform the body.
5663 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5664 if (Body.isInvalid())
5665 return StmtError();
5666
5667 // If nothing changed, just retain this statement.
5668 if (!getDerived().AlwaysRebuild() &&
5669 Body.get() == S->getSubStmt())
5670 return SemaRef.Owned(S);
5671
5672 // Build a new statement.
5673 return getDerived().RebuildObjCAutoreleasePoolStmt(
5674 S->getAtLoc(), Body.get());
5675}
5676
5677template<typename Derived>
5678StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005679TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005680 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005681 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005682 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005683 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005684 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005685
Douglas Gregorc3203e72010-04-22 23:10:45 +00005686 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005687 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005688 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005689 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005690 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5691 Collection.take());
5692 if (Collection.isInvalid())
5693 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005694
Douglas Gregorc3203e72010-04-22 23:10:45 +00005695 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005696 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005697 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005698 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005699
Douglas Gregorc3203e72010-04-22 23:10:45 +00005700 // If nothing changed, just retain this statement.
5701 if (!getDerived().AlwaysRebuild() &&
5702 Element.get() == S->getElement() &&
5703 Collection.get() == S->getCollection() &&
5704 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005705 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005706
Douglas Gregorc3203e72010-04-22 23:10:45 +00005707 // Build a new statement.
5708 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5709 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005710 Element.get(),
5711 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005712 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005713 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005714}
5715
5716
5717template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005718StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005719TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5720 // Transform the exception declaration, if any.
5721 VarDecl *Var = 0;
5722 if (S->getExceptionDecl()) {
5723 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005724 TypeSourceInfo *T = getDerived().TransformType(
5725 ExceptionDecl->getTypeSourceInfo());
5726 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005727 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005728
Douglas Gregor83cb9422010-09-09 17:09:21 +00005729 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005730 ExceptionDecl->getInnerLocStart(),
5731 ExceptionDecl->getLocation(),
5732 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005733 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005734 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005735 }
Mike Stump1eb44332009-09-09 15:08:12 +00005736
Douglas Gregor43959a92009-08-20 07:17:43 +00005737 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005738 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005739 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005740 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005741
Douglas Gregor43959a92009-08-20 07:17:43 +00005742 if (!getDerived().AlwaysRebuild() &&
5743 !Var &&
5744 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005745 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005746
5747 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5748 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005749 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005750}
Mike Stump1eb44332009-09-09 15:08:12 +00005751
Douglas Gregor43959a92009-08-20 07:17:43 +00005752template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005753StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005754TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5755 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005756 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005757 = getDerived().TransformCompoundStmt(S->getTryBlock());
5758 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005759 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005760
Douglas Gregor43959a92009-08-20 07:17:43 +00005761 // Transform the handlers.
5762 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005763 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005764 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005765 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005766 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5767 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005768 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005769
Douglas Gregor43959a92009-08-20 07:17:43 +00005770 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5771 Handlers.push_back(Handler.takeAs<Stmt>());
5772 }
Mike Stump1eb44332009-09-09 15:08:12 +00005773
Douglas Gregor43959a92009-08-20 07:17:43 +00005774 if (!getDerived().AlwaysRebuild() &&
5775 TryBlock.get() == S->getTryBlock() &&
5776 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005777 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005778
John McCall9ae2f072010-08-23 23:25:46 +00005779 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005780 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005781}
Mike Stump1eb44332009-09-09 15:08:12 +00005782
Richard Smithad762fc2011-04-14 22:09:26 +00005783template<typename Derived>
5784StmtResult
5785TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5786 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5787 if (Range.isInvalid())
5788 return StmtError();
5789
5790 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5791 if (BeginEnd.isInvalid())
5792 return StmtError();
5793
5794 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5795 if (Cond.isInvalid())
5796 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005797 if (Cond.get())
5798 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5799 if (Cond.isInvalid())
5800 return StmtError();
5801 if (Cond.get())
5802 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005803
5804 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5805 if (Inc.isInvalid())
5806 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005807 if (Inc.get())
5808 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005809
5810 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5811 if (LoopVar.isInvalid())
5812 return StmtError();
5813
5814 StmtResult NewStmt = S;
5815 if (getDerived().AlwaysRebuild() ||
5816 Range.get() != S->getRangeStmt() ||
5817 BeginEnd.get() != S->getBeginEndStmt() ||
5818 Cond.get() != S->getCond() ||
5819 Inc.get() != S->getInc() ||
5820 LoopVar.get() != S->getLoopVarStmt())
5821 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5822 S->getColonLoc(), Range.get(),
5823 BeginEnd.get(), Cond.get(),
5824 Inc.get(), LoopVar.get(),
5825 S->getRParenLoc());
5826
5827 StmtResult Body = getDerived().TransformStmt(S->getBody());
5828 if (Body.isInvalid())
5829 return StmtError();
5830
5831 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5832 // it now so we have a new statement to attach the body to.
5833 if (Body.get() != S->getBody() && NewStmt.get() == S)
5834 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5835 S->getColonLoc(), Range.get(),
5836 BeginEnd.get(), Cond.get(),
5837 Inc.get(), LoopVar.get(),
5838 S->getRParenLoc());
5839
5840 if (NewStmt.get() == S)
5841 return SemaRef.Owned(S);
5842
5843 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5844}
5845
John Wiegley28bbe4b2011-04-28 01:08:34 +00005846template<typename Derived>
5847StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005848TreeTransform<Derived>::TransformMSDependentExistsStmt(
5849 MSDependentExistsStmt *S) {
5850 // Transform the nested-name-specifier, if any.
5851 NestedNameSpecifierLoc QualifierLoc;
5852 if (S->getQualifierLoc()) {
5853 QualifierLoc
5854 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5855 if (!QualifierLoc)
5856 return StmtError();
5857 }
5858
5859 // Transform the declaration name.
5860 DeclarationNameInfo NameInfo = S->getNameInfo();
5861 if (NameInfo.getName()) {
5862 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5863 if (!NameInfo.getName())
5864 return StmtError();
5865 }
5866
5867 // Check whether anything changed.
5868 if (!getDerived().AlwaysRebuild() &&
5869 QualifierLoc == S->getQualifierLoc() &&
5870 NameInfo.getName() == S->getNameInfo().getName())
5871 return S;
5872
5873 // Determine whether this name exists, if we can.
5874 CXXScopeSpec SS;
5875 SS.Adopt(QualifierLoc);
5876 bool Dependent = false;
5877 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5878 case Sema::IER_Exists:
5879 if (S->isIfExists())
5880 break;
5881
5882 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5883
5884 case Sema::IER_DoesNotExist:
5885 if (S->isIfNotExists())
5886 break;
5887
5888 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5889
5890 case Sema::IER_Dependent:
5891 Dependent = true;
5892 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005893
5894 case Sema::IER_Error:
5895 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005896 }
5897
5898 // We need to continue with the instantiation, so do so now.
5899 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5900 if (SubStmt.isInvalid())
5901 return StmtError();
5902
5903 // If we have resolved the name, just transform to the substatement.
5904 if (!Dependent)
5905 return SubStmt;
5906
5907 // The name is still dependent, so build a dependent expression again.
5908 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5909 S->isIfExists(),
5910 QualifierLoc,
5911 NameInfo,
5912 SubStmt.get());
5913}
5914
5915template<typename Derived>
5916StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005917TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5918 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5919 if(TryBlock.isInvalid()) return StmtError();
5920
5921 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5922 if(!getDerived().AlwaysRebuild() &&
5923 TryBlock.get() == S->getTryBlock() &&
5924 Handler.get() == S->getHandler())
5925 return SemaRef.Owned(S);
5926
5927 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5928 S->getTryLoc(),
5929 TryBlock.take(),
5930 Handler.take());
5931}
5932
5933template<typename Derived>
5934StmtResult
5935TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5936 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5937 if(Block.isInvalid()) return StmtError();
5938
5939 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5940 Block.take());
5941}
5942
5943template<typename Derived>
5944StmtResult
5945TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5946 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5947 if(FilterExpr.isInvalid()) return StmtError();
5948
5949 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5950 if(Block.isInvalid()) return StmtError();
5951
5952 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5953 FilterExpr.take(),
5954 Block.take());
5955}
5956
5957template<typename Derived>
5958StmtResult
5959TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5960 if(isa<SEHFinallyStmt>(Handler))
5961 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5962 else
5963 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5964}
5965
Douglas Gregor43959a92009-08-20 07:17:43 +00005966//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005967// Expression transformation
5968//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005969template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005970ExprResult
John McCall454feb92009-12-08 09:21:05 +00005971TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005972 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005973}
Mike Stump1eb44332009-09-09 15:08:12 +00005974
5975template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005976ExprResult
John McCall454feb92009-12-08 09:21:05 +00005977TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005978 NestedNameSpecifierLoc QualifierLoc;
5979 if (E->getQualifierLoc()) {
5980 QualifierLoc
5981 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5982 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005983 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005984 }
John McCalldbd872f2009-12-08 09:08:17 +00005985
5986 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005987 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5988 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005989 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005990 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005991
John McCallec8045d2010-08-17 21:27:17 +00005992 DeclarationNameInfo NameInfo = E->getNameInfo();
5993 if (NameInfo.getName()) {
5994 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5995 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005996 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005997 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005998
5999 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006000 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006001 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006002 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006003 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006004
6005 // Mark it referenced in the new context regardless.
6006 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006007 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006008
John McCall3fa5cae2010-10-26 07:05:15 +00006009 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006010 }
John McCalldbd872f2009-12-08 09:08:17 +00006011
6012 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006013 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006014 TemplateArgs = &TransArgs;
6015 TransArgs.setLAngleLoc(E->getLAngleLoc());
6016 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006017 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6018 E->getNumTemplateArgs(),
6019 TransArgs))
6020 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006021 }
6022
Douglas Gregor40d96a62011-02-28 21:54:11 +00006023 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6024 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006025}
Mike Stump1eb44332009-09-09 15:08:12 +00006026
Douglas Gregorb98b1992009-08-11 05:31:07 +00006027template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006028ExprResult
John McCall454feb92009-12-08 09:21:05 +00006029TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006030 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006031}
Mike Stump1eb44332009-09-09 15:08:12 +00006032
Douglas Gregorb98b1992009-08-11 05:31:07 +00006033template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006034ExprResult
John McCall454feb92009-12-08 09:21:05 +00006035TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006036 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006037}
Mike Stump1eb44332009-09-09 15:08:12 +00006038
Douglas Gregorb98b1992009-08-11 05:31:07 +00006039template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006040ExprResult
John McCall454feb92009-12-08 09:21:05 +00006041TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006042 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006043}
Mike Stump1eb44332009-09-09 15:08:12 +00006044
Douglas Gregorb98b1992009-08-11 05:31:07 +00006045template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006046ExprResult
John McCall454feb92009-12-08 09:21:05 +00006047TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006048 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006049}
Mike Stump1eb44332009-09-09 15:08:12 +00006050
Douglas Gregorb98b1992009-08-11 05:31:07 +00006051template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006052ExprResult
John McCall454feb92009-12-08 09:21:05 +00006053TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006054 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006055}
6056
6057template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006058ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006059TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6060 ExprResult ControllingExpr =
6061 getDerived().TransformExpr(E->getControllingExpr());
6062 if (ControllingExpr.isInvalid())
6063 return ExprError();
6064
Chris Lattner686775d2011-07-20 06:58:45 +00006065 SmallVector<Expr *, 4> AssocExprs;
6066 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006067 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6068 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6069 if (TS) {
6070 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6071 if (!AssocType)
6072 return ExprError();
6073 AssocTypes.push_back(AssocType);
6074 } else {
6075 AssocTypes.push_back(0);
6076 }
6077
6078 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6079 if (AssocExpr.isInvalid())
6080 return ExprError();
6081 AssocExprs.push_back(AssocExpr.release());
6082 }
6083
6084 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6085 E->getDefaultLoc(),
6086 E->getRParenLoc(),
6087 ControllingExpr.release(),
6088 AssocTypes.data(),
6089 AssocExprs.data(),
6090 E->getNumAssocs());
6091}
6092
6093template<typename Derived>
6094ExprResult
John McCall454feb92009-12-08 09:21:05 +00006095TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006096 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006097 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006098 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006099
Douglas Gregorb98b1992009-08-11 05:31:07 +00006100 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006101 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006102
John McCall9ae2f072010-08-23 23:25:46 +00006103 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006104 E->getRParen());
6105}
6106
Mike Stump1eb44332009-09-09 15:08:12 +00006107template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006108ExprResult
John McCall454feb92009-12-08 09:21:05 +00006109TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006110 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006111 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006112 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006113
Douglas Gregorb98b1992009-08-11 05:31:07 +00006114 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006115 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006116
Douglas Gregorb98b1992009-08-11 05:31:07 +00006117 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6118 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006119 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006120}
Mike Stump1eb44332009-09-09 15:08:12 +00006121
Douglas Gregorb98b1992009-08-11 05:31:07 +00006122template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006123ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006124TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6125 // Transform the type.
6126 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6127 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006128 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006129
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006130 // Transform all of the components into components similar to what the
6131 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006132 // FIXME: It would be slightly more efficient in the non-dependent case to
6133 // just map FieldDecls, rather than requiring the rebuilder to look for
6134 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006135 // template code that we don't care.
6136 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006137 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006138 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006139 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006140 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6141 const Node &ON = E->getComponent(I);
6142 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006143 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006144 Comp.LocStart = ON.getSourceRange().getBegin();
6145 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006146 switch (ON.getKind()) {
6147 case Node::Array: {
6148 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006149 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006150 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006151 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006152
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006153 ExprChanged = ExprChanged || Index.get() != FromIndex;
6154 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006155 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006156 break;
6157 }
Sean Huntc3021132010-05-05 15:23:54 +00006158
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006159 case Node::Field:
6160 case Node::Identifier:
6161 Comp.isBrackets = false;
6162 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006163 if (!Comp.U.IdentInfo)
6164 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006165
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006166 break;
Sean Huntc3021132010-05-05 15:23:54 +00006167
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006168 case Node::Base:
6169 // Will be recomputed during the rebuild.
6170 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006171 }
Sean Huntc3021132010-05-05 15:23:54 +00006172
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006173 Components.push_back(Comp);
6174 }
Sean Huntc3021132010-05-05 15:23:54 +00006175
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006176 // If nothing changed, retain the existing expression.
6177 if (!getDerived().AlwaysRebuild() &&
6178 Type == E->getTypeSourceInfo() &&
6179 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006180 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006181
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006182 // Build a new offsetof expression.
6183 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6184 Components.data(), Components.size(),
6185 E->getRParenLoc());
6186}
6187
6188template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006189ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006190TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6191 assert(getDerived().AlreadyTransformed(E->getType()) &&
6192 "opaque value expression requires transformation");
6193 return SemaRef.Owned(E);
6194}
6195
6196template<typename Derived>
6197ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006198TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006199 // Rebuild the syntactic form. The original syntactic form has
6200 // opaque-value expressions in it, so strip those away and rebuild
6201 // the result. This is a really awful way of doing this, but the
6202 // better solution (rebuilding the semantic expressions and
6203 // rebinding OVEs as necessary) doesn't work; we'd need
6204 // TreeTransform to not strip away implicit conversions.
6205 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6206 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006207 if (result.isInvalid()) return ExprError();
6208
6209 // If that gives us a pseudo-object result back, the pseudo-object
6210 // expression must have been an lvalue-to-rvalue conversion which we
6211 // should reapply.
6212 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6213 result = SemaRef.checkPseudoObjectRValue(result.take());
6214
6215 return result;
6216}
6217
6218template<typename Derived>
6219ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006220TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6221 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006222 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006223 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006224
John McCalla93c9342009-12-07 02:54:59 +00006225 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006226 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006227 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006228
John McCall5ab75172009-11-04 07:28:41 +00006229 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006230 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006231
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006232 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6233 E->getKind(),
6234 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006235 }
Mike Stump1eb44332009-09-09 15:08:12 +00006236
John McCall60d7b3a2010-08-24 06:29:42 +00006237 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00006238 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006239 // C++0x [expr.sizeof]p1:
6240 // The operand is either an expression, which is an unevaluated operand
6241 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00006242 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006243
Douglas Gregorb98b1992009-08-11 05:31:07 +00006244 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6245 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006246 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006247
Douglas Gregorb98b1992009-08-11 05:31:07 +00006248 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006249 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006250 }
Mike Stump1eb44332009-09-09 15:08:12 +00006251
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006252 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6253 E->getOperatorLoc(),
6254 E->getKind(),
6255 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006256}
Mike Stump1eb44332009-09-09 15:08:12 +00006257
Douglas Gregorb98b1992009-08-11 05:31:07 +00006258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006259ExprResult
John McCall454feb92009-12-08 09:21:05 +00006260TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006261 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006262 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006263 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006264
John McCall60d7b3a2010-08-24 06:29:42 +00006265 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006266 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006267 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006268
6269
Douglas Gregorb98b1992009-08-11 05:31:07 +00006270 if (!getDerived().AlwaysRebuild() &&
6271 LHS.get() == E->getLHS() &&
6272 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006273 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006274
John McCall9ae2f072010-08-23 23:25:46 +00006275 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006276 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006277 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006278 E->getRBracketLoc());
6279}
Mike Stump1eb44332009-09-09 15:08:12 +00006280
6281template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006282ExprResult
John McCall454feb92009-12-08 09:21:05 +00006283TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006284 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006285 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006286 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006287 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006288
6289 // Transform arguments.
6290 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006291 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006292 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6293 &ArgChanged))
6294 return ExprError();
6295
Douglas Gregorb98b1992009-08-11 05:31:07 +00006296 if (!getDerived().AlwaysRebuild() &&
6297 Callee.get() == E->getCallee() &&
6298 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006299 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006300
Douglas Gregorb98b1992009-08-11 05:31:07 +00006301 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006302 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006303 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006304 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006305 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006306 E->getRParenLoc());
6307}
Mike Stump1eb44332009-09-09 15:08:12 +00006308
6309template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006310ExprResult
John McCall454feb92009-12-08 09:21:05 +00006311TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006312 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006313 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006314 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006315
Douglas Gregor40d96a62011-02-28 21:54:11 +00006316 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006317 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006318 QualifierLoc
6319 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6320
6321 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006322 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006323 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006324 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006325
Eli Friedmanf595cc42009-12-04 06:40:45 +00006326 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006327 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6328 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006329 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006330 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006331
John McCall6bb80172010-03-30 21:47:33 +00006332 NamedDecl *FoundDecl = E->getFoundDecl();
6333 if (FoundDecl == E->getMemberDecl()) {
6334 FoundDecl = Member;
6335 } else {
6336 FoundDecl = cast_or_null<NamedDecl>(
6337 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6338 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006339 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006340 }
6341
Douglas Gregorb98b1992009-08-11 05:31:07 +00006342 if (!getDerived().AlwaysRebuild() &&
6343 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006344 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006345 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006346 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006347 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006348
Anders Carlsson1f240322009-12-22 05:24:09 +00006349 // Mark it referenced in the new context regardless.
6350 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006351 SemaRef.MarkMemberReferenced(E);
6352
John McCall3fa5cae2010-10-26 07:05:15 +00006353 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006354 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006355
John McCalld5532b62009-11-23 01:53:49 +00006356 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006357 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006358 TransArgs.setLAngleLoc(E->getLAngleLoc());
6359 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006360 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6361 E->getNumTemplateArgs(),
6362 TransArgs))
6363 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006364 }
Sean Huntc3021132010-05-05 15:23:54 +00006365
Douglas Gregorb98b1992009-08-11 05:31:07 +00006366 // FIXME: Bogus source location for the operator
6367 SourceLocation FakeOperatorLoc
6368 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6369
John McCallc2233c52010-01-15 08:34:02 +00006370 // FIXME: to do this check properly, we will need to preserve the
6371 // first-qualifier-in-scope here, just in case we had a dependent
6372 // base (and therefore couldn't do the check) and a
6373 // nested-name-qualifier (and therefore could do the lookup).
6374 NamedDecl *FirstQualifierInScope = 0;
6375
John McCall9ae2f072010-08-23 23:25:46 +00006376 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006377 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006378 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006379 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006380 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006381 Member,
John McCall6bb80172010-03-30 21:47:33 +00006382 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006383 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006384 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006385 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006386}
Mike Stump1eb44332009-09-09 15:08:12 +00006387
Douglas Gregorb98b1992009-08-11 05:31:07 +00006388template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006389ExprResult
John McCall454feb92009-12-08 09:21:05 +00006390TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006391 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006392 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006393 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006394
John McCall60d7b3a2010-08-24 06:29:42 +00006395 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006396 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006397 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006398
Douglas Gregorb98b1992009-08-11 05:31:07 +00006399 if (!getDerived().AlwaysRebuild() &&
6400 LHS.get() == E->getLHS() &&
6401 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006402 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006403
Douglas Gregorb98b1992009-08-11 05:31:07 +00006404 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006405 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006406}
6407
Mike Stump1eb44332009-09-09 15:08:12 +00006408template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006409ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006410TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006411 CompoundAssignOperator *E) {
6412 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006413}
Mike Stump1eb44332009-09-09 15:08:12 +00006414
Douglas Gregorb98b1992009-08-11 05:31:07 +00006415template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006416ExprResult TreeTransform<Derived>::
6417TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6418 // Just rebuild the common and RHS expressions and see whether we
6419 // get any changes.
6420
6421 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6422 if (commonExpr.isInvalid())
6423 return ExprError();
6424
6425 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6426 if (rhs.isInvalid())
6427 return ExprError();
6428
6429 if (!getDerived().AlwaysRebuild() &&
6430 commonExpr.get() == e->getCommon() &&
6431 rhs.get() == e->getFalseExpr())
6432 return SemaRef.Owned(e);
6433
6434 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6435 e->getQuestionLoc(),
6436 0,
6437 e->getColonLoc(),
6438 rhs.get());
6439}
6440
6441template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006442ExprResult
John McCall454feb92009-12-08 09:21:05 +00006443TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006444 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006445 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006446 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006447
John McCall60d7b3a2010-08-24 06:29:42 +00006448 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006450 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006451
John McCall60d7b3a2010-08-24 06:29:42 +00006452 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006453 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006454 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006455
Douglas Gregorb98b1992009-08-11 05:31:07 +00006456 if (!getDerived().AlwaysRebuild() &&
6457 Cond.get() == E->getCond() &&
6458 LHS.get() == E->getLHS() &&
6459 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006460 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006461
John McCall9ae2f072010-08-23 23:25:46 +00006462 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006463 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006464 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006465 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006466 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006467}
Mike Stump1eb44332009-09-09 15:08:12 +00006468
6469template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006470ExprResult
John McCall454feb92009-12-08 09:21:05 +00006471TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006472 // Implicit casts are eliminated during transformation, since they
6473 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006474 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006475}
Mike Stump1eb44332009-09-09 15:08:12 +00006476
Douglas Gregorb98b1992009-08-11 05:31:07 +00006477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006478ExprResult
John McCall454feb92009-12-08 09:21:05 +00006479TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006480 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6481 if (!Type)
6482 return ExprError();
6483
John McCall60d7b3a2010-08-24 06:29:42 +00006484 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006485 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006486 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006487 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006488
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006490 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006492 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006493
John McCall9d125032010-01-15 18:39:57 +00006494 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006495 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006496 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006497 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498}
Mike Stump1eb44332009-09-09 15:08:12 +00006499
Douglas Gregorb98b1992009-08-11 05:31:07 +00006500template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006501ExprResult
John McCall454feb92009-12-08 09:21:05 +00006502TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006503 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6504 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6505 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006506 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006507
John McCall60d7b3a2010-08-24 06:29:42 +00006508 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006509 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006510 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006511
Douglas Gregorb98b1992009-08-11 05:31:07 +00006512 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006513 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006514 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006515 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006516
John McCall1d7d8d62010-01-19 22:33:45 +00006517 // Note: the expression type doesn't necessarily match the
6518 // type-as-written, but that's okay, because it should always be
6519 // derivable from the initializer.
6520
John McCall42f56b52010-01-18 19:35:47 +00006521 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006522 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006523 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524}
Mike Stump1eb44332009-09-09 15:08:12 +00006525
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006527ExprResult
John McCall454feb92009-12-08 09:21:05 +00006528TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006529 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006530 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006531 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006532
Douglas Gregorb98b1992009-08-11 05:31:07 +00006533 if (!getDerived().AlwaysRebuild() &&
6534 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006535 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006536
Douglas Gregorb98b1992009-08-11 05:31:07 +00006537 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006538 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006540 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541 E->getAccessorLoc(),
6542 E->getAccessor());
6543}
Mike Stump1eb44332009-09-09 15:08:12 +00006544
Douglas Gregorb98b1992009-08-11 05:31:07 +00006545template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006546ExprResult
John McCall454feb92009-12-08 09:21:05 +00006547TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006549
John McCallca0408f2010-08-23 06:44:23 +00006550 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006551 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6552 Inits, &InitChanged))
6553 return ExprError();
6554
Douglas Gregorb98b1992009-08-11 05:31:07 +00006555 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006556 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006557
Douglas Gregorb98b1992009-08-11 05:31:07 +00006558 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006559 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006560}
Mike Stump1eb44332009-09-09 15:08:12 +00006561
Douglas Gregorb98b1992009-08-11 05:31:07 +00006562template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006563ExprResult
John McCall454feb92009-12-08 09:21:05 +00006564TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006566
Douglas Gregor43959a92009-08-20 07:17:43 +00006567 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006568 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006569 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006570 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006571
Douglas Gregor43959a92009-08-20 07:17:43 +00006572 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006573 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006574 bool ExprChanged = false;
6575 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6576 DEnd = E->designators_end();
6577 D != DEnd; ++D) {
6578 if (D->isFieldDesignator()) {
6579 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6580 D->getDotLoc(),
6581 D->getFieldLoc()));
6582 continue;
6583 }
Mike Stump1eb44332009-09-09 15:08:12 +00006584
Douglas Gregorb98b1992009-08-11 05:31:07 +00006585 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006586 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006587 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006588 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006589
6590 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006592
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6594 ArrayExprs.push_back(Index.release());
6595 continue;
6596 }
Mike Stump1eb44332009-09-09 15:08:12 +00006597
Douglas Gregorb98b1992009-08-11 05:31:07 +00006598 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006599 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006600 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6601 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006602 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006603
John McCall60d7b3a2010-08-24 06:29:42 +00006604 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006605 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006606 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006607
6608 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006609 End.get(),
6610 D->getLBracketLoc(),
6611 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006612
Douglas Gregorb98b1992009-08-11 05:31:07 +00006613 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6614 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006615
Douglas Gregorb98b1992009-08-11 05:31:07 +00006616 ArrayExprs.push_back(Start.release());
6617 ArrayExprs.push_back(End.release());
6618 }
Mike Stump1eb44332009-09-09 15:08:12 +00006619
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620 if (!getDerived().AlwaysRebuild() &&
6621 Init.get() == E->getInit() &&
6622 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006623 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006624
Douglas Gregorb98b1992009-08-11 05:31:07 +00006625 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6626 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006627 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628}
Mike Stump1eb44332009-09-09 15:08:12 +00006629
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006631ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006633 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006634 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006635
Douglas Gregor5557b252009-10-28 00:29:27 +00006636 // FIXME: Will we ever have proper type location here? Will we actually
6637 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006638 QualType T = getDerived().TransformType(E->getType());
6639 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006640 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006641
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642 if (!getDerived().AlwaysRebuild() &&
6643 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006644 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006645
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 return getDerived().RebuildImplicitValueInitExpr(T);
6647}
Mike Stump1eb44332009-09-09 15:08:12 +00006648
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006650ExprResult
John McCall454feb92009-12-08 09:21:05 +00006651TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006652 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6653 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006654 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006655
John McCall60d7b3a2010-08-24 06:29:42 +00006656 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006657 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006658 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006659
Douglas Gregorb98b1992009-08-11 05:31:07 +00006660 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006661 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006662 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006663 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006664
John McCall9ae2f072010-08-23 23:25:46 +00006665 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006666 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667}
6668
6669template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006670ExprResult
John McCall454feb92009-12-08 09:21:05 +00006671TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006673 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006674 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6675 &ArgumentChanged))
6676 return ExprError();
6677
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6679 move_arg(Inits),
6680 E->getRParenLoc());
6681}
Mike Stump1eb44332009-09-09 15:08:12 +00006682
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683/// \brief Transform an address-of-label expression.
6684///
6685/// By default, the transformation of an address-of-label expression always
6686/// rebuilds the expression, so that the label identifier can be resolved to
6687/// the corresponding label statement by semantic analysis.
6688template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006689ExprResult
John McCall454feb92009-12-08 09:21:05 +00006690TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006691 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6692 E->getLabel());
6693 if (!LD)
6694 return ExprError();
6695
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006697 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698}
Mike Stump1eb44332009-09-09 15:08:12 +00006699
6700template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006701ExprResult
John McCall454feb92009-12-08 09:21:05 +00006702TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006703 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6705 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006706 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006707
Douglas Gregorb98b1992009-08-11 05:31:07 +00006708 if (!getDerived().AlwaysRebuild() &&
6709 SubStmt.get() == E->getSubStmt())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006710 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006711
6712 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006713 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714 E->getRParenLoc());
6715}
Mike Stump1eb44332009-09-09 15:08:12 +00006716
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006718ExprResult
John McCall454feb92009-12-08 09:21:05 +00006719TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006720 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006722 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006723
John McCall60d7b3a2010-08-24 06:29:42 +00006724 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006726 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006727
John McCall60d7b3a2010-08-24 06:29:42 +00006728 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006729 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006730 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006731
Douglas Gregorb98b1992009-08-11 05:31:07 +00006732 if (!getDerived().AlwaysRebuild() &&
6733 Cond.get() == E->getCond() &&
6734 LHS.get() == E->getLHS() &&
6735 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006736 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006737
Douglas Gregorb98b1992009-08-11 05:31:07 +00006738 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006739 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006740 E->getRParenLoc());
6741}
Mike Stump1eb44332009-09-09 15:08:12 +00006742
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006744ExprResult
John McCall454feb92009-12-08 09:21:05 +00006745TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006746 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747}
6748
6749template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006750ExprResult
John McCall454feb92009-12-08 09:21:05 +00006751TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006752 switch (E->getOperator()) {
6753 case OO_New:
6754 case OO_Delete:
6755 case OO_Array_New:
6756 case OO_Array_Delete:
6757 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Sean Huntc3021132010-05-05 15:23:54 +00006758
Douglas Gregor668d6d92009-12-13 20:44:55 +00006759 case OO_Call: {
6760 // This is a call to an object's operator().
6761 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6762
6763 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006764 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006765 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006766 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006767
6768 // FIXME: Poor location information
6769 SourceLocation FakeLParenLoc
6770 = SemaRef.PP.getLocForEndOfToken(
6771 static_cast<Expr *>(Object.get())->getLocEnd());
6772
6773 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006774 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006775 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6776 Args))
6777 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006778
John McCall9ae2f072010-08-23 23:25:46 +00006779 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006780 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006781 E->getLocEnd());
6782 }
6783
6784#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6785 case OO_##Name:
6786#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6787#include "clang/Basic/OperatorKinds.def"
6788 case OO_Subscript:
6789 // Handled below.
6790 break;
6791
6792 case OO_Conditional:
6793 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006794
6795 case OO_None:
6796 case NUM_OVERLOADED_OPERATORS:
6797 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006798 }
6799
John McCall60d7b3a2010-08-24 06:29:42 +00006800 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006801 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006802 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006803
John McCall60d7b3a2010-08-24 06:29:42 +00006804 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006805 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006806 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807
John McCall60d7b3a2010-08-24 06:29:42 +00006808 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006809 if (E->getNumArgs() == 2) {
6810 Second = getDerived().TransformExpr(E->getArg(1));
6811 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006812 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006813 }
Mike Stump1eb44332009-09-09 15:08:12 +00006814
Douglas Gregorb98b1992009-08-11 05:31:07 +00006815 if (!getDerived().AlwaysRebuild() &&
6816 Callee.get() == E->getCallee() &&
6817 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006818 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006819 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006820
Douglas Gregorb98b1992009-08-11 05:31:07 +00006821 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6822 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006823 Callee.get(),
6824 First.get(),
6825 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006826}
Mike Stump1eb44332009-09-09 15:08:12 +00006827
Douglas Gregorb98b1992009-08-11 05:31:07 +00006828template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006829ExprResult
John McCall454feb92009-12-08 09:21:05 +00006830TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6831 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006832}
Mike Stump1eb44332009-09-09 15:08:12 +00006833
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006835ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006836TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6837 // Transform the callee.
6838 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6839 if (Callee.isInvalid())
6840 return ExprError();
6841
6842 // Transform exec config.
6843 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6844 if (EC.isInvalid())
6845 return ExprError();
6846
6847 // Transform arguments.
6848 bool ArgChanged = false;
6849 ASTOwningVector<Expr*> Args(SemaRef);
6850 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6851 &ArgChanged))
6852 return ExprError();
6853
6854 if (!getDerived().AlwaysRebuild() &&
6855 Callee.get() == E->getCallee() &&
6856 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006857 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006858
6859 // FIXME: Wrong source location information for the '('.
6860 SourceLocation FakeLParenLoc
6861 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6862 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6863 move_arg(Args),
6864 E->getRParenLoc(), EC.get());
6865}
6866
6867template<typename Derived>
6868ExprResult
John McCall454feb92009-12-08 09:21:05 +00006869TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006870 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6871 if (!Type)
6872 return ExprError();
6873
John McCall60d7b3a2010-08-24 06:29:42 +00006874 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006875 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006876 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006877 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006878
Douglas Gregorb98b1992009-08-11 05:31:07 +00006879 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006880 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006881 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006882 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006883
Douglas Gregorb98b1992009-08-11 05:31:07 +00006884 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006885 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006886 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6887 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6888 SourceLocation FakeRParenLoc
6889 = SemaRef.PP.getLocForEndOfToken(
6890 E->getSubExpr()->getSourceRange().getEnd());
6891 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006892 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006893 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006894 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006895 FakeRAngleLoc,
6896 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006897 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006898 FakeRParenLoc);
6899}
Mike Stump1eb44332009-09-09 15:08:12 +00006900
Douglas Gregorb98b1992009-08-11 05:31:07 +00006901template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006902ExprResult
John McCall454feb92009-12-08 09:21:05 +00006903TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6904 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006905}
Mike Stump1eb44332009-09-09 15:08:12 +00006906
6907template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006908ExprResult
John McCall454feb92009-12-08 09:21:05 +00006909TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6910 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006911}
6912
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006914ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006915TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006916 CXXReinterpretCastExpr *E) {
6917 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006918}
Mike Stump1eb44332009-09-09 15:08:12 +00006919
Douglas Gregorb98b1992009-08-11 05:31:07 +00006920template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006921ExprResult
John McCall454feb92009-12-08 09:21:05 +00006922TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6923 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006924}
Mike Stump1eb44332009-09-09 15:08:12 +00006925
Douglas Gregorb98b1992009-08-11 05:31:07 +00006926template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006927ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006929 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006930 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6931 if (!Type)
6932 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006933
John McCall60d7b3a2010-08-24 06:29:42 +00006934 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006935 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006936 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006937 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006938
Douglas Gregorb98b1992009-08-11 05:31:07 +00006939 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006940 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006941 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006942 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006943
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006944 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006945 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006946 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006947 E->getRParenLoc());
6948}
Mike Stump1eb44332009-09-09 15:08:12 +00006949
Douglas Gregorb98b1992009-08-11 05:31:07 +00006950template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006951ExprResult
John McCall454feb92009-12-08 09:21:05 +00006952TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006953 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006954 TypeSourceInfo *TInfo
6955 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6956 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006957 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006958
Douglas Gregorb98b1992009-08-11 05:31:07 +00006959 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006960 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006961 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006962
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006963 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6964 E->getLocStart(),
6965 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966 E->getLocEnd());
6967 }
Mike Stump1eb44332009-09-09 15:08:12 +00006968
Eli Friedmanef331b72012-01-20 01:26:23 +00006969 // We don't know whether the subexpression is potentially evaluated until
6970 // after we perform semantic analysis. We speculatively assume it is
6971 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00006973 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006974
John McCall60d7b3a2010-08-24 06:29:42 +00006975 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006977 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006978
Douglas Gregorb98b1992009-08-11 05:31:07 +00006979 if (!getDerived().AlwaysRebuild() &&
6980 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006981 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006982
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006983 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6984 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006985 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006986 E->getLocEnd());
6987}
6988
6989template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006990ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006991TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6992 if (E->isTypeOperand()) {
6993 TypeSourceInfo *TInfo
6994 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6995 if (!TInfo)
6996 return ExprError();
6997
6998 if (!getDerived().AlwaysRebuild() &&
6999 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007000 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007001
Douglas Gregor3c52a212011-03-06 17:40:41 +00007002 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007003 E->getLocStart(),
7004 TInfo,
7005 E->getLocEnd());
7006 }
7007
Francois Pichet01b7c302010-09-08 12:20:18 +00007008 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7009
7010 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7011 if (SubExpr.isInvalid())
7012 return ExprError();
7013
7014 if (!getDerived().AlwaysRebuild() &&
7015 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007016 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007017
7018 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7019 E->getLocStart(),
7020 SubExpr.get(),
7021 E->getLocEnd());
7022}
7023
7024template<typename Derived>
7025ExprResult
John McCall454feb92009-12-08 09:21:05 +00007026TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007027 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028}
Mike Stump1eb44332009-09-09 15:08:12 +00007029
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007031ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007032TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007033 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007034 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007035}
Mike Stump1eb44332009-09-09 15:08:12 +00007036
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007038ExprResult
John McCall454feb92009-12-08 09:21:05 +00007039TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007040 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007041 QualType T;
7042 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7043 T = MD->getThisType(getSema().Context);
7044 else
7045 T = getSema().Context.getPointerType(
7046 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007047
Douglas Gregorec79d872012-02-24 17:41:38 +00007048 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7049 // Make sure that we capture 'this'.
7050 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007051 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007052 }
7053
Douglas Gregor828a1972010-01-07 23:12:05 +00007054 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007055}
Mike Stump1eb44332009-09-09 15:08:12 +00007056
Douglas Gregorb98b1992009-08-11 05:31:07 +00007057template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007058ExprResult
John McCall454feb92009-12-08 09:21:05 +00007059TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007060 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007062 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007063
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064 if (!getDerived().AlwaysRebuild() &&
7065 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007066 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007067
Douglas Gregorbca01b42011-07-06 22:04:06 +00007068 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7069 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070}
Mike Stump1eb44332009-09-09 15:08:12 +00007071
Douglas Gregorb98b1992009-08-11 05:31:07 +00007072template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007073ExprResult
John McCall454feb92009-12-08 09:21:05 +00007074TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007075 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007076 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7077 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007078 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007079 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007080
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007081 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007083 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007084
Douglas Gregor036aed12009-12-23 23:03:06 +00007085 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007086}
Mike Stump1eb44332009-09-09 15:08:12 +00007087
Douglas Gregorb98b1992009-08-11 05:31:07 +00007088template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007089ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007090TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7091 CXXScalarValueInitExpr *E) {
7092 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7093 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007094 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007095
Douglas Gregorb98b1992009-08-11 05:31:07 +00007096 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007097 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007098 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007099
Douglas Gregorab6677e2010-09-08 00:15:04 +00007100 return getDerived().RebuildCXXScalarValueInitExpr(T,
7101 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007102 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007103}
Mike Stump1eb44332009-09-09 15:08:12 +00007104
Douglas Gregorb98b1992009-08-11 05:31:07 +00007105template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007106ExprResult
John McCall454feb92009-12-08 09:21:05 +00007107TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007108 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007109 TypeSourceInfo *AllocTypeInfo
7110 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7111 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007112 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007113
Douglas Gregorb98b1992009-08-11 05:31:07 +00007114 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007115 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007116 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007117 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007118
Douglas Gregorb98b1992009-08-11 05:31:07 +00007119 // Transform the placement arguments (if any).
7120 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007121 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007122 if (getDerived().TransformExprs(E->getPlacementArgs(),
7123 E->getNumPlacementArgs(), true,
7124 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007125 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007126
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007127 // Transform the initializer (if any).
7128 Expr *OldInit = E->getInitializer();
7129 ExprResult NewInit;
7130 if (OldInit)
7131 NewInit = getDerived().TransformExpr(OldInit);
7132 if (NewInit.isInvalid())
7133 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007134
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007135 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007136 FunctionDecl *OperatorNew = 0;
7137 if (E->getOperatorNew()) {
7138 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007139 getDerived().TransformDecl(E->getLocStart(),
7140 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007141 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007142 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007143 }
7144
7145 FunctionDecl *OperatorDelete = 0;
7146 if (E->getOperatorDelete()) {
7147 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007148 getDerived().TransformDecl(E->getLocStart(),
7149 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007150 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007151 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007152 }
Sean Huntc3021132010-05-05 15:23:54 +00007153
Douglas Gregorb98b1992009-08-11 05:31:07 +00007154 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007155 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007156 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007157 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007158 OperatorNew == E->getOperatorNew() &&
7159 OperatorDelete == E->getOperatorDelete() &&
7160 !ArgumentChanged) {
7161 // Mark any declarations we need as referenced.
7162 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007163 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007164 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007165 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007166 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007167
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007168 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007169 QualType ElementType
7170 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7171 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7172 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7173 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007174 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007175 }
7176 }
7177 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007178
John McCall3fa5cae2010-10-26 07:05:15 +00007179 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007180 }
Mike Stump1eb44332009-09-09 15:08:12 +00007181
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007182 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007183 if (!ArraySize.get()) {
7184 // If no array size was specified, but the new expression was
7185 // instantiated with an array type (e.g., "new T" where T is
7186 // instantiated with "int[4]"), extract the outer bound from the
7187 // array type as our array size. We do this with constant and
7188 // dependently-sized array types.
7189 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7190 if (!ArrayT) {
7191 // Do nothing
7192 } else if (const ConstantArrayType *ConsArrayT
7193 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007194 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007195 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7196 ConsArrayT->getSize(),
7197 SemaRef.Context.getSizeType(),
7198 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007199 AllocType = ConsArrayT->getElementType();
7200 } else if (const DependentSizedArrayType *DepArrayT
7201 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7202 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007203 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007204 AllocType = DepArrayT->getElementType();
7205 }
7206 }
7207 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007208
Douglas Gregorb98b1992009-08-11 05:31:07 +00007209 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7210 E->isGlobalNew(),
7211 /*FIXME:*/E->getLocStart(),
7212 move_arg(PlacementArgs),
7213 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007214 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007215 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007216 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007217 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007218 E->getDirectInitRange(),
7219 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007220}
Mike Stump1eb44332009-09-09 15:08:12 +00007221
Douglas Gregorb98b1992009-08-11 05:31:07 +00007222template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007223ExprResult
John McCall454feb92009-12-08 09:21:05 +00007224TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007225 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007226 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007227 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007228
Douglas Gregor1af74512010-02-26 00:38:10 +00007229 // Transform the delete operator, if known.
7230 FunctionDecl *OperatorDelete = 0;
7231 if (E->getOperatorDelete()) {
7232 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007233 getDerived().TransformDecl(E->getLocStart(),
7234 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007235 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007236 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007237 }
Sean Huntc3021132010-05-05 15:23:54 +00007238
Douglas Gregorb98b1992009-08-11 05:31:07 +00007239 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007240 Operand.get() == E->getArgument() &&
7241 OperatorDelete == E->getOperatorDelete()) {
7242 // Mark any declarations we need as referenced.
7243 // FIXME: instantiation-specific.
7244 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007245 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007246
7247 if (!E->getArgument()->isTypeDependent()) {
7248 QualType Destroyed = SemaRef.Context.getBaseElementType(
7249 E->getDestroyedType());
7250 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7251 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007252 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7253 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007254 }
7255 }
7256
John McCall3fa5cae2010-10-26 07:05:15 +00007257 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007258 }
Mike Stump1eb44332009-09-09 15:08:12 +00007259
Douglas Gregorb98b1992009-08-11 05:31:07 +00007260 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7261 E->isGlobalDelete(),
7262 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007263 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007264}
Mike Stump1eb44332009-09-09 15:08:12 +00007265
Douglas Gregorb98b1992009-08-11 05:31:07 +00007266template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007267ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007268TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007269 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007270 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007271 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007272 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007273
John McCallb3d87482010-08-24 05:47:05 +00007274 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007275 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007276 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007277 E->getOperatorLoc(),
7278 E->isArrow()? tok::arrow : tok::period,
7279 ObjectTypePtr,
7280 MayBePseudoDestructor);
7281 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007282 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007283
John McCallb3d87482010-08-24 05:47:05 +00007284 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007285 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7286 if (QualifierLoc) {
7287 QualifierLoc
7288 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7289 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007290 return ExprError();
7291 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007292 CXXScopeSpec SS;
7293 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007294
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007295 PseudoDestructorTypeStorage Destroyed;
7296 if (E->getDestroyedTypeInfo()) {
7297 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007298 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007299 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007300 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007301 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007302 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007303 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007304 // We aren't likely to be able to resolve the identifier down to a type
7305 // now anyway, so just retain the identifier.
7306 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7307 E->getDestroyedTypeLoc());
7308 } else {
7309 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007310 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007311 *E->getDestroyedTypeIdentifier(),
7312 E->getDestroyedTypeLoc(),
7313 /*Scope=*/0,
7314 SS, ObjectTypePtr,
7315 false);
7316 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007317 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007318
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007319 Destroyed
7320 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7321 E->getDestroyedTypeLoc());
7322 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007323
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007324 TypeSourceInfo *ScopeTypeInfo = 0;
7325 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007326 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007327 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007328 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007329 }
Sean Huntc3021132010-05-05 15:23:54 +00007330
John McCall9ae2f072010-08-23 23:25:46 +00007331 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007332 E->getOperatorLoc(),
7333 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007334 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007335 ScopeTypeInfo,
7336 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007337 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007338 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007339}
Mike Stump1eb44332009-09-09 15:08:12 +00007340
Douglas Gregora71d8192009-09-04 17:36:40 +00007341template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007342ExprResult
John McCallba135432009-11-21 08:51:07 +00007343TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007344 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007345 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7346 Sema::LookupOrdinaryName);
7347
7348 // Transform all the decls.
7349 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7350 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007351 NamedDecl *InstD = static_cast<NamedDecl*>(
7352 getDerived().TransformDecl(Old->getNameLoc(),
7353 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007354 if (!InstD) {
7355 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7356 // This can happen because of dependent hiding.
7357 if (isa<UsingShadowDecl>(*I))
7358 continue;
7359 else
John McCallf312b1e2010-08-26 23:41:50 +00007360 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007361 }
John McCallf7a1a742009-11-24 19:00:30 +00007362
7363 // Expand using declarations.
7364 if (isa<UsingDecl>(InstD)) {
7365 UsingDecl *UD = cast<UsingDecl>(InstD);
7366 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7367 E = UD->shadow_end(); I != E; ++I)
7368 R.addDecl(*I);
7369 continue;
7370 }
7371
7372 R.addDecl(InstD);
7373 }
7374
7375 // Resolve a kind, but don't do any further analysis. If it's
7376 // ambiguous, the callee needs to deal with it.
7377 R.resolveKind();
7378
7379 // Rebuild the nested-name qualifier, if present.
7380 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007381 if (Old->getQualifierLoc()) {
7382 NestedNameSpecifierLoc QualifierLoc
7383 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7384 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007385 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007386
Douglas Gregor4c9be892011-02-28 20:01:57 +00007387 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007388 }
7389
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007390 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007391 CXXRecordDecl *NamingClass
7392 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7393 Old->getNameLoc(),
7394 Old->getNamingClass()));
7395 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007396 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007397
Douglas Gregor66c45152010-04-27 16:10:10 +00007398 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007399 }
7400
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007401 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7402
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007403 // If we have neither explicit template arguments, nor the template keyword,
7404 // it's a normal declaration name.
7405 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007406 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7407
7408 // If we have template arguments, rebuild them, then rebuild the
7409 // templateid expression.
7410 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007411 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7412 Old->getNumTemplateArgs(),
7413 TransArgs))
7414 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007415
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007416 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007417 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007418}
Mike Stump1eb44332009-09-09 15:08:12 +00007419
Douglas Gregorb98b1992009-08-11 05:31:07 +00007420template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007421ExprResult
John McCall454feb92009-12-08 09:21:05 +00007422TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007423 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7424 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007425 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007426
Douglas Gregorb98b1992009-08-11 05:31:07 +00007427 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007428 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007429 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007430
Mike Stump1eb44332009-09-09 15:08:12 +00007431 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007432 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007433 T,
7434 E->getLocEnd());
7435}
Mike Stump1eb44332009-09-09 15:08:12 +00007436
Douglas Gregorb98b1992009-08-11 05:31:07 +00007437template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007438ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007439TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7440 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7441 if (!LhsT)
7442 return ExprError();
7443
7444 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7445 if (!RhsT)
7446 return ExprError();
7447
7448 if (!getDerived().AlwaysRebuild() &&
7449 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7450 return SemaRef.Owned(E);
7451
7452 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7453 E->getLocStart(),
7454 LhsT, RhsT,
7455 E->getLocEnd());
7456}
7457
7458template<typename Derived>
7459ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007460TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7461 bool ArgChanged = false;
7462 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7463 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7464 TypeSourceInfo *From = E->getArg(I);
7465 TypeLoc FromTL = From->getTypeLoc();
7466 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7467 TypeLocBuilder TLB;
7468 TLB.reserve(FromTL.getFullDataSize());
7469 QualType To = getDerived().TransformType(TLB, FromTL);
7470 if (To.isNull())
7471 return ExprError();
7472
7473 if (To == From->getType())
7474 Args.push_back(From);
7475 else {
7476 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7477 ArgChanged = true;
7478 }
7479 continue;
7480 }
7481
7482 ArgChanged = true;
7483
7484 // We have a pack expansion. Instantiate it.
7485 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
7486 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7487 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7488 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7489
7490 // Determine whether the set of unexpanded parameter packs can and should
7491 // be expanded.
7492 bool Expand = true;
7493 bool RetainExpansion = false;
7494 llvm::Optional<unsigned> OrigNumExpansions
7495 = ExpansionTL.getTypePtr()->getNumExpansions();
7496 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7497 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7498 PatternTL.getSourceRange(),
7499 Unexpanded,
7500 Expand, RetainExpansion,
7501 NumExpansions))
7502 return ExprError();
7503
7504 if (!Expand) {
7505 // The transform has determined that we should perform a simple
7506 // transformation on the pack expansion, producing another pack
7507 // expansion.
7508 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7509
7510 TypeLocBuilder TLB;
7511 TLB.reserve(From->getTypeLoc().getFullDataSize());
7512
7513 QualType To = getDerived().TransformType(TLB, PatternTL);
7514 if (To.isNull())
7515 return ExprError();
7516
7517 To = getDerived().RebuildPackExpansionType(To,
7518 PatternTL.getSourceRange(),
7519 ExpansionTL.getEllipsisLoc(),
7520 NumExpansions);
7521 if (To.isNull())
7522 return ExprError();
7523
7524 PackExpansionTypeLoc ToExpansionTL
7525 = TLB.push<PackExpansionTypeLoc>(To);
7526 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7527 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7528 continue;
7529 }
7530
7531 // Expand the pack expansion by substituting for each argument in the
7532 // pack(s).
7533 for (unsigned I = 0; I != *NumExpansions; ++I) {
7534 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7535 TypeLocBuilder TLB;
7536 TLB.reserve(PatternTL.getFullDataSize());
7537 QualType To = getDerived().TransformType(TLB, PatternTL);
7538 if (To.isNull())
7539 return ExprError();
7540
7541 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7542 }
7543
7544 if (!RetainExpansion)
7545 continue;
7546
7547 // If we're supposed to retain a pack expansion, do so by temporarily
7548 // forgetting the partially-substituted parameter pack.
7549 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7550
7551 TypeLocBuilder TLB;
7552 TLB.reserve(From->getTypeLoc().getFullDataSize());
7553
7554 QualType To = getDerived().TransformType(TLB, PatternTL);
7555 if (To.isNull())
7556 return ExprError();
7557
7558 To = getDerived().RebuildPackExpansionType(To,
7559 PatternTL.getSourceRange(),
7560 ExpansionTL.getEllipsisLoc(),
7561 NumExpansions);
7562 if (To.isNull())
7563 return ExprError();
7564
7565 PackExpansionTypeLoc ToExpansionTL
7566 = TLB.push<PackExpansionTypeLoc>(To);
7567 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7568 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7569 }
7570
7571 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7572 return SemaRef.Owned(E);
7573
7574 return getDerived().RebuildTypeTrait(E->getTrait(),
7575 E->getLocStart(),
7576 Args,
7577 E->getLocEnd());
7578}
7579
7580template<typename Derived>
7581ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007582TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7583 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7584 if (!T)
7585 return ExprError();
7586
7587 if (!getDerived().AlwaysRebuild() &&
7588 T == E->getQueriedTypeSourceInfo())
7589 return SemaRef.Owned(E);
7590
7591 ExprResult SubExpr;
7592 {
7593 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7594 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7595 if (SubExpr.isInvalid())
7596 return ExprError();
7597
7598 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7599 return SemaRef.Owned(E);
7600 }
7601
7602 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7603 E->getLocStart(),
7604 T,
7605 SubExpr.get(),
7606 E->getLocEnd());
7607}
7608
7609template<typename Derived>
7610ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007611TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7612 ExprResult SubExpr;
7613 {
7614 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7615 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7616 if (SubExpr.isInvalid())
7617 return ExprError();
7618
7619 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7620 return SemaRef.Owned(E);
7621 }
7622
7623 return getDerived().RebuildExpressionTrait(
7624 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7625}
7626
7627template<typename Derived>
7628ExprResult
John McCall865d4472009-11-19 22:55:06 +00007629TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007630 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007631 NestedNameSpecifierLoc QualifierLoc
7632 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7633 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007634 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007635 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007636
John McCall43fed0d2010-11-12 08:19:04 +00007637 // TODO: If this is a conversion-function-id, verify that the
7638 // destination type name (if present) resolves the same way after
7639 // instantiation as it did in the local scope.
7640
Abramo Bagnara25777432010-08-11 22:01:17 +00007641 DeclarationNameInfo NameInfo
7642 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7643 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007644 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007645
John McCallf7a1a742009-11-24 19:00:30 +00007646 if (!E->hasExplicitTemplateArgs()) {
7647 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007648 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007649 // Note: it is sufficient to compare the Name component of NameInfo:
7650 // if name has not changed, DNLoc has not changed either.
7651 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007652 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007653
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007654 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007655 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007656 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007657 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007658 }
John McCalld5532b62009-11-23 01:53:49 +00007659
7660 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007661 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7662 E->getNumTemplateArgs(),
7663 TransArgs))
7664 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007665
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007666 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007667 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007668 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007669 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007670}
7671
7672template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007673ExprResult
John McCall454feb92009-12-08 09:21:05 +00007674TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007675 // CXXConstructExprs are always implicit, so when we have a
7676 // 1-argument construction we just transform that argument.
7677 if (E->getNumArgs() == 1 ||
7678 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7679 return getDerived().TransformExpr(E->getArg(0));
7680
Douglas Gregorb98b1992009-08-11 05:31:07 +00007681 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7682
7683 QualType T = getDerived().TransformType(E->getType());
7684 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007685 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007686
7687 CXXConstructorDecl *Constructor
7688 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007689 getDerived().TransformDecl(E->getLocStart(),
7690 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007691 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007692 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007693
Douglas Gregorb98b1992009-08-11 05:31:07 +00007694 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007695 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007696 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7697 &ArgumentChanged))
7698 return ExprError();
7699
Douglas Gregorb98b1992009-08-11 05:31:07 +00007700 if (!getDerived().AlwaysRebuild() &&
7701 T == E->getType() &&
7702 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007703 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007704 // Mark the constructor as referenced.
7705 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007706 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007707 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007708 }
Mike Stump1eb44332009-09-09 15:08:12 +00007709
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007710 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7711 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007712 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007713 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007714 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007715 E->getConstructionKind(),
7716 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007717}
Mike Stump1eb44332009-09-09 15:08:12 +00007718
Douglas Gregorb98b1992009-08-11 05:31:07 +00007719/// \brief Transform a C++ temporary-binding expression.
7720///
Douglas Gregor51326552009-12-24 18:51:59 +00007721/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7722/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007723template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007724ExprResult
John McCall454feb92009-12-08 09:21:05 +00007725TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007726 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007727}
Mike Stump1eb44332009-09-09 15:08:12 +00007728
John McCall4765fa02010-12-06 08:20:24 +00007729/// \brief Transform a C++ expression that contains cleanups that should
7730/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007731///
John McCall4765fa02010-12-06 08:20:24 +00007732/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007733/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007734template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007735ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007736TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007737 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007738}
Mike Stump1eb44332009-09-09 15:08:12 +00007739
Douglas Gregorb98b1992009-08-11 05:31:07 +00007740template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007741ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007742TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007743 CXXTemporaryObjectExpr *E) {
7744 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7745 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007746 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007747
Douglas Gregorb98b1992009-08-11 05:31:07 +00007748 CXXConstructorDecl *Constructor
7749 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007750 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007751 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007752 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007753 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007754
Douglas Gregorb98b1992009-08-11 05:31:07 +00007755 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007756 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007757 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007758 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7759 &ArgumentChanged))
7760 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007761
Douglas Gregorb98b1992009-08-11 05:31:07 +00007762 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007763 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007764 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007765 !ArgumentChanged) {
7766 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007767 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007768 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007769 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007770
7771 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7772 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007773 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007774 E->getLocEnd());
7775}
Mike Stump1eb44332009-09-09 15:08:12 +00007776
Douglas Gregorb98b1992009-08-11 05:31:07 +00007777template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007778ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007779TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007780 // Create the local class that will describe the lambda.
7781 CXXRecordDecl *Class
7782 = getSema().createLambdaClosureType(E->getIntroducerRange());
7783 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7784
7785 // Transform the type of the lambda parameters and start the definition of
7786 // the lambda itself.
7787 TypeSourceInfo *MethodTy
7788 = TransformType(E->getCallOperator()->getTypeSourceInfo());
7789 if (!MethodTy)
7790 return ExprError();
7791
Douglas Gregorc6889e72012-02-14 22:28:59 +00007792 // Transform lambda parameters.
7793 bool Invalid = false;
7794 llvm::SmallVector<QualType, 4> ParamTypes;
7795 llvm::SmallVector<ParmVarDecl *, 4> Params;
7796 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7797 E->getCallOperator()->param_begin(),
7798 E->getCallOperator()->param_size(),
7799 0, ParamTypes, &Params))
7800 Invalid = true;
7801
Douglas Gregordfca6f52012-02-13 22:00:16 +00007802 // Build the call operator.
7803 CXXMethodDecl *CallOperator
7804 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7805 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007806 E->getCallOperator()->getLocEnd(),
7807 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007808 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7809
Douglas Gregord5387e82012-02-14 00:00:48 +00007810 // FIXME: Instantiation-specific.
7811 CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(),
7812 TSK_ImplicitInstantiation);
7813
7814 // Introduce the context of the call operator.
7815 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7816
Douglas Gregordfca6f52012-02-13 22:00:16 +00007817 // Enter the scope of the lambda.
7818 sema::LambdaScopeInfo *LSI
7819 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7820 E->getCaptureDefault(),
7821 E->hasExplicitParameters(),
7822 E->hasExplicitResultType(),
7823 E->isMutable());
7824
7825 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00007826 bool FinishedExplicitCaptures = false;
7827 for (LambdaExpr::capture_iterator C = E->capture_begin(),
7828 CEnd = E->capture_end();
7829 C != CEnd; ++C) {
7830 // When we hit the first implicit capture, tell Sema that we've finished
7831 // the list of explicit captures.
7832 if (!FinishedExplicitCaptures && C->isImplicit()) {
7833 getSema().finishLambdaExplicitCaptures(LSI);
7834 FinishedExplicitCaptures = true;
7835 }
7836
7837 // Capturing 'this' is trivial.
7838 if (C->capturesThis()) {
7839 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7840 continue;
7841 }
7842
Douglas Gregora7365242012-02-14 19:27:52 +00007843 // Determine the capture kind for Sema.
7844 Sema::TryCaptureKind Kind
7845 = C->isImplicit()? Sema::TryCapture_Implicit
7846 : C->getCaptureKind() == LCK_ByCopy
7847 ? Sema::TryCapture_ExplicitByVal
7848 : Sema::TryCapture_ExplicitByRef;
7849 SourceLocation EllipsisLoc;
7850 if (C->isPackExpansion()) {
7851 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7852 bool ShouldExpand = false;
7853 bool RetainExpansion = false;
7854 llvm::Optional<unsigned> NumExpansions;
7855 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7856 C->getLocation(),
7857 Unexpanded,
7858 ShouldExpand, RetainExpansion,
7859 NumExpansions))
7860 return ExprError();
7861
7862 if (ShouldExpand) {
7863 // The transform has determined that we should perform an expansion;
7864 // transform and capture each of the arguments.
7865 // expansion of the pattern. Do so.
7866 VarDecl *Pack = C->getCapturedVar();
7867 for (unsigned I = 0; I != *NumExpansions; ++I) {
7868 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7869 VarDecl *CapturedVar
7870 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7871 Pack));
7872 if (!CapturedVar) {
7873 Invalid = true;
7874 continue;
7875 }
7876
7877 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007878 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregora7365242012-02-14 19:27:52 +00007879 }
7880 continue;
7881 }
7882
7883 EllipsisLoc = C->getEllipsisLoc();
7884 }
7885
Douglas Gregordfca6f52012-02-13 22:00:16 +00007886 // Transform the captured variable.
7887 VarDecl *CapturedVar
7888 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7889 C->getCapturedVar()));
7890 if (!CapturedVar) {
7891 Invalid = true;
7892 continue;
7893 }
Douglas Gregora7365242012-02-14 19:27:52 +00007894
Douglas Gregordfca6f52012-02-13 22:00:16 +00007895 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007896 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007897 }
7898 if (!FinishedExplicitCaptures)
7899 getSema().finishLambdaExplicitCaptures(LSI);
7900
Douglas Gregordfca6f52012-02-13 22:00:16 +00007901
7902 // Enter a new evaluation context to insulate the lambda from any
7903 // cleanups from the enclosing full-expression.
7904 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
7905
7906 if (Invalid) {
7907 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7908 /*IsInstantiation=*/true);
7909 return ExprError();
7910 }
7911
7912 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00007913 StmtResult Body = getDerived().TransformStmt(E->getBody());
7914 if (Body.isInvalid()) {
7915 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7916 /*IsInstantiation=*/true);
7917 return ExprError();
7918 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007919
7920 // Note: Once a lambda mangling number and context declaration have been
7921 // assigned, they never change.
Douglas Gregor9e8c92a2012-02-20 19:44:39 +00007922 unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber();
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007923 Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl();
Douglas Gregordfca6f52012-02-13 22:00:16 +00007924 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregor9e8c92a2012-02-20 19:44:39 +00007925 /*CurScope=*/0, ManglingNumber,
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007926 ContextDecl,
Douglas Gregordfca6f52012-02-13 22:00:16 +00007927 /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00007928}
7929
7930template<typename Derived>
7931ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007932TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007933 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007934 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7935 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007936 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007937
Douglas Gregorb98b1992009-08-11 05:31:07 +00007938 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007939 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007940 Args.reserve(E->arg_size());
7941 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7942 &ArgumentChanged))
7943 return ExprError();
7944
Douglas Gregorb98b1992009-08-11 05:31:07 +00007945 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007946 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007947 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007948 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007949
Douglas Gregorb98b1992009-08-11 05:31:07 +00007950 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007951 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007952 E->getLParenLoc(),
7953 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007954 E->getRParenLoc());
7955}
Mike Stump1eb44332009-09-09 15:08:12 +00007956
Douglas Gregorb98b1992009-08-11 05:31:07 +00007957template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007958ExprResult
John McCall865d4472009-11-19 22:55:06 +00007959TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007960 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007961 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007962 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007963 Expr *OldBase;
7964 QualType BaseType;
7965 QualType ObjectType;
7966 if (!E->isImplicitAccess()) {
7967 OldBase = E->getBase();
7968 Base = getDerived().TransformExpr(OldBase);
7969 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007970 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007971
John McCallaa81e162009-12-01 22:10:20 +00007972 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007973 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007974 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007975 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007976 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007977 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007978 ObjectTy,
7979 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007980 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007981 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007982
John McCallb3d87482010-08-24 05:47:05 +00007983 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007984 BaseType = ((Expr*) Base.get())->getType();
7985 } else {
7986 OldBase = 0;
7987 BaseType = getDerived().TransformType(E->getBaseType());
7988 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7989 }
Mike Stump1eb44332009-09-09 15:08:12 +00007990
Douglas Gregor6cd21982009-10-20 05:58:46 +00007991 // Transform the first part of the nested-name-specifier that qualifies
7992 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007993 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007994 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007995 E->getFirstQualifierFoundInScope(),
7996 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007997
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007998 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007999 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008000 QualifierLoc
8001 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8002 ObjectType,
8003 FirstQualifierInScope);
8004 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008005 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008006 }
Mike Stump1eb44332009-09-09 15:08:12 +00008007
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008008 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8009
John McCall43fed0d2010-11-12 08:19:04 +00008010 // TODO: If this is a conversion-function-id, verify that the
8011 // destination type name (if present) resolves the same way after
8012 // instantiation as it did in the local scope.
8013
Abramo Bagnara25777432010-08-11 22:01:17 +00008014 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008015 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008016 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008017 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008018
John McCallaa81e162009-12-01 22:10:20 +00008019 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008020 // This is a reference to a member without an explicitly-specified
8021 // template argument list. Optimize for this common case.
8022 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008023 Base.get() == OldBase &&
8024 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008025 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008026 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008027 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008028 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008029
John McCall9ae2f072010-08-23 23:25:46 +00008030 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008031 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008032 E->isArrow(),
8033 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008034 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008035 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008036 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008037 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008038 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008039 }
8040
John McCalld5532b62009-11-23 01:53:49 +00008041 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008042 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8043 E->getNumTemplateArgs(),
8044 TransArgs))
8045 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008046
John McCall9ae2f072010-08-23 23:25:46 +00008047 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008048 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008049 E->isArrow(),
8050 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008051 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008052 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008053 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008054 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008055 &TransArgs);
8056}
8057
8058template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008059ExprResult
John McCall454feb92009-12-08 09:21:05 +00008060TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008061 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008062 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008063 QualType BaseType;
8064 if (!Old->isImplicitAccess()) {
8065 Base = getDerived().TransformExpr(Old->getBase());
8066 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008067 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008068 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8069 Old->isArrow());
8070 if (Base.isInvalid())
8071 return ExprError();
8072 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008073 } else {
8074 BaseType = getDerived().TransformType(Old->getBaseType());
8075 }
John McCall129e2df2009-11-30 22:42:35 +00008076
Douglas Gregor4c9be892011-02-28 20:01:57 +00008077 NestedNameSpecifierLoc QualifierLoc;
8078 if (Old->getQualifierLoc()) {
8079 QualifierLoc
8080 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8081 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008082 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008083 }
8084
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008085 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8086
Abramo Bagnara25777432010-08-11 22:01:17 +00008087 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008088 Sema::LookupOrdinaryName);
8089
8090 // Transform all the decls.
8091 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8092 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008093 NamedDecl *InstD = static_cast<NamedDecl*>(
8094 getDerived().TransformDecl(Old->getMemberLoc(),
8095 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008096 if (!InstD) {
8097 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8098 // This can happen because of dependent hiding.
8099 if (isa<UsingShadowDecl>(*I))
8100 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008101 else {
8102 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008103 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008104 }
John McCall9f54ad42009-12-10 09:41:52 +00008105 }
John McCall129e2df2009-11-30 22:42:35 +00008106
8107 // Expand using declarations.
8108 if (isa<UsingDecl>(InstD)) {
8109 UsingDecl *UD = cast<UsingDecl>(InstD);
8110 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8111 E = UD->shadow_end(); I != E; ++I)
8112 R.addDecl(*I);
8113 continue;
8114 }
8115
8116 R.addDecl(InstD);
8117 }
8118
8119 R.resolveKind();
8120
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008121 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008122 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00008123 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008124 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008125 Old->getMemberLoc(),
8126 Old->getNamingClass()));
8127 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008128 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008129
Douglas Gregor66c45152010-04-27 16:10:10 +00008130 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008131 }
Sean Huntc3021132010-05-05 15:23:54 +00008132
John McCall129e2df2009-11-30 22:42:35 +00008133 TemplateArgumentListInfo TransArgs;
8134 if (Old->hasExplicitTemplateArgs()) {
8135 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8136 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008137 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8138 Old->getNumTemplateArgs(),
8139 TransArgs))
8140 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008141 }
John McCallc2233c52010-01-15 08:34:02 +00008142
8143 // FIXME: to do this check properly, we will need to preserve the
8144 // first-qualifier-in-scope here, just in case we had a dependent
8145 // base (and therefore couldn't do the check) and a
8146 // nested-name-qualifier (and therefore could do the lookup).
8147 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00008148
John McCall9ae2f072010-08-23 23:25:46 +00008149 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008150 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008151 Old->getOperatorLoc(),
8152 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008153 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008154 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008155 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008156 R,
8157 (Old->hasExplicitTemplateArgs()
8158 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008159}
8160
8161template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008162ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008163TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008164 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008165 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8166 if (SubExpr.isInvalid())
8167 return ExprError();
8168
8169 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008170 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008171
8172 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8173}
8174
8175template<typename Derived>
8176ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008177TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008178 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8179 if (Pattern.isInvalid())
8180 return ExprError();
8181
8182 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8183 return SemaRef.Owned(E);
8184
Douglas Gregor67fd1252011-01-14 21:20:45 +00008185 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8186 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008187}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008188
8189template<typename Derived>
8190ExprResult
8191TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8192 // If E is not value-dependent, then nothing will change when we transform it.
8193 // Note: This is an instantiation-centric view.
8194 if (!E->isValueDependent())
8195 return SemaRef.Owned(E);
8196
8197 // Note: None of the implementations of TryExpandParameterPacks can ever
8198 // produce a diagnostic when given only a single unexpanded parameter pack,
8199 // so
8200 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8201 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008202 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008203 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00008204 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008205 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008206 ShouldExpand, RetainExpansion,
8207 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008208 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00008209
Douglas Gregor089e8932011-10-10 18:59:29 +00008210 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008211 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00008212
8213 NamedDecl *Pack = E->getPack();
8214 if (!ShouldExpand) {
8215 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8216 Pack));
8217 if (!Pack)
8218 return ExprError();
8219 }
8220
Douglas Gregoree8aff02011-01-04 17:33:58 +00008221
8222 // We now know the length of the parameter pack, so build a new expression
8223 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00008224 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00008225 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008226 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008227}
8228
Douglas Gregorbe230c32011-01-03 17:17:50 +00008229template<typename Derived>
8230ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008231TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8232 SubstNonTypeTemplateParmPackExpr *E) {
8233 // Default behavior is to do nothing with this transformation.
8234 return SemaRef.Owned(E);
8235}
8236
8237template<typename Derived>
8238ExprResult
John McCall91a57552011-07-15 05:09:51 +00008239TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8240 SubstNonTypeTemplateParmExpr *E) {
8241 // Default behavior is to do nothing with this transformation.
8242 return SemaRef.Owned(E);
8243}
8244
8245template<typename Derived>
8246ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008247TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8248 MaterializeTemporaryExpr *E) {
8249 return getDerived().TransformExpr(E->GetTemporaryExpr());
8250}
8251
8252template<typename Derived>
8253ExprResult
John McCall454feb92009-12-08 09:21:05 +00008254TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008255 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008256}
8257
Mike Stump1eb44332009-09-09 15:08:12 +00008258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008259ExprResult
John McCall454feb92009-12-08 09:21:05 +00008260TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008261 TypeSourceInfo *EncodedTypeInfo
8262 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8263 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008264 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008265
Douglas Gregorb98b1992009-08-11 05:31:07 +00008266 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008267 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008268 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008269
8270 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008271 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008272 E->getRParenLoc());
8273}
Mike Stump1eb44332009-09-09 15:08:12 +00008274
Douglas Gregorb98b1992009-08-11 05:31:07 +00008275template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008276ExprResult TreeTransform<Derived>::
8277TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8278 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8279 if (result.isInvalid()) return ExprError();
8280 Expr *subExpr = result.take();
8281
8282 if (!getDerived().AlwaysRebuild() &&
8283 subExpr == E->getSubExpr())
8284 return SemaRef.Owned(E);
8285
8286 return SemaRef.Owned(new(SemaRef.Context)
8287 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8288}
8289
8290template<typename Derived>
8291ExprResult TreeTransform<Derived>::
8292TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
8293 TypeSourceInfo *TSInfo
8294 = getDerived().TransformType(E->getTypeInfoAsWritten());
8295 if (!TSInfo)
8296 return ExprError();
8297
8298 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
8299 if (Result.isInvalid())
8300 return ExprError();
8301
8302 if (!getDerived().AlwaysRebuild() &&
8303 TSInfo == E->getTypeInfoAsWritten() &&
8304 Result.get() == E->getSubExpr())
8305 return SemaRef.Owned(E);
8306
8307 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8308 E->getBridgeKeywordLoc(), TSInfo,
8309 Result.get());
8310}
8311
8312template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008313ExprResult
John McCall454feb92009-12-08 09:21:05 +00008314TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008315 // Transform arguments.
8316 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008317 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008318 Args.reserve(E->getNumArgs());
8319 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8320 &ArgChanged))
8321 return ExprError();
8322
Douglas Gregor92e986e2010-04-22 16:44:27 +00008323 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8324 // Class message: transform the receiver type.
8325 TypeSourceInfo *ReceiverTypeInfo
8326 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8327 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008328 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008329
Douglas Gregor92e986e2010-04-22 16:44:27 +00008330 // If nothing changed, just retain the existing message send.
8331 if (!getDerived().AlwaysRebuild() &&
8332 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008333 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008334
8335 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008336 SmallVector<SourceLocation, 16> SelLocs;
8337 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008338 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8339 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008340 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008341 E->getMethodDecl(),
8342 E->getLeftLoc(),
8343 move_arg(Args),
8344 E->getRightLoc());
8345 }
8346
8347 // Instance message: transform the receiver
8348 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8349 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008350 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008351 = getDerived().TransformExpr(E->getInstanceReceiver());
8352 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008353 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008354
8355 // If nothing changed, just retain the existing message send.
8356 if (!getDerived().AlwaysRebuild() &&
8357 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008358 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008359
Douglas Gregor92e986e2010-04-22 16:44:27 +00008360 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008361 SmallVector<SourceLocation, 16> SelLocs;
8362 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008363 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008364 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008365 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008366 E->getMethodDecl(),
8367 E->getLeftLoc(),
8368 move_arg(Args),
8369 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008370}
8371
Mike Stump1eb44332009-09-09 15:08:12 +00008372template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008373ExprResult
John McCall454feb92009-12-08 09:21:05 +00008374TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008375 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008376}
8377
Mike Stump1eb44332009-09-09 15:08:12 +00008378template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008379ExprResult
John McCall454feb92009-12-08 09:21:05 +00008380TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008381 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008382}
8383
Mike Stump1eb44332009-09-09 15:08:12 +00008384template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008385ExprResult
John McCall454feb92009-12-08 09:21:05 +00008386TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008387 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008388 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008389 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008390 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008391
8392 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008393
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008394 // If nothing changed, just retain the existing expression.
8395 if (!getDerived().AlwaysRebuild() &&
8396 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008397 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008398
John McCall9ae2f072010-08-23 23:25:46 +00008399 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008400 E->getLocation(),
8401 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008402}
8403
Mike Stump1eb44332009-09-09 15:08:12 +00008404template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008405ExprResult
John McCall454feb92009-12-08 09:21:05 +00008406TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008407 // 'super' and types never change. Property never changes. Just
8408 // retain the existing expression.
8409 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008410 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008411
Douglas Gregore3303542010-04-26 20:47:02 +00008412 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008413 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008414 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008415 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008416
Douglas Gregore3303542010-04-26 20:47:02 +00008417 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008418
Douglas Gregore3303542010-04-26 20:47:02 +00008419 // If nothing changed, just retain the existing expression.
8420 if (!getDerived().AlwaysRebuild() &&
8421 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008422 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008423
John McCall12f78a62010-12-02 01:19:52 +00008424 if (E->isExplicitProperty())
8425 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8426 E->getExplicitProperty(),
8427 E->getLocation());
8428
8429 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008430 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008431 E->getImplicitPropertyGetter(),
8432 E->getImplicitPropertySetter(),
8433 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008434}
8435
Mike Stump1eb44332009-09-09 15:08:12 +00008436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008437ExprResult
John McCall454feb92009-12-08 09:21:05 +00008438TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008439 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008440 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008441 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008442 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008443
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008444 // If nothing changed, just retain the existing expression.
8445 if (!getDerived().AlwaysRebuild() &&
8446 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008447 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008448
John McCall9ae2f072010-08-23 23:25:46 +00008449 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008450 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008451}
8452
Mike Stump1eb44332009-09-09 15:08:12 +00008453template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008454ExprResult
John McCall454feb92009-12-08 09:21:05 +00008455TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008456 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008457 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008458 SubExprs.reserve(E->getNumSubExprs());
8459 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8460 SubExprs, &ArgumentChanged))
8461 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008462
Douglas Gregorb98b1992009-08-11 05:31:07 +00008463 if (!getDerived().AlwaysRebuild() &&
8464 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008465 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008466
Douglas Gregorb98b1992009-08-11 05:31:07 +00008467 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8468 move_arg(SubExprs),
8469 E->getRParenLoc());
8470}
8471
Mike Stump1eb44332009-09-09 15:08:12 +00008472template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008473ExprResult
John McCall454feb92009-12-08 09:21:05 +00008474TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008475 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008476
John McCallc6ac9c32011-02-04 18:33:18 +00008477 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8478 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8479
8480 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008481 blockScope->TheDecl->setBlockMissingReturnType(
8482 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008483
Chris Lattner686775d2011-07-20 06:58:45 +00008484 SmallVector<ParmVarDecl*, 4> params;
8485 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008486
8487 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008488 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8489 oldBlock->param_begin(),
8490 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008491 0, paramTypes, &params)) {
8492 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008493 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008494 }
John McCallc6ac9c32011-02-04 18:33:18 +00008495
8496 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008497 QualType exprResultType =
8498 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008499
8500 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008501 if (exprResultType->isObjCObjectType()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008502 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008503 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008504 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008505 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008506 return ExprError();
8507 }
John McCall711c52b2011-01-05 12:14:39 +00008508
John McCallc6ac9c32011-02-04 18:33:18 +00008509 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008510 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008511 paramTypes.data(),
8512 paramTypes.size(),
8513 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008514 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008515 exprFunctionType->getExtInfo());
8516 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008517
8518 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008519 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008520 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008521
8522 if (!oldBlock->blockMissingReturnType()) {
8523 blockScope->HasImplicitReturnType = false;
8524 blockScope->ReturnType = exprResultType;
8525 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008526
John McCall711c52b2011-01-05 12:14:39 +00008527 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008528 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008529 if (body.isInvalid()) {
8530 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008531 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008532 }
John McCall711c52b2011-01-05 12:14:39 +00008533
John McCallc6ac9c32011-02-04 18:33:18 +00008534#ifndef NDEBUG
8535 // In builds with assertions, make sure that we captured everything we
8536 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008537 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8538 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8539 e = oldBlock->capture_end(); i != e; ++i) {
8540 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008541
Douglas Gregorfc921372011-05-20 15:32:55 +00008542 // Ignore parameter packs.
8543 if (isa<ParmVarDecl>(oldCapture) &&
8544 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8545 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008546
Douglas Gregorfc921372011-05-20 15:32:55 +00008547 VarDecl *newCapture =
8548 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8549 oldCapture));
8550 assert(blockScope->CaptureMap.count(newCapture));
8551 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008552 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008553 }
8554#endif
8555
8556 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8557 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008558}
8559
Mike Stump1eb44332009-09-09 15:08:12 +00008560template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008561ExprResult
John McCall454feb92009-12-08 09:21:05 +00008562TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008563 ValueDecl *ND
8564 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8565 E->getDecl()));
8566 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00008567 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00008568
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008569 if (!getDerived().AlwaysRebuild() &&
8570 ND == E->getDecl()) {
8571 // Mark it referenced in the new context regardless.
8572 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00008573 SemaRef.MarkBlockDeclRefReferenced(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008574
John McCall3fa5cae2010-10-26 07:05:15 +00008575 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008576 }
8577
Abramo Bagnara25777432010-08-11 22:01:17 +00008578 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00008579 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00008580 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008581}
Mike Stump1eb44332009-09-09 15:08:12 +00008582
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008583template<typename Derived>
8584ExprResult
8585TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008586 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008587}
Eli Friedman276b0612011-10-11 02:20:01 +00008588
8589template<typename Derived>
8590ExprResult
8591TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008592 QualType RetTy = getDerived().TransformType(E->getType());
8593 bool ArgumentChanged = false;
8594 ASTOwningVector<Expr*> SubExprs(SemaRef);
8595 SubExprs.reserve(E->getNumSubExprs());
8596 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8597 SubExprs, &ArgumentChanged))
8598 return ExprError();
8599
8600 if (!getDerived().AlwaysRebuild() &&
8601 !ArgumentChanged)
8602 return SemaRef.Owned(E);
8603
8604 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8605 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008606}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008607
Douglas Gregorb98b1992009-08-11 05:31:07 +00008608//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008609// Type reconstruction
8610//===----------------------------------------------------------------------===//
8611
Mike Stump1eb44332009-09-09 15:08:12 +00008612template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008613QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8614 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008615 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008616 getDerived().getBaseEntity());
8617}
8618
Mike Stump1eb44332009-09-09 15:08:12 +00008619template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008620QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8621 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008622 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008623 getDerived().getBaseEntity());
8624}
8625
Mike Stump1eb44332009-09-09 15:08:12 +00008626template<typename Derived>
8627QualType
John McCall85737a72009-10-30 00:06:24 +00008628TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8629 bool WrittenAsLValue,
8630 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008631 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008632 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008633}
8634
8635template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008636QualType
John McCall85737a72009-10-30 00:06:24 +00008637TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8638 QualType ClassType,
8639 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008640 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008641 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008642}
8643
8644template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008645QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008646TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8647 ArrayType::ArraySizeModifier SizeMod,
8648 const llvm::APInt *Size,
8649 Expr *SizeExpr,
8650 unsigned IndexTypeQuals,
8651 SourceRange BracketsRange) {
8652 if (SizeExpr || !Size)
8653 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8654 IndexTypeQuals, BracketsRange,
8655 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008656
8657 QualType Types[] = {
8658 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8659 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8660 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008661 };
8662 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8663 QualType SizeType;
8664 for (unsigned I = 0; I != NumTypes; ++I)
8665 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8666 SizeType = Types[I];
8667 break;
8668 }
Mike Stump1eb44332009-09-09 15:08:12 +00008669
Eli Friedman01f276d2012-01-25 23:20:27 +00008670 // Note that we can return a VariableArrayType here in the case where
8671 // the element type was a dependent VariableArrayType.
8672 IntegerLiteral *ArraySize
8673 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8674 /*FIXME*/BracketsRange.getBegin());
8675 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008676 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008677 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008678}
Mike Stump1eb44332009-09-09 15:08:12 +00008679
Douglas Gregor577f75a2009-08-04 16:50:30 +00008680template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008681QualType
8682TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008683 ArrayType::ArraySizeModifier SizeMod,
8684 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008685 unsigned IndexTypeQuals,
8686 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008687 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008688 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008689}
8690
8691template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008692QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008693TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008694 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008695 unsigned IndexTypeQuals,
8696 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008697 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008698 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008699}
Mike Stump1eb44332009-09-09 15:08:12 +00008700
Douglas Gregor577f75a2009-08-04 16:50:30 +00008701template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008702QualType
8703TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008704 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008705 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008706 unsigned IndexTypeQuals,
8707 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008708 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008709 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008710 IndexTypeQuals, BracketsRange);
8711}
8712
8713template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008714QualType
8715TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008716 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008717 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008718 unsigned IndexTypeQuals,
8719 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008720 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008721 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008722 IndexTypeQuals, BracketsRange);
8723}
8724
8725template<typename Derived>
8726QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008727 unsigned NumElements,
8728 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008729 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008730 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008731}
Mike Stump1eb44332009-09-09 15:08:12 +00008732
Douglas Gregor577f75a2009-08-04 16:50:30 +00008733template<typename Derived>
8734QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8735 unsigned NumElements,
8736 SourceLocation AttributeLoc) {
8737 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8738 NumElements, true);
8739 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008740 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8741 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008742 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008743}
Mike Stump1eb44332009-09-09 15:08:12 +00008744
Douglas Gregor577f75a2009-08-04 16:50:30 +00008745template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008746QualType
8747TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008748 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008749 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008750 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008751}
Mike Stump1eb44332009-09-09 15:08:12 +00008752
Douglas Gregor577f75a2009-08-04 16:50:30 +00008753template<typename Derived>
8754QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008755 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008756 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008757 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008758 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00008759 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008760 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008761 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008762 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008763 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008764 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008765 getDerived().getBaseEntity(),
8766 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008767}
Mike Stump1eb44332009-09-09 15:08:12 +00008768
Douglas Gregor577f75a2009-08-04 16:50:30 +00008769template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008770QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8771 return SemaRef.Context.getFunctionNoProtoType(T);
8772}
8773
8774template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008775QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8776 assert(D && "no decl found");
8777 if (D->isInvalidDecl()) return QualType();
8778
Douglas Gregor92e986e2010-04-22 16:44:27 +00008779 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008780 TypeDecl *Ty;
8781 if (isa<UsingDecl>(D)) {
8782 UsingDecl *Using = cast<UsingDecl>(D);
8783 assert(Using->isTypeName() &&
8784 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8785
8786 // A valid resolved using typename decl points to exactly one type decl.
8787 assert(++Using->shadow_begin() == Using->shadow_end());
8788 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008789
John McCalled976492009-12-04 22:46:56 +00008790 } else {
8791 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8792 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8793 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8794 }
8795
8796 return SemaRef.Context.getTypeDeclType(Ty);
8797}
8798
8799template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008800QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8801 SourceLocation Loc) {
8802 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008803}
8804
8805template<typename Derived>
8806QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8807 return SemaRef.Context.getTypeOfType(Underlying);
8808}
8809
8810template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008811QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8812 SourceLocation Loc) {
8813 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008814}
8815
8816template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008817QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8818 UnaryTransformType::UTTKind UKind,
8819 SourceLocation Loc) {
8820 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8821}
8822
8823template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008824QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008825 TemplateName Template,
8826 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008827 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008828 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008829}
Mike Stump1eb44332009-09-09 15:08:12 +00008830
Douglas Gregordcee1a12009-08-06 05:28:30 +00008831template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00008832QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8833 SourceLocation KWLoc) {
8834 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8835}
8836
8837template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008838TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008839TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008840 bool TemplateKW,
8841 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008842 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008843 Template);
8844}
8845
8846template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008847TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008848TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8849 const IdentifierInfo &Name,
8850 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008851 QualType ObjectType,
8852 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008853 UnqualifiedId TemplateName;
8854 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008855 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008856 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00008857 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008858 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008859 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008860 /*EnteringContext=*/false,
8861 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008862 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008863}
Mike Stump1eb44332009-09-09 15:08:12 +00008864
Douglas Gregorb98b1992009-08-11 05:31:07 +00008865template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008866TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008867TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008868 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008869 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008870 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008871 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008872 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008873 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008874 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008875 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00008876 Sema::TemplateTy Template;
8877 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008878 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00008879 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008880 /*EnteringContext=*/false,
8881 Template);
8882 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008883}
Sean Huntc3021132010-05-05 15:23:54 +00008884
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008885template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008886ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008887TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8888 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008889 Expr *OrigCallee,
8890 Expr *First,
8891 Expr *Second) {
8892 Expr *Callee = OrigCallee->IgnoreParenCasts();
8893 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008894
Douglas Gregorb98b1992009-08-11 05:31:07 +00008895 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008896 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008897 if (!First->getType()->isOverloadableType() &&
8898 !Second->getType()->isOverloadableType())
8899 return getSema().CreateBuiltinArraySubscriptExpr(First,
8900 Callee->getLocStart(),
8901 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008902 } else if (Op == OO_Arrow) {
8903 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008904 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8905 } else if (Second == 0 || isPostIncDec) {
8906 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008907 // The argument is not of overloadable type, so try to create a
8908 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008909 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008910 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008911
John McCall9ae2f072010-08-23 23:25:46 +00008912 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008913 }
8914 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008915 if (!First->getType()->isOverloadableType() &&
8916 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008917 // Neither of the arguments is an overloadable type, so try to
8918 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008919 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008920 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008921 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008922 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008923 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008924
Douglas Gregorb98b1992009-08-11 05:31:07 +00008925 return move(Result);
8926 }
8927 }
Mike Stump1eb44332009-09-09 15:08:12 +00008928
8929 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008930 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008931 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008932
John McCall9ae2f072010-08-23 23:25:46 +00008933 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008934 assert(ULE->requiresADL());
8935
8936 // FIXME: Do we have to check
8937 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008938 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008939 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008940 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008941 }
Mike Stump1eb44332009-09-09 15:08:12 +00008942
Douglas Gregorb98b1992009-08-11 05:31:07 +00008943 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008944 Expr *Args[2] = { First, Second };
8945 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008946
Douglas Gregorb98b1992009-08-11 05:31:07 +00008947 // Create the overloaded operator invocation for unary operators.
8948 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008949 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008950 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008951 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008952 }
Mike Stump1eb44332009-09-09 15:08:12 +00008953
Douglas Gregor5b8968c2011-07-15 16:25:15 +00008954 if (Op == OO_Subscript) {
8955 SourceLocation LBrace;
8956 SourceLocation RBrace;
8957
8958 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8959 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8960 LBrace = SourceLocation::getFromRawEncoding(
8961 NameLoc.CXXOperatorName.BeginOpNameLoc);
8962 RBrace = SourceLocation::getFromRawEncoding(
8963 NameLoc.CXXOperatorName.EndOpNameLoc);
8964 } else {
8965 LBrace = Callee->getLocStart();
8966 RBrace = OpLoc;
8967 }
8968
8969 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8970 First, Second);
8971 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00008972
Douglas Gregorb98b1992009-08-11 05:31:07 +00008973 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008974 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008975 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008976 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8977 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008978 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008979
Mike Stump1eb44332009-09-09 15:08:12 +00008980 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008981}
Mike Stump1eb44332009-09-09 15:08:12 +00008982
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008983template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008984ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008985TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008986 SourceLocation OperatorLoc,
8987 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008988 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008989 TypeSourceInfo *ScopeType,
8990 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008991 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008992 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008993 QualType BaseType = Base->getType();
8994 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008995 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008996 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008997 !BaseType->getAs<PointerType>()->getPointeeType()
8998 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008999 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009000 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009001 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009002 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009003 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009004 /*FIXME?*/true);
9005 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009006
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009007 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009008 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9009 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9010 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9011 NameInfo.setNamedTypeInfo(DestroyedType);
9012
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009013 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00009014
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009015 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009016 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009017 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009018 SS, TemplateKWLoc,
9019 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009020 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009021 /*TemplateArgs*/ 0);
9022}
9023
Douglas Gregor577f75a2009-08-04 16:50:30 +00009024} // end namespace clang
9025
9026#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H