blob: 363e2c408db65ba21417dda654f427ace3d802ad [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
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004277 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4278 if (E.isInvalid())
4279 return QualType();
4280
John McCalla2becad2009-10-21 00:40:46 +00004281 QualType Result = TL.getType();
4282 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004283 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004284 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004285 if (Result.isNull())
4286 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004287 }
John McCalla2becad2009-10-21 00:40:46 +00004288 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004289
John McCalla2becad2009-10-21 00:40:46 +00004290 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004291 NewTL.setTypeofLoc(TL.getTypeofLoc());
4292 NewTL.setLParenLoc(TL.getLParenLoc());
4293 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004294
4295 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004296}
Mike Stump1eb44332009-09-09 15:08:12 +00004297
4298template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004299QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004300 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004301 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4302 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4303 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004304 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004305
John McCalla2becad2009-10-21 00:40:46 +00004306 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004307 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4308 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004309 if (Result.isNull())
4310 return QualType();
4311 }
Mike Stump1eb44332009-09-09 15:08:12 +00004312
John McCalla2becad2009-10-21 00:40:46 +00004313 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004314 NewTL.setTypeofLoc(TL.getTypeofLoc());
4315 NewTL.setLParenLoc(TL.getLParenLoc());
4316 NewTL.setRParenLoc(TL.getRParenLoc());
4317 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004318
4319 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004320}
Mike Stump1eb44332009-09-09 15:08:12 +00004321
4322template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004323QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004324 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004325 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004326
Douglas Gregor670444e2009-08-04 22:27:00 +00004327 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004328 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4329 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004330
John McCall60d7b3a2010-08-24 06:29:42 +00004331 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004332 if (E.isInvalid())
4333 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004334
Richard Smith76f3f692012-02-22 02:04:18 +00004335 E = getSema().ActOnDecltypeExpression(E.take());
4336 if (E.isInvalid())
4337 return QualType();
4338
John McCalla2becad2009-10-21 00:40:46 +00004339 QualType Result = TL.getType();
4340 if (getDerived().AlwaysRebuild() ||
4341 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004342 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004343 if (Result.isNull())
4344 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004345 }
John McCalla2becad2009-10-21 00:40:46 +00004346 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004347
John McCalla2becad2009-10-21 00:40:46 +00004348 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4349 NewTL.setNameLoc(TL.getNameLoc());
4350
4351 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004352}
4353
4354template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004355QualType TreeTransform<Derived>::TransformUnaryTransformType(
4356 TypeLocBuilder &TLB,
4357 UnaryTransformTypeLoc TL) {
4358 QualType Result = TL.getType();
4359 if (Result->isDependentType()) {
4360 const UnaryTransformType *T = TL.getTypePtr();
4361 QualType NewBase =
4362 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4363 Result = getDerived().RebuildUnaryTransformType(NewBase,
4364 T->getUTTKind(),
4365 TL.getKWLoc());
4366 if (Result.isNull())
4367 return QualType();
4368 }
4369
4370 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4371 NewTL.setKWLoc(TL.getKWLoc());
4372 NewTL.setParensRange(TL.getParensRange());
4373 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4374 return Result;
4375}
4376
4377template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004378QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4379 AutoTypeLoc TL) {
4380 const AutoType *T = TL.getTypePtr();
4381 QualType OldDeduced = T->getDeducedType();
4382 QualType NewDeduced;
4383 if (!OldDeduced.isNull()) {
4384 NewDeduced = getDerived().TransformType(OldDeduced);
4385 if (NewDeduced.isNull())
4386 return QualType();
4387 }
4388
4389 QualType Result = TL.getType();
4390 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4391 Result = getDerived().RebuildAutoType(NewDeduced);
4392 if (Result.isNull())
4393 return QualType();
4394 }
4395
4396 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4397 NewTL.setNameLoc(TL.getNameLoc());
4398
4399 return Result;
4400}
4401
4402template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004403QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004404 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004405 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004406 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004407 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4408 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004409 if (!Record)
4410 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004411
John McCalla2becad2009-10-21 00:40:46 +00004412 QualType Result = TL.getType();
4413 if (getDerived().AlwaysRebuild() ||
4414 Record != T->getDecl()) {
4415 Result = getDerived().RebuildRecordType(Record);
4416 if (Result.isNull())
4417 return QualType();
4418 }
Mike Stump1eb44332009-09-09 15:08:12 +00004419
John McCalla2becad2009-10-21 00:40:46 +00004420 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4421 NewTL.setNameLoc(TL.getNameLoc());
4422
4423 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004424}
Mike Stump1eb44332009-09-09 15:08:12 +00004425
4426template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004427QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004428 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004429 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004430 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004431 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4432 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004433 if (!Enum)
4434 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004435
John McCalla2becad2009-10-21 00:40:46 +00004436 QualType Result = TL.getType();
4437 if (getDerived().AlwaysRebuild() ||
4438 Enum != T->getDecl()) {
4439 Result = getDerived().RebuildEnumType(Enum);
4440 if (Result.isNull())
4441 return QualType();
4442 }
Mike Stump1eb44332009-09-09 15:08:12 +00004443
John McCalla2becad2009-10-21 00:40:46 +00004444 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4445 NewTL.setNameLoc(TL.getNameLoc());
4446
4447 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004448}
John McCall7da24312009-09-05 00:15:47 +00004449
John McCall3cb0ebd2010-03-10 03:28:59 +00004450template<typename Derived>
4451QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4452 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004453 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004454 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4455 TL.getTypePtr()->getDecl());
4456 if (!D) return QualType();
4457
4458 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4459 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4460 return T;
4461}
4462
Douglas Gregor577f75a2009-08-04 16:50:30 +00004463template<typename Derived>
4464QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004465 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004466 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004467 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004468}
4469
Mike Stump1eb44332009-09-09 15:08:12 +00004470template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004471QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004472 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004473 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004474 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4475
4476 // Substitute into the replacement type, which itself might involve something
4477 // that needs to be transformed. This only tends to occur with default
4478 // template arguments of template template parameters.
4479 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4480 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4481 if (Replacement.isNull())
4482 return QualType();
4483
4484 // Always canonicalize the replacement type.
4485 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4486 QualType Result
4487 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4488 Replacement);
4489
4490 // Propagate type-source information.
4491 SubstTemplateTypeParmTypeLoc NewTL
4492 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4493 NewTL.setNameLoc(TL.getNameLoc());
4494 return Result;
4495
John McCall49a832b2009-10-18 09:09:24 +00004496}
4497
4498template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004499QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4500 TypeLocBuilder &TLB,
4501 SubstTemplateTypeParmPackTypeLoc TL) {
4502 return TransformTypeSpecType(TLB, TL);
4503}
4504
4505template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004506QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004507 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004508 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004509 const TemplateSpecializationType *T = TL.getTypePtr();
4510
Douglas Gregor1d752d72011-03-02 18:46:51 +00004511 // The nested-name-specifier never matters in a TemplateSpecializationType,
4512 // because we can't have a dependent nested-name-specifier anyway.
4513 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004514 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004515 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4516 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004517 if (Template.isNull())
4518 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004519
John McCall43fed0d2010-11-12 08:19:04 +00004520 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4521}
4522
Eli Friedmanb001de72011-10-06 23:00:33 +00004523template<typename Derived>
4524QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4525 AtomicTypeLoc TL) {
4526 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4527 if (ValueType.isNull())
4528 return QualType();
4529
4530 QualType Result = TL.getType();
4531 if (getDerived().AlwaysRebuild() ||
4532 ValueType != TL.getValueLoc().getType()) {
4533 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4534 if (Result.isNull())
4535 return QualType();
4536 }
4537
4538 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4539 NewTL.setKWLoc(TL.getKWLoc());
4540 NewTL.setLParenLoc(TL.getLParenLoc());
4541 NewTL.setRParenLoc(TL.getRParenLoc());
4542
4543 return Result;
4544}
4545
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004546namespace {
4547 /// \brief Simple iterator that traverses the template arguments in a
4548 /// container that provides a \c getArgLoc() member function.
4549 ///
4550 /// This iterator is intended to be used with the iterator form of
4551 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4552 template<typename ArgLocContainer>
4553 class TemplateArgumentLocContainerIterator {
4554 ArgLocContainer *Container;
4555 unsigned Index;
4556
4557 public:
4558 typedef TemplateArgumentLoc value_type;
4559 typedef TemplateArgumentLoc reference;
4560 typedef int difference_type;
4561 typedef std::input_iterator_tag iterator_category;
4562
4563 class pointer {
4564 TemplateArgumentLoc Arg;
4565
4566 public:
4567 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4568
4569 const TemplateArgumentLoc *operator->() const {
4570 return &Arg;
4571 }
4572 };
4573
4574
4575 TemplateArgumentLocContainerIterator() {}
4576
4577 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4578 unsigned Index)
4579 : Container(&Container), Index(Index) { }
4580
4581 TemplateArgumentLocContainerIterator &operator++() {
4582 ++Index;
4583 return *this;
4584 }
4585
4586 TemplateArgumentLocContainerIterator operator++(int) {
4587 TemplateArgumentLocContainerIterator Old(*this);
4588 ++(*this);
4589 return Old;
4590 }
4591
4592 TemplateArgumentLoc operator*() const {
4593 return Container->getArgLoc(Index);
4594 }
4595
4596 pointer operator->() const {
4597 return pointer(Container->getArgLoc(Index));
4598 }
4599
4600 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004601 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004602 return X.Container == Y.Container && X.Index == Y.Index;
4603 }
4604
4605 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004606 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004607 return !(X == Y);
4608 }
4609 };
4610}
4611
4612
John McCall43fed0d2010-11-12 08:19:04 +00004613template <typename Derived>
4614QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4615 TypeLocBuilder &TLB,
4616 TemplateSpecializationTypeLoc TL,
4617 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004618 TemplateArgumentListInfo NewTemplateArgs;
4619 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4620 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004621 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4622 ArgIterator;
4623 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4624 ArgIterator(TL, TL.getNumArgs()),
4625 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004626 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004627
John McCall833ca992009-10-29 08:12:44 +00004628 // FIXME: maybe don't rebuild if all the template arguments are the same.
4629
4630 QualType Result =
4631 getDerived().RebuildTemplateSpecializationType(Template,
4632 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004633 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004634
4635 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004636 // Specializations of template template parameters are represented as
4637 // TemplateSpecializationTypes, and substitution of type alias templates
4638 // within a dependent context can transform them into
4639 // DependentTemplateSpecializationTypes.
4640 if (isa<DependentTemplateSpecializationType>(Result)) {
4641 DependentTemplateSpecializationTypeLoc NewTL
4642 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004643 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004644 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004645 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004646 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004647 NewTL.setLAngleLoc(TL.getLAngleLoc());
4648 NewTL.setRAngleLoc(TL.getRAngleLoc());
4649 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4650 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4651 return Result;
4652 }
4653
John McCall833ca992009-10-29 08:12:44 +00004654 TemplateSpecializationTypeLoc NewTL
4655 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004656 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004657 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4658 NewTL.setLAngleLoc(TL.getLAngleLoc());
4659 NewTL.setRAngleLoc(TL.getRAngleLoc());
4660 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4661 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004662 }
Mike Stump1eb44332009-09-09 15:08:12 +00004663
John McCall833ca992009-10-29 08:12:44 +00004664 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004665}
Mike Stump1eb44332009-09-09 15:08:12 +00004666
Douglas Gregora88f09f2011-02-28 17:23:35 +00004667template <typename Derived>
4668QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4669 TypeLocBuilder &TLB,
4670 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004671 TemplateName Template,
4672 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004673 TemplateArgumentListInfo NewTemplateArgs;
4674 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4675 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4676 typedef TemplateArgumentLocContainerIterator<
4677 DependentTemplateSpecializationTypeLoc> ArgIterator;
4678 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4679 ArgIterator(TL, TL.getNumArgs()),
4680 NewTemplateArgs))
4681 return QualType();
4682
4683 // FIXME: maybe don't rebuild if all the template arguments are the same.
4684
4685 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4686 QualType Result
4687 = getSema().Context.getDependentTemplateSpecializationType(
4688 TL.getTypePtr()->getKeyword(),
4689 DTN->getQualifier(),
4690 DTN->getIdentifier(),
4691 NewTemplateArgs);
4692
4693 DependentTemplateSpecializationTypeLoc NewTL
4694 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004695 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004696 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004697 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004698 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004699 NewTL.setLAngleLoc(TL.getLAngleLoc());
4700 NewTL.setRAngleLoc(TL.getRAngleLoc());
4701 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4702 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4703 return Result;
4704 }
4705
4706 QualType Result
4707 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004708 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004709 NewTemplateArgs);
4710
4711 if (!Result.isNull()) {
4712 /// FIXME: Wrap this in an elaborated-type-specifier?
4713 TemplateSpecializationTypeLoc NewTL
4714 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004715 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004716 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004717 NewTL.setLAngleLoc(TL.getLAngleLoc());
4718 NewTL.setRAngleLoc(TL.getRAngleLoc());
4719 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4720 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4721 }
4722
4723 return Result;
4724}
4725
Mike Stump1eb44332009-09-09 15:08:12 +00004726template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004727QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004728TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004729 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004730 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004731
Douglas Gregor9e876872011-03-01 18:12:44 +00004732 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004733 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004734 if (TL.getQualifierLoc()) {
4735 QualifierLoc
4736 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4737 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004738 return QualType();
4739 }
Mike Stump1eb44332009-09-09 15:08:12 +00004740
John McCall43fed0d2010-11-12 08:19:04 +00004741 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4742 if (NamedT.isNull())
4743 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004744
Richard Smith3e4c6c42011-05-05 21:57:07 +00004745 // C++0x [dcl.type.elab]p2:
4746 // If the identifier resolves to a typedef-name or the simple-template-id
4747 // resolves to an alias template specialization, the
4748 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004749 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4750 if (const TemplateSpecializationType *TST =
4751 NamedT->getAs<TemplateSpecializationType>()) {
4752 TemplateName Template = TST->getTemplateName();
4753 if (TypeAliasTemplateDecl *TAT =
4754 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4755 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4756 diag::err_tag_reference_non_tag) << 4;
4757 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4758 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004759 }
4760 }
4761
John McCalla2becad2009-10-21 00:40:46 +00004762 QualType Result = TL.getType();
4763 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004764 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004765 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004766 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004767 T->getKeyword(),
4768 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004769 if (Result.isNull())
4770 return QualType();
4771 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004772
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004773 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004774 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004775 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004776 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004777}
Mike Stump1eb44332009-09-09 15:08:12 +00004778
4779template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004780QualType TreeTransform<Derived>::TransformAttributedType(
4781 TypeLocBuilder &TLB,
4782 AttributedTypeLoc TL) {
4783 const AttributedType *oldType = TL.getTypePtr();
4784 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4785 if (modifiedType.isNull())
4786 return QualType();
4787
4788 QualType result = TL.getType();
4789
4790 // FIXME: dependent operand expressions?
4791 if (getDerived().AlwaysRebuild() ||
4792 modifiedType != oldType->getModifiedType()) {
4793 // TODO: this is really lame; we should really be rebuilding the
4794 // equivalent type from first principles.
4795 QualType equivalentType
4796 = getDerived().TransformType(oldType->getEquivalentType());
4797 if (equivalentType.isNull())
4798 return QualType();
4799 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4800 modifiedType,
4801 equivalentType);
4802 }
4803
4804 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4805 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4806 if (TL.hasAttrOperand())
4807 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4808 if (TL.hasAttrExprOperand())
4809 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4810 else if (TL.hasAttrEnumOperand())
4811 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4812
4813 return result;
4814}
4815
4816template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004817QualType
4818TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4819 ParenTypeLoc TL) {
4820 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4821 if (Inner.isNull())
4822 return QualType();
4823
4824 QualType Result = TL.getType();
4825 if (getDerived().AlwaysRebuild() ||
4826 Inner != TL.getInnerLoc().getType()) {
4827 Result = getDerived().RebuildParenType(Inner);
4828 if (Result.isNull())
4829 return QualType();
4830 }
4831
4832 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4833 NewTL.setLParenLoc(TL.getLParenLoc());
4834 NewTL.setRParenLoc(TL.getRParenLoc());
4835 return Result;
4836}
4837
4838template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004839QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004840 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004841 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004842
Douglas Gregor2494dd02011-03-01 01:34:45 +00004843 NestedNameSpecifierLoc QualifierLoc
4844 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4845 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004846 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004847
John McCall33500952010-06-11 00:33:02 +00004848 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004849 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004850 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004851 QualifierLoc,
4852 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004853 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004854 if (Result.isNull())
4855 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004856
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004857 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4858 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004859 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4860
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004861 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004862 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004863 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004864 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004865 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004866 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004867 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004868 NewTL.setNameLoc(TL.getNameLoc());
4869 }
John McCalla2becad2009-10-21 00:40:46 +00004870 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004871}
Mike Stump1eb44332009-09-09 15:08:12 +00004872
Douglas Gregor577f75a2009-08-04 16:50:30 +00004873template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004874QualType TreeTransform<Derived>::
4875 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004876 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004877 NestedNameSpecifierLoc QualifierLoc;
4878 if (TL.getQualifierLoc()) {
4879 QualifierLoc
4880 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4881 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004882 return QualType();
4883 }
4884
John McCall43fed0d2010-11-12 08:19:04 +00004885 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004886 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004887}
4888
4889template<typename Derived>
4890QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004891TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4892 DependentTemplateSpecializationTypeLoc TL,
4893 NestedNameSpecifierLoc QualifierLoc) {
4894 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4895
4896 TemplateArgumentListInfo NewTemplateArgs;
4897 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4898 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4899
4900 typedef TemplateArgumentLocContainerIterator<
4901 DependentTemplateSpecializationTypeLoc> ArgIterator;
4902 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4903 ArgIterator(TL, TL.getNumArgs()),
4904 NewTemplateArgs))
4905 return QualType();
4906
4907 QualType Result
4908 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4909 QualifierLoc,
4910 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004911 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004912 NewTemplateArgs);
4913 if (Result.isNull())
4914 return QualType();
4915
4916 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4917 QualType NamedT = ElabT->getNamedType();
4918
4919 // Copy information relevant to the template specialization.
4920 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004921 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004922 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004923 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004924 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4925 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004926 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004927 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004928
4929 // Copy information relevant to the elaborated type.
4930 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004931 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004932 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004933 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4934 DependentTemplateSpecializationTypeLoc SpecTL
4935 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004936 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004937 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004938 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004939 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004940 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4941 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004942 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004943 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004944 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004945 TemplateSpecializationTypeLoc SpecTL
4946 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004947 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004948 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004949 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4950 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004951 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004952 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004953 }
4954 return Result;
4955}
4956
4957template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004958QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4959 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004960 QualType Pattern
4961 = getDerived().TransformType(TLB, TL.getPatternLoc());
4962 if (Pattern.isNull())
4963 return QualType();
4964
4965 QualType Result = TL.getType();
4966 if (getDerived().AlwaysRebuild() ||
4967 Pattern != TL.getPatternLoc().getType()) {
4968 Result = getDerived().RebuildPackExpansionType(Pattern,
4969 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004970 TL.getEllipsisLoc(),
4971 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004972 if (Result.isNull())
4973 return QualType();
4974 }
4975
4976 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4977 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4978 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004979}
4980
4981template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004982QualType
4983TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004984 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004985 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004986 TLB.pushFullCopy(TL);
4987 return TL.getType();
4988}
4989
4990template<typename Derived>
4991QualType
4992TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004993 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004994 // ObjCObjectType is never dependent.
4995 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004996 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004997}
Mike Stump1eb44332009-09-09 15:08:12 +00004998
4999template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005000QualType
5001TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005002 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005003 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005004 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005005 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005006}
5007
Douglas Gregor577f75a2009-08-04 16:50:30 +00005008//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005009// Statement transformation
5010//===----------------------------------------------------------------------===//
5011template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005012StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005013TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005014 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005015}
5016
5017template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005018StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005019TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5020 return getDerived().TransformCompoundStmt(S, false);
5021}
5022
5023template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005024StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005025TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005026 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005027 Sema::CompoundScopeRAII CompoundScope(getSema());
5028
John McCall7114cba2010-08-27 19:56:05 +00005029 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005030 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005031 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005032 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5033 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005034 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005035 if (Result.isInvalid()) {
5036 // Immediately fail if this was a DeclStmt, since it's very
5037 // likely that this will cause problems for future statements.
5038 if (isa<DeclStmt>(*B))
5039 return StmtError();
5040
5041 // Otherwise, just keep processing substatements and fail later.
5042 SubStmtInvalid = true;
5043 continue;
5044 }
Mike Stump1eb44332009-09-09 15:08:12 +00005045
Douglas Gregor43959a92009-08-20 07:17:43 +00005046 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5047 Statements.push_back(Result.takeAs<Stmt>());
5048 }
Mike Stump1eb44332009-09-09 15:08:12 +00005049
John McCall7114cba2010-08-27 19:56:05 +00005050 if (SubStmtInvalid)
5051 return StmtError();
5052
Douglas Gregor43959a92009-08-20 07:17:43 +00005053 if (!getDerived().AlwaysRebuild() &&
5054 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005055 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005056
5057 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5058 move_arg(Statements),
5059 S->getRBracLoc(),
5060 IsStmtExpr);
5061}
Mike Stump1eb44332009-09-09 15:08:12 +00005062
Douglas Gregor43959a92009-08-20 07:17:43 +00005063template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005064StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005065TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005066 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005067 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005068 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5069 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005070
Eli Friedman264c1f82009-11-19 03:14:00 +00005071 // Transform the left-hand case value.
5072 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005073 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005074 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005075 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005076
Eli Friedman264c1f82009-11-19 03:14:00 +00005077 // Transform the right-hand case value (for the GNU case-range extension).
5078 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005079 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005080 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005081 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005082 }
Mike Stump1eb44332009-09-09 15:08:12 +00005083
Douglas Gregor43959a92009-08-20 07:17:43 +00005084 // Build the case statement.
5085 // Case statements are always rebuilt so that they will attached to their
5086 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005087 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005088 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005089 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005090 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005091 S->getColonLoc());
5092 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005093 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005094
Douglas Gregor43959a92009-08-20 07:17:43 +00005095 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005096 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005097 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005098 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005099
Douglas Gregor43959a92009-08-20 07:17:43 +00005100 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005101 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005102}
5103
5104template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005105StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005106TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005107 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005108 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005109 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005110 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005111
Douglas Gregor43959a92009-08-20 07:17:43 +00005112 // Default statements are always rebuilt
5113 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005114 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005115}
Mike Stump1eb44332009-09-09 15:08:12 +00005116
Douglas Gregor43959a92009-08-20 07:17:43 +00005117template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005118StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005119TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005120 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005121 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005122 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005123
Chris Lattner57ad3782011-02-17 20:34:02 +00005124 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5125 S->getDecl());
5126 if (!LD)
5127 return StmtError();
5128
5129
Douglas Gregor43959a92009-08-20 07:17:43 +00005130 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005131 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005132 cast<LabelDecl>(LD), SourceLocation(),
5133 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005134}
Mike Stump1eb44332009-09-09 15:08:12 +00005135
Douglas Gregor43959a92009-08-20 07:17:43 +00005136template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005137StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005138TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005139 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005140 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005141 VarDecl *ConditionVar = 0;
5142 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005143 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005144 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005145 getDerived().TransformDefinition(
5146 S->getConditionVariable()->getLocation(),
5147 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005148 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005149 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005150 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005151 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005152
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005153 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005154 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005155
5156 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005157 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005158 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5159 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005160 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005161 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005162
John McCall9ae2f072010-08-23 23:25:46 +00005163 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005164 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005165 }
Sean Huntc3021132010-05-05 15:23:54 +00005166
John McCall9ae2f072010-08-23 23:25:46 +00005167 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5168 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005169 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005170
Douglas Gregor43959a92009-08-20 07:17:43 +00005171 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005172 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005173 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005174 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005175
Douglas Gregor43959a92009-08-20 07:17:43 +00005176 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005177 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005178 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005179 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005180
Douglas Gregor43959a92009-08-20 07:17:43 +00005181 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005182 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005183 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005184 Then.get() == S->getThen() &&
5185 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005186 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005187
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005188 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005189 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005190 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005191}
5192
5193template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005194StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005195TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005196 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005197 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005198 VarDecl *ConditionVar = 0;
5199 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005200 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005201 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005202 getDerived().TransformDefinition(
5203 S->getConditionVariable()->getLocation(),
5204 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005205 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005206 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005207 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005208 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005209
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005210 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005211 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005212 }
Mike Stump1eb44332009-09-09 15:08:12 +00005213
Douglas Gregor43959a92009-08-20 07:17:43 +00005214 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005215 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005216 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005217 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005218 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005219 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005220
Douglas Gregor43959a92009-08-20 07:17:43 +00005221 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005222 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005223 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005224 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005225
Douglas Gregor43959a92009-08-20 07:17:43 +00005226 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005227 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5228 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005229}
Mike Stump1eb44332009-09-09 15:08:12 +00005230
Douglas Gregor43959a92009-08-20 07:17:43 +00005231template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005232StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005233TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005234 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005235 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005236 VarDecl *ConditionVar = 0;
5237 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005238 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005239 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005240 getDerived().TransformDefinition(
5241 S->getConditionVariable()->getLocation(),
5242 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005243 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005244 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005245 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005246 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005247
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005248 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005249 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005250
5251 if (S->getCond()) {
5252 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005253 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5254 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005255 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005256 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005257 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005258 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005259 }
Mike Stump1eb44332009-09-09 15:08:12 +00005260
John McCall9ae2f072010-08-23 23:25:46 +00005261 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5262 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005263 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005264
Douglas Gregor43959a92009-08-20 07:17:43 +00005265 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005266 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005267 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005268 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005269
Douglas Gregor43959a92009-08-20 07:17:43 +00005270 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005271 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005272 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005273 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005274 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005275
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005276 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005277 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005278}
Mike Stump1eb44332009-09-09 15:08:12 +00005279
Douglas Gregor43959a92009-08-20 07:17:43 +00005280template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005281StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005282TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005283 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005284 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005285 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005286 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005287
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005288 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005289 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005290 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005291 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005292
Douglas Gregor43959a92009-08-20 07:17:43 +00005293 if (!getDerived().AlwaysRebuild() &&
5294 Cond.get() == S->getCond() &&
5295 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005296 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005297
John McCall9ae2f072010-08-23 23:25:46 +00005298 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5299 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005300 S->getRParenLoc());
5301}
Mike Stump1eb44332009-09-09 15:08:12 +00005302
Douglas Gregor43959a92009-08-20 07:17:43 +00005303template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005304StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005305TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005306 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005307 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005308 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005309 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005310
Douglas Gregor43959a92009-08-20 07:17:43 +00005311 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005312 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005313 VarDecl *ConditionVar = 0;
5314 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005315 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005316 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005317 getDerived().TransformDefinition(
5318 S->getConditionVariable()->getLocation(),
5319 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005320 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005321 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005322 } else {
5323 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005324
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005325 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005326 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005327
5328 if (S->getCond()) {
5329 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005330 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5331 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005332 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005333 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005334
John McCall9ae2f072010-08-23 23:25:46 +00005335 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005336 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005337 }
Mike Stump1eb44332009-09-09 15:08:12 +00005338
John McCall9ae2f072010-08-23 23:25:46 +00005339 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5340 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005341 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005342
Douglas Gregor43959a92009-08-20 07:17:43 +00005343 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005344 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005345 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005346 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005347
John McCall9ae2f072010-08-23 23:25:46 +00005348 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5349 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005350 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005351
Douglas Gregor43959a92009-08-20 07:17:43 +00005352 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005353 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005354 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005355 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005356
Douglas Gregor43959a92009-08-20 07:17:43 +00005357 if (!getDerived().AlwaysRebuild() &&
5358 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005359 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005360 Inc.get() == S->getInc() &&
5361 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005362 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005363
Douglas Gregor43959a92009-08-20 07:17:43 +00005364 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005365 Init.get(), FullCond, ConditionVar,
5366 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005367}
5368
5369template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005370StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005371TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005372 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5373 S->getLabel());
5374 if (!LD)
5375 return StmtError();
5376
Douglas Gregor43959a92009-08-20 07:17:43 +00005377 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005378 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005379 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005380}
5381
5382template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005383StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005384TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005385 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005386 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005387 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005388 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005389
Douglas Gregor43959a92009-08-20 07:17:43 +00005390 if (!getDerived().AlwaysRebuild() &&
5391 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005392 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005393
5394 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005395 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005396}
5397
5398template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005399StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005400TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005401 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005402}
Mike Stump1eb44332009-09-09 15:08:12 +00005403
Douglas Gregor43959a92009-08-20 07:17:43 +00005404template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005405StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005406TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005407 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005408}
Mike Stump1eb44332009-09-09 15:08:12 +00005409
Douglas Gregor43959a92009-08-20 07:17:43 +00005410template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005411StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005412TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005413 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005415 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005416
Mike Stump1eb44332009-09-09 15:08:12 +00005417 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005418 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005419 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005420}
Mike Stump1eb44332009-09-09 15:08:12 +00005421
Douglas Gregor43959a92009-08-20 07:17:43 +00005422template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005423StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005424TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005425 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005426 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005427 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5428 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005429 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5430 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005431 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005432 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005433
Douglas Gregor43959a92009-08-20 07:17:43 +00005434 if (Transformed != *D)
5435 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005436
Douglas Gregor43959a92009-08-20 07:17:43 +00005437 Decls.push_back(Transformed);
5438 }
Mike Stump1eb44332009-09-09 15:08:12 +00005439
Douglas Gregor43959a92009-08-20 07:17:43 +00005440 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005441 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005442
5443 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005444 S->getStartLoc(), S->getEndLoc());
5445}
Mike Stump1eb44332009-09-09 15:08:12 +00005446
Douglas Gregor43959a92009-08-20 07:17:43 +00005447template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005448StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005449TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005450
John McCallca0408f2010-08-23 06:44:23 +00005451 ASTOwningVector<Expr*> Constraints(getSema());
5452 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005453 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005454
John McCall60d7b3a2010-08-24 06:29:42 +00005455 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005456 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005457
5458 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005459
Anders Carlsson703e3942010-01-24 05:50:09 +00005460 // Go through the outputs.
5461 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005462 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005463
Anders Carlsson703e3942010-01-24 05:50:09 +00005464 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005465 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005466
Anders Carlsson703e3942010-01-24 05:50:09 +00005467 // Transform the output expr.
5468 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005469 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005470 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005471 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005472
Anders Carlsson703e3942010-01-24 05:50:09 +00005473 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005474
John McCall9ae2f072010-08-23 23:25:46 +00005475 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005476 }
Sean Huntc3021132010-05-05 15:23:54 +00005477
Anders Carlsson703e3942010-01-24 05:50:09 +00005478 // Go through the inputs.
5479 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005480 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005481
Anders Carlsson703e3942010-01-24 05:50:09 +00005482 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005483 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005484
Anders Carlsson703e3942010-01-24 05:50:09 +00005485 // Transform the input expr.
5486 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005487 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005488 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005489 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005490
Anders Carlsson703e3942010-01-24 05:50:09 +00005491 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005492
John McCall9ae2f072010-08-23 23:25:46 +00005493 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005494 }
Sean Huntc3021132010-05-05 15:23:54 +00005495
Anders Carlsson703e3942010-01-24 05:50:09 +00005496 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005497 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005498
5499 // Go through the clobbers.
5500 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005501 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005502
5503 // No need to transform the asm string literal.
5504 AsmString = SemaRef.Owned(S->getAsmString());
5505
5506 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5507 S->isSimple(),
5508 S->isVolatile(),
5509 S->getNumOutputs(),
5510 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005511 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005512 move_arg(Constraints),
5513 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005514 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005515 move_arg(Clobbers),
5516 S->getRParenLoc(),
5517 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005518}
5519
5520
5521template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005522StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005523TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005524 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005525 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005526 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005527 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005528
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005529 // Transform the @catch statements (if present).
5530 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005531 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005532 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005533 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005534 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005535 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005536 if (Catch.get() != S->getCatchStmt(I))
5537 AnyCatchChanged = true;
5538 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005539 }
Sean Huntc3021132010-05-05 15:23:54 +00005540
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005541 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005542 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005543 if (S->getFinallyStmt()) {
5544 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5545 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005546 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005547 }
5548
5549 // If nothing changed, just retain this statement.
5550 if (!getDerived().AlwaysRebuild() &&
5551 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005552 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005553 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005554 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005555
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005556 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005557 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5558 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005559}
Mike Stump1eb44332009-09-09 15:08:12 +00005560
Douglas Gregor43959a92009-08-20 07:17:43 +00005561template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005562StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005563TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005564 // Transform the @catch parameter, if there is one.
5565 VarDecl *Var = 0;
5566 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5567 TypeSourceInfo *TSInfo = 0;
5568 if (FromVar->getTypeSourceInfo()) {
5569 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5570 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005571 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005572 }
Sean Huntc3021132010-05-05 15:23:54 +00005573
Douglas Gregorbe270a02010-04-26 17:57:08 +00005574 QualType T;
5575 if (TSInfo)
5576 T = TSInfo->getType();
5577 else {
5578 T = getDerived().TransformType(FromVar->getType());
5579 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005580 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005581 }
Sean Huntc3021132010-05-05 15:23:54 +00005582
Douglas Gregorbe270a02010-04-26 17:57:08 +00005583 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5584 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005585 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005586 }
Sean Huntc3021132010-05-05 15:23:54 +00005587
John McCall60d7b3a2010-08-24 06:29:42 +00005588 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005589 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005590 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005591
5592 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005593 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005594 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005595}
Mike Stump1eb44332009-09-09 15:08:12 +00005596
Douglas Gregor43959a92009-08-20 07:17:43 +00005597template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005598StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005599TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005600 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005601 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005602 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005603 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005604
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005605 // If nothing changed, just retain this statement.
5606 if (!getDerived().AlwaysRebuild() &&
5607 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005608 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005609
5610 // Build a new statement.
5611 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005612 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005613}
Mike Stump1eb44332009-09-09 15:08:12 +00005614
Douglas Gregor43959a92009-08-20 07:17:43 +00005615template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005616StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005617TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005618 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005619 if (S->getThrowExpr()) {
5620 Operand = getDerived().TransformExpr(S->getThrowExpr());
5621 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005622 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005623 }
Sean Huntc3021132010-05-05 15:23:54 +00005624
Douglas Gregord1377b22010-04-22 21:44:01 +00005625 if (!getDerived().AlwaysRebuild() &&
5626 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005627 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005628
John McCall9ae2f072010-08-23 23:25:46 +00005629 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005630}
Mike Stump1eb44332009-09-09 15:08:12 +00005631
Douglas Gregor43959a92009-08-20 07:17:43 +00005632template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005633StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005634TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005635 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005636 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005637 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005638 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005639 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005640 Object =
5641 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5642 Object.get());
5643 if (Object.isInvalid())
5644 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005645
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005646 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005647 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005648 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005649 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005650
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005651 // If nothing change, just retain the current statement.
5652 if (!getDerived().AlwaysRebuild() &&
5653 Object.get() == S->getSynchExpr() &&
5654 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005655 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005656
5657 // Build a new statement.
5658 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005659 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005660}
5661
5662template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005663StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005664TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5665 ObjCAutoreleasePoolStmt *S) {
5666 // Transform the body.
5667 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5668 if (Body.isInvalid())
5669 return StmtError();
5670
5671 // If nothing changed, just retain this statement.
5672 if (!getDerived().AlwaysRebuild() &&
5673 Body.get() == S->getSubStmt())
5674 return SemaRef.Owned(S);
5675
5676 // Build a new statement.
5677 return getDerived().RebuildObjCAutoreleasePoolStmt(
5678 S->getAtLoc(), Body.get());
5679}
5680
5681template<typename Derived>
5682StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005683TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005684 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005685 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005686 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005687 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005688 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005689
Douglas Gregorc3203e72010-04-22 23:10:45 +00005690 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005691 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005692 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005693 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005694 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5695 Collection.take());
5696 if (Collection.isInvalid())
5697 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005698
Douglas Gregorc3203e72010-04-22 23:10:45 +00005699 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005700 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005701 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005702 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005703
Douglas Gregorc3203e72010-04-22 23:10:45 +00005704 // If nothing changed, just retain this statement.
5705 if (!getDerived().AlwaysRebuild() &&
5706 Element.get() == S->getElement() &&
5707 Collection.get() == S->getCollection() &&
5708 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005709 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005710
Douglas Gregorc3203e72010-04-22 23:10:45 +00005711 // Build a new statement.
5712 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5713 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005714 Element.get(),
5715 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005716 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005717 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005718}
5719
5720
5721template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005722StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005723TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5724 // Transform the exception declaration, if any.
5725 VarDecl *Var = 0;
5726 if (S->getExceptionDecl()) {
5727 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005728 TypeSourceInfo *T = getDerived().TransformType(
5729 ExceptionDecl->getTypeSourceInfo());
5730 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005731 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005732
Douglas Gregor83cb9422010-09-09 17:09:21 +00005733 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005734 ExceptionDecl->getInnerLocStart(),
5735 ExceptionDecl->getLocation(),
5736 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005737 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005738 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005739 }
Mike Stump1eb44332009-09-09 15:08:12 +00005740
Douglas Gregor43959a92009-08-20 07:17:43 +00005741 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005742 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005743 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005744 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005745
Douglas Gregor43959a92009-08-20 07:17:43 +00005746 if (!getDerived().AlwaysRebuild() &&
5747 !Var &&
5748 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005749 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005750
5751 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5752 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005753 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005754}
Mike Stump1eb44332009-09-09 15:08:12 +00005755
Douglas Gregor43959a92009-08-20 07:17:43 +00005756template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005757StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005758TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5759 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005760 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005761 = getDerived().TransformCompoundStmt(S->getTryBlock());
5762 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005763 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005764
Douglas Gregor43959a92009-08-20 07:17:43 +00005765 // Transform the handlers.
5766 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005767 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005768 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005769 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005770 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5771 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005772 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005773
Douglas Gregor43959a92009-08-20 07:17:43 +00005774 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5775 Handlers.push_back(Handler.takeAs<Stmt>());
5776 }
Mike Stump1eb44332009-09-09 15:08:12 +00005777
Douglas Gregor43959a92009-08-20 07:17:43 +00005778 if (!getDerived().AlwaysRebuild() &&
5779 TryBlock.get() == S->getTryBlock() &&
5780 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005781 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005782
John McCall9ae2f072010-08-23 23:25:46 +00005783 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005784 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005785}
Mike Stump1eb44332009-09-09 15:08:12 +00005786
Richard Smithad762fc2011-04-14 22:09:26 +00005787template<typename Derived>
5788StmtResult
5789TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5790 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5791 if (Range.isInvalid())
5792 return StmtError();
5793
5794 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5795 if (BeginEnd.isInvalid())
5796 return StmtError();
5797
5798 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5799 if (Cond.isInvalid())
5800 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005801 if (Cond.get())
5802 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5803 if (Cond.isInvalid())
5804 return StmtError();
5805 if (Cond.get())
5806 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005807
5808 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5809 if (Inc.isInvalid())
5810 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005811 if (Inc.get())
5812 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005813
5814 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5815 if (LoopVar.isInvalid())
5816 return StmtError();
5817
5818 StmtResult NewStmt = S;
5819 if (getDerived().AlwaysRebuild() ||
5820 Range.get() != S->getRangeStmt() ||
5821 BeginEnd.get() != S->getBeginEndStmt() ||
5822 Cond.get() != S->getCond() ||
5823 Inc.get() != S->getInc() ||
5824 LoopVar.get() != S->getLoopVarStmt())
5825 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5826 S->getColonLoc(), Range.get(),
5827 BeginEnd.get(), Cond.get(),
5828 Inc.get(), LoopVar.get(),
5829 S->getRParenLoc());
5830
5831 StmtResult Body = getDerived().TransformStmt(S->getBody());
5832 if (Body.isInvalid())
5833 return StmtError();
5834
5835 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5836 // it now so we have a new statement to attach the body to.
5837 if (Body.get() != S->getBody() && NewStmt.get() == S)
5838 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5839 S->getColonLoc(), Range.get(),
5840 BeginEnd.get(), Cond.get(),
5841 Inc.get(), LoopVar.get(),
5842 S->getRParenLoc());
5843
5844 if (NewStmt.get() == S)
5845 return SemaRef.Owned(S);
5846
5847 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5848}
5849
John Wiegley28bbe4b2011-04-28 01:08:34 +00005850template<typename Derived>
5851StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005852TreeTransform<Derived>::TransformMSDependentExistsStmt(
5853 MSDependentExistsStmt *S) {
5854 // Transform the nested-name-specifier, if any.
5855 NestedNameSpecifierLoc QualifierLoc;
5856 if (S->getQualifierLoc()) {
5857 QualifierLoc
5858 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5859 if (!QualifierLoc)
5860 return StmtError();
5861 }
5862
5863 // Transform the declaration name.
5864 DeclarationNameInfo NameInfo = S->getNameInfo();
5865 if (NameInfo.getName()) {
5866 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5867 if (!NameInfo.getName())
5868 return StmtError();
5869 }
5870
5871 // Check whether anything changed.
5872 if (!getDerived().AlwaysRebuild() &&
5873 QualifierLoc == S->getQualifierLoc() &&
5874 NameInfo.getName() == S->getNameInfo().getName())
5875 return S;
5876
5877 // Determine whether this name exists, if we can.
5878 CXXScopeSpec SS;
5879 SS.Adopt(QualifierLoc);
5880 bool Dependent = false;
5881 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5882 case Sema::IER_Exists:
5883 if (S->isIfExists())
5884 break;
5885
5886 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5887
5888 case Sema::IER_DoesNotExist:
5889 if (S->isIfNotExists())
5890 break;
5891
5892 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5893
5894 case Sema::IER_Dependent:
5895 Dependent = true;
5896 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005897
5898 case Sema::IER_Error:
5899 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005900 }
5901
5902 // We need to continue with the instantiation, so do so now.
5903 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5904 if (SubStmt.isInvalid())
5905 return StmtError();
5906
5907 // If we have resolved the name, just transform to the substatement.
5908 if (!Dependent)
5909 return SubStmt;
5910
5911 // The name is still dependent, so build a dependent expression again.
5912 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5913 S->isIfExists(),
5914 QualifierLoc,
5915 NameInfo,
5916 SubStmt.get());
5917}
5918
5919template<typename Derived>
5920StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005921TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5922 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5923 if(TryBlock.isInvalid()) return StmtError();
5924
5925 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5926 if(!getDerived().AlwaysRebuild() &&
5927 TryBlock.get() == S->getTryBlock() &&
5928 Handler.get() == S->getHandler())
5929 return SemaRef.Owned(S);
5930
5931 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5932 S->getTryLoc(),
5933 TryBlock.take(),
5934 Handler.take());
5935}
5936
5937template<typename Derived>
5938StmtResult
5939TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5940 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5941 if(Block.isInvalid()) return StmtError();
5942
5943 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5944 Block.take());
5945}
5946
5947template<typename Derived>
5948StmtResult
5949TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5950 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5951 if(FilterExpr.isInvalid()) return StmtError();
5952
5953 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5954 if(Block.isInvalid()) return StmtError();
5955
5956 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5957 FilterExpr.take(),
5958 Block.take());
5959}
5960
5961template<typename Derived>
5962StmtResult
5963TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5964 if(isa<SEHFinallyStmt>(Handler))
5965 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5966 else
5967 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5968}
5969
Douglas Gregor43959a92009-08-20 07:17:43 +00005970//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005971// Expression transformation
5972//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005973template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005974ExprResult
John McCall454feb92009-12-08 09:21:05 +00005975TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005976 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005977}
Mike Stump1eb44332009-09-09 15:08:12 +00005978
5979template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005980ExprResult
John McCall454feb92009-12-08 09:21:05 +00005981TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005982 NestedNameSpecifierLoc QualifierLoc;
5983 if (E->getQualifierLoc()) {
5984 QualifierLoc
5985 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5986 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005987 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005988 }
John McCalldbd872f2009-12-08 09:08:17 +00005989
5990 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005991 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5992 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005993 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005994 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005995
John McCallec8045d2010-08-17 21:27:17 +00005996 DeclarationNameInfo NameInfo = E->getNameInfo();
5997 if (NameInfo.getName()) {
5998 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5999 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006000 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006001 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006002
6003 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006004 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006005 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006006 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006007 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006008
6009 // Mark it referenced in the new context regardless.
6010 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006011 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006012
John McCall3fa5cae2010-10-26 07:05:15 +00006013 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006014 }
John McCalldbd872f2009-12-08 09:08:17 +00006015
6016 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006017 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006018 TemplateArgs = &TransArgs;
6019 TransArgs.setLAngleLoc(E->getLAngleLoc());
6020 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006021 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6022 E->getNumTemplateArgs(),
6023 TransArgs))
6024 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006025 }
6026
Douglas Gregor40d96a62011-02-28 21:54:11 +00006027 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6028 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006029}
Mike Stump1eb44332009-09-09 15:08:12 +00006030
Douglas Gregorb98b1992009-08-11 05:31:07 +00006031template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006032ExprResult
John McCall454feb92009-12-08 09:21:05 +00006033TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006034 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006035}
Mike Stump1eb44332009-09-09 15:08:12 +00006036
Douglas Gregorb98b1992009-08-11 05:31:07 +00006037template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006038ExprResult
John McCall454feb92009-12-08 09:21:05 +00006039TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006040 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006041}
Mike Stump1eb44332009-09-09 15:08:12 +00006042
Douglas Gregorb98b1992009-08-11 05:31:07 +00006043template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006044ExprResult
John McCall454feb92009-12-08 09:21:05 +00006045TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006046 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006047}
Mike Stump1eb44332009-09-09 15:08:12 +00006048
Douglas Gregorb98b1992009-08-11 05:31:07 +00006049template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006050ExprResult
John McCall454feb92009-12-08 09:21:05 +00006051TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006052 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006053}
Mike Stump1eb44332009-09-09 15:08:12 +00006054
Douglas Gregorb98b1992009-08-11 05:31:07 +00006055template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006056ExprResult
John McCall454feb92009-12-08 09:21:05 +00006057TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006058 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006059}
6060
6061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006062ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006063TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6064 ExprResult ControllingExpr =
6065 getDerived().TransformExpr(E->getControllingExpr());
6066 if (ControllingExpr.isInvalid())
6067 return ExprError();
6068
Chris Lattner686775d2011-07-20 06:58:45 +00006069 SmallVector<Expr *, 4> AssocExprs;
6070 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006071 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6072 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6073 if (TS) {
6074 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6075 if (!AssocType)
6076 return ExprError();
6077 AssocTypes.push_back(AssocType);
6078 } else {
6079 AssocTypes.push_back(0);
6080 }
6081
6082 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6083 if (AssocExpr.isInvalid())
6084 return ExprError();
6085 AssocExprs.push_back(AssocExpr.release());
6086 }
6087
6088 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6089 E->getDefaultLoc(),
6090 E->getRParenLoc(),
6091 ControllingExpr.release(),
6092 AssocTypes.data(),
6093 AssocExprs.data(),
6094 E->getNumAssocs());
6095}
6096
6097template<typename Derived>
6098ExprResult
John McCall454feb92009-12-08 09:21:05 +00006099TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006100 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006101 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006102 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006103
Douglas Gregorb98b1992009-08-11 05:31:07 +00006104 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006105 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006106
John McCall9ae2f072010-08-23 23:25:46 +00006107 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006108 E->getRParen());
6109}
6110
Mike Stump1eb44332009-09-09 15:08:12 +00006111template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006112ExprResult
John McCall454feb92009-12-08 09:21:05 +00006113TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006114 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006115 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006116 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006117
Douglas Gregorb98b1992009-08-11 05:31:07 +00006118 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006119 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006120
Douglas Gregorb98b1992009-08-11 05:31:07 +00006121 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6122 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006123 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006124}
Mike Stump1eb44332009-09-09 15:08:12 +00006125
Douglas Gregorb98b1992009-08-11 05:31:07 +00006126template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006127ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006128TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6129 // Transform the type.
6130 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6131 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006132 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006133
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006134 // Transform all of the components into components similar to what the
6135 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006136 // FIXME: It would be slightly more efficient in the non-dependent case to
6137 // just map FieldDecls, rather than requiring the rebuilder to look for
6138 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006139 // template code that we don't care.
6140 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006141 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006142 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006143 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006144 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6145 const Node &ON = E->getComponent(I);
6146 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006147 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006148 Comp.LocStart = ON.getSourceRange().getBegin();
6149 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006150 switch (ON.getKind()) {
6151 case Node::Array: {
6152 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006153 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006154 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006155 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006156
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006157 ExprChanged = ExprChanged || Index.get() != FromIndex;
6158 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006159 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006160 break;
6161 }
Sean Huntc3021132010-05-05 15:23:54 +00006162
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006163 case Node::Field:
6164 case Node::Identifier:
6165 Comp.isBrackets = false;
6166 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006167 if (!Comp.U.IdentInfo)
6168 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006169
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006170 break;
Sean Huntc3021132010-05-05 15:23:54 +00006171
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006172 case Node::Base:
6173 // Will be recomputed during the rebuild.
6174 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006175 }
Sean Huntc3021132010-05-05 15:23:54 +00006176
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006177 Components.push_back(Comp);
6178 }
Sean Huntc3021132010-05-05 15:23:54 +00006179
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006180 // If nothing changed, retain the existing expression.
6181 if (!getDerived().AlwaysRebuild() &&
6182 Type == E->getTypeSourceInfo() &&
6183 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006184 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006185
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006186 // Build a new offsetof expression.
6187 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6188 Components.data(), Components.size(),
6189 E->getRParenLoc());
6190}
6191
6192template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006193ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006194TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6195 assert(getDerived().AlreadyTransformed(E->getType()) &&
6196 "opaque value expression requires transformation");
6197 return SemaRef.Owned(E);
6198}
6199
6200template<typename Derived>
6201ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006202TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006203 // Rebuild the syntactic form. The original syntactic form has
6204 // opaque-value expressions in it, so strip those away and rebuild
6205 // the result. This is a really awful way of doing this, but the
6206 // better solution (rebuilding the semantic expressions and
6207 // rebinding OVEs as necessary) doesn't work; we'd need
6208 // TreeTransform to not strip away implicit conversions.
6209 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6210 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006211 if (result.isInvalid()) return ExprError();
6212
6213 // If that gives us a pseudo-object result back, the pseudo-object
6214 // expression must have been an lvalue-to-rvalue conversion which we
6215 // should reapply.
6216 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6217 result = SemaRef.checkPseudoObjectRValue(result.take());
6218
6219 return result;
6220}
6221
6222template<typename Derived>
6223ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006224TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6225 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006226 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006227 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006228
John McCalla93c9342009-12-07 02:54:59 +00006229 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006230 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006231 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006232
John McCall5ab75172009-11-04 07:28:41 +00006233 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006234 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006235
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006236 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6237 E->getKind(),
6238 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006239 }
Mike Stump1eb44332009-09-09 15:08:12 +00006240
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006241 // C++0x [expr.sizeof]p1:
6242 // The operand is either an expression, which is an unevaluated operand
6243 // [...]
6244 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006245
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006246 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6247 if (SubExpr.isInvalid())
6248 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006249
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006250 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6251 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006252
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006253 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6254 E->getOperatorLoc(),
6255 E->getKind(),
6256 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006257}
Mike Stump1eb44332009-09-09 15:08:12 +00006258
Douglas Gregorb98b1992009-08-11 05:31:07 +00006259template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006260ExprResult
John McCall454feb92009-12-08 09:21:05 +00006261TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006262 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006263 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006264 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006265
John McCall60d7b3a2010-08-24 06:29:42 +00006266 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006267 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006268 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006269
6270
Douglas Gregorb98b1992009-08-11 05:31:07 +00006271 if (!getDerived().AlwaysRebuild() &&
6272 LHS.get() == E->getLHS() &&
6273 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006274 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006275
John McCall9ae2f072010-08-23 23:25:46 +00006276 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006277 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006278 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006279 E->getRBracketLoc());
6280}
Mike Stump1eb44332009-09-09 15:08:12 +00006281
6282template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006283ExprResult
John McCall454feb92009-12-08 09:21:05 +00006284TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006285 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006286 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006287 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006288 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006289
6290 // Transform arguments.
6291 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006292 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006293 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6294 &ArgChanged))
6295 return ExprError();
6296
Douglas Gregorb98b1992009-08-11 05:31:07 +00006297 if (!getDerived().AlwaysRebuild() &&
6298 Callee.get() == E->getCallee() &&
6299 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006300 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006301
Douglas Gregorb98b1992009-08-11 05:31:07 +00006302 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006303 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006304 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006305 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006306 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006307 E->getRParenLoc());
6308}
Mike Stump1eb44332009-09-09 15:08:12 +00006309
6310template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006311ExprResult
John McCall454feb92009-12-08 09:21:05 +00006312TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006313 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006314 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006315 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006316
Douglas Gregor40d96a62011-02-28 21:54:11 +00006317 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006318 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006319 QualifierLoc
6320 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6321
6322 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006323 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006324 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006325 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006326
Eli Friedmanf595cc42009-12-04 06:40:45 +00006327 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006328 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6329 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006330 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006331 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006332
John McCall6bb80172010-03-30 21:47:33 +00006333 NamedDecl *FoundDecl = E->getFoundDecl();
6334 if (FoundDecl == E->getMemberDecl()) {
6335 FoundDecl = Member;
6336 } else {
6337 FoundDecl = cast_or_null<NamedDecl>(
6338 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6339 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006340 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006341 }
6342
Douglas Gregorb98b1992009-08-11 05:31:07 +00006343 if (!getDerived().AlwaysRebuild() &&
6344 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006345 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006346 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006347 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006348 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006349
Anders Carlsson1f240322009-12-22 05:24:09 +00006350 // Mark it referenced in the new context regardless.
6351 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006352 SemaRef.MarkMemberReferenced(E);
6353
John McCall3fa5cae2010-10-26 07:05:15 +00006354 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006355 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006356
John McCalld5532b62009-11-23 01:53:49 +00006357 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006358 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006359 TransArgs.setLAngleLoc(E->getLAngleLoc());
6360 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006361 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6362 E->getNumTemplateArgs(),
6363 TransArgs))
6364 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006365 }
Sean Huntc3021132010-05-05 15:23:54 +00006366
Douglas Gregorb98b1992009-08-11 05:31:07 +00006367 // FIXME: Bogus source location for the operator
6368 SourceLocation FakeOperatorLoc
6369 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6370
John McCallc2233c52010-01-15 08:34:02 +00006371 // FIXME: to do this check properly, we will need to preserve the
6372 // first-qualifier-in-scope here, just in case we had a dependent
6373 // base (and therefore couldn't do the check) and a
6374 // nested-name-qualifier (and therefore could do the lookup).
6375 NamedDecl *FirstQualifierInScope = 0;
6376
John McCall9ae2f072010-08-23 23:25:46 +00006377 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006378 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006379 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006380 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006381 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006382 Member,
John McCall6bb80172010-03-30 21:47:33 +00006383 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006384 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006385 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006386 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006387}
Mike Stump1eb44332009-09-09 15:08:12 +00006388
Douglas Gregorb98b1992009-08-11 05:31:07 +00006389template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006390ExprResult
John McCall454feb92009-12-08 09:21:05 +00006391TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006392 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006393 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006394 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006395
John McCall60d7b3a2010-08-24 06:29:42 +00006396 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006397 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006398 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006399
Douglas Gregorb98b1992009-08-11 05:31:07 +00006400 if (!getDerived().AlwaysRebuild() &&
6401 LHS.get() == E->getLHS() &&
6402 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006403 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006404
Douglas Gregorb98b1992009-08-11 05:31:07 +00006405 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006406 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006407}
6408
Mike Stump1eb44332009-09-09 15:08:12 +00006409template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006410ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006411TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006412 CompoundAssignOperator *E) {
6413 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006414}
Mike Stump1eb44332009-09-09 15:08:12 +00006415
Douglas Gregorb98b1992009-08-11 05:31:07 +00006416template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006417ExprResult TreeTransform<Derived>::
6418TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6419 // Just rebuild the common and RHS expressions and see whether we
6420 // get any changes.
6421
6422 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6423 if (commonExpr.isInvalid())
6424 return ExprError();
6425
6426 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6427 if (rhs.isInvalid())
6428 return ExprError();
6429
6430 if (!getDerived().AlwaysRebuild() &&
6431 commonExpr.get() == e->getCommon() &&
6432 rhs.get() == e->getFalseExpr())
6433 return SemaRef.Owned(e);
6434
6435 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6436 e->getQuestionLoc(),
6437 0,
6438 e->getColonLoc(),
6439 rhs.get());
6440}
6441
6442template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006443ExprResult
John McCall454feb92009-12-08 09:21:05 +00006444TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006445 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006446 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006447 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006448
John McCall60d7b3a2010-08-24 06:29:42 +00006449 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006450 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006451 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006452
John McCall60d7b3a2010-08-24 06:29:42 +00006453 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006454 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006455 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006456
Douglas Gregorb98b1992009-08-11 05:31:07 +00006457 if (!getDerived().AlwaysRebuild() &&
6458 Cond.get() == E->getCond() &&
6459 LHS.get() == E->getLHS() &&
6460 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006461 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006462
John McCall9ae2f072010-08-23 23:25:46 +00006463 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006464 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006465 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006466 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006467 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006468}
Mike Stump1eb44332009-09-09 15:08:12 +00006469
6470template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006471ExprResult
John McCall454feb92009-12-08 09:21:05 +00006472TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006473 // Implicit casts are eliminated during transformation, since they
6474 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006475 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476}
Mike Stump1eb44332009-09-09 15:08:12 +00006477
Douglas Gregorb98b1992009-08-11 05:31:07 +00006478template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006479ExprResult
John McCall454feb92009-12-08 09:21:05 +00006480TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006481 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6482 if (!Type)
6483 return ExprError();
6484
John McCall60d7b3a2010-08-24 06:29:42 +00006485 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006486 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006487 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006488 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006489
Douglas Gregorb98b1992009-08-11 05:31:07 +00006490 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006491 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006492 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006493 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006494
John McCall9d125032010-01-15 18:39:57 +00006495 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006496 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006497 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006498 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006499}
Mike Stump1eb44332009-09-09 15:08:12 +00006500
Douglas Gregorb98b1992009-08-11 05:31:07 +00006501template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006502ExprResult
John McCall454feb92009-12-08 09:21:05 +00006503TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006504 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6505 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6506 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006507 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006508
John McCall60d7b3a2010-08-24 06:29:42 +00006509 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006510 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006511 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006512
Douglas Gregorb98b1992009-08-11 05:31:07 +00006513 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006514 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006515 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006516 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517
John McCall1d7d8d62010-01-19 22:33:45 +00006518 // Note: the expression type doesn't necessarily match the
6519 // type-as-written, but that's okay, because it should always be
6520 // derivable from the initializer.
6521
John McCall42f56b52010-01-18 19:35:47 +00006522 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006523 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006524 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006525}
Mike Stump1eb44332009-09-09 15:08:12 +00006526
Douglas Gregorb98b1992009-08-11 05:31:07 +00006527template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006528ExprResult
John McCall454feb92009-12-08 09:21:05 +00006529TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006530 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006531 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006532 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006533
Douglas Gregorb98b1992009-08-11 05:31:07 +00006534 if (!getDerived().AlwaysRebuild() &&
6535 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006536 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006537
Douglas Gregorb98b1992009-08-11 05:31:07 +00006538 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006539 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006540 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006541 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006542 E->getAccessorLoc(),
6543 E->getAccessor());
6544}
Mike Stump1eb44332009-09-09 15:08:12 +00006545
Douglas Gregorb98b1992009-08-11 05:31:07 +00006546template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006547ExprResult
John McCall454feb92009-12-08 09:21:05 +00006548TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006549 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006550
John McCallca0408f2010-08-23 06:44:23 +00006551 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006552 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6553 Inits, &InitChanged))
6554 return ExprError();
6555
Douglas Gregorb98b1992009-08-11 05:31:07 +00006556 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006557 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006558
Douglas Gregorb98b1992009-08-11 05:31:07 +00006559 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006560 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561}
Mike Stump1eb44332009-09-09 15:08:12 +00006562
Douglas Gregorb98b1992009-08-11 05:31:07 +00006563template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006564ExprResult
John McCall454feb92009-12-08 09:21:05 +00006565TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006566 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006567
Douglas Gregor43959a92009-08-20 07:17:43 +00006568 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006569 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006570 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006571 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006572
Douglas Gregor43959a92009-08-20 07:17:43 +00006573 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006574 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006575 bool ExprChanged = false;
6576 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6577 DEnd = E->designators_end();
6578 D != DEnd; ++D) {
6579 if (D->isFieldDesignator()) {
6580 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6581 D->getDotLoc(),
6582 D->getFieldLoc()));
6583 continue;
6584 }
Mike Stump1eb44332009-09-09 15:08:12 +00006585
Douglas Gregorb98b1992009-08-11 05:31:07 +00006586 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006587 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006588 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006589 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006590
6591 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006592 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006593
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6595 ArrayExprs.push_back(Index.release());
6596 continue;
6597 }
Mike Stump1eb44332009-09-09 15:08:12 +00006598
Douglas Gregorb98b1992009-08-11 05:31:07 +00006599 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006600 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006601 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6602 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006603 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006604
John McCall60d7b3a2010-08-24 06:29:42 +00006605 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006607 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006608
6609 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610 End.get(),
6611 D->getLBracketLoc(),
6612 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006613
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6615 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006616
Douglas Gregorb98b1992009-08-11 05:31:07 +00006617 ArrayExprs.push_back(Start.release());
6618 ArrayExprs.push_back(End.release());
6619 }
Mike Stump1eb44332009-09-09 15:08:12 +00006620
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 if (!getDerived().AlwaysRebuild() &&
6622 Init.get() == E->getInit() &&
6623 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006624 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006625
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6627 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006628 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629}
Mike Stump1eb44332009-09-09 15:08:12 +00006630
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006632ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006634 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006635 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006636
Douglas Gregor5557b252009-10-28 00:29:27 +00006637 // FIXME: Will we ever have proper type location here? Will we actually
6638 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639 QualType T = getDerived().TransformType(E->getType());
6640 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006641 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006642
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643 if (!getDerived().AlwaysRebuild() &&
6644 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006645 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006646
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647 return getDerived().RebuildImplicitValueInitExpr(T);
6648}
Mike Stump1eb44332009-09-09 15:08:12 +00006649
Douglas Gregorb98b1992009-08-11 05:31:07 +00006650template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006651ExprResult
John McCall454feb92009-12-08 09:21:05 +00006652TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006653 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6654 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006655 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006656
John McCall60d7b3a2010-08-24 06:29:42 +00006657 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006659 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006660
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006662 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006664 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006665
John McCall9ae2f072010-08-23 23:25:46 +00006666 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006667 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006668}
6669
6670template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006671ExprResult
John McCall454feb92009-12-08 09:21:05 +00006672TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006673 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006674 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006675 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6676 &ArgumentChanged))
6677 return ExprError();
6678
Douglas Gregorb98b1992009-08-11 05:31:07 +00006679 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6680 move_arg(Inits),
6681 E->getRParenLoc());
6682}
Mike Stump1eb44332009-09-09 15:08:12 +00006683
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684/// \brief Transform an address-of-label expression.
6685///
6686/// By default, the transformation of an address-of-label expression always
6687/// rebuilds the expression, so that the label identifier can be resolved to
6688/// the corresponding label statement by semantic analysis.
6689template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006690ExprResult
John McCall454feb92009-12-08 09:21:05 +00006691TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006692 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6693 E->getLabel());
6694 if (!LD)
6695 return ExprError();
6696
Douglas Gregorb98b1992009-08-11 05:31:07 +00006697 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006698 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699}
Mike Stump1eb44332009-09-09 15:08:12 +00006700
6701template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006702ExprResult
John McCall454feb92009-12-08 09:21:05 +00006703TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006704 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006705 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6706 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006707 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006708
Douglas Gregorb98b1992009-08-11 05:31:07 +00006709 if (!getDerived().AlwaysRebuild() &&
6710 SubStmt.get() == E->getSubStmt())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006711 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006712
6713 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006714 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715 E->getRParenLoc());
6716}
Mike Stump1eb44332009-09-09 15:08:12 +00006717
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006719ExprResult
John McCall454feb92009-12-08 09:21:05 +00006720TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006721 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006723 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006724
John McCall60d7b3a2010-08-24 06:29:42 +00006725 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006727 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006728
John McCall60d7b3a2010-08-24 06:29:42 +00006729 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006731 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006732
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733 if (!getDerived().AlwaysRebuild() &&
6734 Cond.get() == E->getCond() &&
6735 LHS.get() == E->getLHS() &&
6736 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006737 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006738
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006740 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006741 E->getRParenLoc());
6742}
Mike Stump1eb44332009-09-09 15:08:12 +00006743
Douglas Gregorb98b1992009-08-11 05:31:07 +00006744template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006745ExprResult
John McCall454feb92009-12-08 09:21:05 +00006746TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006747 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006748}
6749
6750template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006751ExprResult
John McCall454feb92009-12-08 09:21:05 +00006752TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006753 switch (E->getOperator()) {
6754 case OO_New:
6755 case OO_Delete:
6756 case OO_Array_New:
6757 case OO_Array_Delete:
6758 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Sean Huntc3021132010-05-05 15:23:54 +00006759
Douglas Gregor668d6d92009-12-13 20:44:55 +00006760 case OO_Call: {
6761 // This is a call to an object's operator().
6762 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6763
6764 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006765 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006766 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006767 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006768
6769 // FIXME: Poor location information
6770 SourceLocation FakeLParenLoc
6771 = SemaRef.PP.getLocForEndOfToken(
6772 static_cast<Expr *>(Object.get())->getLocEnd());
6773
6774 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006775 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006776 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6777 Args))
6778 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006779
John McCall9ae2f072010-08-23 23:25:46 +00006780 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006781 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006782 E->getLocEnd());
6783 }
6784
6785#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6786 case OO_##Name:
6787#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6788#include "clang/Basic/OperatorKinds.def"
6789 case OO_Subscript:
6790 // Handled below.
6791 break;
6792
6793 case OO_Conditional:
6794 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006795
6796 case OO_None:
6797 case NUM_OVERLOADED_OPERATORS:
6798 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006799 }
6800
John McCall60d7b3a2010-08-24 06:29:42 +00006801 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006802 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006803 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006804
John McCall60d7b3a2010-08-24 06:29:42 +00006805 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006806 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006807 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006808
John McCall60d7b3a2010-08-24 06:29:42 +00006809 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006810 if (E->getNumArgs() == 2) {
6811 Second = getDerived().TransformExpr(E->getArg(1));
6812 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006813 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006814 }
Mike Stump1eb44332009-09-09 15:08:12 +00006815
Douglas Gregorb98b1992009-08-11 05:31:07 +00006816 if (!getDerived().AlwaysRebuild() &&
6817 Callee.get() == E->getCallee() &&
6818 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006819 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006820 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006821
Douglas Gregorb98b1992009-08-11 05:31:07 +00006822 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6823 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006824 Callee.get(),
6825 First.get(),
6826 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006827}
Mike Stump1eb44332009-09-09 15:08:12 +00006828
Douglas Gregorb98b1992009-08-11 05:31:07 +00006829template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006830ExprResult
John McCall454feb92009-12-08 09:21:05 +00006831TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6832 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006833}
Mike Stump1eb44332009-09-09 15:08:12 +00006834
Douglas Gregorb98b1992009-08-11 05:31:07 +00006835template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006836ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006837TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6838 // Transform the callee.
6839 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6840 if (Callee.isInvalid())
6841 return ExprError();
6842
6843 // Transform exec config.
6844 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6845 if (EC.isInvalid())
6846 return ExprError();
6847
6848 // Transform arguments.
6849 bool ArgChanged = false;
6850 ASTOwningVector<Expr*> Args(SemaRef);
6851 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6852 &ArgChanged))
6853 return ExprError();
6854
6855 if (!getDerived().AlwaysRebuild() &&
6856 Callee.get() == E->getCallee() &&
6857 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006858 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006859
6860 // FIXME: Wrong source location information for the '('.
6861 SourceLocation FakeLParenLoc
6862 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6863 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6864 move_arg(Args),
6865 E->getRParenLoc(), EC.get());
6866}
6867
6868template<typename Derived>
6869ExprResult
John McCall454feb92009-12-08 09:21:05 +00006870TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006871 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6872 if (!Type)
6873 return ExprError();
6874
John McCall60d7b3a2010-08-24 06:29:42 +00006875 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006876 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006877 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006878 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006879
Douglas Gregorb98b1992009-08-11 05:31:07 +00006880 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006881 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006882 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006883 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006884
Douglas Gregorb98b1992009-08-11 05:31:07 +00006885 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006886 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006887 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6888 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6889 SourceLocation FakeRParenLoc
6890 = SemaRef.PP.getLocForEndOfToken(
6891 E->getSubExpr()->getSourceRange().getEnd());
6892 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006893 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006894 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006895 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006896 FakeRAngleLoc,
6897 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006898 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006899 FakeRParenLoc);
6900}
Mike Stump1eb44332009-09-09 15:08:12 +00006901
Douglas Gregorb98b1992009-08-11 05:31:07 +00006902template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006903ExprResult
John McCall454feb92009-12-08 09:21:05 +00006904TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6905 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006906}
Mike Stump1eb44332009-09-09 15:08:12 +00006907
6908template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006909ExprResult
John McCall454feb92009-12-08 09:21:05 +00006910TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6911 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006912}
6913
Douglas Gregorb98b1992009-08-11 05:31:07 +00006914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006915ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006916TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006917 CXXReinterpretCastExpr *E) {
6918 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919}
Mike Stump1eb44332009-09-09 15:08:12 +00006920
Douglas Gregorb98b1992009-08-11 05:31:07 +00006921template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006922ExprResult
John McCall454feb92009-12-08 09:21:05 +00006923TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6924 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006925}
Mike Stump1eb44332009-09-09 15:08:12 +00006926
Douglas Gregorb98b1992009-08-11 05:31:07 +00006927template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006928ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006929TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006930 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006931 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6932 if (!Type)
6933 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006934
John McCall60d7b3a2010-08-24 06:29:42 +00006935 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006936 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006938 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006939
Douglas Gregorb98b1992009-08-11 05:31:07 +00006940 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006941 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006942 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006943 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006944
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006945 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006946 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006947 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006948 E->getRParenLoc());
6949}
Mike Stump1eb44332009-09-09 15:08:12 +00006950
Douglas Gregorb98b1992009-08-11 05:31:07 +00006951template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006952ExprResult
John McCall454feb92009-12-08 09:21:05 +00006953TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006954 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006955 TypeSourceInfo *TInfo
6956 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6957 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006958 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006959
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006961 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006962 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006963
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006964 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6965 E->getLocStart(),
6966 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006967 E->getLocEnd());
6968 }
Mike Stump1eb44332009-09-09 15:08:12 +00006969
Eli Friedmanef331b72012-01-20 01:26:23 +00006970 // We don't know whether the subexpression is potentially evaluated until
6971 // after we perform semantic analysis. We speculatively assume it is
6972 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00006973 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00006974 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006975
John McCall60d7b3a2010-08-24 06:29:42 +00006976 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006977 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006978 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006979
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980 if (!getDerived().AlwaysRebuild() &&
6981 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006982 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006983
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006984 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6985 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006986 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006987 E->getLocEnd());
6988}
6989
6990template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006991ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006992TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6993 if (E->isTypeOperand()) {
6994 TypeSourceInfo *TInfo
6995 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6996 if (!TInfo)
6997 return ExprError();
6998
6999 if (!getDerived().AlwaysRebuild() &&
7000 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007001 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007002
Douglas Gregor3c52a212011-03-06 17:40:41 +00007003 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007004 E->getLocStart(),
7005 TInfo,
7006 E->getLocEnd());
7007 }
7008
Francois Pichet01b7c302010-09-08 12:20:18 +00007009 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7010
7011 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7012 if (SubExpr.isInvalid())
7013 return ExprError();
7014
7015 if (!getDerived().AlwaysRebuild() &&
7016 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007017 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007018
7019 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7020 E->getLocStart(),
7021 SubExpr.get(),
7022 E->getLocEnd());
7023}
7024
7025template<typename Derived>
7026ExprResult
John McCall454feb92009-12-08 09:21:05 +00007027TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007028 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029}
Mike Stump1eb44332009-09-09 15:08:12 +00007030
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007032ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007034 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007035 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007036}
Mike Stump1eb44332009-09-09 15:08:12 +00007037
Douglas Gregorb98b1992009-08-11 05:31:07 +00007038template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007039ExprResult
John McCall454feb92009-12-08 09:21:05 +00007040TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007041 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007042 QualType T;
7043 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7044 T = MD->getThisType(getSema().Context);
7045 else
7046 T = getSema().Context.getPointerType(
7047 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007048
Douglas Gregorec79d872012-02-24 17:41:38 +00007049 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7050 // Make sure that we capture 'this'.
7051 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007052 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007053 }
7054
Douglas Gregor828a1972010-01-07 23:12:05 +00007055 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056}
Mike Stump1eb44332009-09-09 15:08:12 +00007057
Douglas Gregorb98b1992009-08-11 05:31:07 +00007058template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007059ExprResult
John McCall454feb92009-12-08 09:21:05 +00007060TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007061 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007062 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007063 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007064
Douglas Gregorb98b1992009-08-11 05:31:07 +00007065 if (!getDerived().AlwaysRebuild() &&
7066 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007067 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007068
Douglas Gregorbca01b42011-07-06 22:04:06 +00007069 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7070 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007071}
Mike Stump1eb44332009-09-09 15:08:12 +00007072
Douglas Gregorb98b1992009-08-11 05:31:07 +00007073template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007074ExprResult
John McCall454feb92009-12-08 09:21:05 +00007075TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007076 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007077 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7078 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007079 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007080 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007081
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007082 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007083 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007084 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007085
Douglas Gregor036aed12009-12-23 23:03:06 +00007086 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007087}
Mike Stump1eb44332009-09-09 15:08:12 +00007088
Douglas Gregorb98b1992009-08-11 05:31:07 +00007089template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007090ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007091TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7092 CXXScalarValueInitExpr *E) {
7093 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7094 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007095 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007096
Douglas Gregorb98b1992009-08-11 05:31:07 +00007097 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007098 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007099 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007100
Douglas Gregorab6677e2010-09-08 00:15:04 +00007101 return getDerived().RebuildCXXScalarValueInitExpr(T,
7102 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007103 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007104}
Mike Stump1eb44332009-09-09 15:08:12 +00007105
Douglas Gregorb98b1992009-08-11 05:31:07 +00007106template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007107ExprResult
John McCall454feb92009-12-08 09:21:05 +00007108TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007109 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007110 TypeSourceInfo *AllocTypeInfo
7111 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7112 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007113 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007114
Douglas Gregorb98b1992009-08-11 05:31:07 +00007115 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007116 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007117 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007118 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007119
Douglas Gregorb98b1992009-08-11 05:31:07 +00007120 // Transform the placement arguments (if any).
7121 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007122 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007123 if (getDerived().TransformExprs(E->getPlacementArgs(),
7124 E->getNumPlacementArgs(), true,
7125 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007126 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007127
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007128 // Transform the initializer (if any).
7129 Expr *OldInit = E->getInitializer();
7130 ExprResult NewInit;
7131 if (OldInit)
7132 NewInit = getDerived().TransformExpr(OldInit);
7133 if (NewInit.isInvalid())
7134 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007135
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007136 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007137 FunctionDecl *OperatorNew = 0;
7138 if (E->getOperatorNew()) {
7139 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007140 getDerived().TransformDecl(E->getLocStart(),
7141 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007142 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007143 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007144 }
7145
7146 FunctionDecl *OperatorDelete = 0;
7147 if (E->getOperatorDelete()) {
7148 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007149 getDerived().TransformDecl(E->getLocStart(),
7150 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007151 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007152 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007153 }
Sean Huntc3021132010-05-05 15:23:54 +00007154
Douglas Gregorb98b1992009-08-11 05:31:07 +00007155 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007156 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007157 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007158 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007159 OperatorNew == E->getOperatorNew() &&
7160 OperatorDelete == E->getOperatorDelete() &&
7161 !ArgumentChanged) {
7162 // Mark any declarations we need as referenced.
7163 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007164 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007165 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007166 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007167 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007168
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007169 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007170 QualType ElementType
7171 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7172 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7173 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7174 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007175 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007176 }
7177 }
7178 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007179
John McCall3fa5cae2010-10-26 07:05:15 +00007180 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007181 }
Mike Stump1eb44332009-09-09 15:08:12 +00007182
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007183 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007184 if (!ArraySize.get()) {
7185 // If no array size was specified, but the new expression was
7186 // instantiated with an array type (e.g., "new T" where T is
7187 // instantiated with "int[4]"), extract the outer bound from the
7188 // array type as our array size. We do this with constant and
7189 // dependently-sized array types.
7190 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7191 if (!ArrayT) {
7192 // Do nothing
7193 } else if (const ConstantArrayType *ConsArrayT
7194 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007195 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007196 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7197 ConsArrayT->getSize(),
7198 SemaRef.Context.getSizeType(),
7199 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007200 AllocType = ConsArrayT->getElementType();
7201 } else if (const DependentSizedArrayType *DepArrayT
7202 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7203 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007204 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007205 AllocType = DepArrayT->getElementType();
7206 }
7207 }
7208 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007209
Douglas Gregorb98b1992009-08-11 05:31:07 +00007210 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7211 E->isGlobalNew(),
7212 /*FIXME:*/E->getLocStart(),
7213 move_arg(PlacementArgs),
7214 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007215 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007216 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007217 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007218 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007219 E->getDirectInitRange(),
7220 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007221}
Mike Stump1eb44332009-09-09 15:08:12 +00007222
Douglas Gregorb98b1992009-08-11 05:31:07 +00007223template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007224ExprResult
John McCall454feb92009-12-08 09:21:05 +00007225TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007226 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007227 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007228 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007229
Douglas Gregor1af74512010-02-26 00:38:10 +00007230 // Transform the delete operator, if known.
7231 FunctionDecl *OperatorDelete = 0;
7232 if (E->getOperatorDelete()) {
7233 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007234 getDerived().TransformDecl(E->getLocStart(),
7235 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007236 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007237 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007238 }
Sean Huntc3021132010-05-05 15:23:54 +00007239
Douglas Gregorb98b1992009-08-11 05:31:07 +00007240 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007241 Operand.get() == E->getArgument() &&
7242 OperatorDelete == E->getOperatorDelete()) {
7243 // Mark any declarations we need as referenced.
7244 // FIXME: instantiation-specific.
7245 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007246 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007247
7248 if (!E->getArgument()->isTypeDependent()) {
7249 QualType Destroyed = SemaRef.Context.getBaseElementType(
7250 E->getDestroyedType());
7251 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7252 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007253 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7254 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007255 }
7256 }
7257
John McCall3fa5cae2010-10-26 07:05:15 +00007258 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007259 }
Mike Stump1eb44332009-09-09 15:08:12 +00007260
Douglas Gregorb98b1992009-08-11 05:31:07 +00007261 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7262 E->isGlobalDelete(),
7263 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007264 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007265}
Mike Stump1eb44332009-09-09 15:08:12 +00007266
Douglas Gregorb98b1992009-08-11 05:31:07 +00007267template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007268ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007269TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007270 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007271 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007272 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007273 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007274
John McCallb3d87482010-08-24 05:47:05 +00007275 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007276 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007277 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007278 E->getOperatorLoc(),
7279 E->isArrow()? tok::arrow : tok::period,
7280 ObjectTypePtr,
7281 MayBePseudoDestructor);
7282 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007283 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007284
John McCallb3d87482010-08-24 05:47:05 +00007285 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007286 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7287 if (QualifierLoc) {
7288 QualifierLoc
7289 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7290 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007291 return ExprError();
7292 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007293 CXXScopeSpec SS;
7294 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007295
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007296 PseudoDestructorTypeStorage Destroyed;
7297 if (E->getDestroyedTypeInfo()) {
7298 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007299 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007300 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007301 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007302 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007303 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007304 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007305 // We aren't likely to be able to resolve the identifier down to a type
7306 // now anyway, so just retain the identifier.
7307 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7308 E->getDestroyedTypeLoc());
7309 } else {
7310 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007311 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007312 *E->getDestroyedTypeIdentifier(),
7313 E->getDestroyedTypeLoc(),
7314 /*Scope=*/0,
7315 SS, ObjectTypePtr,
7316 false);
7317 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007318 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007319
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007320 Destroyed
7321 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7322 E->getDestroyedTypeLoc());
7323 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007324
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007325 TypeSourceInfo *ScopeTypeInfo = 0;
7326 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007327 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007328 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007329 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007330 }
Sean Huntc3021132010-05-05 15:23:54 +00007331
John McCall9ae2f072010-08-23 23:25:46 +00007332 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007333 E->getOperatorLoc(),
7334 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007335 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007336 ScopeTypeInfo,
7337 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007338 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007339 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007340}
Mike Stump1eb44332009-09-09 15:08:12 +00007341
Douglas Gregora71d8192009-09-04 17:36:40 +00007342template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007343ExprResult
John McCallba135432009-11-21 08:51:07 +00007344TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007345 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007346 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7347 Sema::LookupOrdinaryName);
7348
7349 // Transform all the decls.
7350 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7351 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007352 NamedDecl *InstD = static_cast<NamedDecl*>(
7353 getDerived().TransformDecl(Old->getNameLoc(),
7354 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007355 if (!InstD) {
7356 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7357 // This can happen because of dependent hiding.
7358 if (isa<UsingShadowDecl>(*I))
7359 continue;
7360 else
John McCallf312b1e2010-08-26 23:41:50 +00007361 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007362 }
John McCallf7a1a742009-11-24 19:00:30 +00007363
7364 // Expand using declarations.
7365 if (isa<UsingDecl>(InstD)) {
7366 UsingDecl *UD = cast<UsingDecl>(InstD);
7367 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7368 E = UD->shadow_end(); I != E; ++I)
7369 R.addDecl(*I);
7370 continue;
7371 }
7372
7373 R.addDecl(InstD);
7374 }
7375
7376 // Resolve a kind, but don't do any further analysis. If it's
7377 // ambiguous, the callee needs to deal with it.
7378 R.resolveKind();
7379
7380 // Rebuild the nested-name qualifier, if present.
7381 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007382 if (Old->getQualifierLoc()) {
7383 NestedNameSpecifierLoc QualifierLoc
7384 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7385 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007386 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007387
Douglas Gregor4c9be892011-02-28 20:01:57 +00007388 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007389 }
7390
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007391 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007392 CXXRecordDecl *NamingClass
7393 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7394 Old->getNameLoc(),
7395 Old->getNamingClass()));
7396 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007397 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007398
Douglas Gregor66c45152010-04-27 16:10:10 +00007399 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007400 }
7401
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007402 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7403
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007404 // If we have neither explicit template arguments, nor the template keyword,
7405 // it's a normal declaration name.
7406 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007407 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7408
7409 // If we have template arguments, rebuild them, then rebuild the
7410 // templateid expression.
7411 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007412 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7413 Old->getNumTemplateArgs(),
7414 TransArgs))
7415 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007416
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007417 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007418 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007419}
Mike Stump1eb44332009-09-09 15:08:12 +00007420
Douglas Gregorb98b1992009-08-11 05:31:07 +00007421template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007422ExprResult
John McCall454feb92009-12-08 09:21:05 +00007423TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007424 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7425 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007426 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007427
Douglas Gregorb98b1992009-08-11 05:31:07 +00007428 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007429 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007430 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007431
Mike Stump1eb44332009-09-09 15:08:12 +00007432 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007433 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007434 T,
7435 E->getLocEnd());
7436}
Mike Stump1eb44332009-09-09 15:08:12 +00007437
Douglas Gregorb98b1992009-08-11 05:31:07 +00007438template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007439ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007440TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7441 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7442 if (!LhsT)
7443 return ExprError();
7444
7445 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7446 if (!RhsT)
7447 return ExprError();
7448
7449 if (!getDerived().AlwaysRebuild() &&
7450 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7451 return SemaRef.Owned(E);
7452
7453 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7454 E->getLocStart(),
7455 LhsT, RhsT,
7456 E->getLocEnd());
7457}
7458
7459template<typename Derived>
7460ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007461TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7462 bool ArgChanged = false;
7463 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7464 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7465 TypeSourceInfo *From = E->getArg(I);
7466 TypeLoc FromTL = From->getTypeLoc();
7467 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7468 TypeLocBuilder TLB;
7469 TLB.reserve(FromTL.getFullDataSize());
7470 QualType To = getDerived().TransformType(TLB, FromTL);
7471 if (To.isNull())
7472 return ExprError();
7473
7474 if (To == From->getType())
7475 Args.push_back(From);
7476 else {
7477 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7478 ArgChanged = true;
7479 }
7480 continue;
7481 }
7482
7483 ArgChanged = true;
7484
7485 // We have a pack expansion. Instantiate it.
7486 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
7487 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7488 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7489 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7490
7491 // Determine whether the set of unexpanded parameter packs can and should
7492 // be expanded.
7493 bool Expand = true;
7494 bool RetainExpansion = false;
7495 llvm::Optional<unsigned> OrigNumExpansions
7496 = ExpansionTL.getTypePtr()->getNumExpansions();
7497 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7498 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7499 PatternTL.getSourceRange(),
7500 Unexpanded,
7501 Expand, RetainExpansion,
7502 NumExpansions))
7503 return ExprError();
7504
7505 if (!Expand) {
7506 // The transform has determined that we should perform a simple
7507 // transformation on the pack expansion, producing another pack
7508 // expansion.
7509 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7510
7511 TypeLocBuilder TLB;
7512 TLB.reserve(From->getTypeLoc().getFullDataSize());
7513
7514 QualType To = getDerived().TransformType(TLB, PatternTL);
7515 if (To.isNull())
7516 return ExprError();
7517
7518 To = getDerived().RebuildPackExpansionType(To,
7519 PatternTL.getSourceRange(),
7520 ExpansionTL.getEllipsisLoc(),
7521 NumExpansions);
7522 if (To.isNull())
7523 return ExprError();
7524
7525 PackExpansionTypeLoc ToExpansionTL
7526 = TLB.push<PackExpansionTypeLoc>(To);
7527 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7528 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7529 continue;
7530 }
7531
7532 // Expand the pack expansion by substituting for each argument in the
7533 // pack(s).
7534 for (unsigned I = 0; I != *NumExpansions; ++I) {
7535 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7536 TypeLocBuilder TLB;
7537 TLB.reserve(PatternTL.getFullDataSize());
7538 QualType To = getDerived().TransformType(TLB, PatternTL);
7539 if (To.isNull())
7540 return ExprError();
7541
7542 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7543 }
7544
7545 if (!RetainExpansion)
7546 continue;
7547
7548 // If we're supposed to retain a pack expansion, do so by temporarily
7549 // forgetting the partially-substituted parameter pack.
7550 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7551
7552 TypeLocBuilder TLB;
7553 TLB.reserve(From->getTypeLoc().getFullDataSize());
7554
7555 QualType To = getDerived().TransformType(TLB, PatternTL);
7556 if (To.isNull())
7557 return ExprError();
7558
7559 To = getDerived().RebuildPackExpansionType(To,
7560 PatternTL.getSourceRange(),
7561 ExpansionTL.getEllipsisLoc(),
7562 NumExpansions);
7563 if (To.isNull())
7564 return ExprError();
7565
7566 PackExpansionTypeLoc ToExpansionTL
7567 = TLB.push<PackExpansionTypeLoc>(To);
7568 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7569 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7570 }
7571
7572 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7573 return SemaRef.Owned(E);
7574
7575 return getDerived().RebuildTypeTrait(E->getTrait(),
7576 E->getLocStart(),
7577 Args,
7578 E->getLocEnd());
7579}
7580
7581template<typename Derived>
7582ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007583TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7584 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7585 if (!T)
7586 return ExprError();
7587
7588 if (!getDerived().AlwaysRebuild() &&
7589 T == E->getQueriedTypeSourceInfo())
7590 return SemaRef.Owned(E);
7591
7592 ExprResult SubExpr;
7593 {
7594 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7595 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7596 if (SubExpr.isInvalid())
7597 return ExprError();
7598
7599 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7600 return SemaRef.Owned(E);
7601 }
7602
7603 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7604 E->getLocStart(),
7605 T,
7606 SubExpr.get(),
7607 E->getLocEnd());
7608}
7609
7610template<typename Derived>
7611ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007612TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7613 ExprResult SubExpr;
7614 {
7615 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7616 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7617 if (SubExpr.isInvalid())
7618 return ExprError();
7619
7620 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7621 return SemaRef.Owned(E);
7622 }
7623
7624 return getDerived().RebuildExpressionTrait(
7625 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7626}
7627
7628template<typename Derived>
7629ExprResult
John McCall865d4472009-11-19 22:55:06 +00007630TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007631 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007632 NestedNameSpecifierLoc QualifierLoc
7633 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7634 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007635 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007636 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007637
John McCall43fed0d2010-11-12 08:19:04 +00007638 // TODO: If this is a conversion-function-id, verify that the
7639 // destination type name (if present) resolves the same way after
7640 // instantiation as it did in the local scope.
7641
Abramo Bagnara25777432010-08-11 22:01:17 +00007642 DeclarationNameInfo NameInfo
7643 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7644 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007645 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007646
John McCallf7a1a742009-11-24 19:00:30 +00007647 if (!E->hasExplicitTemplateArgs()) {
7648 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007649 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007650 // Note: it is sufficient to compare the Name component of NameInfo:
7651 // if name has not changed, DNLoc has not changed either.
7652 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007653 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007654
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007655 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007656 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007657 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007658 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007659 }
John McCalld5532b62009-11-23 01:53:49 +00007660
7661 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007662 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7663 E->getNumTemplateArgs(),
7664 TransArgs))
7665 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007666
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007667 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007668 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007669 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007670 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007671}
7672
7673template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007674ExprResult
John McCall454feb92009-12-08 09:21:05 +00007675TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007676 // CXXConstructExprs are always implicit, so when we have a
7677 // 1-argument construction we just transform that argument.
7678 if (E->getNumArgs() == 1 ||
7679 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7680 return getDerived().TransformExpr(E->getArg(0));
7681
Douglas Gregorb98b1992009-08-11 05:31:07 +00007682 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7683
7684 QualType T = getDerived().TransformType(E->getType());
7685 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007686 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007687
7688 CXXConstructorDecl *Constructor
7689 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007690 getDerived().TransformDecl(E->getLocStart(),
7691 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007692 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007693 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007694
Douglas Gregorb98b1992009-08-11 05:31:07 +00007695 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007696 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007697 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7698 &ArgumentChanged))
7699 return ExprError();
7700
Douglas Gregorb98b1992009-08-11 05:31:07 +00007701 if (!getDerived().AlwaysRebuild() &&
7702 T == E->getType() &&
7703 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007704 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007705 // Mark the constructor as referenced.
7706 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007707 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007708 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007709 }
Mike Stump1eb44332009-09-09 15:08:12 +00007710
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007711 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7712 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007713 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007714 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007715 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007716 E->getConstructionKind(),
7717 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007718}
Mike Stump1eb44332009-09-09 15:08:12 +00007719
Douglas Gregorb98b1992009-08-11 05:31:07 +00007720/// \brief Transform a C++ temporary-binding expression.
7721///
Douglas Gregor51326552009-12-24 18:51:59 +00007722/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7723/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007724template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007725ExprResult
John McCall454feb92009-12-08 09:21:05 +00007726TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007727 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007728}
Mike Stump1eb44332009-09-09 15:08:12 +00007729
John McCall4765fa02010-12-06 08:20:24 +00007730/// \brief Transform a C++ expression that contains cleanups that should
7731/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007732///
John McCall4765fa02010-12-06 08:20:24 +00007733/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007734/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007735template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007736ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007737TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007738 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007739}
Mike Stump1eb44332009-09-09 15:08:12 +00007740
Douglas Gregorb98b1992009-08-11 05:31:07 +00007741template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007742ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007743TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007744 CXXTemporaryObjectExpr *E) {
7745 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7746 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007747 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007748
Douglas Gregorb98b1992009-08-11 05:31:07 +00007749 CXXConstructorDecl *Constructor
7750 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007751 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007752 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007753 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007754 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007755
Douglas Gregorb98b1992009-08-11 05:31:07 +00007756 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007757 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007758 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007759 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7760 &ArgumentChanged))
7761 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007762
Douglas Gregorb98b1992009-08-11 05:31:07 +00007763 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007764 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007765 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007766 !ArgumentChanged) {
7767 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007768 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007769 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007770 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007771
7772 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7773 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007774 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007775 E->getLocEnd());
7776}
Mike Stump1eb44332009-09-09 15:08:12 +00007777
Douglas Gregorb98b1992009-08-11 05:31:07 +00007778template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007779ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007780TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007781 // Create the local class that will describe the lambda.
7782 CXXRecordDecl *Class
7783 = getSema().createLambdaClosureType(E->getIntroducerRange());
7784 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7785
7786 // Transform the type of the lambda parameters and start the definition of
7787 // the lambda itself.
7788 TypeSourceInfo *MethodTy
7789 = TransformType(E->getCallOperator()->getTypeSourceInfo());
7790 if (!MethodTy)
7791 return ExprError();
7792
Douglas Gregorc6889e72012-02-14 22:28:59 +00007793 // Transform lambda parameters.
7794 bool Invalid = false;
7795 llvm::SmallVector<QualType, 4> ParamTypes;
7796 llvm::SmallVector<ParmVarDecl *, 4> Params;
7797 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7798 E->getCallOperator()->param_begin(),
7799 E->getCallOperator()->param_size(),
7800 0, ParamTypes, &Params))
7801 Invalid = true;
7802
Douglas Gregordfca6f52012-02-13 22:00:16 +00007803 // Build the call operator.
7804 CXXMethodDecl *CallOperator
7805 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7806 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007807 E->getCallOperator()->getLocEnd(),
7808 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007809 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7810
Douglas Gregord5387e82012-02-14 00:00:48 +00007811 // FIXME: Instantiation-specific.
7812 CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(),
7813 TSK_ImplicitInstantiation);
7814
7815 // Introduce the context of the call operator.
7816 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7817
Douglas Gregordfca6f52012-02-13 22:00:16 +00007818 // Enter the scope of the lambda.
7819 sema::LambdaScopeInfo *LSI
7820 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7821 E->getCaptureDefault(),
7822 E->hasExplicitParameters(),
7823 E->hasExplicitResultType(),
7824 E->isMutable());
7825
7826 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00007827 bool FinishedExplicitCaptures = false;
7828 for (LambdaExpr::capture_iterator C = E->capture_begin(),
7829 CEnd = E->capture_end();
7830 C != CEnd; ++C) {
7831 // When we hit the first implicit capture, tell Sema that we've finished
7832 // the list of explicit captures.
7833 if (!FinishedExplicitCaptures && C->isImplicit()) {
7834 getSema().finishLambdaExplicitCaptures(LSI);
7835 FinishedExplicitCaptures = true;
7836 }
7837
7838 // Capturing 'this' is trivial.
7839 if (C->capturesThis()) {
7840 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7841 continue;
7842 }
7843
Douglas Gregora7365242012-02-14 19:27:52 +00007844 // Determine the capture kind for Sema.
7845 Sema::TryCaptureKind Kind
7846 = C->isImplicit()? Sema::TryCapture_Implicit
7847 : C->getCaptureKind() == LCK_ByCopy
7848 ? Sema::TryCapture_ExplicitByVal
7849 : Sema::TryCapture_ExplicitByRef;
7850 SourceLocation EllipsisLoc;
7851 if (C->isPackExpansion()) {
7852 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7853 bool ShouldExpand = false;
7854 bool RetainExpansion = false;
7855 llvm::Optional<unsigned> NumExpansions;
7856 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7857 C->getLocation(),
7858 Unexpanded,
7859 ShouldExpand, RetainExpansion,
7860 NumExpansions))
7861 return ExprError();
7862
7863 if (ShouldExpand) {
7864 // The transform has determined that we should perform an expansion;
7865 // transform and capture each of the arguments.
7866 // expansion of the pattern. Do so.
7867 VarDecl *Pack = C->getCapturedVar();
7868 for (unsigned I = 0; I != *NumExpansions; ++I) {
7869 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7870 VarDecl *CapturedVar
7871 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7872 Pack));
7873 if (!CapturedVar) {
7874 Invalid = true;
7875 continue;
7876 }
7877
7878 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007879 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregora7365242012-02-14 19:27:52 +00007880 }
7881 continue;
7882 }
7883
7884 EllipsisLoc = C->getEllipsisLoc();
7885 }
7886
Douglas Gregordfca6f52012-02-13 22:00:16 +00007887 // Transform the captured variable.
7888 VarDecl *CapturedVar
7889 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7890 C->getCapturedVar()));
7891 if (!CapturedVar) {
7892 Invalid = true;
7893 continue;
7894 }
Douglas Gregora7365242012-02-14 19:27:52 +00007895
Douglas Gregordfca6f52012-02-13 22:00:16 +00007896 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007897 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007898 }
7899 if (!FinishedExplicitCaptures)
7900 getSema().finishLambdaExplicitCaptures(LSI);
7901
Douglas Gregordfca6f52012-02-13 22:00:16 +00007902
7903 // Enter a new evaluation context to insulate the lambda from any
7904 // cleanups from the enclosing full-expression.
7905 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
7906
7907 if (Invalid) {
7908 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7909 /*IsInstantiation=*/true);
7910 return ExprError();
7911 }
7912
7913 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00007914 StmtResult Body = getDerived().TransformStmt(E->getBody());
7915 if (Body.isInvalid()) {
7916 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7917 /*IsInstantiation=*/true);
7918 return ExprError();
7919 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007920
7921 // Note: Once a lambda mangling number and context declaration have been
7922 // assigned, they never change.
Douglas Gregor9e8c92a2012-02-20 19:44:39 +00007923 unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber();
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007924 Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl();
Douglas Gregordfca6f52012-02-13 22:00:16 +00007925 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregor9e8c92a2012-02-20 19:44:39 +00007926 /*CurScope=*/0, ManglingNumber,
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007927 ContextDecl,
Douglas Gregordfca6f52012-02-13 22:00:16 +00007928 /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00007929}
7930
7931template<typename Derived>
7932ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007933TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007934 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007935 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7936 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007937 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007938
Douglas Gregorb98b1992009-08-11 05:31:07 +00007939 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007940 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007941 Args.reserve(E->arg_size());
7942 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7943 &ArgumentChanged))
7944 return ExprError();
7945
Douglas Gregorb98b1992009-08-11 05:31:07 +00007946 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007947 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007948 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007949 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007950
Douglas Gregorb98b1992009-08-11 05:31:07 +00007951 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007952 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007953 E->getLParenLoc(),
7954 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007955 E->getRParenLoc());
7956}
Mike Stump1eb44332009-09-09 15:08:12 +00007957
Douglas Gregorb98b1992009-08-11 05:31:07 +00007958template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007959ExprResult
John McCall865d4472009-11-19 22:55:06 +00007960TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007961 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007962 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007963 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007964 Expr *OldBase;
7965 QualType BaseType;
7966 QualType ObjectType;
7967 if (!E->isImplicitAccess()) {
7968 OldBase = E->getBase();
7969 Base = getDerived().TransformExpr(OldBase);
7970 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007971 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007972
John McCallaa81e162009-12-01 22:10:20 +00007973 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007974 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007975 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007976 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007977 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007978 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007979 ObjectTy,
7980 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007981 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007982 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007983
John McCallb3d87482010-08-24 05:47:05 +00007984 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007985 BaseType = ((Expr*) Base.get())->getType();
7986 } else {
7987 OldBase = 0;
7988 BaseType = getDerived().TransformType(E->getBaseType());
7989 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7990 }
Mike Stump1eb44332009-09-09 15:08:12 +00007991
Douglas Gregor6cd21982009-10-20 05:58:46 +00007992 // Transform the first part of the nested-name-specifier that qualifies
7993 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007994 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007995 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007996 E->getFirstQualifierFoundInScope(),
7997 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007998
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007999 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008000 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008001 QualifierLoc
8002 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8003 ObjectType,
8004 FirstQualifierInScope);
8005 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008006 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008007 }
Mike Stump1eb44332009-09-09 15:08:12 +00008008
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008009 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8010
John McCall43fed0d2010-11-12 08:19:04 +00008011 // TODO: If this is a conversion-function-id, verify that the
8012 // destination type name (if present) resolves the same way after
8013 // instantiation as it did in the local scope.
8014
Abramo Bagnara25777432010-08-11 22:01:17 +00008015 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008016 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008017 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008018 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008019
John McCallaa81e162009-12-01 22:10:20 +00008020 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008021 // This is a reference to a member without an explicitly-specified
8022 // template argument list. Optimize for this common case.
8023 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008024 Base.get() == OldBase &&
8025 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008026 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008027 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008028 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008029 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008030
John McCall9ae2f072010-08-23 23:25:46 +00008031 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008032 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008033 E->isArrow(),
8034 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008035 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008036 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008037 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008038 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008039 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008040 }
8041
John McCalld5532b62009-11-23 01:53:49 +00008042 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008043 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8044 E->getNumTemplateArgs(),
8045 TransArgs))
8046 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008047
John McCall9ae2f072010-08-23 23:25:46 +00008048 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008049 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008050 E->isArrow(),
8051 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008052 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008053 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008054 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008055 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008056 &TransArgs);
8057}
8058
8059template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008060ExprResult
John McCall454feb92009-12-08 09:21:05 +00008061TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008062 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008063 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008064 QualType BaseType;
8065 if (!Old->isImplicitAccess()) {
8066 Base = getDerived().TransformExpr(Old->getBase());
8067 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008068 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008069 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8070 Old->isArrow());
8071 if (Base.isInvalid())
8072 return ExprError();
8073 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008074 } else {
8075 BaseType = getDerived().TransformType(Old->getBaseType());
8076 }
John McCall129e2df2009-11-30 22:42:35 +00008077
Douglas Gregor4c9be892011-02-28 20:01:57 +00008078 NestedNameSpecifierLoc QualifierLoc;
8079 if (Old->getQualifierLoc()) {
8080 QualifierLoc
8081 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8082 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008083 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008084 }
8085
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008086 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8087
Abramo Bagnara25777432010-08-11 22:01:17 +00008088 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008089 Sema::LookupOrdinaryName);
8090
8091 // Transform all the decls.
8092 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8093 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008094 NamedDecl *InstD = static_cast<NamedDecl*>(
8095 getDerived().TransformDecl(Old->getMemberLoc(),
8096 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008097 if (!InstD) {
8098 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8099 // This can happen because of dependent hiding.
8100 if (isa<UsingShadowDecl>(*I))
8101 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008102 else {
8103 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008104 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008105 }
John McCall9f54ad42009-12-10 09:41:52 +00008106 }
John McCall129e2df2009-11-30 22:42:35 +00008107
8108 // Expand using declarations.
8109 if (isa<UsingDecl>(InstD)) {
8110 UsingDecl *UD = cast<UsingDecl>(InstD);
8111 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8112 E = UD->shadow_end(); I != E; ++I)
8113 R.addDecl(*I);
8114 continue;
8115 }
8116
8117 R.addDecl(InstD);
8118 }
8119
8120 R.resolveKind();
8121
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008122 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008123 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00008124 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008125 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008126 Old->getMemberLoc(),
8127 Old->getNamingClass()));
8128 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008129 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008130
Douglas Gregor66c45152010-04-27 16:10:10 +00008131 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008132 }
Sean Huntc3021132010-05-05 15:23:54 +00008133
John McCall129e2df2009-11-30 22:42:35 +00008134 TemplateArgumentListInfo TransArgs;
8135 if (Old->hasExplicitTemplateArgs()) {
8136 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8137 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008138 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8139 Old->getNumTemplateArgs(),
8140 TransArgs))
8141 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008142 }
John McCallc2233c52010-01-15 08:34:02 +00008143
8144 // FIXME: to do this check properly, we will need to preserve the
8145 // first-qualifier-in-scope here, just in case we had a dependent
8146 // base (and therefore couldn't do the check) and a
8147 // nested-name-qualifier (and therefore could do the lookup).
8148 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00008149
John McCall9ae2f072010-08-23 23:25:46 +00008150 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008151 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008152 Old->getOperatorLoc(),
8153 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008154 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008155 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008156 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008157 R,
8158 (Old->hasExplicitTemplateArgs()
8159 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008160}
8161
8162template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008163ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008164TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008165 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008166 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8167 if (SubExpr.isInvalid())
8168 return ExprError();
8169
8170 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008171 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008172
8173 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8174}
8175
8176template<typename Derived>
8177ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008178TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008179 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8180 if (Pattern.isInvalid())
8181 return ExprError();
8182
8183 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8184 return SemaRef.Owned(E);
8185
Douglas Gregor67fd1252011-01-14 21:20:45 +00008186 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8187 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008188}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008189
8190template<typename Derived>
8191ExprResult
8192TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8193 // If E is not value-dependent, then nothing will change when we transform it.
8194 // Note: This is an instantiation-centric view.
8195 if (!E->isValueDependent())
8196 return SemaRef.Owned(E);
8197
8198 // Note: None of the implementations of TryExpandParameterPacks can ever
8199 // produce a diagnostic when given only a single unexpanded parameter pack,
8200 // so
8201 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8202 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008203 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008204 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00008205 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008206 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008207 ShouldExpand, RetainExpansion,
8208 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008209 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00008210
Douglas Gregor089e8932011-10-10 18:59:29 +00008211 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008212 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00008213
8214 NamedDecl *Pack = E->getPack();
8215 if (!ShouldExpand) {
8216 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8217 Pack));
8218 if (!Pack)
8219 return ExprError();
8220 }
8221
Douglas Gregoree8aff02011-01-04 17:33:58 +00008222
8223 // We now know the length of the parameter pack, so build a new expression
8224 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00008225 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00008226 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008227 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008228}
8229
Douglas Gregorbe230c32011-01-03 17:17:50 +00008230template<typename Derived>
8231ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008232TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8233 SubstNonTypeTemplateParmPackExpr *E) {
8234 // Default behavior is to do nothing with this transformation.
8235 return SemaRef.Owned(E);
8236}
8237
8238template<typename Derived>
8239ExprResult
John McCall91a57552011-07-15 05:09:51 +00008240TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8241 SubstNonTypeTemplateParmExpr *E) {
8242 // Default behavior is to do nothing with this transformation.
8243 return SemaRef.Owned(E);
8244}
8245
8246template<typename Derived>
8247ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008248TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8249 MaterializeTemporaryExpr *E) {
8250 return getDerived().TransformExpr(E->GetTemporaryExpr());
8251}
8252
8253template<typename Derived>
8254ExprResult
John McCall454feb92009-12-08 09:21:05 +00008255TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008256 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008257}
8258
Mike Stump1eb44332009-09-09 15:08:12 +00008259template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008260ExprResult
John McCall454feb92009-12-08 09:21:05 +00008261TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008262 TypeSourceInfo *EncodedTypeInfo
8263 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8264 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008265 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008266
Douglas Gregorb98b1992009-08-11 05:31:07 +00008267 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008268 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008269 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008270
8271 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008272 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008273 E->getRParenLoc());
8274}
Mike Stump1eb44332009-09-09 15:08:12 +00008275
Douglas Gregorb98b1992009-08-11 05:31:07 +00008276template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008277ExprResult TreeTransform<Derived>::
8278TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8279 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8280 if (result.isInvalid()) return ExprError();
8281 Expr *subExpr = result.take();
8282
8283 if (!getDerived().AlwaysRebuild() &&
8284 subExpr == E->getSubExpr())
8285 return SemaRef.Owned(E);
8286
8287 return SemaRef.Owned(new(SemaRef.Context)
8288 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8289}
8290
8291template<typename Derived>
8292ExprResult TreeTransform<Derived>::
8293TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
8294 TypeSourceInfo *TSInfo
8295 = getDerived().TransformType(E->getTypeInfoAsWritten());
8296 if (!TSInfo)
8297 return ExprError();
8298
8299 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
8300 if (Result.isInvalid())
8301 return ExprError();
8302
8303 if (!getDerived().AlwaysRebuild() &&
8304 TSInfo == E->getTypeInfoAsWritten() &&
8305 Result.get() == E->getSubExpr())
8306 return SemaRef.Owned(E);
8307
8308 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8309 E->getBridgeKeywordLoc(), TSInfo,
8310 Result.get());
8311}
8312
8313template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008314ExprResult
John McCall454feb92009-12-08 09:21:05 +00008315TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008316 // Transform arguments.
8317 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008318 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008319 Args.reserve(E->getNumArgs());
8320 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8321 &ArgChanged))
8322 return ExprError();
8323
Douglas Gregor92e986e2010-04-22 16:44:27 +00008324 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8325 // Class message: transform the receiver type.
8326 TypeSourceInfo *ReceiverTypeInfo
8327 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8328 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008329 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008330
Douglas Gregor92e986e2010-04-22 16:44:27 +00008331 // If nothing changed, just retain the existing message send.
8332 if (!getDerived().AlwaysRebuild() &&
8333 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008334 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008335
8336 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008337 SmallVector<SourceLocation, 16> SelLocs;
8338 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008339 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8340 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008341 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008342 E->getMethodDecl(),
8343 E->getLeftLoc(),
8344 move_arg(Args),
8345 E->getRightLoc());
8346 }
8347
8348 // Instance message: transform the receiver
8349 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8350 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008351 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008352 = getDerived().TransformExpr(E->getInstanceReceiver());
8353 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008354 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008355
8356 // If nothing changed, just retain the existing message send.
8357 if (!getDerived().AlwaysRebuild() &&
8358 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008359 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008360
Douglas Gregor92e986e2010-04-22 16:44:27 +00008361 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008362 SmallVector<SourceLocation, 16> SelLocs;
8363 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008364 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008365 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008366 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008367 E->getMethodDecl(),
8368 E->getLeftLoc(),
8369 move_arg(Args),
8370 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008371}
8372
Mike Stump1eb44332009-09-09 15:08:12 +00008373template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008374ExprResult
John McCall454feb92009-12-08 09:21:05 +00008375TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008376 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008377}
8378
Mike Stump1eb44332009-09-09 15:08:12 +00008379template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008380ExprResult
John McCall454feb92009-12-08 09:21:05 +00008381TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008382 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008383}
8384
Mike Stump1eb44332009-09-09 15:08:12 +00008385template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008386ExprResult
John McCall454feb92009-12-08 09:21:05 +00008387TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008388 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008389 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008390 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008391 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008392
8393 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008394
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008395 // If nothing changed, just retain the existing expression.
8396 if (!getDerived().AlwaysRebuild() &&
8397 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008398 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008399
John McCall9ae2f072010-08-23 23:25:46 +00008400 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008401 E->getLocation(),
8402 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008403}
8404
Mike Stump1eb44332009-09-09 15:08:12 +00008405template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008406ExprResult
John McCall454feb92009-12-08 09:21:05 +00008407TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008408 // 'super' and types never change. Property never changes. Just
8409 // retain the existing expression.
8410 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008411 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008412
Douglas Gregore3303542010-04-26 20:47:02 +00008413 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008414 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008415 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008416 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008417
Douglas Gregore3303542010-04-26 20:47:02 +00008418 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008419
Douglas Gregore3303542010-04-26 20:47:02 +00008420 // If nothing changed, just retain the existing expression.
8421 if (!getDerived().AlwaysRebuild() &&
8422 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008423 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008424
John McCall12f78a62010-12-02 01:19:52 +00008425 if (E->isExplicitProperty())
8426 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8427 E->getExplicitProperty(),
8428 E->getLocation());
8429
8430 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008431 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008432 E->getImplicitPropertyGetter(),
8433 E->getImplicitPropertySetter(),
8434 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008435}
8436
Mike Stump1eb44332009-09-09 15:08:12 +00008437template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008438ExprResult
John McCall454feb92009-12-08 09:21:05 +00008439TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008440 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008441 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008442 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008443 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008444
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008445 // If nothing changed, just retain the existing expression.
8446 if (!getDerived().AlwaysRebuild() &&
8447 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008448 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008449
John McCall9ae2f072010-08-23 23:25:46 +00008450 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008451 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008452}
8453
Mike Stump1eb44332009-09-09 15:08:12 +00008454template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008455ExprResult
John McCall454feb92009-12-08 09:21:05 +00008456TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008457 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008458 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008459 SubExprs.reserve(E->getNumSubExprs());
8460 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8461 SubExprs, &ArgumentChanged))
8462 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008463
Douglas Gregorb98b1992009-08-11 05:31:07 +00008464 if (!getDerived().AlwaysRebuild() &&
8465 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008466 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008467
Douglas Gregorb98b1992009-08-11 05:31:07 +00008468 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8469 move_arg(SubExprs),
8470 E->getRParenLoc());
8471}
8472
Mike Stump1eb44332009-09-09 15:08:12 +00008473template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008474ExprResult
John McCall454feb92009-12-08 09:21:05 +00008475TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008476 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008477
John McCallc6ac9c32011-02-04 18:33:18 +00008478 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8479 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8480
8481 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008482 blockScope->TheDecl->setBlockMissingReturnType(
8483 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008484
Chris Lattner686775d2011-07-20 06:58:45 +00008485 SmallVector<ParmVarDecl*, 4> params;
8486 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008487
8488 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008489 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8490 oldBlock->param_begin(),
8491 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008492 0, paramTypes, &params)) {
8493 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008494 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008495 }
John McCallc6ac9c32011-02-04 18:33:18 +00008496
8497 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008498 QualType exprResultType =
8499 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008500
8501 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008502 if (exprResultType->isObjCObjectType()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008503 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008504 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008505 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008506 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008507 return ExprError();
8508 }
John McCall711c52b2011-01-05 12:14:39 +00008509
John McCallc6ac9c32011-02-04 18:33:18 +00008510 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008511 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008512 paramTypes.data(),
8513 paramTypes.size(),
8514 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008515 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008516 exprFunctionType->getExtInfo());
8517 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008518
8519 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008520 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008521 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008522
8523 if (!oldBlock->blockMissingReturnType()) {
8524 blockScope->HasImplicitReturnType = false;
8525 blockScope->ReturnType = exprResultType;
8526 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008527
John McCall711c52b2011-01-05 12:14:39 +00008528 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008529 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008530 if (body.isInvalid()) {
8531 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008532 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008533 }
John McCall711c52b2011-01-05 12:14:39 +00008534
John McCallc6ac9c32011-02-04 18:33:18 +00008535#ifndef NDEBUG
8536 // In builds with assertions, make sure that we captured everything we
8537 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008538 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8539 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8540 e = oldBlock->capture_end(); i != e; ++i) {
8541 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008542
Douglas Gregorfc921372011-05-20 15:32:55 +00008543 // Ignore parameter packs.
8544 if (isa<ParmVarDecl>(oldCapture) &&
8545 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8546 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008547
Douglas Gregorfc921372011-05-20 15:32:55 +00008548 VarDecl *newCapture =
8549 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8550 oldCapture));
8551 assert(blockScope->CaptureMap.count(newCapture));
8552 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008553 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008554 }
8555#endif
8556
8557 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8558 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008559}
8560
Mike Stump1eb44332009-09-09 15:08:12 +00008561template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008562ExprResult
John McCall454feb92009-12-08 09:21:05 +00008563TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008564 ValueDecl *ND
8565 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8566 E->getDecl()));
8567 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00008568 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00008569
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008570 if (!getDerived().AlwaysRebuild() &&
8571 ND == E->getDecl()) {
8572 // Mark it referenced in the new context regardless.
8573 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00008574 SemaRef.MarkBlockDeclRefReferenced(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008575
John McCall3fa5cae2010-10-26 07:05:15 +00008576 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008577 }
8578
Abramo Bagnara25777432010-08-11 22:01:17 +00008579 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00008580 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00008581 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008582}
Mike Stump1eb44332009-09-09 15:08:12 +00008583
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008584template<typename Derived>
8585ExprResult
8586TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008587 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008588}
Eli Friedman276b0612011-10-11 02:20:01 +00008589
8590template<typename Derived>
8591ExprResult
8592TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008593 QualType RetTy = getDerived().TransformType(E->getType());
8594 bool ArgumentChanged = false;
8595 ASTOwningVector<Expr*> SubExprs(SemaRef);
8596 SubExprs.reserve(E->getNumSubExprs());
8597 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8598 SubExprs, &ArgumentChanged))
8599 return ExprError();
8600
8601 if (!getDerived().AlwaysRebuild() &&
8602 !ArgumentChanged)
8603 return SemaRef.Owned(E);
8604
8605 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8606 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008607}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008608
Douglas Gregorb98b1992009-08-11 05:31:07 +00008609//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008610// Type reconstruction
8611//===----------------------------------------------------------------------===//
8612
Mike Stump1eb44332009-09-09 15:08:12 +00008613template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008614QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8615 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008616 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008617 getDerived().getBaseEntity());
8618}
8619
Mike Stump1eb44332009-09-09 15:08:12 +00008620template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008621QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8622 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008623 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008624 getDerived().getBaseEntity());
8625}
8626
Mike Stump1eb44332009-09-09 15:08:12 +00008627template<typename Derived>
8628QualType
John McCall85737a72009-10-30 00:06:24 +00008629TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8630 bool WrittenAsLValue,
8631 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008632 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008633 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008634}
8635
8636template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008637QualType
John McCall85737a72009-10-30 00:06:24 +00008638TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8639 QualType ClassType,
8640 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008641 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008642 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008643}
8644
8645template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008646QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008647TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8648 ArrayType::ArraySizeModifier SizeMod,
8649 const llvm::APInt *Size,
8650 Expr *SizeExpr,
8651 unsigned IndexTypeQuals,
8652 SourceRange BracketsRange) {
8653 if (SizeExpr || !Size)
8654 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8655 IndexTypeQuals, BracketsRange,
8656 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008657
8658 QualType Types[] = {
8659 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8660 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8661 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008662 };
8663 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8664 QualType SizeType;
8665 for (unsigned I = 0; I != NumTypes; ++I)
8666 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8667 SizeType = Types[I];
8668 break;
8669 }
Mike Stump1eb44332009-09-09 15:08:12 +00008670
Eli Friedman01f276d2012-01-25 23:20:27 +00008671 // Note that we can return a VariableArrayType here in the case where
8672 // the element type was a dependent VariableArrayType.
8673 IntegerLiteral *ArraySize
8674 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8675 /*FIXME*/BracketsRange.getBegin());
8676 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008677 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008678 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008679}
Mike Stump1eb44332009-09-09 15:08:12 +00008680
Douglas Gregor577f75a2009-08-04 16:50:30 +00008681template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008682QualType
8683TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008684 ArrayType::ArraySizeModifier SizeMod,
8685 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008686 unsigned IndexTypeQuals,
8687 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008688 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008689 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008690}
8691
8692template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008693QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008694TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008695 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008696 unsigned IndexTypeQuals,
8697 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008698 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008699 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008700}
Mike Stump1eb44332009-09-09 15:08:12 +00008701
Douglas Gregor577f75a2009-08-04 16:50:30 +00008702template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008703QualType
8704TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008705 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008706 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008707 unsigned IndexTypeQuals,
8708 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008709 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008710 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008711 IndexTypeQuals, BracketsRange);
8712}
8713
8714template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008715QualType
8716TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008717 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008718 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008719 unsigned IndexTypeQuals,
8720 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008721 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008722 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008723 IndexTypeQuals, BracketsRange);
8724}
8725
8726template<typename Derived>
8727QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008728 unsigned NumElements,
8729 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008730 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008731 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008732}
Mike Stump1eb44332009-09-09 15:08:12 +00008733
Douglas Gregor577f75a2009-08-04 16:50:30 +00008734template<typename Derived>
8735QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8736 unsigned NumElements,
8737 SourceLocation AttributeLoc) {
8738 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8739 NumElements, true);
8740 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008741 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8742 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008743 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008744}
Mike Stump1eb44332009-09-09 15:08:12 +00008745
Douglas Gregor577f75a2009-08-04 16:50:30 +00008746template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008747QualType
8748TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008749 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008750 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008751 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008752}
Mike Stump1eb44332009-09-09 15:08:12 +00008753
Douglas Gregor577f75a2009-08-04 16:50:30 +00008754template<typename Derived>
8755QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008756 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008757 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008758 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008759 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00008760 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008761 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008762 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008763 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008764 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008765 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008766 getDerived().getBaseEntity(),
8767 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008768}
Mike Stump1eb44332009-09-09 15:08:12 +00008769
Douglas Gregor577f75a2009-08-04 16:50:30 +00008770template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008771QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8772 return SemaRef.Context.getFunctionNoProtoType(T);
8773}
8774
8775template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008776QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8777 assert(D && "no decl found");
8778 if (D->isInvalidDecl()) return QualType();
8779
Douglas Gregor92e986e2010-04-22 16:44:27 +00008780 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008781 TypeDecl *Ty;
8782 if (isa<UsingDecl>(D)) {
8783 UsingDecl *Using = cast<UsingDecl>(D);
8784 assert(Using->isTypeName() &&
8785 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8786
8787 // A valid resolved using typename decl points to exactly one type decl.
8788 assert(++Using->shadow_begin() == Using->shadow_end());
8789 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008790
John McCalled976492009-12-04 22:46:56 +00008791 } else {
8792 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8793 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8794 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8795 }
8796
8797 return SemaRef.Context.getTypeDeclType(Ty);
8798}
8799
8800template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008801QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8802 SourceLocation Loc) {
8803 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008804}
8805
8806template<typename Derived>
8807QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8808 return SemaRef.Context.getTypeOfType(Underlying);
8809}
8810
8811template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008812QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8813 SourceLocation Loc) {
8814 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008815}
8816
8817template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008818QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8819 UnaryTransformType::UTTKind UKind,
8820 SourceLocation Loc) {
8821 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8822}
8823
8824template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008825QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008826 TemplateName Template,
8827 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008828 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008829 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008830}
Mike Stump1eb44332009-09-09 15:08:12 +00008831
Douglas Gregordcee1a12009-08-06 05:28:30 +00008832template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00008833QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8834 SourceLocation KWLoc) {
8835 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8836}
8837
8838template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008839TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008840TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008841 bool TemplateKW,
8842 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008843 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008844 Template);
8845}
8846
8847template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008848TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008849TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8850 const IdentifierInfo &Name,
8851 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008852 QualType ObjectType,
8853 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008854 UnqualifiedId TemplateName;
8855 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008856 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008857 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00008858 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008859 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008860 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008861 /*EnteringContext=*/false,
8862 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008863 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008864}
Mike Stump1eb44332009-09-09 15:08:12 +00008865
Douglas Gregorb98b1992009-08-11 05:31:07 +00008866template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008867TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008868TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008869 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008870 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008871 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008872 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008873 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008874 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008875 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008876 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00008877 Sema::TemplateTy Template;
8878 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008879 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00008880 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008881 /*EnteringContext=*/false,
8882 Template);
8883 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008884}
Sean Huntc3021132010-05-05 15:23:54 +00008885
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008886template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008887ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008888TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8889 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008890 Expr *OrigCallee,
8891 Expr *First,
8892 Expr *Second) {
8893 Expr *Callee = OrigCallee->IgnoreParenCasts();
8894 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008895
Douglas Gregorb98b1992009-08-11 05:31:07 +00008896 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008897 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008898 if (!First->getType()->isOverloadableType() &&
8899 !Second->getType()->isOverloadableType())
8900 return getSema().CreateBuiltinArraySubscriptExpr(First,
8901 Callee->getLocStart(),
8902 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008903 } else if (Op == OO_Arrow) {
8904 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008905 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8906 } else if (Second == 0 || isPostIncDec) {
8907 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008908 // The argument is not of overloadable type, so try to create a
8909 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008910 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008911 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008912
John McCall9ae2f072010-08-23 23:25:46 +00008913 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008914 }
8915 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008916 if (!First->getType()->isOverloadableType() &&
8917 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008918 // Neither of the arguments is an overloadable type, so try to
8919 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008920 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008921 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008922 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008923 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008924 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008925
Douglas Gregorb98b1992009-08-11 05:31:07 +00008926 return move(Result);
8927 }
8928 }
Mike Stump1eb44332009-09-09 15:08:12 +00008929
8930 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008931 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008932 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008933
John McCall9ae2f072010-08-23 23:25:46 +00008934 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008935 assert(ULE->requiresADL());
8936
8937 // FIXME: Do we have to check
8938 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008939 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008940 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008941 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008942 }
Mike Stump1eb44332009-09-09 15:08:12 +00008943
Douglas Gregorb98b1992009-08-11 05:31:07 +00008944 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008945 Expr *Args[2] = { First, Second };
8946 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008947
Douglas Gregorb98b1992009-08-11 05:31:07 +00008948 // Create the overloaded operator invocation for unary operators.
8949 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008950 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008951 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008952 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008953 }
Mike Stump1eb44332009-09-09 15:08:12 +00008954
Douglas Gregor5b8968c2011-07-15 16:25:15 +00008955 if (Op == OO_Subscript) {
8956 SourceLocation LBrace;
8957 SourceLocation RBrace;
8958
8959 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8960 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8961 LBrace = SourceLocation::getFromRawEncoding(
8962 NameLoc.CXXOperatorName.BeginOpNameLoc);
8963 RBrace = SourceLocation::getFromRawEncoding(
8964 NameLoc.CXXOperatorName.EndOpNameLoc);
8965 } else {
8966 LBrace = Callee->getLocStart();
8967 RBrace = OpLoc;
8968 }
8969
8970 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8971 First, Second);
8972 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00008973
Douglas Gregorb98b1992009-08-11 05:31:07 +00008974 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008975 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008976 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008977 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8978 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008979 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008980
Mike Stump1eb44332009-09-09 15:08:12 +00008981 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008982}
Mike Stump1eb44332009-09-09 15:08:12 +00008983
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008984template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008985ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008986TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008987 SourceLocation OperatorLoc,
8988 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008989 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008990 TypeSourceInfo *ScopeType,
8991 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008992 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008993 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008994 QualType BaseType = Base->getType();
8995 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008996 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008997 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008998 !BaseType->getAs<PointerType>()->getPointeeType()
8999 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009000 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009001 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009002 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009003 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009004 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009005 /*FIXME?*/true);
9006 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009007
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009008 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009009 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9010 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9011 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9012 NameInfo.setNamedTypeInfo(DestroyedType);
9013
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009014 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00009015
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009016 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009017 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009018 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009019 SS, TemplateKWLoc,
9020 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009021 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009022 /*TemplateArgs*/ 0);
9023}
9024
Douglas Gregor577f75a2009-08-04 16:50:30 +00009025} // end namespace clang
9026
9027#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H