blob: 11f03fc133accc26b5e50b79e63aa506ea93fa3c [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);
John McCall9ae2f072010-08-23 23:25:46 +00002953 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002954 }
2955
2956 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002957 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002958 }
Mike Stump1eb44332009-09-09 15:08:12 +00002959
Douglas Gregor788cd062009-11-11 01:00:40 +00002960 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002961 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2962 if (QualifierLoc) {
2963 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2964 if (!QualifierLoc)
2965 return true;
2966 }
2967
Douglas Gregor1d752d72011-03-02 18:46:51 +00002968 CXXScopeSpec SS;
2969 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002970 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002971 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2972 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002973 if (Template.isNull())
2974 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002975
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002976 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002977 Input.getTemplateNameLoc());
2978 return false;
2979 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002980
2981 case TemplateArgument::TemplateExpansion:
2982 llvm_unreachable("Caller should expand pack expansions");
2983
Douglas Gregor670444e2009-08-04 22:27:00 +00002984 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00002985 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00002986 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002987 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002988
John McCall833ca992009-10-29 08:12:44 +00002989 Expr *InputExpr = Input.getSourceExpression();
2990 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2991
Chris Lattner223de242011-04-25 20:37:58 +00002992 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall833ca992009-10-29 08:12:44 +00002993 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002994 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002995 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002996 }
Mike Stump1eb44332009-09-09 15:08:12 +00002997
Douglas Gregor670444e2009-08-04 22:27:00 +00002998 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00002999 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003000 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003001 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003002 AEnd = Arg.pack_end();
3003 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003004
John McCall833ca992009-10-29 08:12:44 +00003005 // FIXME: preserve source information here when we start
3006 // caring about parameter packs.
3007
John McCall828bff22009-10-29 18:45:58 +00003008 TemplateArgumentLoc InputArg;
3009 TemplateArgumentLoc OutputArg;
3010 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3011 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003012 return true;
3013
John McCall828bff22009-10-29 18:45:58 +00003014 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003015 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003016
3017 TemplateArgument *TransformedArgsPtr
3018 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3019 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3020 TransformedArgsPtr);
3021 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3022 TransformedArgs.size()),
3023 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003024 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003025 }
3026 }
Mike Stump1eb44332009-09-09 15:08:12 +00003027
Douglas Gregor670444e2009-08-04 22:27:00 +00003028 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003029 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003030}
3031
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003032/// \brief Iterator adaptor that invents template argument location information
3033/// for each of the template arguments in its underlying iterator.
3034template<typename Derived, typename InputIterator>
3035class TemplateArgumentLocInventIterator {
3036 TreeTransform<Derived> &Self;
3037 InputIterator Iter;
3038
3039public:
3040 typedef TemplateArgumentLoc value_type;
3041 typedef TemplateArgumentLoc reference;
3042 typedef typename std::iterator_traits<InputIterator>::difference_type
3043 difference_type;
3044 typedef std::input_iterator_tag iterator_category;
3045
3046 class pointer {
3047 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003048
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003049 public:
3050 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3051
3052 const TemplateArgumentLoc *operator->() const { return &Arg; }
3053 };
3054
3055 TemplateArgumentLocInventIterator() { }
3056
3057 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3058 InputIterator Iter)
3059 : Self(Self), Iter(Iter) { }
3060
3061 TemplateArgumentLocInventIterator &operator++() {
3062 ++Iter;
3063 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003064 }
3065
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003066 TemplateArgumentLocInventIterator operator++(int) {
3067 TemplateArgumentLocInventIterator Old(*this);
3068 ++(*this);
3069 return Old;
3070 }
3071
3072 reference operator*() const {
3073 TemplateArgumentLoc Result;
3074 Self.InventTemplateArgumentLoc(*Iter, Result);
3075 return Result;
3076 }
3077
3078 pointer operator->() const { return pointer(**this); }
3079
3080 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3081 const TemplateArgumentLocInventIterator &Y) {
3082 return X.Iter == Y.Iter;
3083 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003084
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003085 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3086 const TemplateArgumentLocInventIterator &Y) {
3087 return X.Iter != Y.Iter;
3088 }
3089};
3090
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003091template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003092template<typename InputIterator>
3093bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3094 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003095 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003096 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003097 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003098 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003099
3100 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3101 // Unpack argument packs, which we translate them into separate
3102 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003103 // FIXME: We could do much better if we could guarantee that the
3104 // TemplateArgumentLocInfo for the pack expansion would be usable for
3105 // all of the template arguments in the argument pack.
3106 typedef TemplateArgumentLocInventIterator<Derived,
3107 TemplateArgument::pack_iterator>
3108 PackLocIterator;
3109 if (TransformTemplateArguments(PackLocIterator(*this,
3110 In.getArgument().pack_begin()),
3111 PackLocIterator(*this,
3112 In.getArgument().pack_end()),
3113 Outputs))
3114 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003115
3116 continue;
3117 }
3118
3119 if (In.getArgument().isPackExpansion()) {
3120 // We have a pack expansion, for which we will be substituting into
3121 // the pattern.
3122 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003123 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003124 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003125 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3126 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003127
Chris Lattner686775d2011-07-20 06:58:45 +00003128 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003129 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3130 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3131
3132 // Determine whether the set of unexpanded parameter packs can and should
3133 // be expanded.
3134 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003135 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003136 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003137 if (getDerived().TryExpandParameterPacks(Ellipsis,
3138 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003139 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003140 Expand,
3141 RetainExpansion,
3142 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003143 return true;
3144
3145 if (!Expand) {
3146 // The transform has determined that we should perform a simple
3147 // transformation on the pack expansion, producing another pack
3148 // expansion.
3149 TemplateArgumentLoc OutPattern;
3150 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3151 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3152 return true;
3153
Douglas Gregorcded4f62011-01-14 17:04:44 +00003154 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3155 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003156 if (Out.getArgument().isNull())
3157 return true;
3158
3159 Outputs.addArgument(Out);
3160 continue;
3161 }
3162
3163 // The transform has determined that we should perform an elementwise
3164 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003165 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003166 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3167
3168 if (getDerived().TransformTemplateArgument(Pattern, Out))
3169 return true;
3170
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003171 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003172 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3173 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003174 if (Out.getArgument().isNull())
3175 return true;
3176 }
3177
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003178 Outputs.addArgument(Out);
3179 }
3180
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003181 // If we're supposed to retain a pack expansion, do so by temporarily
3182 // forgetting the partially-substituted parameter pack.
3183 if (RetainExpansion) {
3184 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3185
3186 if (getDerived().TransformTemplateArgument(Pattern, Out))
3187 return true;
3188
Douglas Gregorcded4f62011-01-14 17:04:44 +00003189 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3190 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003191 if (Out.getArgument().isNull())
3192 return true;
3193
3194 Outputs.addArgument(Out);
3195 }
Douglas Gregord3731192011-01-10 07:32:04 +00003196
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003197 continue;
3198 }
3199
3200 // The simple case:
3201 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003202 return true;
3203
3204 Outputs.addArgument(Out);
3205 }
3206
3207 return false;
3208
3209}
3210
Douglas Gregor577f75a2009-08-04 16:50:30 +00003211//===----------------------------------------------------------------------===//
3212// Type transformation
3213//===----------------------------------------------------------------------===//
3214
3215template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003216QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003217 if (getDerived().AlreadyTransformed(T))
3218 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003219
John McCalla2becad2009-10-21 00:40:46 +00003220 // Temporary workaround. All of these transformations should
3221 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003222 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3223 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003224
John McCall43fed0d2010-11-12 08:19:04 +00003225 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003226
John McCalla2becad2009-10-21 00:40:46 +00003227 if (!NewDI)
3228 return QualType();
3229
3230 return NewDI->getType();
3231}
3232
3233template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003234TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003235 // Refine the base location to the type's location.
3236 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3237 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003238 if (getDerived().AlreadyTransformed(DI->getType()))
3239 return DI;
3240
3241 TypeLocBuilder TLB;
3242
3243 TypeLoc TL = DI->getTypeLoc();
3244 TLB.reserve(TL.getFullDataSize());
3245
John McCall43fed0d2010-11-12 08:19:04 +00003246 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003247 if (Result.isNull())
3248 return 0;
3249
John McCalla93c9342009-12-07 02:54:59 +00003250 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003251}
3252
3253template<typename Derived>
3254QualType
John McCall43fed0d2010-11-12 08:19:04 +00003255TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003256 switch (T.getTypeLocClass()) {
3257#define ABSTRACT_TYPELOC(CLASS, PARENT)
3258#define TYPELOC(CLASS, PARENT) \
3259 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003260 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003261#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003262 }
Mike Stump1eb44332009-09-09 15:08:12 +00003263
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003264 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003265}
3266
3267/// FIXME: By default, this routine adds type qualifiers only to types
3268/// that can have qualifiers, and silently suppresses those qualifiers
3269/// that are not permitted (e.g., qualifiers on reference or function
3270/// types). This is the right thing for template instantiation, but
3271/// probably not for other clients.
3272template<typename Derived>
3273QualType
3274TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003275 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003276 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003277
John McCall43fed0d2010-11-12 08:19:04 +00003278 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003279 if (Result.isNull())
3280 return QualType();
3281
3282 // Silently suppress qualifiers if the result type can't be qualified.
3283 // FIXME: this is the right thing for template instantiation, but
3284 // probably not for other clients.
3285 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003286 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003287
John McCallf85e1932011-06-15 23:02:42 +00003288 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003289 // resulting type.
3290 if (Quals.hasObjCLifetime()) {
3291 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3292 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003293 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003294 // Objective-C ARC:
3295 // A lifetime qualifier applied to a substituted template parameter
3296 // overrides the lifetime qualifier from the template argument.
3297 if (const SubstTemplateTypeParmType *SubstTypeParam
3298 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3299 QualType Replacement = SubstTypeParam->getReplacementType();
3300 Qualifiers Qs = Replacement.getQualifiers();
3301 Qs.removeObjCLifetime();
3302 Replacement
3303 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3304 Qs);
3305 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3306 SubstTypeParam->getReplacedParameter(),
3307 Replacement);
3308 TLB.TypeWasModifiedSafely(Result);
3309 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003310 // Otherwise, complain about the addition of a qualifier to an
3311 // already-qualified type.
3312 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003313 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003314 << Result << R;
3315
Douglas Gregore559ca12011-06-17 22:11:49 +00003316 Quals.removeObjCLifetime();
3317 }
3318 }
3319 }
John McCall28654742010-06-05 06:41:15 +00003320 if (!Quals.empty()) {
3321 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3322 TLB.push<QualifiedTypeLoc>(Result);
3323 // No location information to preserve.
3324 }
John McCalla2becad2009-10-21 00:40:46 +00003325
3326 return Result;
3327}
3328
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003329template<typename Derived>
3330TypeLoc
3331TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3332 QualType ObjectType,
3333 NamedDecl *UnqualLookup,
3334 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003335 QualType T = TL.getType();
3336 if (getDerived().AlreadyTransformed(T))
3337 return TL;
3338
3339 TypeLocBuilder TLB;
3340 QualType Result;
3341
3342 if (isa<TemplateSpecializationType>(T)) {
3343 TemplateSpecializationTypeLoc SpecTL
3344 = cast<TemplateSpecializationTypeLoc>(TL);
3345
3346 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003347 getDerived().TransformTemplateName(SS,
3348 SpecTL.getTypePtr()->getTemplateName(),
3349 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003350 ObjectType, UnqualLookup);
3351 if (Template.isNull())
3352 return TypeLoc();
3353
3354 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3355 Template);
3356 } else if (isa<DependentTemplateSpecializationType>(T)) {
3357 DependentTemplateSpecializationTypeLoc SpecTL
3358 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3359
Douglas Gregora88f09f2011-02-28 17:23:35 +00003360 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003361 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003362 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003363 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003364 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003365 if (Template.isNull())
3366 return TypeLoc();
3367
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003368 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003369 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003370 Template,
3371 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003372 } else {
3373 // Nothing special needs to be done for these.
3374 Result = getDerived().TransformType(TLB, TL);
3375 }
3376
3377 if (Result.isNull())
3378 return TypeLoc();
3379
3380 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3381}
3382
Douglas Gregorb71d8212011-03-02 18:32:08 +00003383template<typename Derived>
3384TypeSourceInfo *
3385TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3386 QualType ObjectType,
3387 NamedDecl *UnqualLookup,
3388 CXXScopeSpec &SS) {
3389 // FIXME: Painfully copy-paste from the above!
3390
3391 QualType T = TSInfo->getType();
3392 if (getDerived().AlreadyTransformed(T))
3393 return TSInfo;
3394
3395 TypeLocBuilder TLB;
3396 QualType Result;
3397
3398 TypeLoc TL = TSInfo->getTypeLoc();
3399 if (isa<TemplateSpecializationType>(T)) {
3400 TemplateSpecializationTypeLoc SpecTL
3401 = cast<TemplateSpecializationTypeLoc>(TL);
3402
3403 TemplateName Template
3404 = getDerived().TransformTemplateName(SS,
3405 SpecTL.getTypePtr()->getTemplateName(),
3406 SpecTL.getTemplateNameLoc(),
3407 ObjectType, UnqualLookup);
3408 if (Template.isNull())
3409 return 0;
3410
3411 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3412 Template);
3413 } else if (isa<DependentTemplateSpecializationType>(T)) {
3414 DependentTemplateSpecializationTypeLoc SpecTL
3415 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3416
3417 TemplateName Template
3418 = getDerived().RebuildTemplateName(SS,
3419 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003420 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003421 ObjectType, UnqualLookup);
3422 if (Template.isNull())
3423 return 0;
3424
3425 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3426 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003427 Template,
3428 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003429 } else {
3430 // Nothing special needs to be done for these.
3431 Result = getDerived().TransformType(TLB, TL);
3432 }
3433
3434 if (Result.isNull())
3435 return 0;
3436
3437 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3438}
3439
John McCalla2becad2009-10-21 00:40:46 +00003440template <class TyLoc> static inline
3441QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3442 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3443 NewT.setNameLoc(T.getNameLoc());
3444 return T.getType();
3445}
3446
John McCalla2becad2009-10-21 00:40:46 +00003447template<typename Derived>
3448QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003449 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003450 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3451 NewT.setBuiltinLoc(T.getBuiltinLoc());
3452 if (T.needsExtraLocalData())
3453 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3454 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003455}
Mike Stump1eb44332009-09-09 15:08:12 +00003456
Douglas Gregor577f75a2009-08-04 16:50:30 +00003457template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003458QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003459 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003460 // FIXME: recurse?
3461 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003462}
Mike Stump1eb44332009-09-09 15:08:12 +00003463
Douglas Gregor577f75a2009-08-04 16:50:30 +00003464template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003465QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003466 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003467 QualType PointeeType
3468 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003469 if (PointeeType.isNull())
3470 return QualType();
3471
3472 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003473 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003474 // A dependent pointer type 'T *' has is being transformed such
3475 // that an Objective-C class type is being replaced for 'T'. The
3476 // resulting pointer type is an ObjCObjectPointerType, not a
3477 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003478 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003479
John McCallc12c5bb2010-05-15 11:32:37 +00003480 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3481 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003482 return Result;
3483 }
John McCall43fed0d2010-11-12 08:19:04 +00003484
Douglas Gregor92e986e2010-04-22 16:44:27 +00003485 if (getDerived().AlwaysRebuild() ||
3486 PointeeType != TL.getPointeeLoc().getType()) {
3487 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3488 if (Result.isNull())
3489 return QualType();
3490 }
John McCallf85e1932011-06-15 23:02:42 +00003491
3492 // Objective-C ARC can add lifetime qualifiers to the type that we're
3493 // pointing to.
3494 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3495
Douglas Gregor92e986e2010-04-22 16:44:27 +00003496 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3497 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003498 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003499}
Mike Stump1eb44332009-09-09 15:08:12 +00003500
3501template<typename Derived>
3502QualType
John McCalla2becad2009-10-21 00:40:46 +00003503TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003504 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003505 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003506 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3507 if (PointeeType.isNull())
3508 return QualType();
3509
3510 QualType Result = TL.getType();
3511 if (getDerived().AlwaysRebuild() ||
3512 PointeeType != TL.getPointeeLoc().getType()) {
3513 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003514 TL.getSigilLoc());
3515 if (Result.isNull())
3516 return QualType();
3517 }
3518
Douglas Gregor39968ad2010-04-22 16:50:51 +00003519 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003520 NewT.setSigilLoc(TL.getSigilLoc());
3521 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003522}
3523
John McCall85737a72009-10-30 00:06:24 +00003524/// Transforms a reference type. Note that somewhat paradoxically we
3525/// don't care whether the type itself is an l-value type or an r-value
3526/// type; we only care if the type was *written* as an l-value type
3527/// or an r-value type.
3528template<typename Derived>
3529QualType
3530TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003531 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003532 const ReferenceType *T = TL.getTypePtr();
3533
3534 // Note that this works with the pointee-as-written.
3535 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3536 if (PointeeType.isNull())
3537 return QualType();
3538
3539 QualType Result = TL.getType();
3540 if (getDerived().AlwaysRebuild() ||
3541 PointeeType != T->getPointeeTypeAsWritten()) {
3542 Result = getDerived().RebuildReferenceType(PointeeType,
3543 T->isSpelledAsLValue(),
3544 TL.getSigilLoc());
3545 if (Result.isNull())
3546 return QualType();
3547 }
3548
John McCallf85e1932011-06-15 23:02:42 +00003549 // Objective-C ARC can add lifetime qualifiers to the type that we're
3550 // referring to.
3551 TLB.TypeWasModifiedSafely(
3552 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3553
John McCall85737a72009-10-30 00:06:24 +00003554 // r-value references can be rebuilt as l-value references.
3555 ReferenceTypeLoc NewTL;
3556 if (isa<LValueReferenceType>(Result))
3557 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3558 else
3559 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3560 NewTL.setSigilLoc(TL.getSigilLoc());
3561
3562 return Result;
3563}
3564
Mike Stump1eb44332009-09-09 15:08:12 +00003565template<typename Derived>
3566QualType
John McCalla2becad2009-10-21 00:40:46 +00003567TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003568 LValueReferenceTypeLoc TL) {
3569 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003570}
3571
Mike Stump1eb44332009-09-09 15:08:12 +00003572template<typename Derived>
3573QualType
John McCalla2becad2009-10-21 00:40:46 +00003574TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003575 RValueReferenceTypeLoc TL) {
3576 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003577}
Mike Stump1eb44332009-09-09 15:08:12 +00003578
Douglas Gregor577f75a2009-08-04 16:50:30 +00003579template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003580QualType
John McCalla2becad2009-10-21 00:40:46 +00003581TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003582 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003583 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003584 if (PointeeType.isNull())
3585 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003586
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003587 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3588 TypeSourceInfo* NewClsTInfo = 0;
3589 if (OldClsTInfo) {
3590 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3591 if (!NewClsTInfo)
3592 return QualType();
3593 }
3594
3595 const MemberPointerType *T = TL.getTypePtr();
3596 QualType OldClsType = QualType(T->getClass(), 0);
3597 QualType NewClsType;
3598 if (NewClsTInfo)
3599 NewClsType = NewClsTInfo->getType();
3600 else {
3601 NewClsType = getDerived().TransformType(OldClsType);
3602 if (NewClsType.isNull())
3603 return QualType();
3604 }
Mike Stump1eb44332009-09-09 15:08:12 +00003605
John McCalla2becad2009-10-21 00:40:46 +00003606 QualType Result = TL.getType();
3607 if (getDerived().AlwaysRebuild() ||
3608 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003609 NewClsType != OldClsType) {
3610 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003611 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003612 if (Result.isNull())
3613 return QualType();
3614 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003615
John McCalla2becad2009-10-21 00:40:46 +00003616 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3617 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003618 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003619
3620 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003621}
3622
Mike Stump1eb44332009-09-09 15:08:12 +00003623template<typename Derived>
3624QualType
John McCalla2becad2009-10-21 00:40:46 +00003625TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003626 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003627 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003628 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003629 if (ElementType.isNull())
3630 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003631
John McCalla2becad2009-10-21 00:40:46 +00003632 QualType Result = TL.getType();
3633 if (getDerived().AlwaysRebuild() ||
3634 ElementType != T->getElementType()) {
3635 Result = getDerived().RebuildConstantArrayType(ElementType,
3636 T->getSizeModifier(),
3637 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003638 T->getIndexTypeCVRQualifiers(),
3639 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003640 if (Result.isNull())
3641 return QualType();
3642 }
Eli Friedman457a3772012-01-25 22:19:07 +00003643
3644 // We might have either a ConstantArrayType or a VariableArrayType now:
3645 // a ConstantArrayType is allowed to have an element type which is a
3646 // VariableArrayType if the type is dependent. Fortunately, all array
3647 // types have the same location layout.
3648 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003649 NewTL.setLBracketLoc(TL.getLBracketLoc());
3650 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003651
John McCalla2becad2009-10-21 00:40:46 +00003652 Expr *Size = TL.getSizeExpr();
3653 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003654 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3655 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003656 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3657 }
3658 NewTL.setSizeExpr(Size);
3659
3660 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003661}
Mike Stump1eb44332009-09-09 15:08:12 +00003662
Douglas Gregor577f75a2009-08-04 16:50:30 +00003663template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003664QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003665 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003666 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003667 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003668 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003669 if (ElementType.isNull())
3670 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003671
John McCalla2becad2009-10-21 00:40:46 +00003672 QualType Result = TL.getType();
3673 if (getDerived().AlwaysRebuild() ||
3674 ElementType != T->getElementType()) {
3675 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003676 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003677 T->getIndexTypeCVRQualifiers(),
3678 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003679 if (Result.isNull())
3680 return QualType();
3681 }
Sean Huntc3021132010-05-05 15:23:54 +00003682
John McCalla2becad2009-10-21 00:40:46 +00003683 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3684 NewTL.setLBracketLoc(TL.getLBracketLoc());
3685 NewTL.setRBracketLoc(TL.getRBracketLoc());
3686 NewTL.setSizeExpr(0);
3687
3688 return Result;
3689}
3690
3691template<typename Derived>
3692QualType
3693TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003694 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003695 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003696 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3697 if (ElementType.isNull())
3698 return QualType();
3699
John McCall60d7b3a2010-08-24 06:29:42 +00003700 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003701 = getDerived().TransformExpr(T->getSizeExpr());
3702 if (SizeResult.isInvalid())
3703 return QualType();
3704
John McCall9ae2f072010-08-23 23:25:46 +00003705 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003706
3707 QualType Result = TL.getType();
3708 if (getDerived().AlwaysRebuild() ||
3709 ElementType != T->getElementType() ||
3710 Size != T->getSizeExpr()) {
3711 Result = getDerived().RebuildVariableArrayType(ElementType,
3712 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003713 Size,
John McCalla2becad2009-10-21 00:40:46 +00003714 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003715 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003716 if (Result.isNull())
3717 return QualType();
3718 }
Sean Huntc3021132010-05-05 15:23:54 +00003719
John McCalla2becad2009-10-21 00:40:46 +00003720 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3721 NewTL.setLBracketLoc(TL.getLBracketLoc());
3722 NewTL.setRBracketLoc(TL.getRBracketLoc());
3723 NewTL.setSizeExpr(Size);
3724
3725 return Result;
3726}
3727
3728template<typename Derived>
3729QualType
3730TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003731 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003732 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003733 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3734 if (ElementType.isNull())
3735 return QualType();
3736
Richard Smithf6702a32011-12-20 02:08:33 +00003737 // Array bounds are constant expressions.
3738 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3739 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003740
John McCall3b657512011-01-19 10:06:00 +00003741 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3742 Expr *origSize = TL.getSizeExpr();
3743 if (!origSize) origSize = T->getSizeExpr();
3744
3745 ExprResult sizeResult
3746 = getDerived().TransformExpr(origSize);
3747 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003748 return QualType();
3749
John McCall3b657512011-01-19 10:06:00 +00003750 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003751
3752 QualType Result = TL.getType();
3753 if (getDerived().AlwaysRebuild() ||
3754 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003755 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003756 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3757 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003758 size,
John McCalla2becad2009-10-21 00:40:46 +00003759 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003760 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003761 if (Result.isNull())
3762 return QualType();
3763 }
John McCalla2becad2009-10-21 00:40:46 +00003764
3765 // We might have any sort of array type now, but fortunately they
3766 // all have the same location layout.
3767 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3768 NewTL.setLBracketLoc(TL.getLBracketLoc());
3769 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003770 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003771
3772 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003773}
Mike Stump1eb44332009-09-09 15:08:12 +00003774
3775template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003776QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003777 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003778 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003779 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003780
3781 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003782 QualType ElementType = getDerived().TransformType(T->getElementType());
3783 if (ElementType.isNull())
3784 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003785
Richard Smithf6702a32011-12-20 02:08:33 +00003786 // Vector sizes are constant expressions.
3787 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3788 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003789
John McCall60d7b3a2010-08-24 06:29:42 +00003790 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003791 if (Size.isInvalid())
3792 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003793
John McCalla2becad2009-10-21 00:40:46 +00003794 QualType Result = TL.getType();
3795 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003796 ElementType != T->getElementType() ||
3797 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003798 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003799 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003800 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003801 if (Result.isNull())
3802 return QualType();
3803 }
John McCalla2becad2009-10-21 00:40:46 +00003804
3805 // Result might be dependent or not.
3806 if (isa<DependentSizedExtVectorType>(Result)) {
3807 DependentSizedExtVectorTypeLoc NewTL
3808 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3809 NewTL.setNameLoc(TL.getNameLoc());
3810 } else {
3811 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3812 NewTL.setNameLoc(TL.getNameLoc());
3813 }
3814
3815 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003816}
Mike Stump1eb44332009-09-09 15:08:12 +00003817
3818template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003819QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003820 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003821 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003822 QualType ElementType = getDerived().TransformType(T->getElementType());
3823 if (ElementType.isNull())
3824 return QualType();
3825
John McCalla2becad2009-10-21 00:40:46 +00003826 QualType Result = TL.getType();
3827 if (getDerived().AlwaysRebuild() ||
3828 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003829 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003830 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003831 if (Result.isNull())
3832 return QualType();
3833 }
Sean Huntc3021132010-05-05 15:23:54 +00003834
John McCalla2becad2009-10-21 00:40:46 +00003835 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3836 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003837
John McCalla2becad2009-10-21 00:40:46 +00003838 return Result;
3839}
3840
3841template<typename Derived>
3842QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003843 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003844 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003845 QualType ElementType = getDerived().TransformType(T->getElementType());
3846 if (ElementType.isNull())
3847 return QualType();
3848
3849 QualType Result = TL.getType();
3850 if (getDerived().AlwaysRebuild() ||
3851 ElementType != T->getElementType()) {
3852 Result = getDerived().RebuildExtVectorType(ElementType,
3853 T->getNumElements(),
3854 /*FIXME*/ SourceLocation());
3855 if (Result.isNull())
3856 return QualType();
3857 }
Sean Huntc3021132010-05-05 15:23:54 +00003858
John McCalla2becad2009-10-21 00:40:46 +00003859 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3860 NewTL.setNameLoc(TL.getNameLoc());
3861
3862 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003863}
Mike Stump1eb44332009-09-09 15:08:12 +00003864
3865template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003866ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003867TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003868 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003869 llvm::Optional<unsigned> NumExpansions,
3870 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003871 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003872 TypeSourceInfo *NewDI = 0;
3873
3874 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3875 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003876 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003877 TypeLoc OldTL = OldDI->getTypeLoc();
3878 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3879
3880 TypeLocBuilder TLB;
3881 TypeLoc NewTL = OldDI->getTypeLoc();
3882 TLB.reserve(NewTL.getFullDataSize());
3883
3884 QualType Result = getDerived().TransformType(TLB,
3885 OldExpansionTL.getPatternLoc());
3886 if (Result.isNull())
3887 return 0;
3888
3889 Result = RebuildPackExpansionType(Result,
3890 OldExpansionTL.getPatternLoc().getSourceRange(),
3891 OldExpansionTL.getEllipsisLoc(),
3892 NumExpansions);
3893 if (Result.isNull())
3894 return 0;
3895
3896 PackExpansionTypeLoc NewExpansionTL
3897 = TLB.push<PackExpansionTypeLoc>(Result);
3898 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3899 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3900 } else
3901 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003902 if (!NewDI)
3903 return 0;
3904
John McCallfb44de92011-05-01 22:35:37 +00003905 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003906 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003907
3908 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3909 OldParm->getDeclContext(),
3910 OldParm->getInnerLocStart(),
3911 OldParm->getLocation(),
3912 OldParm->getIdentifier(),
3913 NewDI->getType(),
3914 NewDI,
3915 OldParm->getStorageClass(),
3916 OldParm->getStorageClassAsWritten(),
3917 /* DefArg */ NULL);
3918 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3919 OldParm->getFunctionScopeIndex() + indexAdjustment);
3920 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003921}
3922
3923template<typename Derived>
3924bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003925 TransformFunctionTypeParams(SourceLocation Loc,
3926 ParmVarDecl **Params, unsigned NumParams,
3927 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003928 SmallVectorImpl<QualType> &OutParamTypes,
3929 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003930 int indexAdjustment = 0;
3931
Douglas Gregora009b592011-01-07 00:20:55 +00003932 for (unsigned i = 0; i != NumParams; ++i) {
3933 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003934 assert(OldParm->getFunctionScopeIndex() == i);
3935
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003936 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003937 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003938 if (OldParm->isParameterPack()) {
3939 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003940 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003941
Douglas Gregor603cfb42011-01-05 23:12:31 +00003942 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003943 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3944 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3945 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3946 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003947 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3948
Douglas Gregor603cfb42011-01-05 23:12:31 +00003949 // Determine whether we should expand the parameter packs.
3950 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003951 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003952 llvm::Optional<unsigned> OrigNumExpansions
3953 = ExpansionTL.getTypePtr()->getNumExpansions();
3954 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003955 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3956 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003957 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003958 ShouldExpand,
3959 RetainExpansion,
3960 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003961 return true;
3962 }
3963
3964 if (ShouldExpand) {
3965 // Expand the function parameter pack into multiple, separate
3966 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003967 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003968 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003969 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3970 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003971 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003972 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003973 OrigNumExpansions,
3974 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003975 if (!NewParm)
3976 return true;
3977
Douglas Gregora009b592011-01-07 00:20:55 +00003978 OutParamTypes.push_back(NewParm->getType());
3979 if (PVars)
3980 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003981 }
Douglas Gregord3731192011-01-10 07:32:04 +00003982
3983 // If we're supposed to retain a pack expansion, do so by temporarily
3984 // forgetting the partially-substituted parameter pack.
3985 if (RetainExpansion) {
3986 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3987 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003988 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003989 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003990 OrigNumExpansions,
3991 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00003992 if (!NewParm)
3993 return true;
3994
3995 OutParamTypes.push_back(NewParm->getType());
3996 if (PVars)
3997 PVars->push_back(NewParm);
3998 }
3999
John McCallfb44de92011-05-01 22:35:37 +00004000 // The next parameter should have the same adjustment as the
4001 // last thing we pushed, but we post-incremented indexAdjustment
4002 // on every push. Also, if we push nothing, the adjustment should
4003 // go down by one.
4004 indexAdjustment--;
4005
Douglas Gregor603cfb42011-01-05 23:12:31 +00004006 // We're done with the pack expansion.
4007 continue;
4008 }
4009
4010 // We'll substitute the parameter now without expanding the pack
4011 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004012 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4013 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004014 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004015 NumExpansions,
4016 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004017 } else {
4018 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004019 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004020 llvm::Optional<unsigned>(),
4021 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004022 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004023
John McCall21ef0fa2010-03-11 09:03:00 +00004024 if (!NewParm)
4025 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004026
Douglas Gregora009b592011-01-07 00:20:55 +00004027 OutParamTypes.push_back(NewParm->getType());
4028 if (PVars)
4029 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004030 continue;
4031 }
John McCall21ef0fa2010-03-11 09:03:00 +00004032
4033 // Deal with the possibility that we don't have a parameter
4034 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004035 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004036 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004037 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004038 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004039 if (const PackExpansionType *Expansion
4040 = dyn_cast<PackExpansionType>(OldType)) {
4041 // We have a function parameter pack that may need to be expanded.
4042 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004043 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004044 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4045
4046 // Determine whether we should expand the parameter packs.
4047 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004048 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004049 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004050 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004051 ShouldExpand,
4052 RetainExpansion,
4053 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004054 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004055 }
4056
4057 if (ShouldExpand) {
4058 // Expand the function parameter pack into multiple, separate
4059 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004060 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004061 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4062 QualType NewType = getDerived().TransformType(Pattern);
4063 if (NewType.isNull())
4064 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004065
Douglas Gregora009b592011-01-07 00:20:55 +00004066 OutParamTypes.push_back(NewType);
4067 if (PVars)
4068 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004069 }
4070
4071 // We're done with the pack expansion.
4072 continue;
4073 }
4074
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004075 // If we're supposed to retain a pack expansion, do so by temporarily
4076 // forgetting the partially-substituted parameter pack.
4077 if (RetainExpansion) {
4078 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4079 QualType NewType = getDerived().TransformType(Pattern);
4080 if (NewType.isNull())
4081 return true;
4082
4083 OutParamTypes.push_back(NewType);
4084 if (PVars)
4085 PVars->push_back(0);
4086 }
Douglas Gregord3731192011-01-10 07:32:04 +00004087
Douglas Gregor603cfb42011-01-05 23:12:31 +00004088 // We'll substitute the parameter now without expanding the pack
4089 // expansion.
4090 OldType = Expansion->getPattern();
4091 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004092 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4093 NewType = getDerived().TransformType(OldType);
4094 } else {
4095 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004096 }
4097
Douglas Gregor603cfb42011-01-05 23:12:31 +00004098 if (NewType.isNull())
4099 return true;
4100
4101 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004102 NewType = getSema().Context.getPackExpansionType(NewType,
4103 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004104
Douglas Gregora009b592011-01-07 00:20:55 +00004105 OutParamTypes.push_back(NewType);
4106 if (PVars)
4107 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004108 }
4109
John McCallfb44de92011-05-01 22:35:37 +00004110#ifndef NDEBUG
4111 if (PVars) {
4112 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4113 if (ParmVarDecl *parm = (*PVars)[i])
4114 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004115 }
John McCallfb44de92011-05-01 22:35:37 +00004116#endif
4117
4118 return false;
4119}
John McCall21ef0fa2010-03-11 09:03:00 +00004120
4121template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004122QualType
John McCalla2becad2009-10-21 00:40:46 +00004123TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004124 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004125 // Transform the parameters and return type.
4126 //
4127 // We instantiate in source order, with the return type first followed by
4128 // the parameters, because users tend to expect this (even if they shouldn't
4129 // rely on it!).
4130 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004131 // When the function has a trailing return type, we instantiate the
4132 // parameters before the return type, since the return type can then refer
4133 // to the parameters themselves (via decltype, sizeof, etc.).
4134 //
Chris Lattner686775d2011-07-20 06:58:45 +00004135 SmallVector<QualType, 4> ParamTypes;
4136 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004137 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004138
Douglas Gregordab60ad2010-10-01 18:44:50 +00004139 QualType ResultType;
4140
4141 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004142 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4143 TL.getParmArray(),
4144 TL.getNumArgs(),
4145 TL.getTypePtr()->arg_type_begin(),
4146 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004147 return QualType();
4148
4149 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4150 if (ResultType.isNull())
4151 return QualType();
4152 }
4153 else {
4154 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4155 if (ResultType.isNull())
4156 return QualType();
4157
Douglas Gregora009b592011-01-07 00:20:55 +00004158 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4159 TL.getParmArray(),
4160 TL.getNumArgs(),
4161 TL.getTypePtr()->arg_type_begin(),
4162 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004163 return QualType();
4164 }
4165
John McCalla2becad2009-10-21 00:40:46 +00004166 QualType Result = TL.getType();
4167 if (getDerived().AlwaysRebuild() ||
4168 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004169 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004170 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4171 Result = getDerived().RebuildFunctionProtoType(ResultType,
4172 ParamTypes.data(),
4173 ParamTypes.size(),
4174 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004175 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004176 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004177 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004178 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004179 if (Result.isNull())
4180 return QualType();
4181 }
Mike Stump1eb44332009-09-09 15:08:12 +00004182
John McCalla2becad2009-10-21 00:40:46 +00004183 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004184 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4185 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004186 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004187 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4188 NewTL.setArg(i, ParamDecls[i]);
4189
4190 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004191}
Mike Stump1eb44332009-09-09 15:08:12 +00004192
Douglas Gregor577f75a2009-08-04 16:50:30 +00004193template<typename Derived>
4194QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004195 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004196 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004197 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004198 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4199 if (ResultType.isNull())
4200 return QualType();
4201
4202 QualType Result = TL.getType();
4203 if (getDerived().AlwaysRebuild() ||
4204 ResultType != T->getResultType())
4205 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4206
4207 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004208 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4209 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004210 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004211
4212 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004213}
Mike Stump1eb44332009-09-09 15:08:12 +00004214
John McCalled976492009-12-04 22:46:56 +00004215template<typename Derived> QualType
4216TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004217 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004218 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004219 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004220 if (!D)
4221 return QualType();
4222
4223 QualType Result = TL.getType();
4224 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4225 Result = getDerived().RebuildUnresolvedUsingType(D);
4226 if (Result.isNull())
4227 return QualType();
4228 }
4229
4230 // We might get an arbitrary type spec type back. We should at
4231 // least always get a type spec type, though.
4232 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4233 NewTL.setNameLoc(TL.getNameLoc());
4234
4235 return Result;
4236}
4237
Douglas Gregor577f75a2009-08-04 16:50:30 +00004238template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004239QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004240 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004241 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004242 TypedefNameDecl *Typedef
4243 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4244 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004245 if (!Typedef)
4246 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004247
John McCalla2becad2009-10-21 00:40:46 +00004248 QualType Result = TL.getType();
4249 if (getDerived().AlwaysRebuild() ||
4250 Typedef != T->getDecl()) {
4251 Result = getDerived().RebuildTypedefType(Typedef);
4252 if (Result.isNull())
4253 return QualType();
4254 }
Mike Stump1eb44332009-09-09 15:08:12 +00004255
John McCalla2becad2009-10-21 00:40:46 +00004256 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4257 NewTL.setNameLoc(TL.getNameLoc());
4258
4259 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004260}
Mike Stump1eb44332009-09-09 15:08:12 +00004261
Douglas Gregor577f75a2009-08-04 16:50:30 +00004262template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004263QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004264 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004265 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004266 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004267
John McCall60d7b3a2010-08-24 06:29:42 +00004268 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004269 if (E.isInvalid())
4270 return QualType();
4271
John McCalla2becad2009-10-21 00:40:46 +00004272 QualType Result = TL.getType();
4273 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004274 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004275 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004276 if (Result.isNull())
4277 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004278 }
John McCalla2becad2009-10-21 00:40:46 +00004279 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004280
John McCalla2becad2009-10-21 00:40:46 +00004281 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004282 NewTL.setTypeofLoc(TL.getTypeofLoc());
4283 NewTL.setLParenLoc(TL.getLParenLoc());
4284 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004285
4286 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004287}
Mike Stump1eb44332009-09-09 15:08:12 +00004288
4289template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004290QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004291 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004292 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4293 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4294 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004295 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004296
John McCalla2becad2009-10-21 00:40:46 +00004297 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004298 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4299 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004300 if (Result.isNull())
4301 return QualType();
4302 }
Mike Stump1eb44332009-09-09 15:08:12 +00004303
John McCalla2becad2009-10-21 00:40:46 +00004304 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004305 NewTL.setTypeofLoc(TL.getTypeofLoc());
4306 NewTL.setLParenLoc(TL.getLParenLoc());
4307 NewTL.setRParenLoc(TL.getRParenLoc());
4308 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004309
4310 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004311}
Mike Stump1eb44332009-09-09 15:08:12 +00004312
4313template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004314QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004315 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004316 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004317
Douglas Gregor670444e2009-08-04 22:27:00 +00004318 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004319 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4320 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004321
John McCall60d7b3a2010-08-24 06:29:42 +00004322 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004323 if (E.isInvalid())
4324 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004325
Richard Smith76f3f692012-02-22 02:04:18 +00004326 E = getSema().ActOnDecltypeExpression(E.take());
4327 if (E.isInvalid())
4328 return QualType();
4329
John McCalla2becad2009-10-21 00:40:46 +00004330 QualType Result = TL.getType();
4331 if (getDerived().AlwaysRebuild() ||
4332 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004333 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004334 if (Result.isNull())
4335 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004336 }
John McCalla2becad2009-10-21 00:40:46 +00004337 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004338
John McCalla2becad2009-10-21 00:40:46 +00004339 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4340 NewTL.setNameLoc(TL.getNameLoc());
4341
4342 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004343}
4344
4345template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004346QualType TreeTransform<Derived>::TransformUnaryTransformType(
4347 TypeLocBuilder &TLB,
4348 UnaryTransformTypeLoc TL) {
4349 QualType Result = TL.getType();
4350 if (Result->isDependentType()) {
4351 const UnaryTransformType *T = TL.getTypePtr();
4352 QualType NewBase =
4353 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4354 Result = getDerived().RebuildUnaryTransformType(NewBase,
4355 T->getUTTKind(),
4356 TL.getKWLoc());
4357 if (Result.isNull())
4358 return QualType();
4359 }
4360
4361 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4362 NewTL.setKWLoc(TL.getKWLoc());
4363 NewTL.setParensRange(TL.getParensRange());
4364 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4365 return Result;
4366}
4367
4368template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004369QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4370 AutoTypeLoc TL) {
4371 const AutoType *T = TL.getTypePtr();
4372 QualType OldDeduced = T->getDeducedType();
4373 QualType NewDeduced;
4374 if (!OldDeduced.isNull()) {
4375 NewDeduced = getDerived().TransformType(OldDeduced);
4376 if (NewDeduced.isNull())
4377 return QualType();
4378 }
4379
4380 QualType Result = TL.getType();
4381 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4382 Result = getDerived().RebuildAutoType(NewDeduced);
4383 if (Result.isNull())
4384 return QualType();
4385 }
4386
4387 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4388 NewTL.setNameLoc(TL.getNameLoc());
4389
4390 return Result;
4391}
4392
4393template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004394QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004395 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004396 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004397 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004398 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4399 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004400 if (!Record)
4401 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004402
John McCalla2becad2009-10-21 00:40:46 +00004403 QualType Result = TL.getType();
4404 if (getDerived().AlwaysRebuild() ||
4405 Record != T->getDecl()) {
4406 Result = getDerived().RebuildRecordType(Record);
4407 if (Result.isNull())
4408 return QualType();
4409 }
Mike Stump1eb44332009-09-09 15:08:12 +00004410
John McCalla2becad2009-10-21 00:40:46 +00004411 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4412 NewTL.setNameLoc(TL.getNameLoc());
4413
4414 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004415}
Mike Stump1eb44332009-09-09 15:08:12 +00004416
4417template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004418QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004419 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004420 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004421 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004422 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4423 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004424 if (!Enum)
4425 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004426
John McCalla2becad2009-10-21 00:40:46 +00004427 QualType Result = TL.getType();
4428 if (getDerived().AlwaysRebuild() ||
4429 Enum != T->getDecl()) {
4430 Result = getDerived().RebuildEnumType(Enum);
4431 if (Result.isNull())
4432 return QualType();
4433 }
Mike Stump1eb44332009-09-09 15:08:12 +00004434
John McCalla2becad2009-10-21 00:40:46 +00004435 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4436 NewTL.setNameLoc(TL.getNameLoc());
4437
4438 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004439}
John McCall7da24312009-09-05 00:15:47 +00004440
John McCall3cb0ebd2010-03-10 03:28:59 +00004441template<typename Derived>
4442QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4443 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004444 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004445 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4446 TL.getTypePtr()->getDecl());
4447 if (!D) return QualType();
4448
4449 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4450 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4451 return T;
4452}
4453
Douglas Gregor577f75a2009-08-04 16:50:30 +00004454template<typename Derived>
4455QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004456 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004457 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004458 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004459}
4460
Mike Stump1eb44332009-09-09 15:08:12 +00004461template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004462QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004463 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004464 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004465 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4466
4467 // Substitute into the replacement type, which itself might involve something
4468 // that needs to be transformed. This only tends to occur with default
4469 // template arguments of template template parameters.
4470 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4471 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4472 if (Replacement.isNull())
4473 return QualType();
4474
4475 // Always canonicalize the replacement type.
4476 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4477 QualType Result
4478 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4479 Replacement);
4480
4481 // Propagate type-source information.
4482 SubstTemplateTypeParmTypeLoc NewTL
4483 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4484 NewTL.setNameLoc(TL.getNameLoc());
4485 return Result;
4486
John McCall49a832b2009-10-18 09:09:24 +00004487}
4488
4489template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004490QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4491 TypeLocBuilder &TLB,
4492 SubstTemplateTypeParmPackTypeLoc TL) {
4493 return TransformTypeSpecType(TLB, TL);
4494}
4495
4496template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004497QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004498 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004499 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004500 const TemplateSpecializationType *T = TL.getTypePtr();
4501
Douglas Gregor1d752d72011-03-02 18:46:51 +00004502 // The nested-name-specifier never matters in a TemplateSpecializationType,
4503 // because we can't have a dependent nested-name-specifier anyway.
4504 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004505 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004506 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4507 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004508 if (Template.isNull())
4509 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004510
John McCall43fed0d2010-11-12 08:19:04 +00004511 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4512}
4513
Eli Friedmanb001de72011-10-06 23:00:33 +00004514template<typename Derived>
4515QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4516 AtomicTypeLoc TL) {
4517 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4518 if (ValueType.isNull())
4519 return QualType();
4520
4521 QualType Result = TL.getType();
4522 if (getDerived().AlwaysRebuild() ||
4523 ValueType != TL.getValueLoc().getType()) {
4524 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4525 if (Result.isNull())
4526 return QualType();
4527 }
4528
4529 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4530 NewTL.setKWLoc(TL.getKWLoc());
4531 NewTL.setLParenLoc(TL.getLParenLoc());
4532 NewTL.setRParenLoc(TL.getRParenLoc());
4533
4534 return Result;
4535}
4536
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004537namespace {
4538 /// \brief Simple iterator that traverses the template arguments in a
4539 /// container that provides a \c getArgLoc() member function.
4540 ///
4541 /// This iterator is intended to be used with the iterator form of
4542 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4543 template<typename ArgLocContainer>
4544 class TemplateArgumentLocContainerIterator {
4545 ArgLocContainer *Container;
4546 unsigned Index;
4547
4548 public:
4549 typedef TemplateArgumentLoc value_type;
4550 typedef TemplateArgumentLoc reference;
4551 typedef int difference_type;
4552 typedef std::input_iterator_tag iterator_category;
4553
4554 class pointer {
4555 TemplateArgumentLoc Arg;
4556
4557 public:
4558 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4559
4560 const TemplateArgumentLoc *operator->() const {
4561 return &Arg;
4562 }
4563 };
4564
4565
4566 TemplateArgumentLocContainerIterator() {}
4567
4568 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4569 unsigned Index)
4570 : Container(&Container), Index(Index) { }
4571
4572 TemplateArgumentLocContainerIterator &operator++() {
4573 ++Index;
4574 return *this;
4575 }
4576
4577 TemplateArgumentLocContainerIterator operator++(int) {
4578 TemplateArgumentLocContainerIterator Old(*this);
4579 ++(*this);
4580 return Old;
4581 }
4582
4583 TemplateArgumentLoc operator*() const {
4584 return Container->getArgLoc(Index);
4585 }
4586
4587 pointer operator->() const {
4588 return pointer(Container->getArgLoc(Index));
4589 }
4590
4591 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004592 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004593 return X.Container == Y.Container && X.Index == Y.Index;
4594 }
4595
4596 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004597 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004598 return !(X == Y);
4599 }
4600 };
4601}
4602
4603
John McCall43fed0d2010-11-12 08:19:04 +00004604template <typename Derived>
4605QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4606 TypeLocBuilder &TLB,
4607 TemplateSpecializationTypeLoc TL,
4608 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004609 TemplateArgumentListInfo NewTemplateArgs;
4610 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4611 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004612 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4613 ArgIterator;
4614 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4615 ArgIterator(TL, TL.getNumArgs()),
4616 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004617 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004618
John McCall833ca992009-10-29 08:12:44 +00004619 // FIXME: maybe don't rebuild if all the template arguments are the same.
4620
4621 QualType Result =
4622 getDerived().RebuildTemplateSpecializationType(Template,
4623 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004624 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004625
4626 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004627 // Specializations of template template parameters are represented as
4628 // TemplateSpecializationTypes, and substitution of type alias templates
4629 // within a dependent context can transform them into
4630 // DependentTemplateSpecializationTypes.
4631 if (isa<DependentTemplateSpecializationType>(Result)) {
4632 DependentTemplateSpecializationTypeLoc NewTL
4633 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004634 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004635 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004636 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004637 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004638 NewTL.setLAngleLoc(TL.getLAngleLoc());
4639 NewTL.setRAngleLoc(TL.getRAngleLoc());
4640 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4641 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4642 return Result;
4643 }
4644
John McCall833ca992009-10-29 08:12:44 +00004645 TemplateSpecializationTypeLoc NewTL
4646 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004647 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004648 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4649 NewTL.setLAngleLoc(TL.getLAngleLoc());
4650 NewTL.setRAngleLoc(TL.getRAngleLoc());
4651 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4652 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004653 }
Mike Stump1eb44332009-09-09 15:08:12 +00004654
John McCall833ca992009-10-29 08:12:44 +00004655 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004656}
Mike Stump1eb44332009-09-09 15:08:12 +00004657
Douglas Gregora88f09f2011-02-28 17:23:35 +00004658template <typename Derived>
4659QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4660 TypeLocBuilder &TLB,
4661 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004662 TemplateName Template,
4663 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004664 TemplateArgumentListInfo NewTemplateArgs;
4665 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4666 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4667 typedef TemplateArgumentLocContainerIterator<
4668 DependentTemplateSpecializationTypeLoc> ArgIterator;
4669 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4670 ArgIterator(TL, TL.getNumArgs()),
4671 NewTemplateArgs))
4672 return QualType();
4673
4674 // FIXME: maybe don't rebuild if all the template arguments are the same.
4675
4676 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4677 QualType Result
4678 = getSema().Context.getDependentTemplateSpecializationType(
4679 TL.getTypePtr()->getKeyword(),
4680 DTN->getQualifier(),
4681 DTN->getIdentifier(),
4682 NewTemplateArgs);
4683
4684 DependentTemplateSpecializationTypeLoc NewTL
4685 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004686 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004687 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004688 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004689 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004690 NewTL.setLAngleLoc(TL.getLAngleLoc());
4691 NewTL.setRAngleLoc(TL.getRAngleLoc());
4692 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4693 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4694 return Result;
4695 }
4696
4697 QualType Result
4698 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004699 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004700 NewTemplateArgs);
4701
4702 if (!Result.isNull()) {
4703 /// FIXME: Wrap this in an elaborated-type-specifier?
4704 TemplateSpecializationTypeLoc NewTL
4705 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004706 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004707 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004708 NewTL.setLAngleLoc(TL.getLAngleLoc());
4709 NewTL.setRAngleLoc(TL.getRAngleLoc());
4710 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4711 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4712 }
4713
4714 return Result;
4715}
4716
Mike Stump1eb44332009-09-09 15:08:12 +00004717template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004718QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004719TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004720 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004721 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004722
Douglas Gregor9e876872011-03-01 18:12:44 +00004723 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004724 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004725 if (TL.getQualifierLoc()) {
4726 QualifierLoc
4727 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4728 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004729 return QualType();
4730 }
Mike Stump1eb44332009-09-09 15:08:12 +00004731
John McCall43fed0d2010-11-12 08:19:04 +00004732 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4733 if (NamedT.isNull())
4734 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004735
Richard Smith3e4c6c42011-05-05 21:57:07 +00004736 // C++0x [dcl.type.elab]p2:
4737 // If the identifier resolves to a typedef-name or the simple-template-id
4738 // resolves to an alias template specialization, the
4739 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004740 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4741 if (const TemplateSpecializationType *TST =
4742 NamedT->getAs<TemplateSpecializationType>()) {
4743 TemplateName Template = TST->getTemplateName();
4744 if (TypeAliasTemplateDecl *TAT =
4745 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4746 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4747 diag::err_tag_reference_non_tag) << 4;
4748 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4749 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004750 }
4751 }
4752
John McCalla2becad2009-10-21 00:40:46 +00004753 QualType Result = TL.getType();
4754 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004755 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004756 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004757 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004758 T->getKeyword(),
4759 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004760 if (Result.isNull())
4761 return QualType();
4762 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004763
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004764 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004765 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004766 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004767 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004768}
Mike Stump1eb44332009-09-09 15:08:12 +00004769
4770template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004771QualType TreeTransform<Derived>::TransformAttributedType(
4772 TypeLocBuilder &TLB,
4773 AttributedTypeLoc TL) {
4774 const AttributedType *oldType = TL.getTypePtr();
4775 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4776 if (modifiedType.isNull())
4777 return QualType();
4778
4779 QualType result = TL.getType();
4780
4781 // FIXME: dependent operand expressions?
4782 if (getDerived().AlwaysRebuild() ||
4783 modifiedType != oldType->getModifiedType()) {
4784 // TODO: this is really lame; we should really be rebuilding the
4785 // equivalent type from first principles.
4786 QualType equivalentType
4787 = getDerived().TransformType(oldType->getEquivalentType());
4788 if (equivalentType.isNull())
4789 return QualType();
4790 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4791 modifiedType,
4792 equivalentType);
4793 }
4794
4795 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4796 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4797 if (TL.hasAttrOperand())
4798 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4799 if (TL.hasAttrExprOperand())
4800 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4801 else if (TL.hasAttrEnumOperand())
4802 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4803
4804 return result;
4805}
4806
4807template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004808QualType
4809TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4810 ParenTypeLoc TL) {
4811 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4812 if (Inner.isNull())
4813 return QualType();
4814
4815 QualType Result = TL.getType();
4816 if (getDerived().AlwaysRebuild() ||
4817 Inner != TL.getInnerLoc().getType()) {
4818 Result = getDerived().RebuildParenType(Inner);
4819 if (Result.isNull())
4820 return QualType();
4821 }
4822
4823 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4824 NewTL.setLParenLoc(TL.getLParenLoc());
4825 NewTL.setRParenLoc(TL.getRParenLoc());
4826 return Result;
4827}
4828
4829template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004830QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004831 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004832 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004833
Douglas Gregor2494dd02011-03-01 01:34:45 +00004834 NestedNameSpecifierLoc QualifierLoc
4835 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4836 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004837 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004838
John McCall33500952010-06-11 00:33:02 +00004839 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004840 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004841 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004842 QualifierLoc,
4843 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004844 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004845 if (Result.isNull())
4846 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004847
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004848 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4849 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004850 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4851
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004852 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004853 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004854 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004855 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004856 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004857 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004858 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004859 NewTL.setNameLoc(TL.getNameLoc());
4860 }
John McCalla2becad2009-10-21 00:40:46 +00004861 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004862}
Mike Stump1eb44332009-09-09 15:08:12 +00004863
Douglas Gregor577f75a2009-08-04 16:50:30 +00004864template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004865QualType TreeTransform<Derived>::
4866 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004867 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004868 NestedNameSpecifierLoc QualifierLoc;
4869 if (TL.getQualifierLoc()) {
4870 QualifierLoc
4871 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4872 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004873 return QualType();
4874 }
4875
John McCall43fed0d2010-11-12 08:19:04 +00004876 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004877 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004878}
4879
4880template<typename Derived>
4881QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004882TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4883 DependentTemplateSpecializationTypeLoc TL,
4884 NestedNameSpecifierLoc QualifierLoc) {
4885 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4886
4887 TemplateArgumentListInfo NewTemplateArgs;
4888 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4889 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4890
4891 typedef TemplateArgumentLocContainerIterator<
4892 DependentTemplateSpecializationTypeLoc> ArgIterator;
4893 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4894 ArgIterator(TL, TL.getNumArgs()),
4895 NewTemplateArgs))
4896 return QualType();
4897
4898 QualType Result
4899 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4900 QualifierLoc,
4901 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004902 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004903 NewTemplateArgs);
4904 if (Result.isNull())
4905 return QualType();
4906
4907 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4908 QualType NamedT = ElabT->getNamedType();
4909
4910 // Copy information relevant to the template specialization.
4911 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004912 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004913 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004914 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004915 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4916 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004917 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004918 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004919
4920 // Copy information relevant to the elaborated type.
4921 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004922 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004923 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004924 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4925 DependentTemplateSpecializationTypeLoc SpecTL
4926 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004927 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004928 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004929 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004930 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004931 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4932 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004933 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004934 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004935 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004936 TemplateSpecializationTypeLoc SpecTL
4937 = TLB.push<TemplateSpecializationTypeLoc>(Result);
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 }
4945 return Result;
4946}
4947
4948template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004949QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4950 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004951 QualType Pattern
4952 = getDerived().TransformType(TLB, TL.getPatternLoc());
4953 if (Pattern.isNull())
4954 return QualType();
4955
4956 QualType Result = TL.getType();
4957 if (getDerived().AlwaysRebuild() ||
4958 Pattern != TL.getPatternLoc().getType()) {
4959 Result = getDerived().RebuildPackExpansionType(Pattern,
4960 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004961 TL.getEllipsisLoc(),
4962 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004963 if (Result.isNull())
4964 return QualType();
4965 }
4966
4967 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4968 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4969 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004970}
4971
4972template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004973QualType
4974TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004975 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004976 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004977 TLB.pushFullCopy(TL);
4978 return TL.getType();
4979}
4980
4981template<typename Derived>
4982QualType
4983TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004984 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004985 // ObjCObjectType is never dependent.
4986 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004987 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004988}
Mike Stump1eb44332009-09-09 15:08:12 +00004989
4990template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004991QualType
4992TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004993 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004994 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004995 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004996 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004997}
4998
Douglas Gregor577f75a2009-08-04 16:50:30 +00004999//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005000// Statement transformation
5001//===----------------------------------------------------------------------===//
5002template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005003StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005004TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005005 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005006}
5007
5008template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005009StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005010TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5011 return getDerived().TransformCompoundStmt(S, false);
5012}
5013
5014template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005015StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005016TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005017 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005018 Sema::CompoundScopeRAII CompoundScope(getSema());
5019
John McCall7114cba2010-08-27 19:56:05 +00005020 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005021 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005022 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005023 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5024 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005025 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005026 if (Result.isInvalid()) {
5027 // Immediately fail if this was a DeclStmt, since it's very
5028 // likely that this will cause problems for future statements.
5029 if (isa<DeclStmt>(*B))
5030 return StmtError();
5031
5032 // Otherwise, just keep processing substatements and fail later.
5033 SubStmtInvalid = true;
5034 continue;
5035 }
Mike Stump1eb44332009-09-09 15:08:12 +00005036
Douglas Gregor43959a92009-08-20 07:17:43 +00005037 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5038 Statements.push_back(Result.takeAs<Stmt>());
5039 }
Mike Stump1eb44332009-09-09 15:08:12 +00005040
John McCall7114cba2010-08-27 19:56:05 +00005041 if (SubStmtInvalid)
5042 return StmtError();
5043
Douglas Gregor43959a92009-08-20 07:17:43 +00005044 if (!getDerived().AlwaysRebuild() &&
5045 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005046 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005047
5048 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5049 move_arg(Statements),
5050 S->getRBracLoc(),
5051 IsStmtExpr);
5052}
Mike Stump1eb44332009-09-09 15:08:12 +00005053
Douglas Gregor43959a92009-08-20 07:17:43 +00005054template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005055StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005056TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005057 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005058 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005059 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5060 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005061
Eli Friedman264c1f82009-11-19 03:14:00 +00005062 // Transform the left-hand case value.
5063 LHS = getDerived().TransformExpr(S->getLHS());
5064 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005065 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005066
Eli Friedman264c1f82009-11-19 03:14:00 +00005067 // Transform the right-hand case value (for the GNU case-range extension).
5068 RHS = getDerived().TransformExpr(S->getRHS());
5069 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005070 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005071 }
Mike Stump1eb44332009-09-09 15:08:12 +00005072
Douglas Gregor43959a92009-08-20 07:17:43 +00005073 // Build the case statement.
5074 // Case statements are always rebuilt so that they will attached to their
5075 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005076 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005077 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005078 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005079 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005080 S->getColonLoc());
5081 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005082 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005083
Douglas Gregor43959a92009-08-20 07:17:43 +00005084 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005085 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005086 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005087 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005088
Douglas Gregor43959a92009-08-20 07:17:43 +00005089 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005090 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005091}
5092
5093template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005094StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005095TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005096 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005097 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005098 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005099 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005100
Douglas Gregor43959a92009-08-20 07:17:43 +00005101 // Default statements are always rebuilt
5102 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005103 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005104}
Mike Stump1eb44332009-09-09 15:08:12 +00005105
Douglas Gregor43959a92009-08-20 07:17:43 +00005106template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005107StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005108TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005109 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005110 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005111 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005112
Chris Lattner57ad3782011-02-17 20:34:02 +00005113 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5114 S->getDecl());
5115 if (!LD)
5116 return StmtError();
5117
5118
Douglas Gregor43959a92009-08-20 07:17:43 +00005119 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005120 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005121 cast<LabelDecl>(LD), SourceLocation(),
5122 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005123}
Mike Stump1eb44332009-09-09 15:08:12 +00005124
Douglas Gregor43959a92009-08-20 07:17:43 +00005125template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005126StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005127TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005128 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005129 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005130 VarDecl *ConditionVar = 0;
5131 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005132 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005133 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005134 getDerived().TransformDefinition(
5135 S->getConditionVariable()->getLocation(),
5136 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005137 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005138 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005139 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005140 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005141
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005142 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005143 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005144
5145 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005146 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005147 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5148 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005149 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005150 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005151
John McCall9ae2f072010-08-23 23:25:46 +00005152 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005153 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005154 }
Sean Huntc3021132010-05-05 15:23:54 +00005155
John McCall9ae2f072010-08-23 23:25:46 +00005156 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5157 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005158 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005159
Douglas Gregor43959a92009-08-20 07:17:43 +00005160 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005161 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005162 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005163 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005164
Douglas Gregor43959a92009-08-20 07:17:43 +00005165 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005166 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005167 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005168 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005169
Douglas Gregor43959a92009-08-20 07:17:43 +00005170 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005171 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005172 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005173 Then.get() == S->getThen() &&
5174 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005175 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005176
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005177 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005178 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005179 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005180}
5181
5182template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005183StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005184TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005185 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005186 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005187 VarDecl *ConditionVar = 0;
5188 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005189 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005190 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005191 getDerived().TransformDefinition(
5192 S->getConditionVariable()->getLocation(),
5193 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005194 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005195 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005196 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005197 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005198
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005199 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005200 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005201 }
Mike Stump1eb44332009-09-09 15:08:12 +00005202
Douglas Gregor43959a92009-08-20 07:17:43 +00005203 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005204 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005205 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005206 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005207 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005208 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Douglas Gregor43959a92009-08-20 07:17:43 +00005210 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005211 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005212 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005213 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005214
Douglas Gregor43959a92009-08-20 07:17:43 +00005215 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005216 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5217 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005218}
Mike Stump1eb44332009-09-09 15:08:12 +00005219
Douglas Gregor43959a92009-08-20 07:17:43 +00005220template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005221StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005222TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005223 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005224 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005225 VarDecl *ConditionVar = 0;
5226 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005227 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005228 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005229 getDerived().TransformDefinition(
5230 S->getConditionVariable()->getLocation(),
5231 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005232 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005233 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005234 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005235 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005236
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005237 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005238 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005239
5240 if (S->getCond()) {
5241 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005242 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5243 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005244 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005245 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005246 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005247 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005248 }
Mike Stump1eb44332009-09-09 15:08:12 +00005249
John McCall9ae2f072010-08-23 23:25:46 +00005250 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5251 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005252 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005253
Douglas Gregor43959a92009-08-20 07:17:43 +00005254 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005255 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005256 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005257 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005258
Douglas Gregor43959a92009-08-20 07:17:43 +00005259 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005260 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005261 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005262 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005263 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005264
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005265 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005266 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005267}
Mike Stump1eb44332009-09-09 15:08:12 +00005268
Douglas Gregor43959a92009-08-20 07:17:43 +00005269template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005270StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005271TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005272 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005273 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005274 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005275 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005276
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005277 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005278 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005279 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005280 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005281
Douglas Gregor43959a92009-08-20 07:17:43 +00005282 if (!getDerived().AlwaysRebuild() &&
5283 Cond.get() == S->getCond() &&
5284 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005285 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005286
John McCall9ae2f072010-08-23 23:25:46 +00005287 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5288 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005289 S->getRParenLoc());
5290}
Mike Stump1eb44332009-09-09 15:08:12 +00005291
Douglas Gregor43959a92009-08-20 07:17:43 +00005292template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005293StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005294TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005295 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005296 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005297 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005298 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005299
Douglas Gregor43959a92009-08-20 07:17:43 +00005300 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005301 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005302 VarDecl *ConditionVar = 0;
5303 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005304 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005305 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005306 getDerived().TransformDefinition(
5307 S->getConditionVariable()->getLocation(),
5308 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005309 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005310 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005311 } else {
5312 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005313
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005314 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005315 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005316
5317 if (S->getCond()) {
5318 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005319 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5320 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005321 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005322 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005323
John McCall9ae2f072010-08-23 23:25:46 +00005324 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005325 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005326 }
Mike Stump1eb44332009-09-09 15:08:12 +00005327
John McCall9ae2f072010-08-23 23:25:46 +00005328 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5329 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005330 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005331
Douglas Gregor43959a92009-08-20 07:17:43 +00005332 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005333 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005334 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005335 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005336
John McCall9ae2f072010-08-23 23:25:46 +00005337 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5338 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005339 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005340
Douglas Gregor43959a92009-08-20 07:17:43 +00005341 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005342 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005343 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005344 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005345
Douglas Gregor43959a92009-08-20 07:17:43 +00005346 if (!getDerived().AlwaysRebuild() &&
5347 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005348 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005349 Inc.get() == S->getInc() &&
5350 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005351 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005352
Douglas Gregor43959a92009-08-20 07:17:43 +00005353 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005354 Init.get(), FullCond, ConditionVar,
5355 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005356}
5357
5358template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005359StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005360TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005361 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5362 S->getLabel());
5363 if (!LD)
5364 return StmtError();
5365
Douglas Gregor43959a92009-08-20 07:17:43 +00005366 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005367 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005368 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005369}
5370
5371template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005372StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005373TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005374 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005375 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005376 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005377 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005378
Douglas Gregor43959a92009-08-20 07:17:43 +00005379 if (!getDerived().AlwaysRebuild() &&
5380 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005381 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005382
5383 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005384 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005385}
5386
5387template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005388StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005389TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005390 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005391}
Mike Stump1eb44332009-09-09 15:08:12 +00005392
Douglas Gregor43959a92009-08-20 07:17:43 +00005393template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005394StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005395TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005396 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005397}
Mike Stump1eb44332009-09-09 15:08:12 +00005398
Douglas Gregor43959a92009-08-20 07:17:43 +00005399template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005400StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005401TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005402 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005403 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005404 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005405
Mike Stump1eb44332009-09-09 15:08:12 +00005406 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005407 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005408 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005409}
Mike Stump1eb44332009-09-09 15:08:12 +00005410
Douglas Gregor43959a92009-08-20 07:17:43 +00005411template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005412StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005413TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005415 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005416 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5417 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005418 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5419 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005420 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005421 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005422
Douglas Gregor43959a92009-08-20 07:17:43 +00005423 if (Transformed != *D)
5424 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005425
Douglas Gregor43959a92009-08-20 07:17:43 +00005426 Decls.push_back(Transformed);
5427 }
Mike Stump1eb44332009-09-09 15:08:12 +00005428
Douglas Gregor43959a92009-08-20 07:17:43 +00005429 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005430 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005431
5432 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005433 S->getStartLoc(), S->getEndLoc());
5434}
Mike Stump1eb44332009-09-09 15:08:12 +00005435
Douglas Gregor43959a92009-08-20 07:17:43 +00005436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005437StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005438TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005439
John McCallca0408f2010-08-23 06:44:23 +00005440 ASTOwningVector<Expr*> Constraints(getSema());
5441 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005442 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005443
John McCall60d7b3a2010-08-24 06:29:42 +00005444 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005445 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005446
5447 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005448
Anders Carlsson703e3942010-01-24 05:50:09 +00005449 // Go through the outputs.
5450 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005451 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005452
Anders Carlsson703e3942010-01-24 05:50:09 +00005453 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005454 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005455
Anders Carlsson703e3942010-01-24 05:50:09 +00005456 // Transform the output expr.
5457 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005458 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005459 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005460 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005461
Anders Carlsson703e3942010-01-24 05:50:09 +00005462 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005463
John McCall9ae2f072010-08-23 23:25:46 +00005464 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005465 }
Sean Huntc3021132010-05-05 15:23:54 +00005466
Anders Carlsson703e3942010-01-24 05:50:09 +00005467 // Go through the inputs.
5468 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005469 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005470
Anders Carlsson703e3942010-01-24 05:50:09 +00005471 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005472 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005473
Anders Carlsson703e3942010-01-24 05:50:09 +00005474 // Transform the input expr.
5475 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005476 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005477 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005478 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005479
Anders Carlsson703e3942010-01-24 05:50:09 +00005480 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005481
John McCall9ae2f072010-08-23 23:25:46 +00005482 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005483 }
Sean Huntc3021132010-05-05 15:23:54 +00005484
Anders Carlsson703e3942010-01-24 05:50:09 +00005485 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005486 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005487
5488 // Go through the clobbers.
5489 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005490 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005491
5492 // No need to transform the asm string literal.
5493 AsmString = SemaRef.Owned(S->getAsmString());
5494
5495 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5496 S->isSimple(),
5497 S->isVolatile(),
5498 S->getNumOutputs(),
5499 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005500 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005501 move_arg(Constraints),
5502 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005503 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005504 move_arg(Clobbers),
5505 S->getRParenLoc(),
5506 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005507}
5508
5509
5510template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005511StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005512TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005513 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005514 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005515 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005516 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005517
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005518 // Transform the @catch statements (if present).
5519 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005520 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005521 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005522 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005523 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005524 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005525 if (Catch.get() != S->getCatchStmt(I))
5526 AnyCatchChanged = true;
5527 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005528 }
Sean Huntc3021132010-05-05 15:23:54 +00005529
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005530 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005531 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005532 if (S->getFinallyStmt()) {
5533 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5534 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005535 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005536 }
5537
5538 // If nothing changed, just retain this statement.
5539 if (!getDerived().AlwaysRebuild() &&
5540 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005541 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005542 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005543 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005544
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005545 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005546 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5547 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005548}
Mike Stump1eb44332009-09-09 15:08:12 +00005549
Douglas Gregor43959a92009-08-20 07:17:43 +00005550template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005551StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005552TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005553 // Transform the @catch parameter, if there is one.
5554 VarDecl *Var = 0;
5555 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5556 TypeSourceInfo *TSInfo = 0;
5557 if (FromVar->getTypeSourceInfo()) {
5558 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5559 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005560 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005561 }
Sean Huntc3021132010-05-05 15:23:54 +00005562
Douglas Gregorbe270a02010-04-26 17:57:08 +00005563 QualType T;
5564 if (TSInfo)
5565 T = TSInfo->getType();
5566 else {
5567 T = getDerived().TransformType(FromVar->getType());
5568 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005569 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005570 }
Sean Huntc3021132010-05-05 15:23:54 +00005571
Douglas Gregorbe270a02010-04-26 17:57:08 +00005572 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5573 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005574 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005575 }
Sean Huntc3021132010-05-05 15:23:54 +00005576
John McCall60d7b3a2010-08-24 06:29:42 +00005577 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005578 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005579 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005580
5581 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005582 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005583 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005584}
Mike Stump1eb44332009-09-09 15:08:12 +00005585
Douglas Gregor43959a92009-08-20 07:17:43 +00005586template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005587StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005588TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005589 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005590 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005591 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005592 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005593
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005594 // If nothing changed, just retain this statement.
5595 if (!getDerived().AlwaysRebuild() &&
5596 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005597 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005598
5599 // Build a new statement.
5600 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005601 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005602}
Mike Stump1eb44332009-09-09 15:08:12 +00005603
Douglas Gregor43959a92009-08-20 07:17:43 +00005604template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005605StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005606TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005607 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005608 if (S->getThrowExpr()) {
5609 Operand = getDerived().TransformExpr(S->getThrowExpr());
5610 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005611 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005612 }
Sean Huntc3021132010-05-05 15:23:54 +00005613
Douglas Gregord1377b22010-04-22 21:44:01 +00005614 if (!getDerived().AlwaysRebuild() &&
5615 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005616 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005617
John McCall9ae2f072010-08-23 23:25:46 +00005618 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005619}
Mike Stump1eb44332009-09-09 15:08:12 +00005620
Douglas Gregor43959a92009-08-20 07:17:43 +00005621template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005622StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005623TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005624 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005625 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005626 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005627 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005628 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005629 Object =
5630 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5631 Object.get());
5632 if (Object.isInvalid())
5633 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005634
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005635 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005636 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005637 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005638 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005639
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005640 // If nothing change, just retain the current statement.
5641 if (!getDerived().AlwaysRebuild() &&
5642 Object.get() == S->getSynchExpr() &&
5643 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005644 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005645
5646 // Build a new statement.
5647 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005648 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005649}
5650
5651template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005652StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005653TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5654 ObjCAutoreleasePoolStmt *S) {
5655 // Transform the body.
5656 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5657 if (Body.isInvalid())
5658 return StmtError();
5659
5660 // If nothing changed, just retain this statement.
5661 if (!getDerived().AlwaysRebuild() &&
5662 Body.get() == S->getSubStmt())
5663 return SemaRef.Owned(S);
5664
5665 // Build a new statement.
5666 return getDerived().RebuildObjCAutoreleasePoolStmt(
5667 S->getAtLoc(), Body.get());
5668}
5669
5670template<typename Derived>
5671StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005672TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005673 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005674 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005675 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005676 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005677 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005678
Douglas Gregorc3203e72010-04-22 23:10:45 +00005679 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005680 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005681 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005682 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005683 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5684 Collection.take());
5685 if (Collection.isInvalid())
5686 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005687
Douglas Gregorc3203e72010-04-22 23:10:45 +00005688 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005689 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005690 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005691 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005692
Douglas Gregorc3203e72010-04-22 23:10:45 +00005693 // If nothing changed, just retain this statement.
5694 if (!getDerived().AlwaysRebuild() &&
5695 Element.get() == S->getElement() &&
5696 Collection.get() == S->getCollection() &&
5697 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005698 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005699
Douglas Gregorc3203e72010-04-22 23:10:45 +00005700 // Build a new statement.
5701 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5702 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005703 Element.get(),
5704 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005705 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005706 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005707}
5708
5709
5710template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005711StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005712TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5713 // Transform the exception declaration, if any.
5714 VarDecl *Var = 0;
5715 if (S->getExceptionDecl()) {
5716 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005717 TypeSourceInfo *T = getDerived().TransformType(
5718 ExceptionDecl->getTypeSourceInfo());
5719 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005720 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005721
Douglas Gregor83cb9422010-09-09 17:09:21 +00005722 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005723 ExceptionDecl->getInnerLocStart(),
5724 ExceptionDecl->getLocation(),
5725 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005726 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005727 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005728 }
Mike Stump1eb44332009-09-09 15:08:12 +00005729
Douglas Gregor43959a92009-08-20 07:17:43 +00005730 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005731 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005732 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005733 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005734
Douglas Gregor43959a92009-08-20 07:17:43 +00005735 if (!getDerived().AlwaysRebuild() &&
5736 !Var &&
5737 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005738 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005739
5740 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5741 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005742 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005743}
Mike Stump1eb44332009-09-09 15:08:12 +00005744
Douglas Gregor43959a92009-08-20 07:17:43 +00005745template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005746StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005747TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5748 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005749 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005750 = getDerived().TransformCompoundStmt(S->getTryBlock());
5751 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005752 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005753
Douglas Gregor43959a92009-08-20 07:17:43 +00005754 // Transform the handlers.
5755 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005756 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005757 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005758 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005759 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5760 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005761 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005762
Douglas Gregor43959a92009-08-20 07:17:43 +00005763 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5764 Handlers.push_back(Handler.takeAs<Stmt>());
5765 }
Mike Stump1eb44332009-09-09 15:08:12 +00005766
Douglas Gregor43959a92009-08-20 07:17:43 +00005767 if (!getDerived().AlwaysRebuild() &&
5768 TryBlock.get() == S->getTryBlock() &&
5769 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005770 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005771
John McCall9ae2f072010-08-23 23:25:46 +00005772 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005773 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005774}
Mike Stump1eb44332009-09-09 15:08:12 +00005775
Richard Smithad762fc2011-04-14 22:09:26 +00005776template<typename Derived>
5777StmtResult
5778TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5779 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5780 if (Range.isInvalid())
5781 return StmtError();
5782
5783 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5784 if (BeginEnd.isInvalid())
5785 return StmtError();
5786
5787 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5788 if (Cond.isInvalid())
5789 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005790 if (Cond.get())
5791 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5792 if (Cond.isInvalid())
5793 return StmtError();
5794 if (Cond.get())
5795 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005796
5797 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5798 if (Inc.isInvalid())
5799 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005800 if (Inc.get())
5801 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005802
5803 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5804 if (LoopVar.isInvalid())
5805 return StmtError();
5806
5807 StmtResult NewStmt = S;
5808 if (getDerived().AlwaysRebuild() ||
5809 Range.get() != S->getRangeStmt() ||
5810 BeginEnd.get() != S->getBeginEndStmt() ||
5811 Cond.get() != S->getCond() ||
5812 Inc.get() != S->getInc() ||
5813 LoopVar.get() != S->getLoopVarStmt())
5814 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5815 S->getColonLoc(), Range.get(),
5816 BeginEnd.get(), Cond.get(),
5817 Inc.get(), LoopVar.get(),
5818 S->getRParenLoc());
5819
5820 StmtResult Body = getDerived().TransformStmt(S->getBody());
5821 if (Body.isInvalid())
5822 return StmtError();
5823
5824 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5825 // it now so we have a new statement to attach the body to.
5826 if (Body.get() != S->getBody() && NewStmt.get() == S)
5827 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5828 S->getColonLoc(), Range.get(),
5829 BeginEnd.get(), Cond.get(),
5830 Inc.get(), LoopVar.get(),
5831 S->getRParenLoc());
5832
5833 if (NewStmt.get() == S)
5834 return SemaRef.Owned(S);
5835
5836 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5837}
5838
John Wiegley28bbe4b2011-04-28 01:08:34 +00005839template<typename Derived>
5840StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005841TreeTransform<Derived>::TransformMSDependentExistsStmt(
5842 MSDependentExistsStmt *S) {
5843 // Transform the nested-name-specifier, if any.
5844 NestedNameSpecifierLoc QualifierLoc;
5845 if (S->getQualifierLoc()) {
5846 QualifierLoc
5847 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5848 if (!QualifierLoc)
5849 return StmtError();
5850 }
5851
5852 // Transform the declaration name.
5853 DeclarationNameInfo NameInfo = S->getNameInfo();
5854 if (NameInfo.getName()) {
5855 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5856 if (!NameInfo.getName())
5857 return StmtError();
5858 }
5859
5860 // Check whether anything changed.
5861 if (!getDerived().AlwaysRebuild() &&
5862 QualifierLoc == S->getQualifierLoc() &&
5863 NameInfo.getName() == S->getNameInfo().getName())
5864 return S;
5865
5866 // Determine whether this name exists, if we can.
5867 CXXScopeSpec SS;
5868 SS.Adopt(QualifierLoc);
5869 bool Dependent = false;
5870 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5871 case Sema::IER_Exists:
5872 if (S->isIfExists())
5873 break;
5874
5875 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5876
5877 case Sema::IER_DoesNotExist:
5878 if (S->isIfNotExists())
5879 break;
5880
5881 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5882
5883 case Sema::IER_Dependent:
5884 Dependent = true;
5885 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005886
5887 case Sema::IER_Error:
5888 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005889 }
5890
5891 // We need to continue with the instantiation, so do so now.
5892 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5893 if (SubStmt.isInvalid())
5894 return StmtError();
5895
5896 // If we have resolved the name, just transform to the substatement.
5897 if (!Dependent)
5898 return SubStmt;
5899
5900 // The name is still dependent, so build a dependent expression again.
5901 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5902 S->isIfExists(),
5903 QualifierLoc,
5904 NameInfo,
5905 SubStmt.get());
5906}
5907
5908template<typename Derived>
5909StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005910TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5911 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5912 if(TryBlock.isInvalid()) return StmtError();
5913
5914 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5915 if(!getDerived().AlwaysRebuild() &&
5916 TryBlock.get() == S->getTryBlock() &&
5917 Handler.get() == S->getHandler())
5918 return SemaRef.Owned(S);
5919
5920 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5921 S->getTryLoc(),
5922 TryBlock.take(),
5923 Handler.take());
5924}
5925
5926template<typename Derived>
5927StmtResult
5928TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5929 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5930 if(Block.isInvalid()) return StmtError();
5931
5932 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5933 Block.take());
5934}
5935
5936template<typename Derived>
5937StmtResult
5938TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5939 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5940 if(FilterExpr.isInvalid()) return StmtError();
5941
5942 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5943 if(Block.isInvalid()) return StmtError();
5944
5945 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5946 FilterExpr.take(),
5947 Block.take());
5948}
5949
5950template<typename Derived>
5951StmtResult
5952TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5953 if(isa<SEHFinallyStmt>(Handler))
5954 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5955 else
5956 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5957}
5958
Douglas Gregor43959a92009-08-20 07:17:43 +00005959//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005960// Expression transformation
5961//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005962template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005963ExprResult
John McCall454feb92009-12-08 09:21:05 +00005964TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005965 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005966}
Mike Stump1eb44332009-09-09 15:08:12 +00005967
5968template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005969ExprResult
John McCall454feb92009-12-08 09:21:05 +00005970TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005971 NestedNameSpecifierLoc QualifierLoc;
5972 if (E->getQualifierLoc()) {
5973 QualifierLoc
5974 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5975 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005976 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005977 }
John McCalldbd872f2009-12-08 09:08:17 +00005978
5979 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005980 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5981 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005982 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005983 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005984
John McCallec8045d2010-08-17 21:27:17 +00005985 DeclarationNameInfo NameInfo = E->getNameInfo();
5986 if (NameInfo.getName()) {
5987 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5988 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005989 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005990 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005991
5992 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005993 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005994 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005995 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005996 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005997
5998 // Mark it referenced in the new context regardless.
5999 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006000 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006001
John McCall3fa5cae2010-10-26 07:05:15 +00006002 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006003 }
John McCalldbd872f2009-12-08 09:08:17 +00006004
6005 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006006 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006007 TemplateArgs = &TransArgs;
6008 TransArgs.setLAngleLoc(E->getLAngleLoc());
6009 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006010 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6011 E->getNumTemplateArgs(),
6012 TransArgs))
6013 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006014 }
6015
Douglas Gregor40d96a62011-02-28 21:54:11 +00006016 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6017 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006018}
Mike Stump1eb44332009-09-09 15:08:12 +00006019
Douglas Gregorb98b1992009-08-11 05:31:07 +00006020template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006021ExprResult
John McCall454feb92009-12-08 09:21:05 +00006022TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006023 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006024}
Mike Stump1eb44332009-09-09 15:08:12 +00006025
Douglas Gregorb98b1992009-08-11 05:31:07 +00006026template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006027ExprResult
John McCall454feb92009-12-08 09:21:05 +00006028TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006029 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006030}
Mike Stump1eb44332009-09-09 15:08:12 +00006031
Douglas Gregorb98b1992009-08-11 05:31:07 +00006032template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006033ExprResult
John McCall454feb92009-12-08 09:21:05 +00006034TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006035 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006036}
Mike Stump1eb44332009-09-09 15:08:12 +00006037
Douglas Gregorb98b1992009-08-11 05:31:07 +00006038template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006039ExprResult
John McCall454feb92009-12-08 09:21:05 +00006040TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006041 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006042}
Mike Stump1eb44332009-09-09 15:08:12 +00006043
Douglas Gregorb98b1992009-08-11 05:31:07 +00006044template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006045ExprResult
John McCall454feb92009-12-08 09:21:05 +00006046TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006047 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006048}
6049
6050template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006051ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006052TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6053 ExprResult ControllingExpr =
6054 getDerived().TransformExpr(E->getControllingExpr());
6055 if (ControllingExpr.isInvalid())
6056 return ExprError();
6057
Chris Lattner686775d2011-07-20 06:58:45 +00006058 SmallVector<Expr *, 4> AssocExprs;
6059 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006060 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6061 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6062 if (TS) {
6063 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6064 if (!AssocType)
6065 return ExprError();
6066 AssocTypes.push_back(AssocType);
6067 } else {
6068 AssocTypes.push_back(0);
6069 }
6070
6071 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6072 if (AssocExpr.isInvalid())
6073 return ExprError();
6074 AssocExprs.push_back(AssocExpr.release());
6075 }
6076
6077 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6078 E->getDefaultLoc(),
6079 E->getRParenLoc(),
6080 ControllingExpr.release(),
6081 AssocTypes.data(),
6082 AssocExprs.data(),
6083 E->getNumAssocs());
6084}
6085
6086template<typename Derived>
6087ExprResult
John McCall454feb92009-12-08 09:21:05 +00006088TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006089 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006090 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006091 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006092
Douglas Gregorb98b1992009-08-11 05:31:07 +00006093 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006094 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006095
John McCall9ae2f072010-08-23 23:25:46 +00006096 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006097 E->getRParen());
6098}
6099
Mike Stump1eb44332009-09-09 15:08:12 +00006100template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006101ExprResult
John McCall454feb92009-12-08 09:21:05 +00006102TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006103 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006104 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006105 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006106
Douglas Gregorb98b1992009-08-11 05:31:07 +00006107 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006108 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006109
Douglas Gregorb98b1992009-08-11 05:31:07 +00006110 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6111 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006112 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006113}
Mike Stump1eb44332009-09-09 15:08:12 +00006114
Douglas Gregorb98b1992009-08-11 05:31:07 +00006115template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006116ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006117TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6118 // Transform the type.
6119 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6120 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006121 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006122
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006123 // Transform all of the components into components similar to what the
6124 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006125 // FIXME: It would be slightly more efficient in the non-dependent case to
6126 // just map FieldDecls, rather than requiring the rebuilder to look for
6127 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006128 // template code that we don't care.
6129 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006130 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006131 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006132 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006133 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6134 const Node &ON = E->getComponent(I);
6135 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006136 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006137 Comp.LocStart = ON.getSourceRange().getBegin();
6138 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006139 switch (ON.getKind()) {
6140 case Node::Array: {
6141 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006142 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006143 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006144 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006145
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006146 ExprChanged = ExprChanged || Index.get() != FromIndex;
6147 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006148 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006149 break;
6150 }
Sean Huntc3021132010-05-05 15:23:54 +00006151
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006152 case Node::Field:
6153 case Node::Identifier:
6154 Comp.isBrackets = false;
6155 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006156 if (!Comp.U.IdentInfo)
6157 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006158
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006159 break;
Sean Huntc3021132010-05-05 15:23:54 +00006160
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006161 case Node::Base:
6162 // Will be recomputed during the rebuild.
6163 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006164 }
Sean Huntc3021132010-05-05 15:23:54 +00006165
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006166 Components.push_back(Comp);
6167 }
Sean Huntc3021132010-05-05 15:23:54 +00006168
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006169 // If nothing changed, retain the existing expression.
6170 if (!getDerived().AlwaysRebuild() &&
6171 Type == E->getTypeSourceInfo() &&
6172 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006173 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006174
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006175 // Build a new offsetof expression.
6176 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6177 Components.data(), Components.size(),
6178 E->getRParenLoc());
6179}
6180
6181template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006182ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006183TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6184 assert(getDerived().AlreadyTransformed(E->getType()) &&
6185 "opaque value expression requires transformation");
6186 return SemaRef.Owned(E);
6187}
6188
6189template<typename Derived>
6190ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006191TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006192 // Rebuild the syntactic form. The original syntactic form has
6193 // opaque-value expressions in it, so strip those away and rebuild
6194 // the result. This is a really awful way of doing this, but the
6195 // better solution (rebuilding the semantic expressions and
6196 // rebinding OVEs as necessary) doesn't work; we'd need
6197 // TreeTransform to not strip away implicit conversions.
6198 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6199 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006200 if (result.isInvalid()) return ExprError();
6201
6202 // If that gives us a pseudo-object result back, the pseudo-object
6203 // expression must have been an lvalue-to-rvalue conversion which we
6204 // should reapply.
6205 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6206 result = SemaRef.checkPseudoObjectRValue(result.take());
6207
6208 return result;
6209}
6210
6211template<typename Derived>
6212ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006213TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6214 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006216 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006217
John McCalla93c9342009-12-07 02:54:59 +00006218 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006219 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006220 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006221
John McCall5ab75172009-11-04 07:28:41 +00006222 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006223 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006224
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006225 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6226 E->getKind(),
6227 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006228 }
Mike Stump1eb44332009-09-09 15:08:12 +00006229
John McCall60d7b3a2010-08-24 06:29:42 +00006230 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00006231 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006232 // C++0x [expr.sizeof]p1:
6233 // The operand is either an expression, which is an unevaluated operand
6234 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00006235 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006236
Douglas Gregorb98b1992009-08-11 05:31:07 +00006237 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6238 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006239 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006240
Douglas Gregorb98b1992009-08-11 05:31:07 +00006241 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006242 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006243 }
Mike Stump1eb44332009-09-09 15:08:12 +00006244
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006245 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6246 E->getOperatorLoc(),
6247 E->getKind(),
6248 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006249}
Mike Stump1eb44332009-09-09 15:08:12 +00006250
Douglas Gregorb98b1992009-08-11 05:31:07 +00006251template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006252ExprResult
John McCall454feb92009-12-08 09:21:05 +00006253TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006254 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006255 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006256 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006257
John McCall60d7b3a2010-08-24 06:29:42 +00006258 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006259 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006260 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006261
6262
Douglas Gregorb98b1992009-08-11 05:31:07 +00006263 if (!getDerived().AlwaysRebuild() &&
6264 LHS.get() == E->getLHS() &&
6265 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006266 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006267
John McCall9ae2f072010-08-23 23:25:46 +00006268 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006269 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006270 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006271 E->getRBracketLoc());
6272}
Mike Stump1eb44332009-09-09 15:08:12 +00006273
6274template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006275ExprResult
John McCall454feb92009-12-08 09:21:05 +00006276TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006277 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006278 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006279 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006280 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006281
6282 // Transform arguments.
6283 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006284 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006285 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6286 &ArgChanged))
6287 return ExprError();
6288
Douglas Gregorb98b1992009-08-11 05:31:07 +00006289 if (!getDerived().AlwaysRebuild() &&
6290 Callee.get() == E->getCallee() &&
6291 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006292 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006293
Douglas Gregorb98b1992009-08-11 05:31:07 +00006294 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006295 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006296 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006297 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006298 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006299 E->getRParenLoc());
6300}
Mike Stump1eb44332009-09-09 15:08:12 +00006301
6302template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006303ExprResult
John McCall454feb92009-12-08 09:21:05 +00006304TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006305 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006306 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006307 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006308
Douglas Gregor40d96a62011-02-28 21:54:11 +00006309 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006310 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006311 QualifierLoc
6312 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6313
6314 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006315 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006316 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006317 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006318
Eli Friedmanf595cc42009-12-04 06:40:45 +00006319 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006320 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6321 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006322 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006323 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006324
John McCall6bb80172010-03-30 21:47:33 +00006325 NamedDecl *FoundDecl = E->getFoundDecl();
6326 if (FoundDecl == E->getMemberDecl()) {
6327 FoundDecl = Member;
6328 } else {
6329 FoundDecl = cast_or_null<NamedDecl>(
6330 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6331 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006332 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006333 }
6334
Douglas Gregorb98b1992009-08-11 05:31:07 +00006335 if (!getDerived().AlwaysRebuild() &&
6336 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006337 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006338 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006339 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006340 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006341
Anders Carlsson1f240322009-12-22 05:24:09 +00006342 // Mark it referenced in the new context regardless.
6343 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006344 SemaRef.MarkMemberReferenced(E);
6345
John McCall3fa5cae2010-10-26 07:05:15 +00006346 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006347 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006348
John McCalld5532b62009-11-23 01:53:49 +00006349 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006350 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006351 TransArgs.setLAngleLoc(E->getLAngleLoc());
6352 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006353 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6354 E->getNumTemplateArgs(),
6355 TransArgs))
6356 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006357 }
Sean Huntc3021132010-05-05 15:23:54 +00006358
Douglas Gregorb98b1992009-08-11 05:31:07 +00006359 // FIXME: Bogus source location for the operator
6360 SourceLocation FakeOperatorLoc
6361 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6362
John McCallc2233c52010-01-15 08:34:02 +00006363 // FIXME: to do this check properly, we will need to preserve the
6364 // first-qualifier-in-scope here, just in case we had a dependent
6365 // base (and therefore couldn't do the check) and a
6366 // nested-name-qualifier (and therefore could do the lookup).
6367 NamedDecl *FirstQualifierInScope = 0;
6368
John McCall9ae2f072010-08-23 23:25:46 +00006369 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006370 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006371 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006372 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006373 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006374 Member,
John McCall6bb80172010-03-30 21:47:33 +00006375 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006376 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006377 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006378 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006379}
Mike Stump1eb44332009-09-09 15:08:12 +00006380
Douglas Gregorb98b1992009-08-11 05:31:07 +00006381template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006382ExprResult
John McCall454feb92009-12-08 09:21:05 +00006383TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006384 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006385 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006386 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006387
John McCall60d7b3a2010-08-24 06:29:42 +00006388 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006389 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006390 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006391
Douglas Gregorb98b1992009-08-11 05:31:07 +00006392 if (!getDerived().AlwaysRebuild() &&
6393 LHS.get() == E->getLHS() &&
6394 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006395 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006396
Douglas Gregorb98b1992009-08-11 05:31:07 +00006397 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006398 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006399}
6400
Mike Stump1eb44332009-09-09 15:08:12 +00006401template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006402ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006403TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006404 CompoundAssignOperator *E) {
6405 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006406}
Mike Stump1eb44332009-09-09 15:08:12 +00006407
Douglas Gregorb98b1992009-08-11 05:31:07 +00006408template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006409ExprResult TreeTransform<Derived>::
6410TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6411 // Just rebuild the common and RHS expressions and see whether we
6412 // get any changes.
6413
6414 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6415 if (commonExpr.isInvalid())
6416 return ExprError();
6417
6418 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6419 if (rhs.isInvalid())
6420 return ExprError();
6421
6422 if (!getDerived().AlwaysRebuild() &&
6423 commonExpr.get() == e->getCommon() &&
6424 rhs.get() == e->getFalseExpr())
6425 return SemaRef.Owned(e);
6426
6427 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6428 e->getQuestionLoc(),
6429 0,
6430 e->getColonLoc(),
6431 rhs.get());
6432}
6433
6434template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006435ExprResult
John McCall454feb92009-12-08 09:21:05 +00006436TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006437 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006439 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006440
John McCall60d7b3a2010-08-24 06:29:42 +00006441 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006442 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006443 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006444
John McCall60d7b3a2010-08-24 06:29:42 +00006445 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006446 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006447 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006448
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449 if (!getDerived().AlwaysRebuild() &&
6450 Cond.get() == E->getCond() &&
6451 LHS.get() == E->getLHS() &&
6452 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006453 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006454
John McCall9ae2f072010-08-23 23:25:46 +00006455 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006456 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006457 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006458 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006459 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006460}
Mike Stump1eb44332009-09-09 15:08:12 +00006461
6462template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006463ExprResult
John McCall454feb92009-12-08 09:21:05 +00006464TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006465 // Implicit casts are eliminated during transformation, since they
6466 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006467 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006468}
Mike Stump1eb44332009-09-09 15:08:12 +00006469
Douglas Gregorb98b1992009-08-11 05:31:07 +00006470template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006471ExprResult
John McCall454feb92009-12-08 09:21:05 +00006472TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006473 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6474 if (!Type)
6475 return ExprError();
6476
John McCall60d7b3a2010-08-24 06:29:42 +00006477 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006478 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006479 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006480 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006481
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006483 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006485 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006486
John McCall9d125032010-01-15 18:39:57 +00006487 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006488 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006490 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491}
Mike Stump1eb44332009-09-09 15:08:12 +00006492
Douglas Gregorb98b1992009-08-11 05:31:07 +00006493template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006494ExprResult
John McCall454feb92009-12-08 09:21:05 +00006495TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006496 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6497 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6498 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006499 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006500
John McCall60d7b3a2010-08-24 06:29:42 +00006501 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006503 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006504
Douglas Gregorb98b1992009-08-11 05:31:07 +00006505 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006506 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006507 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006508 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006509
John McCall1d7d8d62010-01-19 22:33:45 +00006510 // Note: the expression type doesn't necessarily match the
6511 // type-as-written, but that's okay, because it should always be
6512 // derivable from the initializer.
6513
John McCall42f56b52010-01-18 19:35:47 +00006514 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006515 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006516 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517}
Mike Stump1eb44332009-09-09 15:08:12 +00006518
Douglas Gregorb98b1992009-08-11 05:31:07 +00006519template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006520ExprResult
John McCall454feb92009-12-08 09:21:05 +00006521TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006522 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006523 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006524 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006525
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526 if (!getDerived().AlwaysRebuild() &&
6527 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006528 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006529
Douglas Gregorb98b1992009-08-11 05:31:07 +00006530 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006531 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006532 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006533 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006534 E->getAccessorLoc(),
6535 E->getAccessor());
6536}
Mike Stump1eb44332009-09-09 15:08:12 +00006537
Douglas Gregorb98b1992009-08-11 05:31:07 +00006538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006539ExprResult
John McCall454feb92009-12-08 09:21:05 +00006540TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006542
John McCallca0408f2010-08-23 06:44:23 +00006543 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006544 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6545 Inits, &InitChanged))
6546 return ExprError();
6547
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006549 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006550
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006552 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006553}
Mike Stump1eb44332009-09-09 15:08:12 +00006554
Douglas Gregorb98b1992009-08-11 05:31:07 +00006555template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006556ExprResult
John McCall454feb92009-12-08 09:21:05 +00006557TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006558 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006559
Douglas Gregor43959a92009-08-20 07:17:43 +00006560 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006561 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006562 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006563 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006564
Douglas Gregor43959a92009-08-20 07:17:43 +00006565 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006566 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006567 bool ExprChanged = false;
6568 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6569 DEnd = E->designators_end();
6570 D != DEnd; ++D) {
6571 if (D->isFieldDesignator()) {
6572 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6573 D->getDotLoc(),
6574 D->getFieldLoc()));
6575 continue;
6576 }
Mike Stump1eb44332009-09-09 15:08:12 +00006577
Douglas Gregorb98b1992009-08-11 05:31:07 +00006578 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006579 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006581 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006582
6583 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006585
Douglas Gregorb98b1992009-08-11 05:31:07 +00006586 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6587 ArrayExprs.push_back(Index.release());
6588 continue;
6589 }
Mike Stump1eb44332009-09-09 15:08:12 +00006590
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006592 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6594 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006595 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006596
John McCall60d7b3a2010-08-24 06:29:42 +00006597 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006598 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006599 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006600
6601 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006602 End.get(),
6603 D->getLBracketLoc(),
6604 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006605
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6607 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006608
Douglas Gregorb98b1992009-08-11 05:31:07 +00006609 ArrayExprs.push_back(Start.release());
6610 ArrayExprs.push_back(End.release());
6611 }
Mike Stump1eb44332009-09-09 15:08:12 +00006612
Douglas Gregorb98b1992009-08-11 05:31:07 +00006613 if (!getDerived().AlwaysRebuild() &&
6614 Init.get() == E->getInit() &&
6615 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006616 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006617
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6619 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006620 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621}
Mike Stump1eb44332009-09-09 15:08:12 +00006622
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006624ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006625TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006626 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006627 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006628
Douglas Gregor5557b252009-10-28 00:29:27 +00006629 // FIXME: Will we ever have proper type location here? Will we actually
6630 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631 QualType T = getDerived().TransformType(E->getType());
6632 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006633 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006634
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 if (!getDerived().AlwaysRebuild() &&
6636 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006637 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006638
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639 return getDerived().RebuildImplicitValueInitExpr(T);
6640}
Mike Stump1eb44332009-09-09 15:08:12 +00006641
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006643ExprResult
John McCall454feb92009-12-08 09:21:05 +00006644TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006645 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6646 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006647 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006648
John McCall60d7b3a2010-08-24 06:29:42 +00006649 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006650 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006651 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006652
Douglas Gregorb98b1992009-08-11 05:31:07 +00006653 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006654 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006656 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006657
John McCall9ae2f072010-08-23 23:25:46 +00006658 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006659 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006660}
6661
6662template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006663ExprResult
John McCall454feb92009-12-08 09:21:05 +00006664TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006666 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006667 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6668 &ArgumentChanged))
6669 return ExprError();
6670
Douglas Gregorb98b1992009-08-11 05:31:07 +00006671 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6672 move_arg(Inits),
6673 E->getRParenLoc());
6674}
Mike Stump1eb44332009-09-09 15:08:12 +00006675
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676/// \brief Transform an address-of-label expression.
6677///
6678/// By default, the transformation of an address-of-label expression always
6679/// rebuilds the expression, so that the label identifier can be resolved to
6680/// the corresponding label statement by semantic analysis.
6681template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006682ExprResult
John McCall454feb92009-12-08 09:21:05 +00006683TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006684 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6685 E->getLabel());
6686 if (!LD)
6687 return ExprError();
6688
Douglas Gregorb98b1992009-08-11 05:31:07 +00006689 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006690 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006691}
Mike Stump1eb44332009-09-09 15:08:12 +00006692
6693template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006694ExprResult
John McCall454feb92009-12-08 09:21:05 +00006695TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006696 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006697 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6698 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006699 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006700
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701 if (!getDerived().AlwaysRebuild() &&
6702 SubStmt.get() == E->getSubStmt())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006703 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006704
6705 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006706 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 E->getRParenLoc());
6708}
Mike Stump1eb44332009-09-09 15:08:12 +00006709
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006711ExprResult
John McCall454feb92009-12-08 09:21:05 +00006712TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006713 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006715 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006716
John McCall60d7b3a2010-08-24 06:29:42 +00006717 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006719 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006720
John McCall60d7b3a2010-08-24 06:29:42 +00006721 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006723 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006724
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725 if (!getDerived().AlwaysRebuild() &&
6726 Cond.get() == E->getCond() &&
6727 LHS.get() == E->getLHS() &&
6728 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006729 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006730
Douglas Gregorb98b1992009-08-11 05:31:07 +00006731 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006732 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733 E->getRParenLoc());
6734}
Mike Stump1eb44332009-09-09 15:08:12 +00006735
Douglas Gregorb98b1992009-08-11 05:31:07 +00006736template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006737ExprResult
John McCall454feb92009-12-08 09:21:05 +00006738TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006739 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006740}
6741
6742template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006743ExprResult
John McCall454feb92009-12-08 09:21:05 +00006744TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006745 switch (E->getOperator()) {
6746 case OO_New:
6747 case OO_Delete:
6748 case OO_Array_New:
6749 case OO_Array_Delete:
6750 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Sean Huntc3021132010-05-05 15:23:54 +00006751
Douglas Gregor668d6d92009-12-13 20:44:55 +00006752 case OO_Call: {
6753 // This is a call to an object's operator().
6754 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6755
6756 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006757 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006758 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006759 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006760
6761 // FIXME: Poor location information
6762 SourceLocation FakeLParenLoc
6763 = SemaRef.PP.getLocForEndOfToken(
6764 static_cast<Expr *>(Object.get())->getLocEnd());
6765
6766 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006767 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006768 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6769 Args))
6770 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006771
John McCall9ae2f072010-08-23 23:25:46 +00006772 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006773 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006774 E->getLocEnd());
6775 }
6776
6777#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6778 case OO_##Name:
6779#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6780#include "clang/Basic/OperatorKinds.def"
6781 case OO_Subscript:
6782 // Handled below.
6783 break;
6784
6785 case OO_Conditional:
6786 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006787
6788 case OO_None:
6789 case NUM_OVERLOADED_OPERATORS:
6790 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006791 }
6792
John McCall60d7b3a2010-08-24 06:29:42 +00006793 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006794 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006795 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006796
John McCall60d7b3a2010-08-24 06:29:42 +00006797 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006798 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006799 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006800
John McCall60d7b3a2010-08-24 06:29:42 +00006801 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006802 if (E->getNumArgs() == 2) {
6803 Second = getDerived().TransformExpr(E->getArg(1));
6804 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006805 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006806 }
Mike Stump1eb44332009-09-09 15:08:12 +00006807
Douglas Gregorb98b1992009-08-11 05:31:07 +00006808 if (!getDerived().AlwaysRebuild() &&
6809 Callee.get() == E->getCallee() &&
6810 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006811 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006812 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006813
Douglas Gregorb98b1992009-08-11 05:31:07 +00006814 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6815 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006816 Callee.get(),
6817 First.get(),
6818 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006819}
Mike Stump1eb44332009-09-09 15:08:12 +00006820
Douglas Gregorb98b1992009-08-11 05:31:07 +00006821template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006822ExprResult
John McCall454feb92009-12-08 09:21:05 +00006823TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6824 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006825}
Mike Stump1eb44332009-09-09 15:08:12 +00006826
Douglas Gregorb98b1992009-08-11 05:31:07 +00006827template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006828ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006829TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6830 // Transform the callee.
6831 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6832 if (Callee.isInvalid())
6833 return ExprError();
6834
6835 // Transform exec config.
6836 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6837 if (EC.isInvalid())
6838 return ExprError();
6839
6840 // Transform arguments.
6841 bool ArgChanged = false;
6842 ASTOwningVector<Expr*> Args(SemaRef);
6843 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6844 &ArgChanged))
6845 return ExprError();
6846
6847 if (!getDerived().AlwaysRebuild() &&
6848 Callee.get() == E->getCallee() &&
6849 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006850 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006851
6852 // FIXME: Wrong source location information for the '('.
6853 SourceLocation FakeLParenLoc
6854 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6855 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6856 move_arg(Args),
6857 E->getRParenLoc(), EC.get());
6858}
6859
6860template<typename Derived>
6861ExprResult
John McCall454feb92009-12-08 09:21:05 +00006862TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006863 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6864 if (!Type)
6865 return ExprError();
6866
John McCall60d7b3a2010-08-24 06:29:42 +00006867 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006868 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006869 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006870 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006871
Douglas Gregorb98b1992009-08-11 05:31:07 +00006872 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006873 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006874 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006875 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006876
Douglas Gregorb98b1992009-08-11 05:31:07 +00006877 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006878 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006879 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6880 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6881 SourceLocation FakeRParenLoc
6882 = SemaRef.PP.getLocForEndOfToken(
6883 E->getSubExpr()->getSourceRange().getEnd());
6884 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006885 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006886 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006887 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006888 FakeRAngleLoc,
6889 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006890 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006891 FakeRParenLoc);
6892}
Mike Stump1eb44332009-09-09 15:08:12 +00006893
Douglas Gregorb98b1992009-08-11 05:31:07 +00006894template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006895ExprResult
John McCall454feb92009-12-08 09:21:05 +00006896TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6897 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006898}
Mike Stump1eb44332009-09-09 15:08:12 +00006899
6900template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006901ExprResult
John McCall454feb92009-12-08 09:21:05 +00006902TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6903 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006904}
6905
Douglas Gregorb98b1992009-08-11 05:31:07 +00006906template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006907ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006908TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006909 CXXReinterpretCastExpr *E) {
6910 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006911}
Mike Stump1eb44332009-09-09 15:08:12 +00006912
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006914ExprResult
John McCall454feb92009-12-08 09:21:05 +00006915TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6916 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917}
Mike Stump1eb44332009-09-09 15:08:12 +00006918
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006920ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006921TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006922 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006923 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6924 if (!Type)
6925 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006926
John McCall60d7b3a2010-08-24 06:29:42 +00006927 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006928 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006929 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006930 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006931
Douglas Gregorb98b1992009-08-11 05:31:07 +00006932 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006933 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006934 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006935 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006936
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006937 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006938 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006939 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006940 E->getRParenLoc());
6941}
Mike Stump1eb44332009-09-09 15:08:12 +00006942
Douglas Gregorb98b1992009-08-11 05:31:07 +00006943template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006944ExprResult
John McCall454feb92009-12-08 09:21:05 +00006945TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006946 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006947 TypeSourceInfo *TInfo
6948 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6949 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006950 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006951
Douglas Gregorb98b1992009-08-11 05:31:07 +00006952 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006953 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006954 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006955
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006956 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6957 E->getLocStart(),
6958 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006959 E->getLocEnd());
6960 }
Mike Stump1eb44332009-09-09 15:08:12 +00006961
Eli Friedmanef331b72012-01-20 01:26:23 +00006962 // We don't know whether the subexpression is potentially evaluated until
6963 // after we perform semantic analysis. We speculatively assume it is
6964 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00006965 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00006966 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006967
John McCall60d7b3a2010-08-24 06:29:42 +00006968 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006969 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006970 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006971
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972 if (!getDerived().AlwaysRebuild() &&
6973 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006974 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006975
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006976 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6977 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006978 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006979 E->getLocEnd());
6980}
6981
6982template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006983ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006984TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6985 if (E->isTypeOperand()) {
6986 TypeSourceInfo *TInfo
6987 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6988 if (!TInfo)
6989 return ExprError();
6990
6991 if (!getDerived().AlwaysRebuild() &&
6992 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006993 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006994
Douglas Gregor3c52a212011-03-06 17:40:41 +00006995 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006996 E->getLocStart(),
6997 TInfo,
6998 E->getLocEnd());
6999 }
7000
Francois Pichet01b7c302010-09-08 12:20:18 +00007001 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7002
7003 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7004 if (SubExpr.isInvalid())
7005 return ExprError();
7006
7007 if (!getDerived().AlwaysRebuild() &&
7008 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007009 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007010
7011 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7012 E->getLocStart(),
7013 SubExpr.get(),
7014 E->getLocEnd());
7015}
7016
7017template<typename Derived>
7018ExprResult
John McCall454feb92009-12-08 09:21:05 +00007019TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007020 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007021}
Mike Stump1eb44332009-09-09 15:08:12 +00007022
Douglas Gregorb98b1992009-08-11 05:31:07 +00007023template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007024ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007025TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007026 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007027 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028}
Mike Stump1eb44332009-09-09 15:08:12 +00007029
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007031ExprResult
John McCall454feb92009-12-08 09:21:05 +00007032TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007033 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007034 QualType T;
7035 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7036 T = MD->getThisType(getSema().Context);
7037 else
7038 T = getSema().Context.getPointerType(
7039 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007040
Douglas Gregorec79d872012-02-24 17:41:38 +00007041 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7042 // Make sure that we capture 'this'.
7043 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007044 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007045 }
7046
Douglas Gregor828a1972010-01-07 23:12:05 +00007047 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048}
Mike Stump1eb44332009-09-09 15:08:12 +00007049
Douglas Gregorb98b1992009-08-11 05:31:07 +00007050template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007051ExprResult
John McCall454feb92009-12-08 09:21:05 +00007052TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007053 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007054 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007055 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007056
Douglas Gregorb98b1992009-08-11 05:31:07 +00007057 if (!getDerived().AlwaysRebuild() &&
7058 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007059 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007060
Douglas Gregorbca01b42011-07-06 22:04:06 +00007061 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7062 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007063}
Mike Stump1eb44332009-09-09 15:08:12 +00007064
Douglas Gregorb98b1992009-08-11 05:31:07 +00007065template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007066ExprResult
John McCall454feb92009-12-08 09:21:05 +00007067TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007068 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007069 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7070 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007071 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007072 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007073
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007074 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007075 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007076 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007077
Douglas Gregor036aed12009-12-23 23:03:06 +00007078 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007079}
Mike Stump1eb44332009-09-09 15:08:12 +00007080
Douglas Gregorb98b1992009-08-11 05:31:07 +00007081template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007082ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007083TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7084 CXXScalarValueInitExpr *E) {
7085 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7086 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007087 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007088
Douglas Gregorb98b1992009-08-11 05:31:07 +00007089 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007090 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007091 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007092
Douglas Gregorab6677e2010-09-08 00:15:04 +00007093 return getDerived().RebuildCXXScalarValueInitExpr(T,
7094 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007095 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007096}
Mike Stump1eb44332009-09-09 15:08:12 +00007097
Douglas Gregorb98b1992009-08-11 05:31:07 +00007098template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007099ExprResult
John McCall454feb92009-12-08 09:21:05 +00007100TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007101 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007102 TypeSourceInfo *AllocTypeInfo
7103 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7104 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007105 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007106
Douglas Gregorb98b1992009-08-11 05:31:07 +00007107 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007108 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007109 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007110 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007111
Douglas Gregorb98b1992009-08-11 05:31:07 +00007112 // Transform the placement arguments (if any).
7113 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007114 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007115 if (getDerived().TransformExprs(E->getPlacementArgs(),
7116 E->getNumPlacementArgs(), true,
7117 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007118 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007119
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007120 // Transform the initializer (if any).
7121 Expr *OldInit = E->getInitializer();
7122 ExprResult NewInit;
7123 if (OldInit)
7124 NewInit = getDerived().TransformExpr(OldInit);
7125 if (NewInit.isInvalid())
7126 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007127
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007128 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007129 FunctionDecl *OperatorNew = 0;
7130 if (E->getOperatorNew()) {
7131 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007132 getDerived().TransformDecl(E->getLocStart(),
7133 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007134 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007135 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007136 }
7137
7138 FunctionDecl *OperatorDelete = 0;
7139 if (E->getOperatorDelete()) {
7140 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007141 getDerived().TransformDecl(E->getLocStart(),
7142 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007143 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007144 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007145 }
Sean Huntc3021132010-05-05 15:23:54 +00007146
Douglas Gregorb98b1992009-08-11 05:31:07 +00007147 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007148 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007149 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007150 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007151 OperatorNew == E->getOperatorNew() &&
7152 OperatorDelete == E->getOperatorDelete() &&
7153 !ArgumentChanged) {
7154 // Mark any declarations we need as referenced.
7155 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007156 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007157 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007158 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007159 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007160
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007161 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007162 QualType ElementType
7163 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7164 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7165 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7166 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007167 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007168 }
7169 }
7170 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007171
John McCall3fa5cae2010-10-26 07:05:15 +00007172 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007173 }
Mike Stump1eb44332009-09-09 15:08:12 +00007174
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007175 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007176 if (!ArraySize.get()) {
7177 // If no array size was specified, but the new expression was
7178 // instantiated with an array type (e.g., "new T" where T is
7179 // instantiated with "int[4]"), extract the outer bound from the
7180 // array type as our array size. We do this with constant and
7181 // dependently-sized array types.
7182 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7183 if (!ArrayT) {
7184 // Do nothing
7185 } else if (const ConstantArrayType *ConsArrayT
7186 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007187 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007188 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7189 ConsArrayT->getSize(),
7190 SemaRef.Context.getSizeType(),
7191 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007192 AllocType = ConsArrayT->getElementType();
7193 } else if (const DependentSizedArrayType *DepArrayT
7194 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7195 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007196 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007197 AllocType = DepArrayT->getElementType();
7198 }
7199 }
7200 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007201
Douglas Gregorb98b1992009-08-11 05:31:07 +00007202 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7203 E->isGlobalNew(),
7204 /*FIXME:*/E->getLocStart(),
7205 move_arg(PlacementArgs),
7206 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007207 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007208 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007209 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007210 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007211 E->getDirectInitRange(),
7212 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007213}
Mike Stump1eb44332009-09-09 15:08:12 +00007214
Douglas Gregorb98b1992009-08-11 05:31:07 +00007215template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007216ExprResult
John McCall454feb92009-12-08 09:21:05 +00007217TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007218 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007219 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007220 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007221
Douglas Gregor1af74512010-02-26 00:38:10 +00007222 // Transform the delete operator, if known.
7223 FunctionDecl *OperatorDelete = 0;
7224 if (E->getOperatorDelete()) {
7225 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007226 getDerived().TransformDecl(E->getLocStart(),
7227 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007228 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007229 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007230 }
Sean Huntc3021132010-05-05 15:23:54 +00007231
Douglas Gregorb98b1992009-08-11 05:31:07 +00007232 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007233 Operand.get() == E->getArgument() &&
7234 OperatorDelete == E->getOperatorDelete()) {
7235 // Mark any declarations we need as referenced.
7236 // FIXME: instantiation-specific.
7237 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007238 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007239
7240 if (!E->getArgument()->isTypeDependent()) {
7241 QualType Destroyed = SemaRef.Context.getBaseElementType(
7242 E->getDestroyedType());
7243 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7244 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007245 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7246 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007247 }
7248 }
7249
John McCall3fa5cae2010-10-26 07:05:15 +00007250 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007251 }
Mike Stump1eb44332009-09-09 15:08:12 +00007252
Douglas Gregorb98b1992009-08-11 05:31:07 +00007253 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7254 E->isGlobalDelete(),
7255 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007256 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007257}
Mike Stump1eb44332009-09-09 15:08:12 +00007258
Douglas Gregorb98b1992009-08-11 05:31:07 +00007259template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007260ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007261TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007262 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007263 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007264 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007265 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007266
John McCallb3d87482010-08-24 05:47:05 +00007267 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007268 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007269 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007270 E->getOperatorLoc(),
7271 E->isArrow()? tok::arrow : tok::period,
7272 ObjectTypePtr,
7273 MayBePseudoDestructor);
7274 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007275 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007276
John McCallb3d87482010-08-24 05:47:05 +00007277 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007278 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7279 if (QualifierLoc) {
7280 QualifierLoc
7281 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7282 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007283 return ExprError();
7284 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007285 CXXScopeSpec SS;
7286 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007287
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007288 PseudoDestructorTypeStorage Destroyed;
7289 if (E->getDestroyedTypeInfo()) {
7290 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007291 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007292 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007293 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007294 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007295 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007296 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007297 // We aren't likely to be able to resolve the identifier down to a type
7298 // now anyway, so just retain the identifier.
7299 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7300 E->getDestroyedTypeLoc());
7301 } else {
7302 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007303 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007304 *E->getDestroyedTypeIdentifier(),
7305 E->getDestroyedTypeLoc(),
7306 /*Scope=*/0,
7307 SS, ObjectTypePtr,
7308 false);
7309 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007310 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007311
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007312 Destroyed
7313 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7314 E->getDestroyedTypeLoc());
7315 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007316
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007317 TypeSourceInfo *ScopeTypeInfo = 0;
7318 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007319 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007320 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007321 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007322 }
Sean Huntc3021132010-05-05 15:23:54 +00007323
John McCall9ae2f072010-08-23 23:25:46 +00007324 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007325 E->getOperatorLoc(),
7326 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007327 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007328 ScopeTypeInfo,
7329 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007330 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007331 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007332}
Mike Stump1eb44332009-09-09 15:08:12 +00007333
Douglas Gregora71d8192009-09-04 17:36:40 +00007334template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007335ExprResult
John McCallba135432009-11-21 08:51:07 +00007336TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007337 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007338 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7339 Sema::LookupOrdinaryName);
7340
7341 // Transform all the decls.
7342 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7343 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007344 NamedDecl *InstD = static_cast<NamedDecl*>(
7345 getDerived().TransformDecl(Old->getNameLoc(),
7346 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007347 if (!InstD) {
7348 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7349 // This can happen because of dependent hiding.
7350 if (isa<UsingShadowDecl>(*I))
7351 continue;
7352 else
John McCallf312b1e2010-08-26 23:41:50 +00007353 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007354 }
John McCallf7a1a742009-11-24 19:00:30 +00007355
7356 // Expand using declarations.
7357 if (isa<UsingDecl>(InstD)) {
7358 UsingDecl *UD = cast<UsingDecl>(InstD);
7359 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7360 E = UD->shadow_end(); I != E; ++I)
7361 R.addDecl(*I);
7362 continue;
7363 }
7364
7365 R.addDecl(InstD);
7366 }
7367
7368 // Resolve a kind, but don't do any further analysis. If it's
7369 // ambiguous, the callee needs to deal with it.
7370 R.resolveKind();
7371
7372 // Rebuild the nested-name qualifier, if present.
7373 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007374 if (Old->getQualifierLoc()) {
7375 NestedNameSpecifierLoc QualifierLoc
7376 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7377 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007378 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007379
Douglas Gregor4c9be892011-02-28 20:01:57 +00007380 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007381 }
7382
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007383 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007384 CXXRecordDecl *NamingClass
7385 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7386 Old->getNameLoc(),
7387 Old->getNamingClass()));
7388 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007389 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007390
Douglas Gregor66c45152010-04-27 16:10:10 +00007391 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007392 }
7393
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007394 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7395
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007396 // If we have neither explicit template arguments, nor the template keyword,
7397 // it's a normal declaration name.
7398 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007399 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7400
7401 // If we have template arguments, rebuild them, then rebuild the
7402 // templateid expression.
7403 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007404 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7405 Old->getNumTemplateArgs(),
7406 TransArgs))
7407 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007408
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007409 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007410 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007411}
Mike Stump1eb44332009-09-09 15:08:12 +00007412
Douglas Gregorb98b1992009-08-11 05:31:07 +00007413template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007414ExprResult
John McCall454feb92009-12-08 09:21:05 +00007415TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007416 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7417 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007418 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007419
Douglas Gregorb98b1992009-08-11 05:31:07 +00007420 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007421 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007422 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007423
Mike Stump1eb44332009-09-09 15:08:12 +00007424 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007425 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007426 T,
7427 E->getLocEnd());
7428}
Mike Stump1eb44332009-09-09 15:08:12 +00007429
Douglas Gregorb98b1992009-08-11 05:31:07 +00007430template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007431ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007432TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7433 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7434 if (!LhsT)
7435 return ExprError();
7436
7437 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7438 if (!RhsT)
7439 return ExprError();
7440
7441 if (!getDerived().AlwaysRebuild() &&
7442 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7443 return SemaRef.Owned(E);
7444
7445 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7446 E->getLocStart(),
7447 LhsT, RhsT,
7448 E->getLocEnd());
7449}
7450
7451template<typename Derived>
7452ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007453TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7454 bool ArgChanged = false;
7455 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7456 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7457 TypeSourceInfo *From = E->getArg(I);
7458 TypeLoc FromTL = From->getTypeLoc();
7459 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7460 TypeLocBuilder TLB;
7461 TLB.reserve(FromTL.getFullDataSize());
7462 QualType To = getDerived().TransformType(TLB, FromTL);
7463 if (To.isNull())
7464 return ExprError();
7465
7466 if (To == From->getType())
7467 Args.push_back(From);
7468 else {
7469 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7470 ArgChanged = true;
7471 }
7472 continue;
7473 }
7474
7475 ArgChanged = true;
7476
7477 // We have a pack expansion. Instantiate it.
7478 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
7479 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7480 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7481 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7482
7483 // Determine whether the set of unexpanded parameter packs can and should
7484 // be expanded.
7485 bool Expand = true;
7486 bool RetainExpansion = false;
7487 llvm::Optional<unsigned> OrigNumExpansions
7488 = ExpansionTL.getTypePtr()->getNumExpansions();
7489 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7490 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7491 PatternTL.getSourceRange(),
7492 Unexpanded,
7493 Expand, RetainExpansion,
7494 NumExpansions))
7495 return ExprError();
7496
7497 if (!Expand) {
7498 // The transform has determined that we should perform a simple
7499 // transformation on the pack expansion, producing another pack
7500 // expansion.
7501 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7502
7503 TypeLocBuilder TLB;
7504 TLB.reserve(From->getTypeLoc().getFullDataSize());
7505
7506 QualType To = getDerived().TransformType(TLB, PatternTL);
7507 if (To.isNull())
7508 return ExprError();
7509
7510 To = getDerived().RebuildPackExpansionType(To,
7511 PatternTL.getSourceRange(),
7512 ExpansionTL.getEllipsisLoc(),
7513 NumExpansions);
7514 if (To.isNull())
7515 return ExprError();
7516
7517 PackExpansionTypeLoc ToExpansionTL
7518 = TLB.push<PackExpansionTypeLoc>(To);
7519 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7520 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7521 continue;
7522 }
7523
7524 // Expand the pack expansion by substituting for each argument in the
7525 // pack(s).
7526 for (unsigned I = 0; I != *NumExpansions; ++I) {
7527 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7528 TypeLocBuilder TLB;
7529 TLB.reserve(PatternTL.getFullDataSize());
7530 QualType To = getDerived().TransformType(TLB, PatternTL);
7531 if (To.isNull())
7532 return ExprError();
7533
7534 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7535 }
7536
7537 if (!RetainExpansion)
7538 continue;
7539
7540 // If we're supposed to retain a pack expansion, do so by temporarily
7541 // forgetting the partially-substituted parameter pack.
7542 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7543
7544 TypeLocBuilder TLB;
7545 TLB.reserve(From->getTypeLoc().getFullDataSize());
7546
7547 QualType To = getDerived().TransformType(TLB, PatternTL);
7548 if (To.isNull())
7549 return ExprError();
7550
7551 To = getDerived().RebuildPackExpansionType(To,
7552 PatternTL.getSourceRange(),
7553 ExpansionTL.getEllipsisLoc(),
7554 NumExpansions);
7555 if (To.isNull())
7556 return ExprError();
7557
7558 PackExpansionTypeLoc ToExpansionTL
7559 = TLB.push<PackExpansionTypeLoc>(To);
7560 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7561 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7562 }
7563
7564 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7565 return SemaRef.Owned(E);
7566
7567 return getDerived().RebuildTypeTrait(E->getTrait(),
7568 E->getLocStart(),
7569 Args,
7570 E->getLocEnd());
7571}
7572
7573template<typename Derived>
7574ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007575TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7576 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7577 if (!T)
7578 return ExprError();
7579
7580 if (!getDerived().AlwaysRebuild() &&
7581 T == E->getQueriedTypeSourceInfo())
7582 return SemaRef.Owned(E);
7583
7584 ExprResult SubExpr;
7585 {
7586 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7587 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7588 if (SubExpr.isInvalid())
7589 return ExprError();
7590
7591 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7592 return SemaRef.Owned(E);
7593 }
7594
7595 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7596 E->getLocStart(),
7597 T,
7598 SubExpr.get(),
7599 E->getLocEnd());
7600}
7601
7602template<typename Derived>
7603ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007604TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7605 ExprResult SubExpr;
7606 {
7607 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7608 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7609 if (SubExpr.isInvalid())
7610 return ExprError();
7611
7612 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7613 return SemaRef.Owned(E);
7614 }
7615
7616 return getDerived().RebuildExpressionTrait(
7617 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7618}
7619
7620template<typename Derived>
7621ExprResult
John McCall865d4472009-11-19 22:55:06 +00007622TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007623 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007624 NestedNameSpecifierLoc QualifierLoc
7625 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7626 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007627 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007628 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007629
John McCall43fed0d2010-11-12 08:19:04 +00007630 // TODO: If this is a conversion-function-id, verify that the
7631 // destination type name (if present) resolves the same way after
7632 // instantiation as it did in the local scope.
7633
Abramo Bagnara25777432010-08-11 22:01:17 +00007634 DeclarationNameInfo NameInfo
7635 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7636 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007637 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007638
John McCallf7a1a742009-11-24 19:00:30 +00007639 if (!E->hasExplicitTemplateArgs()) {
7640 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007641 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007642 // Note: it is sufficient to compare the Name component of NameInfo:
7643 // if name has not changed, DNLoc has not changed either.
7644 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007645 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007646
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007647 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007648 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007649 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007650 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007651 }
John McCalld5532b62009-11-23 01:53:49 +00007652
7653 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007654 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7655 E->getNumTemplateArgs(),
7656 TransArgs))
7657 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007658
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007659 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007660 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007661 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007662 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007663}
7664
7665template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007666ExprResult
John McCall454feb92009-12-08 09:21:05 +00007667TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007668 // CXXConstructExprs are always implicit, so when we have a
7669 // 1-argument construction we just transform that argument.
7670 if (E->getNumArgs() == 1 ||
7671 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7672 return getDerived().TransformExpr(E->getArg(0));
7673
Douglas Gregorb98b1992009-08-11 05:31:07 +00007674 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7675
7676 QualType T = getDerived().TransformType(E->getType());
7677 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007678 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007679
7680 CXXConstructorDecl *Constructor
7681 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007682 getDerived().TransformDecl(E->getLocStart(),
7683 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007684 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007685 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007686
Douglas Gregorb98b1992009-08-11 05:31:07 +00007687 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007688 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007689 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7690 &ArgumentChanged))
7691 return ExprError();
7692
Douglas Gregorb98b1992009-08-11 05:31:07 +00007693 if (!getDerived().AlwaysRebuild() &&
7694 T == E->getType() &&
7695 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007696 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007697 // Mark the constructor as referenced.
7698 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007699 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007700 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007701 }
Mike Stump1eb44332009-09-09 15:08:12 +00007702
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007703 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7704 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007705 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007706 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007707 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007708 E->getConstructionKind(),
7709 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007710}
Mike Stump1eb44332009-09-09 15:08:12 +00007711
Douglas Gregorb98b1992009-08-11 05:31:07 +00007712/// \brief Transform a C++ temporary-binding expression.
7713///
Douglas Gregor51326552009-12-24 18:51:59 +00007714/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7715/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007716template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007717ExprResult
John McCall454feb92009-12-08 09:21:05 +00007718TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007719 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007720}
Mike Stump1eb44332009-09-09 15:08:12 +00007721
John McCall4765fa02010-12-06 08:20:24 +00007722/// \brief Transform a C++ expression that contains cleanups that should
7723/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007724///
John McCall4765fa02010-12-06 08:20:24 +00007725/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007726/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007727template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007728ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007729TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007730 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007731}
Mike Stump1eb44332009-09-09 15:08:12 +00007732
Douglas Gregorb98b1992009-08-11 05:31:07 +00007733template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007734ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007735TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007736 CXXTemporaryObjectExpr *E) {
7737 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7738 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007739 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007740
Douglas Gregorb98b1992009-08-11 05:31:07 +00007741 CXXConstructorDecl *Constructor
7742 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007743 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007744 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007745 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007746 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007747
Douglas Gregorb98b1992009-08-11 05:31:07 +00007748 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007749 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007750 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007751 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7752 &ArgumentChanged))
7753 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007754
Douglas Gregorb98b1992009-08-11 05:31:07 +00007755 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007756 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007757 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007758 !ArgumentChanged) {
7759 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007760 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007761 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007762 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007763
7764 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7765 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007766 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007767 E->getLocEnd());
7768}
Mike Stump1eb44332009-09-09 15:08:12 +00007769
Douglas Gregorb98b1992009-08-11 05:31:07 +00007770template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007771ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007772TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007773 // Create the local class that will describe the lambda.
7774 CXXRecordDecl *Class
7775 = getSema().createLambdaClosureType(E->getIntroducerRange());
7776 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7777
7778 // Transform the type of the lambda parameters and start the definition of
7779 // the lambda itself.
7780 TypeSourceInfo *MethodTy
7781 = TransformType(E->getCallOperator()->getTypeSourceInfo());
7782 if (!MethodTy)
7783 return ExprError();
7784
Douglas Gregorc6889e72012-02-14 22:28:59 +00007785 // Transform lambda parameters.
7786 bool Invalid = false;
7787 llvm::SmallVector<QualType, 4> ParamTypes;
7788 llvm::SmallVector<ParmVarDecl *, 4> Params;
7789 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7790 E->getCallOperator()->param_begin(),
7791 E->getCallOperator()->param_size(),
7792 0, ParamTypes, &Params))
7793 Invalid = true;
7794
Douglas Gregordfca6f52012-02-13 22:00:16 +00007795 // Build the call operator.
7796 CXXMethodDecl *CallOperator
7797 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7798 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007799 E->getCallOperator()->getLocEnd(),
7800 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007801 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7802
Douglas Gregord5387e82012-02-14 00:00:48 +00007803 // FIXME: Instantiation-specific.
7804 CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(),
7805 TSK_ImplicitInstantiation);
7806
7807 // Introduce the context of the call operator.
7808 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7809
Douglas Gregordfca6f52012-02-13 22:00:16 +00007810 // Enter the scope of the lambda.
7811 sema::LambdaScopeInfo *LSI
7812 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7813 E->getCaptureDefault(),
7814 E->hasExplicitParameters(),
7815 E->hasExplicitResultType(),
7816 E->isMutable());
7817
7818 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00007819 bool FinishedExplicitCaptures = false;
7820 for (LambdaExpr::capture_iterator C = E->capture_begin(),
7821 CEnd = E->capture_end();
7822 C != CEnd; ++C) {
7823 // When we hit the first implicit capture, tell Sema that we've finished
7824 // the list of explicit captures.
7825 if (!FinishedExplicitCaptures && C->isImplicit()) {
7826 getSema().finishLambdaExplicitCaptures(LSI);
7827 FinishedExplicitCaptures = true;
7828 }
7829
7830 // Capturing 'this' is trivial.
7831 if (C->capturesThis()) {
7832 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7833 continue;
7834 }
7835
Douglas Gregora7365242012-02-14 19:27:52 +00007836 // Determine the capture kind for Sema.
7837 Sema::TryCaptureKind Kind
7838 = C->isImplicit()? Sema::TryCapture_Implicit
7839 : C->getCaptureKind() == LCK_ByCopy
7840 ? Sema::TryCapture_ExplicitByVal
7841 : Sema::TryCapture_ExplicitByRef;
7842 SourceLocation EllipsisLoc;
7843 if (C->isPackExpansion()) {
7844 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7845 bool ShouldExpand = false;
7846 bool RetainExpansion = false;
7847 llvm::Optional<unsigned> NumExpansions;
7848 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7849 C->getLocation(),
7850 Unexpanded,
7851 ShouldExpand, RetainExpansion,
7852 NumExpansions))
7853 return ExprError();
7854
7855 if (ShouldExpand) {
7856 // The transform has determined that we should perform an expansion;
7857 // transform and capture each of the arguments.
7858 // expansion of the pattern. Do so.
7859 VarDecl *Pack = C->getCapturedVar();
7860 for (unsigned I = 0; I != *NumExpansions; ++I) {
7861 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7862 VarDecl *CapturedVar
7863 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7864 Pack));
7865 if (!CapturedVar) {
7866 Invalid = true;
7867 continue;
7868 }
7869
7870 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007871 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregora7365242012-02-14 19:27:52 +00007872 }
7873 continue;
7874 }
7875
7876 EllipsisLoc = C->getEllipsisLoc();
7877 }
7878
Douglas Gregordfca6f52012-02-13 22:00:16 +00007879 // Transform the captured variable.
7880 VarDecl *CapturedVar
7881 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7882 C->getCapturedVar()));
7883 if (!CapturedVar) {
7884 Invalid = true;
7885 continue;
7886 }
Douglas Gregora7365242012-02-14 19:27:52 +00007887
Douglas Gregordfca6f52012-02-13 22:00:16 +00007888 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007889 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007890 }
7891 if (!FinishedExplicitCaptures)
7892 getSema().finishLambdaExplicitCaptures(LSI);
7893
Douglas Gregordfca6f52012-02-13 22:00:16 +00007894
7895 // Enter a new evaluation context to insulate the lambda from any
7896 // cleanups from the enclosing full-expression.
7897 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
7898
7899 if (Invalid) {
7900 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7901 /*IsInstantiation=*/true);
7902 return ExprError();
7903 }
7904
7905 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00007906 StmtResult Body = getDerived().TransformStmt(E->getBody());
7907 if (Body.isInvalid()) {
7908 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7909 /*IsInstantiation=*/true);
7910 return ExprError();
7911 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007912
7913 // Note: Once a lambda mangling number and context declaration have been
7914 // assigned, they never change.
Douglas Gregor9e8c92a2012-02-20 19:44:39 +00007915 unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber();
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007916 Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl();
Douglas Gregordfca6f52012-02-13 22:00:16 +00007917 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregor9e8c92a2012-02-20 19:44:39 +00007918 /*CurScope=*/0, ManglingNumber,
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007919 ContextDecl,
Douglas Gregordfca6f52012-02-13 22:00:16 +00007920 /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00007921}
7922
7923template<typename Derived>
7924ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007925TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007926 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007927 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7928 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007929 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007930
Douglas Gregorb98b1992009-08-11 05:31:07 +00007931 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007932 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007933 Args.reserve(E->arg_size());
7934 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7935 &ArgumentChanged))
7936 return ExprError();
7937
Douglas Gregorb98b1992009-08-11 05:31:07 +00007938 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007939 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007940 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007941 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007942
Douglas Gregorb98b1992009-08-11 05:31:07 +00007943 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007944 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007945 E->getLParenLoc(),
7946 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007947 E->getRParenLoc());
7948}
Mike Stump1eb44332009-09-09 15:08:12 +00007949
Douglas Gregorb98b1992009-08-11 05:31:07 +00007950template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007951ExprResult
John McCall865d4472009-11-19 22:55:06 +00007952TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007953 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007954 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007955 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007956 Expr *OldBase;
7957 QualType BaseType;
7958 QualType ObjectType;
7959 if (!E->isImplicitAccess()) {
7960 OldBase = E->getBase();
7961 Base = getDerived().TransformExpr(OldBase);
7962 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007963 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007964
John McCallaa81e162009-12-01 22:10:20 +00007965 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007966 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007967 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007968 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007969 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007970 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007971 ObjectTy,
7972 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007973 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007974 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007975
John McCallb3d87482010-08-24 05:47:05 +00007976 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007977 BaseType = ((Expr*) Base.get())->getType();
7978 } else {
7979 OldBase = 0;
7980 BaseType = getDerived().TransformType(E->getBaseType());
7981 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7982 }
Mike Stump1eb44332009-09-09 15:08:12 +00007983
Douglas Gregor6cd21982009-10-20 05:58:46 +00007984 // Transform the first part of the nested-name-specifier that qualifies
7985 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007986 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007987 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007988 E->getFirstQualifierFoundInScope(),
7989 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007990
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007991 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007992 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007993 QualifierLoc
7994 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7995 ObjectType,
7996 FirstQualifierInScope);
7997 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007998 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007999 }
Mike Stump1eb44332009-09-09 15:08:12 +00008000
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008001 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8002
John McCall43fed0d2010-11-12 08:19:04 +00008003 // TODO: If this is a conversion-function-id, verify that the
8004 // destination type name (if present) resolves the same way after
8005 // instantiation as it did in the local scope.
8006
Abramo Bagnara25777432010-08-11 22:01:17 +00008007 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008008 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008009 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008010 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008011
John McCallaa81e162009-12-01 22:10:20 +00008012 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008013 // This is a reference to a member without an explicitly-specified
8014 // template argument list. Optimize for this common case.
8015 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008016 Base.get() == OldBase &&
8017 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008018 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008019 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008020 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008021 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008022
John McCall9ae2f072010-08-23 23:25:46 +00008023 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008024 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008025 E->isArrow(),
8026 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008027 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008028 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008029 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008030 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008031 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008032 }
8033
John McCalld5532b62009-11-23 01:53:49 +00008034 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008035 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8036 E->getNumTemplateArgs(),
8037 TransArgs))
8038 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008039
John McCall9ae2f072010-08-23 23:25:46 +00008040 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008041 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008042 E->isArrow(),
8043 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008044 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008045 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008046 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008047 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008048 &TransArgs);
8049}
8050
8051template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008052ExprResult
John McCall454feb92009-12-08 09:21:05 +00008053TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008054 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008055 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008056 QualType BaseType;
8057 if (!Old->isImplicitAccess()) {
8058 Base = getDerived().TransformExpr(Old->getBase());
8059 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008060 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008061 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8062 Old->isArrow());
8063 if (Base.isInvalid())
8064 return ExprError();
8065 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008066 } else {
8067 BaseType = getDerived().TransformType(Old->getBaseType());
8068 }
John McCall129e2df2009-11-30 22:42:35 +00008069
Douglas Gregor4c9be892011-02-28 20:01:57 +00008070 NestedNameSpecifierLoc QualifierLoc;
8071 if (Old->getQualifierLoc()) {
8072 QualifierLoc
8073 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8074 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008075 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008076 }
8077
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008078 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8079
Abramo Bagnara25777432010-08-11 22:01:17 +00008080 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008081 Sema::LookupOrdinaryName);
8082
8083 // Transform all the decls.
8084 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8085 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008086 NamedDecl *InstD = static_cast<NamedDecl*>(
8087 getDerived().TransformDecl(Old->getMemberLoc(),
8088 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008089 if (!InstD) {
8090 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8091 // This can happen because of dependent hiding.
8092 if (isa<UsingShadowDecl>(*I))
8093 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008094 else {
8095 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008096 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008097 }
John McCall9f54ad42009-12-10 09:41:52 +00008098 }
John McCall129e2df2009-11-30 22:42:35 +00008099
8100 // Expand using declarations.
8101 if (isa<UsingDecl>(InstD)) {
8102 UsingDecl *UD = cast<UsingDecl>(InstD);
8103 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8104 E = UD->shadow_end(); I != E; ++I)
8105 R.addDecl(*I);
8106 continue;
8107 }
8108
8109 R.addDecl(InstD);
8110 }
8111
8112 R.resolveKind();
8113
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008114 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008115 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00008116 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008117 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008118 Old->getMemberLoc(),
8119 Old->getNamingClass()));
8120 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008121 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008122
Douglas Gregor66c45152010-04-27 16:10:10 +00008123 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008124 }
Sean Huntc3021132010-05-05 15:23:54 +00008125
John McCall129e2df2009-11-30 22:42:35 +00008126 TemplateArgumentListInfo TransArgs;
8127 if (Old->hasExplicitTemplateArgs()) {
8128 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8129 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008130 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8131 Old->getNumTemplateArgs(),
8132 TransArgs))
8133 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008134 }
John McCallc2233c52010-01-15 08:34:02 +00008135
8136 // FIXME: to do this check properly, we will need to preserve the
8137 // first-qualifier-in-scope here, just in case we had a dependent
8138 // base (and therefore couldn't do the check) and a
8139 // nested-name-qualifier (and therefore could do the lookup).
8140 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00008141
John McCall9ae2f072010-08-23 23:25:46 +00008142 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008143 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008144 Old->getOperatorLoc(),
8145 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008146 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008147 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008148 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008149 R,
8150 (Old->hasExplicitTemplateArgs()
8151 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008152}
8153
8154template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008155ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008156TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008157 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008158 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8159 if (SubExpr.isInvalid())
8160 return ExprError();
8161
8162 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008163 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008164
8165 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8166}
8167
8168template<typename Derived>
8169ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008170TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008171 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8172 if (Pattern.isInvalid())
8173 return ExprError();
8174
8175 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8176 return SemaRef.Owned(E);
8177
Douglas Gregor67fd1252011-01-14 21:20:45 +00008178 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8179 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008180}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008181
8182template<typename Derived>
8183ExprResult
8184TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8185 // If E is not value-dependent, then nothing will change when we transform it.
8186 // Note: This is an instantiation-centric view.
8187 if (!E->isValueDependent())
8188 return SemaRef.Owned(E);
8189
8190 // Note: None of the implementations of TryExpandParameterPacks can ever
8191 // produce a diagnostic when given only a single unexpanded parameter pack,
8192 // so
8193 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8194 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008195 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008196 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00008197 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008198 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008199 ShouldExpand, RetainExpansion,
8200 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008201 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00008202
Douglas Gregor089e8932011-10-10 18:59:29 +00008203 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008204 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00008205
8206 NamedDecl *Pack = E->getPack();
8207 if (!ShouldExpand) {
8208 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8209 Pack));
8210 if (!Pack)
8211 return ExprError();
8212 }
8213
Douglas Gregoree8aff02011-01-04 17:33:58 +00008214
8215 // We now know the length of the parameter pack, so build a new expression
8216 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00008217 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00008218 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008219 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008220}
8221
Douglas Gregorbe230c32011-01-03 17:17:50 +00008222template<typename Derived>
8223ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008224TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8225 SubstNonTypeTemplateParmPackExpr *E) {
8226 // Default behavior is to do nothing with this transformation.
8227 return SemaRef.Owned(E);
8228}
8229
8230template<typename Derived>
8231ExprResult
John McCall91a57552011-07-15 05:09:51 +00008232TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8233 SubstNonTypeTemplateParmExpr *E) {
8234 // Default behavior is to do nothing with this transformation.
8235 return SemaRef.Owned(E);
8236}
8237
8238template<typename Derived>
8239ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008240TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8241 MaterializeTemporaryExpr *E) {
8242 return getDerived().TransformExpr(E->GetTemporaryExpr());
8243}
8244
8245template<typename Derived>
8246ExprResult
John McCall454feb92009-12-08 09:21:05 +00008247TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008248 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008249}
8250
Mike Stump1eb44332009-09-09 15:08:12 +00008251template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008252ExprResult
John McCall454feb92009-12-08 09:21:05 +00008253TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008254 TypeSourceInfo *EncodedTypeInfo
8255 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8256 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008257 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008258
Douglas Gregorb98b1992009-08-11 05:31:07 +00008259 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008260 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008261 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008262
8263 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008264 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008265 E->getRParenLoc());
8266}
Mike Stump1eb44332009-09-09 15:08:12 +00008267
Douglas Gregorb98b1992009-08-11 05:31:07 +00008268template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008269ExprResult TreeTransform<Derived>::
8270TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8271 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8272 if (result.isInvalid()) return ExprError();
8273 Expr *subExpr = result.take();
8274
8275 if (!getDerived().AlwaysRebuild() &&
8276 subExpr == E->getSubExpr())
8277 return SemaRef.Owned(E);
8278
8279 return SemaRef.Owned(new(SemaRef.Context)
8280 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8281}
8282
8283template<typename Derived>
8284ExprResult TreeTransform<Derived>::
8285TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
8286 TypeSourceInfo *TSInfo
8287 = getDerived().TransformType(E->getTypeInfoAsWritten());
8288 if (!TSInfo)
8289 return ExprError();
8290
8291 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
8292 if (Result.isInvalid())
8293 return ExprError();
8294
8295 if (!getDerived().AlwaysRebuild() &&
8296 TSInfo == E->getTypeInfoAsWritten() &&
8297 Result.get() == E->getSubExpr())
8298 return SemaRef.Owned(E);
8299
8300 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8301 E->getBridgeKeywordLoc(), TSInfo,
8302 Result.get());
8303}
8304
8305template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008306ExprResult
John McCall454feb92009-12-08 09:21:05 +00008307TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008308 // Transform arguments.
8309 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008310 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008311 Args.reserve(E->getNumArgs());
8312 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8313 &ArgChanged))
8314 return ExprError();
8315
Douglas Gregor92e986e2010-04-22 16:44:27 +00008316 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8317 // Class message: transform the receiver type.
8318 TypeSourceInfo *ReceiverTypeInfo
8319 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8320 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008321 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008322
Douglas Gregor92e986e2010-04-22 16:44:27 +00008323 // If nothing changed, just retain the existing message send.
8324 if (!getDerived().AlwaysRebuild() &&
8325 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008326 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008327
8328 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008329 SmallVector<SourceLocation, 16> SelLocs;
8330 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008331 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8332 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008333 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008334 E->getMethodDecl(),
8335 E->getLeftLoc(),
8336 move_arg(Args),
8337 E->getRightLoc());
8338 }
8339
8340 // Instance message: transform the receiver
8341 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8342 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008343 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008344 = getDerived().TransformExpr(E->getInstanceReceiver());
8345 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008346 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008347
8348 // If nothing changed, just retain the existing message send.
8349 if (!getDerived().AlwaysRebuild() &&
8350 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008351 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008352
Douglas Gregor92e986e2010-04-22 16:44:27 +00008353 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008354 SmallVector<SourceLocation, 16> SelLocs;
8355 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008356 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008357 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008358 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008359 E->getMethodDecl(),
8360 E->getLeftLoc(),
8361 move_arg(Args),
8362 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008363}
8364
Mike Stump1eb44332009-09-09 15:08:12 +00008365template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008366ExprResult
John McCall454feb92009-12-08 09:21:05 +00008367TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008368 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008369}
8370
Mike Stump1eb44332009-09-09 15:08:12 +00008371template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008372ExprResult
John McCall454feb92009-12-08 09:21:05 +00008373TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008374 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008375}
8376
Mike Stump1eb44332009-09-09 15:08:12 +00008377template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008378ExprResult
John McCall454feb92009-12-08 09:21:05 +00008379TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008380 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008381 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008382 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008383 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008384
8385 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008386
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008387 // If nothing changed, just retain the existing expression.
8388 if (!getDerived().AlwaysRebuild() &&
8389 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008390 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008391
John McCall9ae2f072010-08-23 23:25:46 +00008392 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008393 E->getLocation(),
8394 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008395}
8396
Mike Stump1eb44332009-09-09 15:08:12 +00008397template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008398ExprResult
John McCall454feb92009-12-08 09:21:05 +00008399TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008400 // 'super' and types never change. Property never changes. Just
8401 // retain the existing expression.
8402 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008403 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008404
Douglas Gregore3303542010-04-26 20:47:02 +00008405 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008406 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008407 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008408 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008409
Douglas Gregore3303542010-04-26 20:47:02 +00008410 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008411
Douglas Gregore3303542010-04-26 20:47:02 +00008412 // If nothing changed, just retain the existing expression.
8413 if (!getDerived().AlwaysRebuild() &&
8414 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008415 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008416
John McCall12f78a62010-12-02 01:19:52 +00008417 if (E->isExplicitProperty())
8418 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8419 E->getExplicitProperty(),
8420 E->getLocation());
8421
8422 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008423 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008424 E->getImplicitPropertyGetter(),
8425 E->getImplicitPropertySetter(),
8426 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008427}
8428
Mike Stump1eb44332009-09-09 15:08:12 +00008429template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008430ExprResult
John McCall454feb92009-12-08 09:21:05 +00008431TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008432 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008433 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008434 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008435 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008436
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008437 // If nothing changed, just retain the existing expression.
8438 if (!getDerived().AlwaysRebuild() &&
8439 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008440 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008441
John McCall9ae2f072010-08-23 23:25:46 +00008442 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008443 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008444}
8445
Mike Stump1eb44332009-09-09 15:08:12 +00008446template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008447ExprResult
John McCall454feb92009-12-08 09:21:05 +00008448TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008449 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008450 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008451 SubExprs.reserve(E->getNumSubExprs());
8452 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8453 SubExprs, &ArgumentChanged))
8454 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008455
Douglas Gregorb98b1992009-08-11 05:31:07 +00008456 if (!getDerived().AlwaysRebuild() &&
8457 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008458 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008459
Douglas Gregorb98b1992009-08-11 05:31:07 +00008460 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8461 move_arg(SubExprs),
8462 E->getRParenLoc());
8463}
8464
Mike Stump1eb44332009-09-09 15:08:12 +00008465template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008466ExprResult
John McCall454feb92009-12-08 09:21:05 +00008467TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008468 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008469
John McCallc6ac9c32011-02-04 18:33:18 +00008470 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8471 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8472
8473 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008474 blockScope->TheDecl->setBlockMissingReturnType(
8475 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008476
Chris Lattner686775d2011-07-20 06:58:45 +00008477 SmallVector<ParmVarDecl*, 4> params;
8478 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008479
8480 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008481 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8482 oldBlock->param_begin(),
8483 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008484 0, paramTypes, &params)) {
8485 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008486 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008487 }
John McCallc6ac9c32011-02-04 18:33:18 +00008488
8489 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008490 QualType exprResultType =
8491 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008492
8493 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008494 if (exprResultType->isObjCObjectType()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008495 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008496 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008497 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008498 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008499 return ExprError();
8500 }
John McCall711c52b2011-01-05 12:14:39 +00008501
John McCallc6ac9c32011-02-04 18:33:18 +00008502 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008503 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008504 paramTypes.data(),
8505 paramTypes.size(),
8506 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008507 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008508 exprFunctionType->getExtInfo());
8509 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008510
8511 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008512 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008513 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008514
8515 if (!oldBlock->blockMissingReturnType()) {
8516 blockScope->HasImplicitReturnType = false;
8517 blockScope->ReturnType = exprResultType;
8518 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008519
John McCall711c52b2011-01-05 12:14:39 +00008520 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008521 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008522 if (body.isInvalid()) {
8523 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008524 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008525 }
John McCall711c52b2011-01-05 12:14:39 +00008526
John McCallc6ac9c32011-02-04 18:33:18 +00008527#ifndef NDEBUG
8528 // In builds with assertions, make sure that we captured everything we
8529 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008530 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8531 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8532 e = oldBlock->capture_end(); i != e; ++i) {
8533 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008534
Douglas Gregorfc921372011-05-20 15:32:55 +00008535 // Ignore parameter packs.
8536 if (isa<ParmVarDecl>(oldCapture) &&
8537 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8538 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008539
Douglas Gregorfc921372011-05-20 15:32:55 +00008540 VarDecl *newCapture =
8541 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8542 oldCapture));
8543 assert(blockScope->CaptureMap.count(newCapture));
8544 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008545 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008546 }
8547#endif
8548
8549 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8550 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008551}
8552
Mike Stump1eb44332009-09-09 15:08:12 +00008553template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008554ExprResult
John McCall454feb92009-12-08 09:21:05 +00008555TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008556 ValueDecl *ND
8557 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8558 E->getDecl()));
8559 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00008560 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00008561
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008562 if (!getDerived().AlwaysRebuild() &&
8563 ND == E->getDecl()) {
8564 // Mark it referenced in the new context regardless.
8565 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00008566 SemaRef.MarkBlockDeclRefReferenced(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008567
John McCall3fa5cae2010-10-26 07:05:15 +00008568 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008569 }
8570
Abramo Bagnara25777432010-08-11 22:01:17 +00008571 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00008572 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00008573 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008574}
Mike Stump1eb44332009-09-09 15:08:12 +00008575
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008576template<typename Derived>
8577ExprResult
8578TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008579 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008580}
Eli Friedman276b0612011-10-11 02:20:01 +00008581
8582template<typename Derived>
8583ExprResult
8584TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008585 QualType RetTy = getDerived().TransformType(E->getType());
8586 bool ArgumentChanged = false;
8587 ASTOwningVector<Expr*> SubExprs(SemaRef);
8588 SubExprs.reserve(E->getNumSubExprs());
8589 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8590 SubExprs, &ArgumentChanged))
8591 return ExprError();
8592
8593 if (!getDerived().AlwaysRebuild() &&
8594 !ArgumentChanged)
8595 return SemaRef.Owned(E);
8596
8597 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8598 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008599}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008600
Douglas Gregorb98b1992009-08-11 05:31:07 +00008601//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008602// Type reconstruction
8603//===----------------------------------------------------------------------===//
8604
Mike Stump1eb44332009-09-09 15:08:12 +00008605template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008606QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8607 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008608 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008609 getDerived().getBaseEntity());
8610}
8611
Mike Stump1eb44332009-09-09 15:08:12 +00008612template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008613QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8614 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008615 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008616 getDerived().getBaseEntity());
8617}
8618
Mike Stump1eb44332009-09-09 15:08:12 +00008619template<typename Derived>
8620QualType
John McCall85737a72009-10-30 00:06:24 +00008621TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8622 bool WrittenAsLValue,
8623 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008624 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008625 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008626}
8627
8628template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008629QualType
John McCall85737a72009-10-30 00:06:24 +00008630TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8631 QualType ClassType,
8632 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008633 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008634 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008635}
8636
8637template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008638QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008639TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8640 ArrayType::ArraySizeModifier SizeMod,
8641 const llvm::APInt *Size,
8642 Expr *SizeExpr,
8643 unsigned IndexTypeQuals,
8644 SourceRange BracketsRange) {
8645 if (SizeExpr || !Size)
8646 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8647 IndexTypeQuals, BracketsRange,
8648 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008649
8650 QualType Types[] = {
8651 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8652 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8653 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008654 };
8655 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8656 QualType SizeType;
8657 for (unsigned I = 0; I != NumTypes; ++I)
8658 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8659 SizeType = Types[I];
8660 break;
8661 }
Mike Stump1eb44332009-09-09 15:08:12 +00008662
Eli Friedman01f276d2012-01-25 23:20:27 +00008663 // Note that we can return a VariableArrayType here in the case where
8664 // the element type was a dependent VariableArrayType.
8665 IntegerLiteral *ArraySize
8666 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8667 /*FIXME*/BracketsRange.getBegin());
8668 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008669 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008670 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008671}
Mike Stump1eb44332009-09-09 15:08:12 +00008672
Douglas Gregor577f75a2009-08-04 16:50:30 +00008673template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008674QualType
8675TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008676 ArrayType::ArraySizeModifier SizeMod,
8677 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008678 unsigned IndexTypeQuals,
8679 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008680 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008681 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008682}
8683
8684template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008685QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008686TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008687 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008688 unsigned IndexTypeQuals,
8689 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008690 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008691 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008692}
Mike Stump1eb44332009-09-09 15:08:12 +00008693
Douglas Gregor577f75a2009-08-04 16:50:30 +00008694template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008695QualType
8696TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008697 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008698 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008699 unsigned IndexTypeQuals,
8700 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008701 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008702 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008703 IndexTypeQuals, BracketsRange);
8704}
8705
8706template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008707QualType
8708TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008709 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008710 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008711 unsigned IndexTypeQuals,
8712 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008713 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008714 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008715 IndexTypeQuals, BracketsRange);
8716}
8717
8718template<typename Derived>
8719QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008720 unsigned NumElements,
8721 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008722 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008723 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008724}
Mike Stump1eb44332009-09-09 15:08:12 +00008725
Douglas Gregor577f75a2009-08-04 16:50:30 +00008726template<typename Derived>
8727QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8728 unsigned NumElements,
8729 SourceLocation AttributeLoc) {
8730 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8731 NumElements, true);
8732 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008733 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8734 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008735 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008736}
Mike Stump1eb44332009-09-09 15:08:12 +00008737
Douglas Gregor577f75a2009-08-04 16:50:30 +00008738template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008739QualType
8740TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008741 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008742 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008743 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, 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>
8747QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008748 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008749 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008750 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008751 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00008752 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008753 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008754 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008755 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008756 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008757 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008758 getDerived().getBaseEntity(),
8759 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008760}
Mike Stump1eb44332009-09-09 15:08:12 +00008761
Douglas Gregor577f75a2009-08-04 16:50:30 +00008762template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008763QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8764 return SemaRef.Context.getFunctionNoProtoType(T);
8765}
8766
8767template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008768QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8769 assert(D && "no decl found");
8770 if (D->isInvalidDecl()) return QualType();
8771
Douglas Gregor92e986e2010-04-22 16:44:27 +00008772 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008773 TypeDecl *Ty;
8774 if (isa<UsingDecl>(D)) {
8775 UsingDecl *Using = cast<UsingDecl>(D);
8776 assert(Using->isTypeName() &&
8777 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8778
8779 // A valid resolved using typename decl points to exactly one type decl.
8780 assert(++Using->shadow_begin() == Using->shadow_end());
8781 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008782
John McCalled976492009-12-04 22:46:56 +00008783 } else {
8784 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8785 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8786 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8787 }
8788
8789 return SemaRef.Context.getTypeDeclType(Ty);
8790}
8791
8792template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008793QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8794 SourceLocation Loc) {
8795 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008796}
8797
8798template<typename Derived>
8799QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8800 return SemaRef.Context.getTypeOfType(Underlying);
8801}
8802
8803template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008804QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8805 SourceLocation Loc) {
8806 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008807}
8808
8809template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008810QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8811 UnaryTransformType::UTTKind UKind,
8812 SourceLocation Loc) {
8813 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8814}
8815
8816template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008817QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008818 TemplateName Template,
8819 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008820 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008821 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008822}
Mike Stump1eb44332009-09-09 15:08:12 +00008823
Douglas Gregordcee1a12009-08-06 05:28:30 +00008824template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00008825QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8826 SourceLocation KWLoc) {
8827 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8828}
8829
8830template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008831TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008832TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008833 bool TemplateKW,
8834 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008835 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008836 Template);
8837}
8838
8839template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008840TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008841TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8842 const IdentifierInfo &Name,
8843 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008844 QualType ObjectType,
8845 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008846 UnqualifiedId TemplateName;
8847 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008848 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008849 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00008850 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008851 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008852 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008853 /*EnteringContext=*/false,
8854 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008855 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008856}
Mike Stump1eb44332009-09-09 15:08:12 +00008857
Douglas Gregorb98b1992009-08-11 05:31:07 +00008858template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008859TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008860TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008861 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008862 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008863 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008864 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008865 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008866 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008867 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008868 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00008869 Sema::TemplateTy Template;
8870 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008871 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00008872 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008873 /*EnteringContext=*/false,
8874 Template);
8875 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008876}
Sean Huntc3021132010-05-05 15:23:54 +00008877
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008878template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008879ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008880TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8881 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008882 Expr *OrigCallee,
8883 Expr *First,
8884 Expr *Second) {
8885 Expr *Callee = OrigCallee->IgnoreParenCasts();
8886 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008887
Douglas Gregorb98b1992009-08-11 05:31:07 +00008888 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008889 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008890 if (!First->getType()->isOverloadableType() &&
8891 !Second->getType()->isOverloadableType())
8892 return getSema().CreateBuiltinArraySubscriptExpr(First,
8893 Callee->getLocStart(),
8894 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008895 } else if (Op == OO_Arrow) {
8896 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008897 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8898 } else if (Second == 0 || isPostIncDec) {
8899 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008900 // The argument is not of overloadable type, so try to create a
8901 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008902 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008903 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008904
John McCall9ae2f072010-08-23 23:25:46 +00008905 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008906 }
8907 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008908 if (!First->getType()->isOverloadableType() &&
8909 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008910 // Neither of the arguments is an overloadable type, so try to
8911 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008912 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008913 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008914 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008915 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008916 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008917
Douglas Gregorb98b1992009-08-11 05:31:07 +00008918 return move(Result);
8919 }
8920 }
Mike Stump1eb44332009-09-09 15:08:12 +00008921
8922 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008923 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008924 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008925
John McCall9ae2f072010-08-23 23:25:46 +00008926 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008927 assert(ULE->requiresADL());
8928
8929 // FIXME: Do we have to check
8930 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008931 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008932 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008933 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008934 }
Mike Stump1eb44332009-09-09 15:08:12 +00008935
Douglas Gregorb98b1992009-08-11 05:31:07 +00008936 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008937 Expr *Args[2] = { First, Second };
8938 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008939
Douglas Gregorb98b1992009-08-11 05:31:07 +00008940 // Create the overloaded operator invocation for unary operators.
8941 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008942 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008943 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008944 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008945 }
Mike Stump1eb44332009-09-09 15:08:12 +00008946
Douglas Gregor5b8968c2011-07-15 16:25:15 +00008947 if (Op == OO_Subscript) {
8948 SourceLocation LBrace;
8949 SourceLocation RBrace;
8950
8951 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8952 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8953 LBrace = SourceLocation::getFromRawEncoding(
8954 NameLoc.CXXOperatorName.BeginOpNameLoc);
8955 RBrace = SourceLocation::getFromRawEncoding(
8956 NameLoc.CXXOperatorName.EndOpNameLoc);
8957 } else {
8958 LBrace = Callee->getLocStart();
8959 RBrace = OpLoc;
8960 }
8961
8962 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8963 First, Second);
8964 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00008965
Douglas Gregorb98b1992009-08-11 05:31:07 +00008966 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008967 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008968 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008969 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8970 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008971 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008972
Mike Stump1eb44332009-09-09 15:08:12 +00008973 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008974}
Mike Stump1eb44332009-09-09 15:08:12 +00008975
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008976template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008977ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008978TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008979 SourceLocation OperatorLoc,
8980 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008981 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008982 TypeSourceInfo *ScopeType,
8983 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008984 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008985 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008986 QualType BaseType = Base->getType();
8987 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008988 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008989 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008990 !BaseType->getAs<PointerType>()->getPointeeType()
8991 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008992 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008993 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008994 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008995 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008996 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008997 /*FIXME?*/true);
8998 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008999
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009000 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009001 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9002 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9003 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9004 NameInfo.setNamedTypeInfo(DestroyedType);
9005
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009006 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00009007
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009008 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009009 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009010 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009011 SS, TemplateKWLoc,
9012 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009013 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009014 /*TemplateArgs*/ 0);
9015}
9016
Douglas Gregor577f75a2009-08-04 16:50:30 +00009017} // end namespace clang
9018
9019#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H