blob: acfea6e3e4c6939eaf62503c46458976e8bb1f01 [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
Richard Smith534986f2012-04-14 00:33:13 +00001047 /// \brief Build a new label statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
1051 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, const AttrVec &Attrs,
1052 Stmt *SubStmt) {
1053 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1054 }
1055
Douglas Gregor43959a92009-08-20 07:17:43 +00001056 /// \brief Build a new "if" statement.
1057 ///
1058 /// By default, performs semantic analysis to build the new statement.
1059 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001060 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001061 VarDecl *CondVar, Stmt *Then,
1062 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001063 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001064 }
Mike Stump1eb44332009-09-09 15:08:12 +00001065
Douglas Gregor43959a92009-08-20 07:17:43 +00001066 /// \brief Start building a new switch statement.
1067 ///
1068 /// By default, performs semantic analysis to build the new statement.
1069 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001070 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001071 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001072 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001073 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001074 }
Mike Stump1eb44332009-09-09 15:08:12 +00001075
Douglas Gregor43959a92009-08-20 07:17:43 +00001076 /// \brief Attach the body to the switch statement.
1077 ///
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001080 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001081 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001082 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001083 }
1084
1085 /// \brief Build a new while statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001089 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1090 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001091 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001092 }
Mike Stump1eb44332009-09-09 15:08:12 +00001093
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 /// \brief Build a new do-while statement.
1095 ///
1096 /// By default, performs semantic analysis to build the new statement.
1097 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001098 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001099 SourceLocation WhileLoc, SourceLocation LParenLoc,
1100 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001101 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1102 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001103 }
1104
1105 /// \brief Build a new for statement.
1106 ///
1107 /// By default, performs semantic analysis to build the new statement.
1108 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001109 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1110 Stmt *Init, Sema::FullExprArg Cond,
1111 VarDecl *CondVar, Sema::FullExprArg Inc,
1112 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001113 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001114 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001115 }
Mike Stump1eb44332009-09-09 15:08:12 +00001116
Douglas Gregor43959a92009-08-20 07:17:43 +00001117 /// \brief Build a new goto statement.
1118 ///
1119 /// By default, performs semantic analysis to build the new statement.
1120 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001121 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1122 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001123 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001124 }
1125
1126 /// \brief Build a new indirect goto statement.
1127 ///
1128 /// By default, performs semantic analysis to build the new statement.
1129 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001130 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001131 SourceLocation StarLoc,
1132 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001133 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001134 }
Mike Stump1eb44332009-09-09 15:08:12 +00001135
Douglas Gregor43959a92009-08-20 07:17:43 +00001136 /// \brief Build a new return statement.
1137 ///
1138 /// By default, performs semantic analysis to build the new statement.
1139 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001140 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001141 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001142 }
Mike Stump1eb44332009-09-09 15:08:12 +00001143
Douglas Gregor43959a92009-08-20 07:17:43 +00001144 /// \brief Build a new declaration statement.
1145 ///
1146 /// By default, performs semantic analysis to build the new statement.
1147 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001148 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001149 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001150 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001151 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1152 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001153 }
Mike Stump1eb44332009-09-09 15:08:12 +00001154
Anders Carlsson703e3942010-01-24 05:50:09 +00001155 /// \brief Build a new inline asm statement.
1156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001159 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001160 bool IsSimple,
1161 bool IsVolatile,
1162 unsigned NumOutputs,
1163 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001164 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001165 MultiExprArg Constraints,
1166 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001167 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001168 MultiExprArg Clobbers,
1169 SourceLocation RParenLoc,
1170 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001171 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001172 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001173 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001174 RParenLoc, MSAsm);
1175 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001176
1177 /// \brief Build a new Objective-C @try statement.
1178 ///
1179 /// By default, performs semantic analysis to build the new statement.
1180 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001181 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001182 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001183 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001184 Stmt *Finally) {
1185 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1186 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001187 }
1188
Douglas Gregorbe270a02010-04-26 17:57:08 +00001189 /// \brief Rebuild an Objective-C exception declaration.
1190 ///
1191 /// By default, performs semantic analysis to build the new declaration.
1192 /// Subclasses may override this routine to provide different behavior.
1193 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1194 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001195 return getSema().BuildObjCExceptionDecl(TInfo, T,
1196 ExceptionDecl->getInnerLocStart(),
1197 ExceptionDecl->getLocation(),
1198 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001199 }
Sean Huntc3021132010-05-05 15:23:54 +00001200
Douglas Gregorbe270a02010-04-26 17:57:08 +00001201 /// \brief Build a new Objective-C @catch statement.
1202 ///
1203 /// By default, performs semantic analysis to build the new statement.
1204 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001205 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001206 SourceLocation RParenLoc,
1207 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001208 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001209 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001210 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001211 }
Sean Huntc3021132010-05-05 15:23:54 +00001212
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001213 /// \brief Build a new Objective-C @finally statement.
1214 ///
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 RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001218 Stmt *Body) {
1219 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001220 }
Sean Huntc3021132010-05-05 15:23:54 +00001221
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001222 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001226 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001227 Expr *Operand) {
1228 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001229 }
Sean Huntc3021132010-05-05 15:23:54 +00001230
John McCall07524032011-07-27 21:50:02 +00001231 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1232 ///
1233 /// By default, performs semantic analysis to build the new statement.
1234 /// Subclasses may override this routine to provide different behavior.
1235 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1236 Expr *object) {
1237 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1238 }
1239
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001240 /// \brief Build a new Objective-C @synchronized statement.
1241 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001242 /// By default, performs semantic analysis to build the new statement.
1243 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001244 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001245 Expr *Object, Stmt *Body) {
1246 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001247 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001248
John McCallf85e1932011-06-15 23:02:42 +00001249 /// \brief Build a new Objective-C @autoreleasepool statement.
1250 ///
1251 /// By default, performs semantic analysis to build the new statement.
1252 /// Subclasses may override this routine to provide different behavior.
1253 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1254 Stmt *Body) {
1255 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1256 }
John McCall990567c2011-07-27 01:07:15 +00001257
1258 /// \brief Build the collection operand to a new Objective-C fast
1259 /// enumeration statement.
1260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
1263 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1264 Expr *collection) {
1265 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1266 }
John McCallf85e1932011-06-15 23:02:42 +00001267
Douglas Gregorc3203e72010-04-22 23:10:45 +00001268 /// \brief Build a new Objective-C fast enumeration statement.
1269 ///
1270 /// By default, performs semantic analysis to build the new statement.
1271 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001272 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001273 SourceLocation LParenLoc,
1274 Stmt *Element,
1275 Expr *Collection,
1276 SourceLocation RParenLoc,
1277 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001278 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001279 Element,
1280 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001281 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001282 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001283 }
Sean Huntc3021132010-05-05 15:23:54 +00001284
Douglas Gregor43959a92009-08-20 07:17:43 +00001285 /// \brief Build a new C++ exception declaration.
1286 ///
1287 /// By default, performs semantic analysis to build the new decaration.
1288 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001289 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001290 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001291 SourceLocation StartLoc,
1292 SourceLocation IdLoc,
1293 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001294 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1295 StartLoc, IdLoc, Id);
1296 if (Var)
1297 getSema().CurContext->addDecl(Var);
1298 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001299 }
1300
1301 /// \brief Build a new C++ catch statement.
1302 ///
1303 /// By default, performs semantic analysis to build the new statement.
1304 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001305 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001306 VarDecl *ExceptionDecl,
1307 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001308 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1309 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001310 }
Mike Stump1eb44332009-09-09 15:08:12 +00001311
Douglas Gregor43959a92009-08-20 07:17:43 +00001312 /// \brief Build a new C++ try statement.
1313 ///
1314 /// By default, performs semantic analysis to build the new statement.
1315 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001316 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001317 Stmt *TryBlock,
1318 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001319 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001320 }
Mike Stump1eb44332009-09-09 15:08:12 +00001321
Richard Smithad762fc2011-04-14 22:09:26 +00001322 /// \brief Build a new C++0x range-based for statement.
1323 ///
1324 /// By default, performs semantic analysis to build the new statement.
1325 /// Subclasses may override this routine to provide different behavior.
1326 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1327 SourceLocation ColonLoc,
1328 Stmt *Range, Stmt *BeginEnd,
1329 Expr *Cond, Expr *Inc,
1330 Stmt *LoopVar,
1331 SourceLocation RParenLoc) {
1332 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1333 Cond, Inc, LoopVar, RParenLoc);
1334 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001335
1336 /// \brief Build a new C++0x range-based for statement.
1337 ///
1338 /// By default, performs semantic analysis to build the new statement.
1339 /// Subclasses may override this routine to provide different behavior.
1340 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1341 bool IsIfExists,
1342 NestedNameSpecifierLoc QualifierLoc,
1343 DeclarationNameInfo NameInfo,
1344 Stmt *Nested) {
1345 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1346 QualifierLoc, NameInfo, Nested);
1347 }
1348
Richard Smithad762fc2011-04-14 22:09:26 +00001349 /// \brief Attach body to a C++0x range-based for statement.
1350 ///
1351 /// By default, performs semantic analysis to finish the new statement.
1352 /// Subclasses may override this routine to provide different behavior.
1353 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1354 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1355 }
1356
John Wiegley28bbe4b2011-04-28 01:08:34 +00001357 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1358 SourceLocation TryLoc,
1359 Stmt *TryBlock,
1360 Stmt *Handler) {
1361 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1362 }
1363
1364 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1365 Expr *FilterExpr,
1366 Stmt *Block) {
1367 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1368 }
1369
1370 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1371 Stmt *Block) {
1372 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1373 }
1374
Douglas Gregorb98b1992009-08-11 05:31:07 +00001375 /// \brief Build a new expression that references a declaration.
1376 ///
1377 /// By default, performs semantic analysis to build the new expression.
1378 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001379 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001380 LookupResult &R,
1381 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001382 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1383 }
1384
1385
1386 /// \brief Build a new expression that references a declaration.
1387 ///
1388 /// By default, performs semantic analysis to build the new expression.
1389 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001390 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001391 ValueDecl *VD,
1392 const DeclarationNameInfo &NameInfo,
1393 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001394 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001395 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001396
1397 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001398
1399 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 }
Mike Stump1eb44332009-09-09 15:08:12 +00001401
Douglas Gregorb98b1992009-08-11 05:31:07 +00001402 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001403 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +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 RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001407 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001408 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 }
1410
Douglas Gregora71d8192009-09-04 17:36:40 +00001411 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001412 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001413 /// By default, performs semantic analysis to build the new expression.
1414 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001415 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001416 SourceLocation OperatorLoc,
1417 bool isArrow,
1418 CXXScopeSpec &SS,
1419 TypeSourceInfo *ScopeType,
1420 SourceLocation CCLoc,
1421 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001422 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001423
Douglas Gregorb98b1992009-08-11 05:31:07 +00001424 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001425 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001428 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001429 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001430 Expr *SubExpr) {
1431 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001432 }
Mike Stump1eb44332009-09-09 15:08:12 +00001433
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001434 /// \brief Build a new builtin offsetof expression.
1435 ///
1436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001438 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001439 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001440 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001441 unsigned NumComponents,
1442 SourceLocation RParenLoc) {
1443 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1444 NumComponents, RParenLoc);
1445 }
Sean Huntc3021132010-05-05 15:23:54 +00001446
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001447 /// \brief Build a new sizeof, alignof or vec_step expression with a
1448 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001449 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 /// By default, performs semantic analysis to build the new expression.
1451 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001452 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1453 SourceLocation OpLoc,
1454 UnaryExprOrTypeTrait ExprKind,
1455 SourceRange R) {
1456 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001457 }
1458
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001459 /// \brief Build a new sizeof, alignof or vec step expression with an
1460 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001461 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 /// By default, performs semantic analysis to build the new expression.
1463 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001464 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1465 UnaryExprOrTypeTrait ExprKind,
1466 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001467 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001468 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001469 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001470 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001471
Douglas Gregorb98b1992009-08-11 05:31:07 +00001472 return move(Result);
1473 }
Mike Stump1eb44332009-09-09 15:08:12 +00001474
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001476 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001479 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001481 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001483 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1484 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 RBracketLoc);
1486 }
1487
1488 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001489 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 /// By default, performs semantic analysis to build the new expression.
1491 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001492 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001494 SourceLocation RParenLoc,
1495 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001496 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001497 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 }
1499
1500 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001501 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 /// By default, performs semantic analysis to build the new expression.
1503 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001504 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001505 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001506 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001507 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001508 const DeclarationNameInfo &MemberNameInfo,
1509 ValueDecl *Member,
1510 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001511 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001512 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001513 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1514 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001515 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001516 // We have a reference to an unnamed field. This is always the
1517 // base of an anonymous struct/union member access, i.e. the
1518 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001519 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001520 assert(Member->getType()->isRecordType() &&
1521 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001522
Richard Smith9138b4e2011-10-26 19:06:56 +00001523 BaseResult =
1524 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001525 QualifierLoc.getNestedNameSpecifier(),
1526 FoundDecl, Member);
1527 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001528 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001529 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001530 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001531 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001532 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001533 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001534 cast<FieldDecl>(Member)->getType(),
1535 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001536 return getSema().Owned(ME);
1537 }
Mike Stump1eb44332009-09-09 15:08:12 +00001538
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001539 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001540 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001541
John Wiegley429bb272011-04-08 18:41:53 +00001542 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001543 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001544
John McCall6bb80172010-03-30 21:47:33 +00001545 // FIXME: this involves duplicating earlier analysis in a lot of
1546 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001547 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001548 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001549 R.resolveKind();
1550
John McCall9ae2f072010-08-23 23:25:46 +00001551 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001552 SS, TemplateKWLoc,
1553 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001554 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 }
Mike Stump1eb44332009-09-09 15:08:12 +00001556
Douglas Gregorb98b1992009-08-11 05:31:07 +00001557 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001558 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001561 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001562 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001563 Expr *LHS, Expr *RHS) {
1564 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 }
1566
1567 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001568 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001571 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001572 SourceLocation QuestionLoc,
1573 Expr *LHS,
1574 SourceLocation ColonLoc,
1575 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001576 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1577 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 }
1579
Douglas Gregorb98b1992009-08-11 05:31:07 +00001580 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001581 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001584 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001585 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001587 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001588 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001589 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 }
Mike Stump1eb44332009-09-09 15:08:12 +00001591
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001593 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 /// By default, performs semantic analysis to build the new expression.
1595 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001596 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001597 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001599 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001600 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001601 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 }
Mike Stump1eb44332009-09-09 15:08:12 +00001603
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001605 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 /// By default, performs semantic analysis to build the new expression.
1607 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001608 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 SourceLocation OpLoc,
1610 SourceLocation AccessorLoc,
1611 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001612
John McCall129e2df2009-11-30 22:42:35 +00001613 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001614 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001615 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001616 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001617 SS, SourceLocation(),
1618 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001619 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001620 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001621 }
Mike Stump1eb44332009-09-09 15:08:12 +00001622
Douglas Gregorb98b1992009-08-11 05:31:07 +00001623 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001624 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001625 /// By default, performs semantic analysis to build the new expression.
1626 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001627 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001628 MultiExprArg Inits,
1629 SourceLocation RBraceLoc,
1630 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001631 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001632 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1633 if (Result.isInvalid() || ResultTy->isDependentType())
1634 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001635
Douglas Gregore48319a2009-11-09 17:16:50 +00001636 // Patch in the result type we were given, which may have been computed
1637 // when the initial InitListExpr was built.
1638 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1639 ILE->setType(ResultTy);
1640 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 }
Mike Stump1eb44332009-09-09 15:08:12 +00001642
Douglas Gregorb98b1992009-08-11 05:31:07 +00001643 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001644 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 /// By default, performs semantic analysis to build the new expression.
1646 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001647 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 MultiExprArg ArrayExprs,
1649 SourceLocation EqualOrColonLoc,
1650 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001651 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001652 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001654 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001656 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001657
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 ArrayExprs.release();
1659 return move(Result);
1660 }
Mike Stump1eb44332009-09-09 15:08:12 +00001661
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001663 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 /// By default, builds the implicit value initialization without performing
1665 /// any semantic analysis. Subclasses may override this routine to provide
1666 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001667 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1669 }
Mike Stump1eb44332009-09-09 15:08:12 +00001670
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001672 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 /// By default, performs semantic analysis to build the new expression.
1674 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001675 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001676 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001677 SourceLocation RParenLoc) {
1678 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001679 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001680 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 }
1682
1683 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001684 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 /// By default, performs semantic analysis to build the new expression.
1686 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001687 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001688 MultiExprArg SubExprs,
1689 SourceLocation RParenLoc) {
1690 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 }
Mike Stump1eb44332009-09-09 15:08:12 +00001692
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001694 ///
1695 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 /// rather than attempting to map the label statement itself.
1697 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001698 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001699 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001700 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 }
Mike Stump1eb44332009-09-09 15:08:12 +00001702
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001704 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 /// By default, performs semantic analysis to build the new expression.
1706 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001707 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001708 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001709 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001710 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 }
Mike Stump1eb44332009-09-09 15:08:12 +00001712
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 /// \brief Build a new __builtin_choose_expr expression.
1714 ///
1715 /// By default, performs semantic analysis to build the new expression.
1716 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001717 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001718 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719 SourceLocation RParenLoc) {
1720 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001721 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 RParenLoc);
1723 }
Mike Stump1eb44332009-09-09 15:08:12 +00001724
Peter Collingbournef111d932011-04-15 00:35:48 +00001725 /// \brief Build a new generic selection expression.
1726 ///
1727 /// By default, performs semantic analysis to build the new expression.
1728 /// Subclasses may override this routine to provide different behavior.
1729 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1730 SourceLocation DefaultLoc,
1731 SourceLocation RParenLoc,
1732 Expr *ControllingExpr,
1733 TypeSourceInfo **Types,
1734 Expr **Exprs,
1735 unsigned NumAssocs) {
1736 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1737 ControllingExpr, Types, Exprs,
1738 NumAssocs);
1739 }
1740
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 /// \brief Build a new overloaded operator call expression.
1742 ///
1743 /// By default, performs semantic analysis to build the new expression.
1744 /// The semantic analysis provides the behavior of template instantiation,
1745 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001746 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001747 /// argument-dependent lookup, etc. Subclasses may override this routine to
1748 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001749 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001751 Expr *Callee,
1752 Expr *First,
1753 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001754
1755 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 /// reinterpret_cast.
1757 ///
1758 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001759 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001761 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 Stmt::StmtClass Class,
1763 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001764 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 SourceLocation RAngleLoc,
1766 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001767 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001768 SourceLocation RParenLoc) {
1769 switch (Class) {
1770 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001771 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001772 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001773 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001774
1775 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001776 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001777 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001778 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001779
Douglas Gregorb98b1992009-08-11 05:31:07 +00001780 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001781 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001782 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001783 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001785
Douglas Gregorb98b1992009-08-11 05:31:07 +00001786 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001787 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001788 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001789 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001790
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001792 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 }
Mike Stump1eb44332009-09-09 15:08:12 +00001795
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 /// \brief Build a new C++ static_cast expression.
1797 ///
1798 /// By default, performs semantic analysis to build the new expression.
1799 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001800 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001802 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 SourceLocation RAngleLoc,
1804 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001805 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001807 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001808 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001809 SourceRange(LAngleLoc, RAngleLoc),
1810 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 }
1812
1813 /// \brief Build a new C++ dynamic_cast expression.
1814 ///
1815 /// By default, performs semantic analysis to build the new expression.
1816 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001817 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001818 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001819 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001820 SourceLocation RAngleLoc,
1821 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001822 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001823 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001824 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001825 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001826 SourceRange(LAngleLoc, RAngleLoc),
1827 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 }
1829
1830 /// \brief Build a new C++ reinterpret_cast expression.
1831 ///
1832 /// By default, performs semantic analysis to build the new expression.
1833 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001834 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001835 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001836 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001837 SourceLocation RAngleLoc,
1838 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001839 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001841 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001842 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001843 SourceRange(LAngleLoc, RAngleLoc),
1844 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 }
1846
1847 /// \brief Build a new C++ const_cast expression.
1848 ///
1849 /// By default, performs semantic analysis to build the new expression.
1850 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001851 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001852 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001853 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001854 SourceLocation RAngleLoc,
1855 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001856 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001857 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001858 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001859 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001860 SourceRange(LAngleLoc, RAngleLoc),
1861 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001862 }
Mike Stump1eb44332009-09-09 15:08:12 +00001863
Douglas Gregorb98b1992009-08-11 05:31:07 +00001864 /// \brief Build a new C++ functional-style cast expression.
1865 ///
1866 /// By default, performs semantic analysis to build the new expression.
1867 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001868 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1869 SourceLocation LParenLoc,
1870 Expr *Sub,
1871 SourceLocation RParenLoc) {
1872 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001873 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001874 RParenLoc);
1875 }
Mike Stump1eb44332009-09-09 15:08:12 +00001876
Douglas Gregorb98b1992009-08-11 05:31:07 +00001877 /// \brief Build a new C++ typeid(type) expression.
1878 ///
1879 /// By default, performs semantic analysis to build the new expression.
1880 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001881 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001882 SourceLocation TypeidLoc,
1883 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001884 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001885 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001886 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001887 }
Mike Stump1eb44332009-09-09 15:08:12 +00001888
Francois Pichet01b7c302010-09-08 12:20:18 +00001889
Douglas Gregorb98b1992009-08-11 05:31:07 +00001890 /// \brief Build a new C++ typeid(expr) expression.
1891 ///
1892 /// By default, performs semantic analysis to build the new expression.
1893 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001894 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001895 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001896 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001898 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001899 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001900 }
1901
Francois Pichet01b7c302010-09-08 12:20:18 +00001902 /// \brief Build a new C++ __uuidof(type) expression.
1903 ///
1904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
1906 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1907 SourceLocation TypeidLoc,
1908 TypeSourceInfo *Operand,
1909 SourceLocation RParenLoc) {
1910 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1911 RParenLoc);
1912 }
1913
1914 /// \brief Build a new C++ __uuidof(expr) expression.
1915 ///
1916 /// By default, performs semantic analysis to build the new expression.
1917 /// Subclasses may override this routine to provide different behavior.
1918 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1919 SourceLocation TypeidLoc,
1920 Expr *Operand,
1921 SourceLocation RParenLoc) {
1922 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1923 RParenLoc);
1924 }
1925
Douglas Gregorb98b1992009-08-11 05:31:07 +00001926 /// \brief Build a new C++ "this" expression.
1927 ///
1928 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001929 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001930 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001931 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001932 QualType ThisType,
1933 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001934 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001936 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1937 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 }
1939
1940 /// \brief Build a new C++ throw expression.
1941 ///
1942 /// By default, performs semantic analysis to build the new expression.
1943 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001944 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1945 bool IsThrownVariableInScope) {
1946 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 }
1948
1949 /// \brief Build a new C++ default-argument expression.
1950 ///
1951 /// By default, builds a new default-argument expression, which does not
1952 /// require any semantic analysis. Subclasses may override this routine to
1953 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001954 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001955 ParmVarDecl *Param) {
1956 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1957 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001958 }
1959
1960 /// \brief Build a new C++ zero-initialization expression.
1961 ///
1962 /// By default, performs semantic analysis to build the new expression.
1963 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001964 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1965 SourceLocation LParenLoc,
1966 SourceLocation RParenLoc) {
1967 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001968 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001969 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 }
Mike Stump1eb44332009-09-09 15:08:12 +00001971
Douglas Gregorb98b1992009-08-11 05:31:07 +00001972 /// \brief Build a new C++ "new" expression.
1973 ///
1974 /// By default, performs semantic analysis to build the new expression.
1975 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001976 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001977 bool UseGlobal,
1978 SourceLocation PlacementLParen,
1979 MultiExprArg PlacementArgs,
1980 SourceLocation PlacementRParen,
1981 SourceRange TypeIdParens,
1982 QualType AllocatedType,
1983 TypeSourceInfo *AllocatedTypeInfo,
1984 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001985 SourceRange DirectInitRange,
1986 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001987 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001988 PlacementLParen,
1989 move(PlacementArgs),
1990 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001991 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001992 AllocatedType,
1993 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001994 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001995 DirectInitRange,
1996 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001997 }
Mike Stump1eb44332009-09-09 15:08:12 +00001998
Douglas Gregorb98b1992009-08-11 05:31:07 +00001999 /// \brief Build a new C++ "delete" expression.
2000 ///
2001 /// By default, performs semantic analysis to build the new expression.
2002 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002003 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002004 bool IsGlobalDelete,
2005 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002006 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002007 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002008 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002009 }
Mike Stump1eb44332009-09-09 15:08:12 +00002010
Douglas Gregorb98b1992009-08-11 05:31:07 +00002011 /// \brief Build a new unary type trait expression.
2012 ///
2013 /// By default, performs semantic analysis to build the new expression.
2014 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002015 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002016 SourceLocation StartLoc,
2017 TypeSourceInfo *T,
2018 SourceLocation RParenLoc) {
2019 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002020 }
2021
Francois Pichet6ad6f282010-12-07 00:08:36 +00002022 /// \brief Build a new binary type trait expression.
2023 ///
2024 /// By default, performs semantic analysis to build the new expression.
2025 /// Subclasses may override this routine to provide different behavior.
2026 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2027 SourceLocation StartLoc,
2028 TypeSourceInfo *LhsT,
2029 TypeSourceInfo *RhsT,
2030 SourceLocation RParenLoc) {
2031 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2032 }
2033
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002034 /// \brief Build a new type trait expression.
2035 ///
2036 /// By default, performs semantic analysis to build the new expression.
2037 /// Subclasses may override this routine to provide different behavior.
2038 ExprResult RebuildTypeTrait(TypeTrait Trait,
2039 SourceLocation StartLoc,
2040 ArrayRef<TypeSourceInfo *> Args,
2041 SourceLocation RParenLoc) {
2042 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2043 }
2044
John Wiegley21ff2e52011-04-28 00:16:57 +00002045 /// \brief Build a new array type trait expression.
2046 ///
2047 /// By default, performs semantic analysis to build the new expression.
2048 /// Subclasses may override this routine to provide different behavior.
2049 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2050 SourceLocation StartLoc,
2051 TypeSourceInfo *TSInfo,
2052 Expr *DimExpr,
2053 SourceLocation RParenLoc) {
2054 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2055 }
2056
John Wiegley55262202011-04-25 06:54:41 +00002057 /// \brief Build a new expression trait expression.
2058 ///
2059 /// By default, performs semantic analysis to build the new expression.
2060 /// Subclasses may override this routine to provide different behavior.
2061 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2062 SourceLocation StartLoc,
2063 Expr *Queried,
2064 SourceLocation RParenLoc) {
2065 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2066 }
2067
Mike Stump1eb44332009-09-09 15:08:12 +00002068 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002069 /// expression.
2070 ///
2071 /// By default, performs semantic analysis to build the new expression.
2072 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002073 ExprResult RebuildDependentScopeDeclRefExpr(
2074 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002075 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002076 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002077 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002078 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002079 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002080
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002081 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002082 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002083 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002084
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002085 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002086 }
2087
2088 /// \brief Build a new template-id expression.
2089 ///
2090 /// By default, performs semantic analysis to build the new expression.
2091 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002092 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002093 SourceLocation TemplateKWLoc,
2094 LookupResult &R,
2095 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002096 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002097 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2098 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002099 }
2100
2101 /// \brief Build a new object-construction expression.
2102 ///
2103 /// By default, performs semantic analysis to build the new expression.
2104 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002105 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002106 SourceLocation Loc,
2107 CXXConstructorDecl *Constructor,
2108 bool IsElidable,
2109 MultiExprArg Args,
2110 bool HadMultipleCandidates,
2111 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002112 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002113 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002114 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002115 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002116 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002117 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002118
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002119 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002120 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002121 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002122 RequiresZeroInit, ConstructKind,
2123 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002124 }
2125
2126 /// \brief Build a new object-construction expression.
2127 ///
2128 /// By default, performs semantic analysis to build the new expression.
2129 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002130 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2131 SourceLocation LParenLoc,
2132 MultiExprArg Args,
2133 SourceLocation RParenLoc) {
2134 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002135 LParenLoc,
2136 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002137 RParenLoc);
2138 }
2139
2140 /// \brief Build a new object-construction expression.
2141 ///
2142 /// By default, performs semantic analysis to build the new expression.
2143 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002144 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2145 SourceLocation LParenLoc,
2146 MultiExprArg Args,
2147 SourceLocation RParenLoc) {
2148 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002149 LParenLoc,
2150 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002151 RParenLoc);
2152 }
Mike Stump1eb44332009-09-09 15:08:12 +00002153
Douglas Gregorb98b1992009-08-11 05:31:07 +00002154 /// \brief Build a new member reference expression.
2155 ///
2156 /// By default, performs semantic analysis to build the new expression.
2157 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002158 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002159 QualType BaseType,
2160 bool IsArrow,
2161 SourceLocation OperatorLoc,
2162 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002163 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002164 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002165 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002166 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002167 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002168 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002169
John McCall9ae2f072010-08-23 23:25:46 +00002170 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002171 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002172 SS, TemplateKWLoc,
2173 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002174 MemberNameInfo,
2175 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002176 }
2177
John McCall129e2df2009-11-30 22:42:35 +00002178 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002179 ///
2180 /// By default, performs semantic analysis to build the new expression.
2181 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002182 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2183 SourceLocation OperatorLoc,
2184 bool IsArrow,
2185 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002186 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002187 NamedDecl *FirstQualifierInScope,
2188 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002189 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002190 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002191 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002192
John McCall9ae2f072010-08-23 23:25:46 +00002193 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002194 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002195 SS, TemplateKWLoc,
2196 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002197 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002198 }
Mike Stump1eb44332009-09-09 15:08:12 +00002199
Sebastian Redl2e156222010-09-10 20:55:43 +00002200 /// \brief Build a new noexcept expression.
2201 ///
2202 /// By default, performs semantic analysis to build the new expression.
2203 /// Subclasses may override this routine to provide different behavior.
2204 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2205 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2206 }
2207
Douglas Gregoree8aff02011-01-04 17:33:58 +00002208 /// \brief Build a new expression to compute the length of a parameter pack.
2209 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2210 SourceLocation PackLoc,
2211 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002212 llvm::Optional<unsigned> Length) {
2213 if (Length)
2214 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2215 OperatorLoc, Pack, PackLoc,
2216 RParenLoc, *Length);
2217
Douglas Gregoree8aff02011-01-04 17:33:58 +00002218 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2219 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002220 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002221 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002222
2223 /// \brief Build a new Objective-C array literal.
2224 ///
2225 /// By default, performs semantic analysis to build the new expression.
2226 /// Subclasses may override this routine to provide different behavior.
2227 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2228 Expr **Elements, unsigned NumElements) {
2229 return getSema().BuildObjCArrayLiteral(Range,
2230 MultiExprArg(Elements, NumElements));
2231 }
2232
2233 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2234 Expr *Base, Expr *Key,
2235 ObjCMethodDecl *getterMethod,
2236 ObjCMethodDecl *setterMethod) {
2237 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2238 getterMethod, setterMethod);
2239 }
2240
2241 /// \brief Build a new Objective-C dictionary literal.
2242 ///
2243 /// By default, performs semantic analysis to build the new expression.
2244 /// Subclasses may override this routine to provide different behavior.
2245 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2246 ObjCDictionaryElement *Elements,
2247 unsigned NumElements) {
2248 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2249 }
2250
Douglas Gregorb98b1992009-08-11 05:31:07 +00002251 /// \brief Build a new Objective-C @encode expression.
2252 ///
2253 /// By default, performs semantic analysis to build the new expression.
2254 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002255 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002256 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002257 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002258 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002259 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002260 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002261
Douglas Gregor92e986e2010-04-22 16:44:27 +00002262 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002263 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002264 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002265 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002266 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002267 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002268 MultiExprArg Args,
2269 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002270 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2271 ReceiverTypeInfo->getType(),
2272 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002273 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002274 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002275 }
2276
2277 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002278 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002279 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002280 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002281 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002282 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002283 MultiExprArg Args,
2284 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002285 return SemaRef.BuildInstanceMessage(Receiver,
2286 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002287 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002288 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002289 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002290 }
2291
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002292 /// \brief Build a new Objective-C ivar reference expression.
2293 ///
2294 /// By default, performs semantic analysis to build the new expression.
2295 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002296 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002297 SourceLocation IvarLoc,
2298 bool IsArrow, bool IsFreeIvar) {
2299 // FIXME: We lose track of the IsFreeIvar bit.
2300 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002301 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002302 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2303 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002304 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002305 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002306 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002307 false);
John Wiegley429bb272011-04-08 18:41:53 +00002308 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002309 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002310
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002311 if (Result.get())
2312 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002313
John Wiegley429bb272011-04-08 18:41:53 +00002314 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002315 /*FIXME:*/IvarLoc, IsArrow,
2316 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002317 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002318 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002319 /*TemplateArgs=*/0);
2320 }
Douglas Gregore3303542010-04-26 20:47:02 +00002321
2322 /// \brief Build a new Objective-C property reference expression.
2323 ///
2324 /// By default, performs semantic analysis to build the new expression.
2325 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002326 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002327 ObjCPropertyDecl *Property,
2328 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002329 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002330 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002331 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2332 Sema::LookupMemberName);
2333 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002334 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002335 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002336 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002337 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002338 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002339
Douglas Gregore3303542010-04-26 20:47:02 +00002340 if (Result.get())
2341 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002342
John Wiegley429bb272011-04-08 18:41:53 +00002343 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002344 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002345 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002346 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002347 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002348 /*TemplateArgs=*/0);
2349 }
Sean Huntc3021132010-05-05 15:23:54 +00002350
John McCall12f78a62010-12-02 01:19:52 +00002351 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002352 ///
2353 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002354 /// Subclasses may override this routine to provide different behavior.
2355 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2356 ObjCMethodDecl *Getter,
2357 ObjCMethodDecl *Setter,
2358 SourceLocation PropertyLoc) {
2359 // Since these expressions can only be value-dependent, we do not
2360 // need to perform semantic analysis again.
2361 return Owned(
2362 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2363 VK_LValue, OK_ObjCProperty,
2364 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002365 }
2366
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002367 /// \brief Build a new Objective-C "isa" expression.
2368 ///
2369 /// By default, performs semantic analysis to build the new expression.
2370 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002371 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002372 bool IsArrow) {
2373 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002374 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002375 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2376 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002377 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002378 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002379 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002380 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002381 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002382
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002383 if (Result.get())
2384 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002385
John Wiegley429bb272011-04-08 18:41:53 +00002386 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002387 /*FIXME:*/IsaLoc, IsArrow,
2388 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002389 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002390 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002391 /*TemplateArgs=*/0);
2392 }
Sean Huntc3021132010-05-05 15:23:54 +00002393
Douglas Gregorb98b1992009-08-11 05:31:07 +00002394 /// \brief Build a new shuffle vector expression.
2395 ///
2396 /// By default, performs semantic analysis to build the new expression.
2397 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002398 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002399 MultiExprArg SubExprs,
2400 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002401 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002402 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002403 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2404 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2405 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2406 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002407
Douglas Gregorb98b1992009-08-11 05:31:07 +00002408 // Build a reference to the __builtin_shufflevector builtin
2409 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002410 ExprResult Callee
John McCallf4b88a42012-03-10 09:33:50 +00002411 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2412 Builtin->getType(),
John Wiegley429bb272011-04-08 18:41:53 +00002413 VK_LValue, BuiltinLoc));
2414 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2415 if (Callee.isInvalid())
2416 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002417
2418 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002419 unsigned NumSubExprs = SubExprs.size();
2420 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002421 ExprResult TheCall = SemaRef.Owned(
2422 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002423 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002424 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002425 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002426 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002427
Douglas Gregorb98b1992009-08-11 05:31:07 +00002428 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002429 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002430 }
John McCall43fed0d2010-11-12 08:19:04 +00002431
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002432 /// \brief Build a new template argument pack expansion.
2433 ///
2434 /// By default, performs semantic analysis to build a new pack expansion
2435 /// for a template argument. Subclasses may override this routine to provide
2436 /// different behavior.
2437 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002438 SourceLocation EllipsisLoc,
2439 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002440 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002441 case TemplateArgument::Expression: {
2442 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002443 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2444 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002445 if (Result.isInvalid())
2446 return TemplateArgumentLoc();
2447
2448 return TemplateArgumentLoc(Result.get(), Result.get());
2449 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002450
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002451 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002452 return TemplateArgumentLoc(TemplateArgument(
2453 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002454 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002455 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002456 Pattern.getTemplateNameLoc(),
2457 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002458
2459 case TemplateArgument::Null:
2460 case TemplateArgument::Integral:
2461 case TemplateArgument::Declaration:
2462 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002463 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002464 llvm_unreachable("Pack expansion pattern has no parameter packs");
2465
2466 case TemplateArgument::Type:
2467 if (TypeSourceInfo *Expansion
2468 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002469 EllipsisLoc,
2470 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002471 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2472 Expansion);
2473 break;
2474 }
2475
2476 return TemplateArgumentLoc();
2477 }
2478
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002479 /// \brief Build a new expression pack expansion.
2480 ///
2481 /// By default, performs semantic analysis to build a new pack expansion
2482 /// for an expression. Subclasses may override this routine to provide
2483 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002484 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2485 llvm::Optional<unsigned> NumExpansions) {
2486 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002487 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002488
2489 /// \brief Build a new atomic operation expression.
2490 ///
2491 /// By default, performs semantic analysis to build the new expression.
2492 /// Subclasses may override this routine to provide different behavior.
2493 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2494 MultiExprArg SubExprs,
2495 QualType RetTy,
2496 AtomicExpr::AtomicOp Op,
2497 SourceLocation RParenLoc) {
2498 // Just create the expression; there is not any interesting semantic
2499 // analysis here because we can't actually build an AtomicExpr until
2500 // we are sure it is semantically sound.
2501 unsigned NumSubExprs = SubExprs.size();
2502 Expr **Subs = (Expr **)SubExprs.release();
2503 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2504 NumSubExprs, RetTy, Op,
2505 RParenLoc);
2506 }
2507
John McCall43fed0d2010-11-12 08:19:04 +00002508private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002509 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2510 QualType ObjectType,
2511 NamedDecl *FirstQualifierInScope,
2512 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002513
2514 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2515 QualType ObjectType,
2516 NamedDecl *FirstQualifierInScope,
2517 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002518};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002519
Douglas Gregor43959a92009-08-20 07:17:43 +00002520template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002521StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002522 if (!S)
2523 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002524
Douglas Gregor43959a92009-08-20 07:17:43 +00002525 switch (S->getStmtClass()) {
2526 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002527
Douglas Gregor43959a92009-08-20 07:17:43 +00002528 // Transform individual statement nodes
2529#define STMT(Node, Parent) \
2530 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002531#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002532#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002533#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002534
Douglas Gregor43959a92009-08-20 07:17:43 +00002535 // Transform expressions by calling TransformExpr.
2536#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002537#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002538#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002539#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002540 {
John McCall60d7b3a2010-08-24 06:29:42 +00002541 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002542 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002543 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002544
John McCall9ae2f072010-08-23 23:25:46 +00002545 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002546 }
Mike Stump1eb44332009-09-09 15:08:12 +00002547 }
2548
John McCall3fa5cae2010-10-26 07:05:15 +00002549 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002550}
Mike Stump1eb44332009-09-09 15:08:12 +00002551
2552
Douglas Gregor670444e2009-08-04 22:27:00 +00002553template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002554ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002555 if (!E)
2556 return SemaRef.Owned(E);
2557
2558 switch (E->getStmtClass()) {
2559 case Stmt::NoStmtClass: break;
2560#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002561#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002562#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002563 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002564#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002565 }
2566
John McCall3fa5cae2010-10-26 07:05:15 +00002567 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002568}
2569
2570template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002571bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2572 unsigned NumInputs,
2573 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002574 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002575 bool *ArgChanged) {
2576 for (unsigned I = 0; I != NumInputs; ++I) {
2577 // If requested, drop call arguments that need to be dropped.
2578 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2579 if (ArgChanged)
2580 *ArgChanged = true;
2581
2582 break;
2583 }
2584
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002585 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2586 Expr *Pattern = Expansion->getPattern();
2587
Chris Lattner686775d2011-07-20 06:58:45 +00002588 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002589 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2590 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2591
2592 // Determine whether the set of unexpanded parameter packs can and should
2593 // be expanded.
2594 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002595 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002596 llvm::Optional<unsigned> OrigNumExpansions
2597 = Expansion->getNumExpansions();
2598 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002599 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2600 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002601 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002602 Expand, RetainExpansion,
2603 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002604 return true;
2605
2606 if (!Expand) {
2607 // The transform has determined that we should perform a simple
2608 // transformation on the pack expansion, producing another pack
2609 // expansion.
2610 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2611 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2612 if (OutPattern.isInvalid())
2613 return true;
2614
2615 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002616 Expansion->getEllipsisLoc(),
2617 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002618 if (Out.isInvalid())
2619 return true;
2620
2621 if (ArgChanged)
2622 *ArgChanged = true;
2623 Outputs.push_back(Out.get());
2624 continue;
2625 }
John McCallc8fc90a2011-07-06 07:30:07 +00002626
2627 // Record right away that the argument was changed. This needs
2628 // to happen even if the array expands to nothing.
2629 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002630
2631 // The transform has determined that we should perform an elementwise
2632 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002633 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002634 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2635 ExprResult Out = getDerived().TransformExpr(Pattern);
2636 if (Out.isInvalid())
2637 return true;
2638
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002639 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002640 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2641 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002642 if (Out.isInvalid())
2643 return true;
2644 }
2645
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002646 Outputs.push_back(Out.get());
2647 }
2648
2649 continue;
2650 }
2651
Douglas Gregoraa165f82011-01-03 19:04:46 +00002652 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2653 if (Result.isInvalid())
2654 return true;
2655
2656 if (Result.get() != Inputs[I] && ArgChanged)
2657 *ArgChanged = true;
2658
2659 Outputs.push_back(Result.get());
2660 }
2661
2662 return false;
2663}
2664
2665template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002666NestedNameSpecifierLoc
2667TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2668 NestedNameSpecifierLoc NNS,
2669 QualType ObjectType,
2670 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002671 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002672 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2673 Qualifier = Qualifier.getPrefix())
2674 Qualifiers.push_back(Qualifier);
2675
2676 CXXScopeSpec SS;
2677 while (!Qualifiers.empty()) {
2678 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2679 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2680
2681 switch (QNNS->getKind()) {
2682 case NestedNameSpecifier::Identifier:
2683 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2684 *QNNS->getAsIdentifier(),
2685 Q.getLocalBeginLoc(),
2686 Q.getLocalEndLoc(),
2687 ObjectType, false, SS,
2688 FirstQualifierInScope, false))
2689 return NestedNameSpecifierLoc();
2690
2691 break;
2692
2693 case NestedNameSpecifier::Namespace: {
2694 NamespaceDecl *NS
2695 = cast_or_null<NamespaceDecl>(
2696 getDerived().TransformDecl(
2697 Q.getLocalBeginLoc(),
2698 QNNS->getAsNamespace()));
2699 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2700 break;
2701 }
2702
2703 case NestedNameSpecifier::NamespaceAlias: {
2704 NamespaceAliasDecl *Alias
2705 = cast_or_null<NamespaceAliasDecl>(
2706 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2707 QNNS->getAsNamespaceAlias()));
2708 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2709 Q.getLocalEndLoc());
2710 break;
2711 }
2712
2713 case NestedNameSpecifier::Global:
2714 // There is no meaningful transformation that one could perform on the
2715 // global scope.
2716 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2717 break;
2718
2719 case NestedNameSpecifier::TypeSpecWithTemplate:
2720 case NestedNameSpecifier::TypeSpec: {
2721 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2722 FirstQualifierInScope, SS);
2723
2724 if (!TL)
2725 return NestedNameSpecifierLoc();
2726
2727 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
David Blaikie4e4d0842012-03-11 07:00:24 +00002728 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002729 TL.getType()->isEnumeralType())) {
2730 assert(!TL.getType().hasLocalQualifiers() &&
2731 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002732 if (TL.getType()->isEnumeralType())
2733 SemaRef.Diag(TL.getBeginLoc(),
2734 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002735 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2736 Q.getLocalEndLoc());
2737 break;
2738 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002739 // If the nested-name-specifier is an invalid type def, don't emit an
2740 // error because a previous error should have already been emitted.
2741 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2742 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2743 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2744 << TL.getType() << SS.getRange();
2745 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002746 return NestedNameSpecifierLoc();
2747 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002748 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002749
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002750 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002751 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002752 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002753 }
2754
2755 // Don't rebuild the nested-name-specifier if we don't have to.
2756 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2757 !getDerived().AlwaysRebuild())
2758 return NNS;
2759
2760 // If we can re-use the source-location data from the original
2761 // nested-name-specifier, do so.
2762 if (SS.location_size() == NNS.getDataLength() &&
2763 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2764 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2765
2766 // Allocate new nested-name-specifier location information.
2767 return SS.getWithLocInContext(SemaRef.Context);
2768}
2769
2770template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002771DeclarationNameInfo
2772TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002773::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002774 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002775 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002776 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002777
2778 switch (Name.getNameKind()) {
2779 case DeclarationName::Identifier:
2780 case DeclarationName::ObjCZeroArgSelector:
2781 case DeclarationName::ObjCOneArgSelector:
2782 case DeclarationName::ObjCMultiArgSelector:
2783 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002784 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002785 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002786 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002787
Douglas Gregor81499bb2009-09-03 22:13:48 +00002788 case DeclarationName::CXXConstructorName:
2789 case DeclarationName::CXXDestructorName:
2790 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002791 TypeSourceInfo *NewTInfo;
2792 CanQualType NewCanTy;
2793 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002794 NewTInfo = getDerived().TransformType(OldTInfo);
2795 if (!NewTInfo)
2796 return DeclarationNameInfo();
2797 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002798 }
2799 else {
2800 NewTInfo = 0;
2801 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002802 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002803 if (NewT.isNull())
2804 return DeclarationNameInfo();
2805 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2806 }
Mike Stump1eb44332009-09-09 15:08:12 +00002807
Abramo Bagnara25777432010-08-11 22:01:17 +00002808 DeclarationName NewName
2809 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2810 NewCanTy);
2811 DeclarationNameInfo NewNameInfo(NameInfo);
2812 NewNameInfo.setName(NewName);
2813 NewNameInfo.setNamedTypeInfo(NewTInfo);
2814 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002815 }
Mike Stump1eb44332009-09-09 15:08:12 +00002816 }
2817
David Blaikieb219cfc2011-09-23 05:06:16 +00002818 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002819}
2820
2821template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002822TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002823TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2824 TemplateName Name,
2825 SourceLocation NameLoc,
2826 QualType ObjectType,
2827 NamedDecl *FirstQualifierInScope) {
2828 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2829 TemplateDecl *Template = QTN->getTemplateDecl();
2830 assert(Template && "qualified template name must refer to a template");
2831
2832 TemplateDecl *TransTemplate
2833 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2834 Template));
2835 if (!TransTemplate)
2836 return TemplateName();
2837
2838 if (!getDerived().AlwaysRebuild() &&
2839 SS.getScopeRep() == QTN->getQualifier() &&
2840 TransTemplate == Template)
2841 return Name;
2842
2843 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2844 TransTemplate);
2845 }
2846
2847 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2848 if (SS.getScopeRep()) {
2849 // These apply to the scope specifier, not the template.
2850 ObjectType = QualType();
2851 FirstQualifierInScope = 0;
2852 }
2853
2854 if (!getDerived().AlwaysRebuild() &&
2855 SS.getScopeRep() == DTN->getQualifier() &&
2856 ObjectType.isNull())
2857 return Name;
2858
2859 if (DTN->isIdentifier()) {
2860 return getDerived().RebuildTemplateName(SS,
2861 *DTN->getIdentifier(),
2862 NameLoc,
2863 ObjectType,
2864 FirstQualifierInScope);
2865 }
2866
2867 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2868 ObjectType);
2869 }
2870
2871 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2872 TemplateDecl *TransTemplate
2873 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2874 Template));
2875 if (!TransTemplate)
2876 return TemplateName();
2877
2878 if (!getDerived().AlwaysRebuild() &&
2879 TransTemplate == Template)
2880 return Name;
2881
2882 return TemplateName(TransTemplate);
2883 }
2884
2885 if (SubstTemplateTemplateParmPackStorage *SubstPack
2886 = Name.getAsSubstTemplateTemplateParmPack()) {
2887 TemplateTemplateParmDecl *TransParam
2888 = cast_or_null<TemplateTemplateParmDecl>(
2889 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2890 if (!TransParam)
2891 return TemplateName();
2892
2893 if (!getDerived().AlwaysRebuild() &&
2894 TransParam == SubstPack->getParameterPack())
2895 return Name;
2896
2897 return getDerived().RebuildTemplateName(TransParam,
2898 SubstPack->getArgumentPack());
2899 }
2900
2901 // These should be getting filtered out before they reach the AST.
2902 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002903}
2904
2905template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002906void TreeTransform<Derived>::InventTemplateArgumentLoc(
2907 const TemplateArgument &Arg,
2908 TemplateArgumentLoc &Output) {
2909 SourceLocation Loc = getDerived().getBaseLocation();
2910 switch (Arg.getKind()) {
2911 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002912 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002913 break;
2914
2915 case TemplateArgument::Type:
2916 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002917 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002918
John McCall833ca992009-10-29 08:12:44 +00002919 break;
2920
Douglas Gregor788cd062009-11-11 01:00:40 +00002921 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002922 case TemplateArgument::TemplateExpansion: {
2923 NestedNameSpecifierLocBuilder Builder;
2924 TemplateName Template = Arg.getAsTemplate();
2925 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2926 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2927 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2928 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2929
2930 if (Arg.getKind() == TemplateArgument::Template)
2931 Output = TemplateArgumentLoc(Arg,
2932 Builder.getWithLocInContext(SemaRef.Context),
2933 Loc);
2934 else
2935 Output = TemplateArgumentLoc(Arg,
2936 Builder.getWithLocInContext(SemaRef.Context),
2937 Loc, Loc);
2938
Douglas Gregor788cd062009-11-11 01:00:40 +00002939 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002940 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002941
John McCall833ca992009-10-29 08:12:44 +00002942 case TemplateArgument::Expression:
2943 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2944 break;
2945
2946 case TemplateArgument::Declaration:
2947 case TemplateArgument::Integral:
2948 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002949 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002950 break;
2951 }
2952}
2953
2954template<typename Derived>
2955bool TreeTransform<Derived>::TransformTemplateArgument(
2956 const TemplateArgumentLoc &Input,
2957 TemplateArgumentLoc &Output) {
2958 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002959 switch (Arg.getKind()) {
2960 case TemplateArgument::Null:
2961 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002962 Output = Input;
2963 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002964
Douglas Gregor670444e2009-08-04 22:27:00 +00002965 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002966 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002967 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002968 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002969
2970 DI = getDerived().TransformType(DI);
2971 if (!DI) return true;
2972
2973 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2974 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002975 }
Mike Stump1eb44332009-09-09 15:08:12 +00002976
Douglas Gregor670444e2009-08-04 22:27:00 +00002977 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002978 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002979 DeclarationName Name;
2980 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2981 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002982 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002983 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002984 if (!D) return true;
2985
John McCall828bff22009-10-29 18:45:58 +00002986 Expr *SourceExpr = Input.getSourceDeclExpression();
2987 if (SourceExpr) {
2988 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002989 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002990 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00002991 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00002992 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002993 }
2994
2995 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002996 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002997 }
Mike Stump1eb44332009-09-09 15:08:12 +00002998
Douglas Gregor788cd062009-11-11 01:00:40 +00002999 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003000 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3001 if (QualifierLoc) {
3002 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3003 if (!QualifierLoc)
3004 return true;
3005 }
3006
Douglas Gregor1d752d72011-03-02 18:46:51 +00003007 CXXScopeSpec SS;
3008 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003009 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003010 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3011 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003012 if (Template.isNull())
3013 return true;
Sean Huntc3021132010-05-05 15:23:54 +00003014
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003015 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003016 Input.getTemplateNameLoc());
3017 return false;
3018 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003019
3020 case TemplateArgument::TemplateExpansion:
3021 llvm_unreachable("Caller should expand pack expansions");
3022
Douglas Gregor670444e2009-08-04 22:27:00 +00003023 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003024 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003025 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003026 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003027
John McCall833ca992009-10-29 08:12:44 +00003028 Expr *InputExpr = Input.getSourceExpression();
3029 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3030
Chris Lattner223de242011-04-25 20:37:58 +00003031 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003032 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003033 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003034 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003035 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003036 }
Mike Stump1eb44332009-09-09 15:08:12 +00003037
Douglas Gregor670444e2009-08-04 22:27:00 +00003038 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003039 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003040 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003041 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003042 AEnd = Arg.pack_end();
3043 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003044
John McCall833ca992009-10-29 08:12:44 +00003045 // FIXME: preserve source information here when we start
3046 // caring about parameter packs.
3047
John McCall828bff22009-10-29 18:45:58 +00003048 TemplateArgumentLoc InputArg;
3049 TemplateArgumentLoc OutputArg;
3050 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3051 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003052 return true;
3053
John McCall828bff22009-10-29 18:45:58 +00003054 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003055 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003056
3057 TemplateArgument *TransformedArgsPtr
3058 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3059 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3060 TransformedArgsPtr);
3061 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3062 TransformedArgs.size()),
3063 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003064 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003065 }
3066 }
Mike Stump1eb44332009-09-09 15:08:12 +00003067
Douglas Gregor670444e2009-08-04 22:27:00 +00003068 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003069 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003070}
3071
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003072/// \brief Iterator adaptor that invents template argument location information
3073/// for each of the template arguments in its underlying iterator.
3074template<typename Derived, typename InputIterator>
3075class TemplateArgumentLocInventIterator {
3076 TreeTransform<Derived> &Self;
3077 InputIterator Iter;
3078
3079public:
3080 typedef TemplateArgumentLoc value_type;
3081 typedef TemplateArgumentLoc reference;
3082 typedef typename std::iterator_traits<InputIterator>::difference_type
3083 difference_type;
3084 typedef std::input_iterator_tag iterator_category;
3085
3086 class pointer {
3087 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003088
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003089 public:
3090 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3091
3092 const TemplateArgumentLoc *operator->() const { return &Arg; }
3093 };
3094
3095 TemplateArgumentLocInventIterator() { }
3096
3097 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3098 InputIterator Iter)
3099 : Self(Self), Iter(Iter) { }
3100
3101 TemplateArgumentLocInventIterator &operator++() {
3102 ++Iter;
3103 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003104 }
3105
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003106 TemplateArgumentLocInventIterator operator++(int) {
3107 TemplateArgumentLocInventIterator Old(*this);
3108 ++(*this);
3109 return Old;
3110 }
3111
3112 reference operator*() const {
3113 TemplateArgumentLoc Result;
3114 Self.InventTemplateArgumentLoc(*Iter, Result);
3115 return Result;
3116 }
3117
3118 pointer operator->() const { return pointer(**this); }
3119
3120 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3121 const TemplateArgumentLocInventIterator &Y) {
3122 return X.Iter == Y.Iter;
3123 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003124
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003125 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3126 const TemplateArgumentLocInventIterator &Y) {
3127 return X.Iter != Y.Iter;
3128 }
3129};
3130
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003131template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003132template<typename InputIterator>
3133bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3134 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003135 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003136 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003137 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003138 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003139
3140 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3141 // Unpack argument packs, which we translate them into separate
3142 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003143 // FIXME: We could do much better if we could guarantee that the
3144 // TemplateArgumentLocInfo for the pack expansion would be usable for
3145 // all of the template arguments in the argument pack.
3146 typedef TemplateArgumentLocInventIterator<Derived,
3147 TemplateArgument::pack_iterator>
3148 PackLocIterator;
3149 if (TransformTemplateArguments(PackLocIterator(*this,
3150 In.getArgument().pack_begin()),
3151 PackLocIterator(*this,
3152 In.getArgument().pack_end()),
3153 Outputs))
3154 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003155
3156 continue;
3157 }
3158
3159 if (In.getArgument().isPackExpansion()) {
3160 // We have a pack expansion, for which we will be substituting into
3161 // the pattern.
3162 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003163 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003164 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003165 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3166 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003167
Chris Lattner686775d2011-07-20 06:58:45 +00003168 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003169 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3170 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3171
3172 // Determine whether the set of unexpanded parameter packs can and should
3173 // be expanded.
3174 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003175 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003176 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003177 if (getDerived().TryExpandParameterPacks(Ellipsis,
3178 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003179 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003180 Expand,
3181 RetainExpansion,
3182 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003183 return true;
3184
3185 if (!Expand) {
3186 // The transform has determined that we should perform a simple
3187 // transformation on the pack expansion, producing another pack
3188 // expansion.
3189 TemplateArgumentLoc OutPattern;
3190 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3191 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3192 return true;
3193
Douglas Gregorcded4f62011-01-14 17:04:44 +00003194 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3195 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003196 if (Out.getArgument().isNull())
3197 return true;
3198
3199 Outputs.addArgument(Out);
3200 continue;
3201 }
3202
3203 // The transform has determined that we should perform an elementwise
3204 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003205 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003206 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3207
3208 if (getDerived().TransformTemplateArgument(Pattern, Out))
3209 return true;
3210
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003211 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003212 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3213 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003214 if (Out.getArgument().isNull())
3215 return true;
3216 }
3217
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003218 Outputs.addArgument(Out);
3219 }
3220
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003221 // If we're supposed to retain a pack expansion, do so by temporarily
3222 // forgetting the partially-substituted parameter pack.
3223 if (RetainExpansion) {
3224 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3225
3226 if (getDerived().TransformTemplateArgument(Pattern, Out))
3227 return true;
3228
Douglas Gregorcded4f62011-01-14 17:04:44 +00003229 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3230 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003231 if (Out.getArgument().isNull())
3232 return true;
3233
3234 Outputs.addArgument(Out);
3235 }
Douglas Gregord3731192011-01-10 07:32:04 +00003236
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003237 continue;
3238 }
3239
3240 // The simple case:
3241 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003242 return true;
3243
3244 Outputs.addArgument(Out);
3245 }
3246
3247 return false;
3248
3249}
3250
Douglas Gregor577f75a2009-08-04 16:50:30 +00003251//===----------------------------------------------------------------------===//
3252// Type transformation
3253//===----------------------------------------------------------------------===//
3254
3255template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003256QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003257 if (getDerived().AlreadyTransformed(T))
3258 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003259
John McCalla2becad2009-10-21 00:40:46 +00003260 // Temporary workaround. All of these transformations should
3261 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003262 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3263 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003264
John McCall43fed0d2010-11-12 08:19:04 +00003265 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003266
John McCalla2becad2009-10-21 00:40:46 +00003267 if (!NewDI)
3268 return QualType();
3269
3270 return NewDI->getType();
3271}
3272
3273template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003274TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003275 // Refine the base location to the type's location.
3276 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3277 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003278 if (getDerived().AlreadyTransformed(DI->getType()))
3279 return DI;
3280
3281 TypeLocBuilder TLB;
3282
3283 TypeLoc TL = DI->getTypeLoc();
3284 TLB.reserve(TL.getFullDataSize());
3285
John McCall43fed0d2010-11-12 08:19:04 +00003286 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003287 if (Result.isNull())
3288 return 0;
3289
John McCalla93c9342009-12-07 02:54:59 +00003290 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003291}
3292
3293template<typename Derived>
3294QualType
John McCall43fed0d2010-11-12 08:19:04 +00003295TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003296 switch (T.getTypeLocClass()) {
3297#define ABSTRACT_TYPELOC(CLASS, PARENT)
3298#define TYPELOC(CLASS, PARENT) \
3299 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003300 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003301#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003302 }
Mike Stump1eb44332009-09-09 15:08:12 +00003303
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003304 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003305}
3306
3307/// FIXME: By default, this routine adds type qualifiers only to types
3308/// that can have qualifiers, and silently suppresses those qualifiers
3309/// that are not permitted (e.g., qualifiers on reference or function
3310/// types). This is the right thing for template instantiation, but
3311/// probably not for other clients.
3312template<typename Derived>
3313QualType
3314TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003315 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003316 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003317
John McCall43fed0d2010-11-12 08:19:04 +00003318 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003319 if (Result.isNull())
3320 return QualType();
3321
3322 // Silently suppress qualifiers if the result type can't be qualified.
3323 // FIXME: this is the right thing for template instantiation, but
3324 // probably not for other clients.
3325 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003326 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003327
John McCallf85e1932011-06-15 23:02:42 +00003328 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003329 // resulting type.
3330 if (Quals.hasObjCLifetime()) {
3331 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3332 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003333 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003334 // Objective-C ARC:
3335 // A lifetime qualifier applied to a substituted template parameter
3336 // overrides the lifetime qualifier from the template argument.
3337 if (const SubstTemplateTypeParmType *SubstTypeParam
3338 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3339 QualType Replacement = SubstTypeParam->getReplacementType();
3340 Qualifiers Qs = Replacement.getQualifiers();
3341 Qs.removeObjCLifetime();
3342 Replacement
3343 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3344 Qs);
3345 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3346 SubstTypeParam->getReplacedParameter(),
3347 Replacement);
3348 TLB.TypeWasModifiedSafely(Result);
3349 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003350 // Otherwise, complain about the addition of a qualifier to an
3351 // already-qualified type.
3352 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003353 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003354 << Result << R;
3355
Douglas Gregore559ca12011-06-17 22:11:49 +00003356 Quals.removeObjCLifetime();
3357 }
3358 }
3359 }
John McCall28654742010-06-05 06:41:15 +00003360 if (!Quals.empty()) {
3361 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3362 TLB.push<QualifiedTypeLoc>(Result);
3363 // No location information to preserve.
3364 }
John McCalla2becad2009-10-21 00:40:46 +00003365
3366 return Result;
3367}
3368
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003369template<typename Derived>
3370TypeLoc
3371TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3372 QualType ObjectType,
3373 NamedDecl *UnqualLookup,
3374 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003375 QualType T = TL.getType();
3376 if (getDerived().AlreadyTransformed(T))
3377 return TL;
3378
3379 TypeLocBuilder TLB;
3380 QualType Result;
3381
3382 if (isa<TemplateSpecializationType>(T)) {
3383 TemplateSpecializationTypeLoc SpecTL
3384 = cast<TemplateSpecializationTypeLoc>(TL);
3385
3386 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003387 getDerived().TransformTemplateName(SS,
3388 SpecTL.getTypePtr()->getTemplateName(),
3389 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003390 ObjectType, UnqualLookup);
3391 if (Template.isNull())
3392 return TypeLoc();
3393
3394 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3395 Template);
3396 } else if (isa<DependentTemplateSpecializationType>(T)) {
3397 DependentTemplateSpecializationTypeLoc SpecTL
3398 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3399
Douglas Gregora88f09f2011-02-28 17:23:35 +00003400 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003401 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003402 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003403 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003404 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003405 if (Template.isNull())
3406 return TypeLoc();
3407
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003408 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003409 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003410 Template,
3411 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003412 } else {
3413 // Nothing special needs to be done for these.
3414 Result = getDerived().TransformType(TLB, TL);
3415 }
3416
3417 if (Result.isNull())
3418 return TypeLoc();
3419
3420 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3421}
3422
Douglas Gregorb71d8212011-03-02 18:32:08 +00003423template<typename Derived>
3424TypeSourceInfo *
3425TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3426 QualType ObjectType,
3427 NamedDecl *UnqualLookup,
3428 CXXScopeSpec &SS) {
3429 // FIXME: Painfully copy-paste from the above!
3430
3431 QualType T = TSInfo->getType();
3432 if (getDerived().AlreadyTransformed(T))
3433 return TSInfo;
3434
3435 TypeLocBuilder TLB;
3436 QualType Result;
3437
3438 TypeLoc TL = TSInfo->getTypeLoc();
3439 if (isa<TemplateSpecializationType>(T)) {
3440 TemplateSpecializationTypeLoc SpecTL
3441 = cast<TemplateSpecializationTypeLoc>(TL);
3442
3443 TemplateName Template
3444 = getDerived().TransformTemplateName(SS,
3445 SpecTL.getTypePtr()->getTemplateName(),
3446 SpecTL.getTemplateNameLoc(),
3447 ObjectType, UnqualLookup);
3448 if (Template.isNull())
3449 return 0;
3450
3451 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3452 Template);
3453 } else if (isa<DependentTemplateSpecializationType>(T)) {
3454 DependentTemplateSpecializationTypeLoc SpecTL
3455 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3456
3457 TemplateName Template
3458 = getDerived().RebuildTemplateName(SS,
3459 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003460 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003461 ObjectType, UnqualLookup);
3462 if (Template.isNull())
3463 return 0;
3464
3465 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3466 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003467 Template,
3468 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003469 } else {
3470 // Nothing special needs to be done for these.
3471 Result = getDerived().TransformType(TLB, TL);
3472 }
3473
3474 if (Result.isNull())
3475 return 0;
3476
3477 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3478}
3479
John McCalla2becad2009-10-21 00:40:46 +00003480template <class TyLoc> static inline
3481QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3482 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3483 NewT.setNameLoc(T.getNameLoc());
3484 return T.getType();
3485}
3486
John McCalla2becad2009-10-21 00:40:46 +00003487template<typename Derived>
3488QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003489 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003490 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3491 NewT.setBuiltinLoc(T.getBuiltinLoc());
3492 if (T.needsExtraLocalData())
3493 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3494 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003495}
Mike Stump1eb44332009-09-09 15:08:12 +00003496
Douglas Gregor577f75a2009-08-04 16:50:30 +00003497template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003498QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003499 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003500 // FIXME: recurse?
3501 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003502}
Mike Stump1eb44332009-09-09 15:08:12 +00003503
Douglas Gregor577f75a2009-08-04 16:50:30 +00003504template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003505QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003506 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003507 QualType PointeeType
3508 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003509 if (PointeeType.isNull())
3510 return QualType();
3511
3512 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003513 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003514 // A dependent pointer type 'T *' has is being transformed such
3515 // that an Objective-C class type is being replaced for 'T'. The
3516 // resulting pointer type is an ObjCObjectPointerType, not a
3517 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003518 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003519
John McCallc12c5bb2010-05-15 11:32:37 +00003520 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3521 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003522 return Result;
3523 }
John McCall43fed0d2010-11-12 08:19:04 +00003524
Douglas Gregor92e986e2010-04-22 16:44:27 +00003525 if (getDerived().AlwaysRebuild() ||
3526 PointeeType != TL.getPointeeLoc().getType()) {
3527 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3528 if (Result.isNull())
3529 return QualType();
3530 }
John McCallf85e1932011-06-15 23:02:42 +00003531
3532 // Objective-C ARC can add lifetime qualifiers to the type that we're
3533 // pointing to.
3534 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3535
Douglas Gregor92e986e2010-04-22 16:44:27 +00003536 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3537 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003538 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003539}
Mike Stump1eb44332009-09-09 15:08:12 +00003540
3541template<typename Derived>
3542QualType
John McCalla2becad2009-10-21 00:40:46 +00003543TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003544 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003545 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003546 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3547 if (PointeeType.isNull())
3548 return QualType();
3549
3550 QualType Result = TL.getType();
3551 if (getDerived().AlwaysRebuild() ||
3552 PointeeType != TL.getPointeeLoc().getType()) {
3553 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003554 TL.getSigilLoc());
3555 if (Result.isNull())
3556 return QualType();
3557 }
3558
Douglas Gregor39968ad2010-04-22 16:50:51 +00003559 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003560 NewT.setSigilLoc(TL.getSigilLoc());
3561 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003562}
3563
John McCall85737a72009-10-30 00:06:24 +00003564/// Transforms a reference type. Note that somewhat paradoxically we
3565/// don't care whether the type itself is an l-value type or an r-value
3566/// type; we only care if the type was *written* as an l-value type
3567/// or an r-value type.
3568template<typename Derived>
3569QualType
3570TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003571 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003572 const ReferenceType *T = TL.getTypePtr();
3573
3574 // Note that this works with the pointee-as-written.
3575 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3576 if (PointeeType.isNull())
3577 return QualType();
3578
3579 QualType Result = TL.getType();
3580 if (getDerived().AlwaysRebuild() ||
3581 PointeeType != T->getPointeeTypeAsWritten()) {
3582 Result = getDerived().RebuildReferenceType(PointeeType,
3583 T->isSpelledAsLValue(),
3584 TL.getSigilLoc());
3585 if (Result.isNull())
3586 return QualType();
3587 }
3588
John McCallf85e1932011-06-15 23:02:42 +00003589 // Objective-C ARC can add lifetime qualifiers to the type that we're
3590 // referring to.
3591 TLB.TypeWasModifiedSafely(
3592 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3593
John McCall85737a72009-10-30 00:06:24 +00003594 // r-value references can be rebuilt as l-value references.
3595 ReferenceTypeLoc NewTL;
3596 if (isa<LValueReferenceType>(Result))
3597 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3598 else
3599 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3600 NewTL.setSigilLoc(TL.getSigilLoc());
3601
3602 return Result;
3603}
3604
Mike Stump1eb44332009-09-09 15:08:12 +00003605template<typename Derived>
3606QualType
John McCalla2becad2009-10-21 00:40:46 +00003607TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003608 LValueReferenceTypeLoc TL) {
3609 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003610}
3611
Mike Stump1eb44332009-09-09 15:08:12 +00003612template<typename Derived>
3613QualType
John McCalla2becad2009-10-21 00:40:46 +00003614TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003615 RValueReferenceTypeLoc TL) {
3616 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003617}
Mike Stump1eb44332009-09-09 15:08:12 +00003618
Douglas Gregor577f75a2009-08-04 16:50:30 +00003619template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003620QualType
John McCalla2becad2009-10-21 00:40:46 +00003621TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003622 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003623 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003624 if (PointeeType.isNull())
3625 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003626
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003627 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3628 TypeSourceInfo* NewClsTInfo = 0;
3629 if (OldClsTInfo) {
3630 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3631 if (!NewClsTInfo)
3632 return QualType();
3633 }
3634
3635 const MemberPointerType *T = TL.getTypePtr();
3636 QualType OldClsType = QualType(T->getClass(), 0);
3637 QualType NewClsType;
3638 if (NewClsTInfo)
3639 NewClsType = NewClsTInfo->getType();
3640 else {
3641 NewClsType = getDerived().TransformType(OldClsType);
3642 if (NewClsType.isNull())
3643 return QualType();
3644 }
Mike Stump1eb44332009-09-09 15:08:12 +00003645
John McCalla2becad2009-10-21 00:40:46 +00003646 QualType Result = TL.getType();
3647 if (getDerived().AlwaysRebuild() ||
3648 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003649 NewClsType != OldClsType) {
3650 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003651 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003652 if (Result.isNull())
3653 return QualType();
3654 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003655
John McCalla2becad2009-10-21 00:40:46 +00003656 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3657 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003658 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003659
3660 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003661}
3662
Mike Stump1eb44332009-09-09 15:08:12 +00003663template<typename Derived>
3664QualType
John McCalla2becad2009-10-21 00:40:46 +00003665TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003666 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003667 const ConstantArrayType *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().RebuildConstantArrayType(ElementType,
3676 T->getSizeModifier(),
3677 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003678 T->getIndexTypeCVRQualifiers(),
3679 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003680 if (Result.isNull())
3681 return QualType();
3682 }
Eli Friedman457a3772012-01-25 22:19:07 +00003683
3684 // We might have either a ConstantArrayType or a VariableArrayType now:
3685 // a ConstantArrayType is allowed to have an element type which is a
3686 // VariableArrayType if the type is dependent. Fortunately, all array
3687 // types have the same location layout.
3688 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003689 NewTL.setLBracketLoc(TL.getLBracketLoc());
3690 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003691
John McCalla2becad2009-10-21 00:40:46 +00003692 Expr *Size = TL.getSizeExpr();
3693 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003694 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3695 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003696 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003697 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003698 }
3699 NewTL.setSizeExpr(Size);
3700
3701 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003702}
Mike Stump1eb44332009-09-09 15:08:12 +00003703
Douglas Gregor577f75a2009-08-04 16:50:30 +00003704template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003705QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003706 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003707 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003708 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003709 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003710 if (ElementType.isNull())
3711 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003712
John McCalla2becad2009-10-21 00:40:46 +00003713 QualType Result = TL.getType();
3714 if (getDerived().AlwaysRebuild() ||
3715 ElementType != T->getElementType()) {
3716 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003717 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003718 T->getIndexTypeCVRQualifiers(),
3719 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003720 if (Result.isNull())
3721 return QualType();
3722 }
Sean Huntc3021132010-05-05 15:23:54 +00003723
John McCalla2becad2009-10-21 00:40:46 +00003724 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3725 NewTL.setLBracketLoc(TL.getLBracketLoc());
3726 NewTL.setRBracketLoc(TL.getRBracketLoc());
3727 NewTL.setSizeExpr(0);
3728
3729 return Result;
3730}
3731
3732template<typename Derived>
3733QualType
3734TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003735 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003736 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003737 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3738 if (ElementType.isNull())
3739 return QualType();
3740
John McCall60d7b3a2010-08-24 06:29:42 +00003741 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003742 = getDerived().TransformExpr(T->getSizeExpr());
3743 if (SizeResult.isInvalid())
3744 return QualType();
3745
John McCall9ae2f072010-08-23 23:25:46 +00003746 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003747
3748 QualType Result = TL.getType();
3749 if (getDerived().AlwaysRebuild() ||
3750 ElementType != T->getElementType() ||
3751 Size != T->getSizeExpr()) {
3752 Result = getDerived().RebuildVariableArrayType(ElementType,
3753 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003754 Size,
John McCalla2becad2009-10-21 00:40:46 +00003755 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003756 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003757 if (Result.isNull())
3758 return QualType();
3759 }
Sean Huntc3021132010-05-05 15:23:54 +00003760
John McCalla2becad2009-10-21 00:40:46 +00003761 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3762 NewTL.setLBracketLoc(TL.getLBracketLoc());
3763 NewTL.setRBracketLoc(TL.getRBracketLoc());
3764 NewTL.setSizeExpr(Size);
3765
3766 return Result;
3767}
3768
3769template<typename Derived>
3770QualType
3771TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003772 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003773 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003774 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3775 if (ElementType.isNull())
3776 return QualType();
3777
Richard Smithf6702a32011-12-20 02:08:33 +00003778 // Array bounds are constant expressions.
3779 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3780 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003781
John McCall3b657512011-01-19 10:06:00 +00003782 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3783 Expr *origSize = TL.getSizeExpr();
3784 if (!origSize) origSize = T->getSizeExpr();
3785
3786 ExprResult sizeResult
3787 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003788 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003789 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003790 return QualType();
3791
John McCall3b657512011-01-19 10:06:00 +00003792 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003793
3794 QualType Result = TL.getType();
3795 if (getDerived().AlwaysRebuild() ||
3796 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003797 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003798 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3799 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003800 size,
John McCalla2becad2009-10-21 00:40:46 +00003801 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003802 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003803 if (Result.isNull())
3804 return QualType();
3805 }
John McCalla2becad2009-10-21 00:40:46 +00003806
3807 // We might have any sort of array type now, but fortunately they
3808 // all have the same location layout.
3809 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3810 NewTL.setLBracketLoc(TL.getLBracketLoc());
3811 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003812 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003813
3814 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003815}
Mike Stump1eb44332009-09-09 15:08:12 +00003816
3817template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003818QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003819 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003820 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003821 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003822
3823 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003824 QualType ElementType = getDerived().TransformType(T->getElementType());
3825 if (ElementType.isNull())
3826 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003827
Richard Smithf6702a32011-12-20 02:08:33 +00003828 // Vector sizes are constant expressions.
3829 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3830 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003831
John McCall60d7b3a2010-08-24 06:29:42 +00003832 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003833 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003834 if (Size.isInvalid())
3835 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003836
John McCalla2becad2009-10-21 00:40:46 +00003837 QualType Result = TL.getType();
3838 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003839 ElementType != T->getElementType() ||
3840 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003841 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003842 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003843 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003844 if (Result.isNull())
3845 return QualType();
3846 }
John McCalla2becad2009-10-21 00:40:46 +00003847
3848 // Result might be dependent or not.
3849 if (isa<DependentSizedExtVectorType>(Result)) {
3850 DependentSizedExtVectorTypeLoc NewTL
3851 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3852 NewTL.setNameLoc(TL.getNameLoc());
3853 } else {
3854 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3855 NewTL.setNameLoc(TL.getNameLoc());
3856 }
3857
3858 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003859}
Mike Stump1eb44332009-09-09 15:08:12 +00003860
3861template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003862QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003863 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003864 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003865 QualType ElementType = getDerived().TransformType(T->getElementType());
3866 if (ElementType.isNull())
3867 return QualType();
3868
John McCalla2becad2009-10-21 00:40:46 +00003869 QualType Result = TL.getType();
3870 if (getDerived().AlwaysRebuild() ||
3871 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003872 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003873 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003874 if (Result.isNull())
3875 return QualType();
3876 }
Sean Huntc3021132010-05-05 15:23:54 +00003877
John McCalla2becad2009-10-21 00:40:46 +00003878 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3879 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003880
John McCalla2becad2009-10-21 00:40:46 +00003881 return Result;
3882}
3883
3884template<typename Derived>
3885QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003886 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003887 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003888 QualType ElementType = getDerived().TransformType(T->getElementType());
3889 if (ElementType.isNull())
3890 return QualType();
3891
3892 QualType Result = TL.getType();
3893 if (getDerived().AlwaysRebuild() ||
3894 ElementType != T->getElementType()) {
3895 Result = getDerived().RebuildExtVectorType(ElementType,
3896 T->getNumElements(),
3897 /*FIXME*/ SourceLocation());
3898 if (Result.isNull())
3899 return QualType();
3900 }
Sean Huntc3021132010-05-05 15:23:54 +00003901
John McCalla2becad2009-10-21 00:40:46 +00003902 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3903 NewTL.setNameLoc(TL.getNameLoc());
3904
3905 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003906}
Mike Stump1eb44332009-09-09 15:08:12 +00003907
3908template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003909ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003910TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003911 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003912 llvm::Optional<unsigned> NumExpansions,
3913 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003914 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003915 TypeSourceInfo *NewDI = 0;
3916
3917 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3918 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003919 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003920 TypeLoc OldTL = OldDI->getTypeLoc();
3921 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3922
3923 TypeLocBuilder TLB;
3924 TypeLoc NewTL = OldDI->getTypeLoc();
3925 TLB.reserve(NewTL.getFullDataSize());
3926
3927 QualType Result = getDerived().TransformType(TLB,
3928 OldExpansionTL.getPatternLoc());
3929 if (Result.isNull())
3930 return 0;
3931
3932 Result = RebuildPackExpansionType(Result,
3933 OldExpansionTL.getPatternLoc().getSourceRange(),
3934 OldExpansionTL.getEllipsisLoc(),
3935 NumExpansions);
3936 if (Result.isNull())
3937 return 0;
3938
3939 PackExpansionTypeLoc NewExpansionTL
3940 = TLB.push<PackExpansionTypeLoc>(Result);
3941 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3942 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3943 } else
3944 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003945 if (!NewDI)
3946 return 0;
3947
John McCallfb44de92011-05-01 22:35:37 +00003948 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003949 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003950
3951 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3952 OldParm->getDeclContext(),
3953 OldParm->getInnerLocStart(),
3954 OldParm->getLocation(),
3955 OldParm->getIdentifier(),
3956 NewDI->getType(),
3957 NewDI,
3958 OldParm->getStorageClass(),
3959 OldParm->getStorageClassAsWritten(),
3960 /* DefArg */ NULL);
3961 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3962 OldParm->getFunctionScopeIndex() + indexAdjustment);
3963 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003964}
3965
3966template<typename Derived>
3967bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003968 TransformFunctionTypeParams(SourceLocation Loc,
3969 ParmVarDecl **Params, unsigned NumParams,
3970 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003971 SmallVectorImpl<QualType> &OutParamTypes,
3972 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003973 int indexAdjustment = 0;
3974
Douglas Gregora009b592011-01-07 00:20:55 +00003975 for (unsigned i = 0; i != NumParams; ++i) {
3976 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003977 assert(OldParm->getFunctionScopeIndex() == i);
3978
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003979 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003980 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003981 if (OldParm->isParameterPack()) {
3982 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003983 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003984
Douglas Gregor603cfb42011-01-05 23:12:31 +00003985 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003986 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3987 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3988 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3989 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003990 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3991
Douglas Gregor603cfb42011-01-05 23:12:31 +00003992 // Determine whether we should expand the parameter packs.
3993 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003994 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003995 llvm::Optional<unsigned> OrigNumExpansions
3996 = ExpansionTL.getTypePtr()->getNumExpansions();
3997 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003998 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3999 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004000 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004001 ShouldExpand,
4002 RetainExpansion,
4003 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004004 return true;
4005 }
4006
4007 if (ShouldExpand) {
4008 // Expand the function parameter pack into multiple, separate
4009 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004010 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004011 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004012 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4013 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004014 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004015 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004016 OrigNumExpansions,
4017 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004018 if (!NewParm)
4019 return true;
4020
Douglas Gregora009b592011-01-07 00:20:55 +00004021 OutParamTypes.push_back(NewParm->getType());
4022 if (PVars)
4023 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004024 }
Douglas Gregord3731192011-01-10 07:32:04 +00004025
4026 // If we're supposed to retain a pack expansion, do so by temporarily
4027 // forgetting the partially-substituted parameter pack.
4028 if (RetainExpansion) {
4029 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4030 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004031 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004032 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004033 OrigNumExpansions,
4034 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004035 if (!NewParm)
4036 return true;
4037
4038 OutParamTypes.push_back(NewParm->getType());
4039 if (PVars)
4040 PVars->push_back(NewParm);
4041 }
4042
John McCallfb44de92011-05-01 22:35:37 +00004043 // The next parameter should have the same adjustment as the
4044 // last thing we pushed, but we post-incremented indexAdjustment
4045 // on every push. Also, if we push nothing, the adjustment should
4046 // go down by one.
4047 indexAdjustment--;
4048
Douglas Gregor603cfb42011-01-05 23:12:31 +00004049 // We're done with the pack expansion.
4050 continue;
4051 }
4052
4053 // We'll substitute the parameter now without expanding the pack
4054 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004055 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4056 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004057 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004058 NumExpansions,
4059 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004060 } else {
4061 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004062 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004063 llvm::Optional<unsigned>(),
4064 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004065 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004066
John McCall21ef0fa2010-03-11 09:03:00 +00004067 if (!NewParm)
4068 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004069
Douglas Gregora009b592011-01-07 00:20:55 +00004070 OutParamTypes.push_back(NewParm->getType());
4071 if (PVars)
4072 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004073 continue;
4074 }
John McCall21ef0fa2010-03-11 09:03:00 +00004075
4076 // Deal with the possibility that we don't have a parameter
4077 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004078 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004079 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004080 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004081 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004082 if (const PackExpansionType *Expansion
4083 = dyn_cast<PackExpansionType>(OldType)) {
4084 // We have a function parameter pack that may need to be expanded.
4085 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004086 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004087 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4088
4089 // Determine whether we should expand the parameter packs.
4090 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004091 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004092 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004093 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004094 ShouldExpand,
4095 RetainExpansion,
4096 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004097 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004098 }
4099
4100 if (ShouldExpand) {
4101 // Expand the function parameter pack into multiple, separate
4102 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004103 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004104 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4105 QualType NewType = getDerived().TransformType(Pattern);
4106 if (NewType.isNull())
4107 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004108
Douglas Gregora009b592011-01-07 00:20:55 +00004109 OutParamTypes.push_back(NewType);
4110 if (PVars)
4111 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004112 }
4113
4114 // We're done with the pack expansion.
4115 continue;
4116 }
4117
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004118 // If we're supposed to retain a pack expansion, do so by temporarily
4119 // forgetting the partially-substituted parameter pack.
4120 if (RetainExpansion) {
4121 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4122 QualType NewType = getDerived().TransformType(Pattern);
4123 if (NewType.isNull())
4124 return true;
4125
4126 OutParamTypes.push_back(NewType);
4127 if (PVars)
4128 PVars->push_back(0);
4129 }
Douglas Gregord3731192011-01-10 07:32:04 +00004130
Douglas Gregor603cfb42011-01-05 23:12:31 +00004131 // We'll substitute the parameter now without expanding the pack
4132 // expansion.
4133 OldType = Expansion->getPattern();
4134 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004135 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4136 NewType = getDerived().TransformType(OldType);
4137 } else {
4138 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004139 }
4140
Douglas Gregor603cfb42011-01-05 23:12:31 +00004141 if (NewType.isNull())
4142 return true;
4143
4144 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004145 NewType = getSema().Context.getPackExpansionType(NewType,
4146 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004147
Douglas Gregora009b592011-01-07 00:20:55 +00004148 OutParamTypes.push_back(NewType);
4149 if (PVars)
4150 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004151 }
4152
John McCallfb44de92011-05-01 22:35:37 +00004153#ifndef NDEBUG
4154 if (PVars) {
4155 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4156 if (ParmVarDecl *parm = (*PVars)[i])
4157 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004158 }
John McCallfb44de92011-05-01 22:35:37 +00004159#endif
4160
4161 return false;
4162}
John McCall21ef0fa2010-03-11 09:03:00 +00004163
4164template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004165QualType
John McCalla2becad2009-10-21 00:40:46 +00004166TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004167 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004168 // Transform the parameters and return type.
4169 //
4170 // We instantiate in source order, with the return type first followed by
4171 // the parameters, because users tend to expect this (even if they shouldn't
4172 // rely on it!).
4173 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004174 // When the function has a trailing return type, we instantiate the
4175 // parameters before the return type, since the return type can then refer
4176 // to the parameters themselves (via decltype, sizeof, etc.).
4177 //
Chris Lattner686775d2011-07-20 06:58:45 +00004178 SmallVector<QualType, 4> ParamTypes;
4179 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004180 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004181
Douglas Gregordab60ad2010-10-01 18:44:50 +00004182 QualType ResultType;
4183
4184 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004185 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4186 TL.getParmArray(),
4187 TL.getNumArgs(),
4188 TL.getTypePtr()->arg_type_begin(),
4189 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004190 return QualType();
4191
4192 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4193 if (ResultType.isNull())
4194 return QualType();
4195 }
4196 else {
4197 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4198 if (ResultType.isNull())
4199 return QualType();
4200
Douglas Gregora009b592011-01-07 00:20:55 +00004201 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4202 TL.getParmArray(),
4203 TL.getNumArgs(),
4204 TL.getTypePtr()->arg_type_begin(),
4205 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004206 return QualType();
4207 }
4208
John McCalla2becad2009-10-21 00:40:46 +00004209 QualType Result = TL.getType();
4210 if (getDerived().AlwaysRebuild() ||
4211 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004212 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004213 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4214 Result = getDerived().RebuildFunctionProtoType(ResultType,
4215 ParamTypes.data(),
4216 ParamTypes.size(),
4217 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004218 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004219 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004220 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004221 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004222 if (Result.isNull())
4223 return QualType();
4224 }
Mike Stump1eb44332009-09-09 15:08:12 +00004225
John McCalla2becad2009-10-21 00:40:46 +00004226 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004227 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4228 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004229 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004230 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4231 NewTL.setArg(i, ParamDecls[i]);
4232
4233 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004234}
Mike Stump1eb44332009-09-09 15:08:12 +00004235
Douglas Gregor577f75a2009-08-04 16:50:30 +00004236template<typename Derived>
4237QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004238 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004239 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004240 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004241 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4242 if (ResultType.isNull())
4243 return QualType();
4244
4245 QualType Result = TL.getType();
4246 if (getDerived().AlwaysRebuild() ||
4247 ResultType != T->getResultType())
4248 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4249
4250 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004251 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4252 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004253 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004254
4255 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004256}
Mike Stump1eb44332009-09-09 15:08:12 +00004257
John McCalled976492009-12-04 22:46:56 +00004258template<typename Derived> QualType
4259TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004260 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004261 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004262 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004263 if (!D)
4264 return QualType();
4265
4266 QualType Result = TL.getType();
4267 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4268 Result = getDerived().RebuildUnresolvedUsingType(D);
4269 if (Result.isNull())
4270 return QualType();
4271 }
4272
4273 // We might get an arbitrary type spec type back. We should at
4274 // least always get a type spec type, though.
4275 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4276 NewTL.setNameLoc(TL.getNameLoc());
4277
4278 return Result;
4279}
4280
Douglas Gregor577f75a2009-08-04 16:50:30 +00004281template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004282QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004283 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004284 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004285 TypedefNameDecl *Typedef
4286 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4287 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004288 if (!Typedef)
4289 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004290
John McCalla2becad2009-10-21 00:40:46 +00004291 QualType Result = TL.getType();
4292 if (getDerived().AlwaysRebuild() ||
4293 Typedef != T->getDecl()) {
4294 Result = getDerived().RebuildTypedefType(Typedef);
4295 if (Result.isNull())
4296 return QualType();
4297 }
Mike Stump1eb44332009-09-09 15:08:12 +00004298
John McCalla2becad2009-10-21 00:40:46 +00004299 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4300 NewTL.setNameLoc(TL.getNameLoc());
4301
4302 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004303}
Mike Stump1eb44332009-09-09 15:08:12 +00004304
Douglas Gregor577f75a2009-08-04 16:50:30 +00004305template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004306QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004307 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004308 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004309 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004310
John McCall60d7b3a2010-08-24 06:29:42 +00004311 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004312 if (E.isInvalid())
4313 return QualType();
4314
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004315 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4316 if (E.isInvalid())
4317 return QualType();
4318
John McCalla2becad2009-10-21 00:40:46 +00004319 QualType Result = TL.getType();
4320 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004321 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004322 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004323 if (Result.isNull())
4324 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004325 }
John McCalla2becad2009-10-21 00:40:46 +00004326 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004327
John McCalla2becad2009-10-21 00:40:46 +00004328 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004329 NewTL.setTypeofLoc(TL.getTypeofLoc());
4330 NewTL.setLParenLoc(TL.getLParenLoc());
4331 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004332
4333 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004334}
Mike Stump1eb44332009-09-09 15:08:12 +00004335
4336template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004337QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004338 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004339 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4340 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4341 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004342 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004343
John McCalla2becad2009-10-21 00:40:46 +00004344 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004345 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4346 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004347 if (Result.isNull())
4348 return QualType();
4349 }
Mike Stump1eb44332009-09-09 15:08:12 +00004350
John McCalla2becad2009-10-21 00:40:46 +00004351 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004352 NewTL.setTypeofLoc(TL.getTypeofLoc());
4353 NewTL.setLParenLoc(TL.getLParenLoc());
4354 NewTL.setRParenLoc(TL.getRParenLoc());
4355 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004356
4357 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004358}
Mike Stump1eb44332009-09-09 15:08:12 +00004359
4360template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004361QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004362 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004363 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004364
Douglas Gregor670444e2009-08-04 22:27:00 +00004365 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004366 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4367 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004368
John McCall60d7b3a2010-08-24 06:29:42 +00004369 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004370 if (E.isInvalid())
4371 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004372
Richard Smith76f3f692012-02-22 02:04:18 +00004373 E = getSema().ActOnDecltypeExpression(E.take());
4374 if (E.isInvalid())
4375 return QualType();
4376
John McCalla2becad2009-10-21 00:40:46 +00004377 QualType Result = TL.getType();
4378 if (getDerived().AlwaysRebuild() ||
4379 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004380 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004381 if (Result.isNull())
4382 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004383 }
John McCalla2becad2009-10-21 00:40:46 +00004384 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004385
John McCalla2becad2009-10-21 00:40:46 +00004386 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4387 NewTL.setNameLoc(TL.getNameLoc());
4388
4389 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004390}
4391
4392template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004393QualType TreeTransform<Derived>::TransformUnaryTransformType(
4394 TypeLocBuilder &TLB,
4395 UnaryTransformTypeLoc TL) {
4396 QualType Result = TL.getType();
4397 if (Result->isDependentType()) {
4398 const UnaryTransformType *T = TL.getTypePtr();
4399 QualType NewBase =
4400 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4401 Result = getDerived().RebuildUnaryTransformType(NewBase,
4402 T->getUTTKind(),
4403 TL.getKWLoc());
4404 if (Result.isNull())
4405 return QualType();
4406 }
4407
4408 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4409 NewTL.setKWLoc(TL.getKWLoc());
4410 NewTL.setParensRange(TL.getParensRange());
4411 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4412 return Result;
4413}
4414
4415template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004416QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4417 AutoTypeLoc TL) {
4418 const AutoType *T = TL.getTypePtr();
4419 QualType OldDeduced = T->getDeducedType();
4420 QualType NewDeduced;
4421 if (!OldDeduced.isNull()) {
4422 NewDeduced = getDerived().TransformType(OldDeduced);
4423 if (NewDeduced.isNull())
4424 return QualType();
4425 }
4426
4427 QualType Result = TL.getType();
4428 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4429 Result = getDerived().RebuildAutoType(NewDeduced);
4430 if (Result.isNull())
4431 return QualType();
4432 }
4433
4434 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4435 NewTL.setNameLoc(TL.getNameLoc());
4436
4437 return Result;
4438}
4439
4440template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004441QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004442 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004443 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004444 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004445 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4446 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004447 if (!Record)
4448 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004449
John McCalla2becad2009-10-21 00:40:46 +00004450 QualType Result = TL.getType();
4451 if (getDerived().AlwaysRebuild() ||
4452 Record != T->getDecl()) {
4453 Result = getDerived().RebuildRecordType(Record);
4454 if (Result.isNull())
4455 return QualType();
4456 }
Mike Stump1eb44332009-09-09 15:08:12 +00004457
John McCalla2becad2009-10-21 00:40:46 +00004458 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4459 NewTL.setNameLoc(TL.getNameLoc());
4460
4461 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004462}
Mike Stump1eb44332009-09-09 15:08:12 +00004463
4464template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004465QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004466 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004467 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004468 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004469 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4470 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004471 if (!Enum)
4472 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004473
John McCalla2becad2009-10-21 00:40:46 +00004474 QualType Result = TL.getType();
4475 if (getDerived().AlwaysRebuild() ||
4476 Enum != T->getDecl()) {
4477 Result = getDerived().RebuildEnumType(Enum);
4478 if (Result.isNull())
4479 return QualType();
4480 }
Mike Stump1eb44332009-09-09 15:08:12 +00004481
John McCalla2becad2009-10-21 00:40:46 +00004482 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4483 NewTL.setNameLoc(TL.getNameLoc());
4484
4485 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004486}
John McCall7da24312009-09-05 00:15:47 +00004487
John McCall3cb0ebd2010-03-10 03:28:59 +00004488template<typename Derived>
4489QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4490 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004491 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004492 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4493 TL.getTypePtr()->getDecl());
4494 if (!D) return QualType();
4495
4496 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4497 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4498 return T;
4499}
4500
Douglas Gregor577f75a2009-08-04 16:50:30 +00004501template<typename Derived>
4502QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004503 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004504 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004505 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004506}
4507
Mike Stump1eb44332009-09-09 15:08:12 +00004508template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004509QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004510 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004511 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004512 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4513
4514 // Substitute into the replacement type, which itself might involve something
4515 // that needs to be transformed. This only tends to occur with default
4516 // template arguments of template template parameters.
4517 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4518 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4519 if (Replacement.isNull())
4520 return QualType();
4521
4522 // Always canonicalize the replacement type.
4523 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4524 QualType Result
4525 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4526 Replacement);
4527
4528 // Propagate type-source information.
4529 SubstTemplateTypeParmTypeLoc NewTL
4530 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4531 NewTL.setNameLoc(TL.getNameLoc());
4532 return Result;
4533
John McCall49a832b2009-10-18 09:09:24 +00004534}
4535
4536template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004537QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4538 TypeLocBuilder &TLB,
4539 SubstTemplateTypeParmPackTypeLoc TL) {
4540 return TransformTypeSpecType(TLB, TL);
4541}
4542
4543template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004544QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004545 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004546 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004547 const TemplateSpecializationType *T = TL.getTypePtr();
4548
Douglas Gregor1d752d72011-03-02 18:46:51 +00004549 // The nested-name-specifier never matters in a TemplateSpecializationType,
4550 // because we can't have a dependent nested-name-specifier anyway.
4551 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004552 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004553 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4554 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004555 if (Template.isNull())
4556 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004557
John McCall43fed0d2010-11-12 08:19:04 +00004558 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4559}
4560
Eli Friedmanb001de72011-10-06 23:00:33 +00004561template<typename Derived>
4562QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4563 AtomicTypeLoc TL) {
4564 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4565 if (ValueType.isNull())
4566 return QualType();
4567
4568 QualType Result = TL.getType();
4569 if (getDerived().AlwaysRebuild() ||
4570 ValueType != TL.getValueLoc().getType()) {
4571 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4572 if (Result.isNull())
4573 return QualType();
4574 }
4575
4576 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4577 NewTL.setKWLoc(TL.getKWLoc());
4578 NewTL.setLParenLoc(TL.getLParenLoc());
4579 NewTL.setRParenLoc(TL.getRParenLoc());
4580
4581 return Result;
4582}
4583
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004584namespace {
4585 /// \brief Simple iterator that traverses the template arguments in a
4586 /// container that provides a \c getArgLoc() member function.
4587 ///
4588 /// This iterator is intended to be used with the iterator form of
4589 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4590 template<typename ArgLocContainer>
4591 class TemplateArgumentLocContainerIterator {
4592 ArgLocContainer *Container;
4593 unsigned Index;
4594
4595 public:
4596 typedef TemplateArgumentLoc value_type;
4597 typedef TemplateArgumentLoc reference;
4598 typedef int difference_type;
4599 typedef std::input_iterator_tag iterator_category;
4600
4601 class pointer {
4602 TemplateArgumentLoc Arg;
4603
4604 public:
4605 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4606
4607 const TemplateArgumentLoc *operator->() const {
4608 return &Arg;
4609 }
4610 };
4611
4612
4613 TemplateArgumentLocContainerIterator() {}
4614
4615 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4616 unsigned Index)
4617 : Container(&Container), Index(Index) { }
4618
4619 TemplateArgumentLocContainerIterator &operator++() {
4620 ++Index;
4621 return *this;
4622 }
4623
4624 TemplateArgumentLocContainerIterator operator++(int) {
4625 TemplateArgumentLocContainerIterator Old(*this);
4626 ++(*this);
4627 return Old;
4628 }
4629
4630 TemplateArgumentLoc operator*() const {
4631 return Container->getArgLoc(Index);
4632 }
4633
4634 pointer operator->() const {
4635 return pointer(Container->getArgLoc(Index));
4636 }
4637
4638 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004639 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004640 return X.Container == Y.Container && X.Index == Y.Index;
4641 }
4642
4643 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004644 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004645 return !(X == Y);
4646 }
4647 };
4648}
4649
4650
John McCall43fed0d2010-11-12 08:19:04 +00004651template <typename Derived>
4652QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4653 TypeLocBuilder &TLB,
4654 TemplateSpecializationTypeLoc TL,
4655 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004656 TemplateArgumentListInfo NewTemplateArgs;
4657 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4658 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004659 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4660 ArgIterator;
4661 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4662 ArgIterator(TL, TL.getNumArgs()),
4663 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004664 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004665
John McCall833ca992009-10-29 08:12:44 +00004666 // FIXME: maybe don't rebuild if all the template arguments are the same.
4667
4668 QualType Result =
4669 getDerived().RebuildTemplateSpecializationType(Template,
4670 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004671 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004672
4673 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004674 // Specializations of template template parameters are represented as
4675 // TemplateSpecializationTypes, and substitution of type alias templates
4676 // within a dependent context can transform them into
4677 // DependentTemplateSpecializationTypes.
4678 if (isa<DependentTemplateSpecializationType>(Result)) {
4679 DependentTemplateSpecializationTypeLoc NewTL
4680 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004681 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004682 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004683 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004684 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004685 NewTL.setLAngleLoc(TL.getLAngleLoc());
4686 NewTL.setRAngleLoc(TL.getRAngleLoc());
4687 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4688 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4689 return Result;
4690 }
4691
John McCall833ca992009-10-29 08:12:44 +00004692 TemplateSpecializationTypeLoc NewTL
4693 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004694 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004695 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4696 NewTL.setLAngleLoc(TL.getLAngleLoc());
4697 NewTL.setRAngleLoc(TL.getRAngleLoc());
4698 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4699 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004700 }
Mike Stump1eb44332009-09-09 15:08:12 +00004701
John McCall833ca992009-10-29 08:12:44 +00004702 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004703}
Mike Stump1eb44332009-09-09 15:08:12 +00004704
Douglas Gregora88f09f2011-02-28 17:23:35 +00004705template <typename Derived>
4706QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4707 TypeLocBuilder &TLB,
4708 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004709 TemplateName Template,
4710 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004711 TemplateArgumentListInfo NewTemplateArgs;
4712 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4713 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4714 typedef TemplateArgumentLocContainerIterator<
4715 DependentTemplateSpecializationTypeLoc> ArgIterator;
4716 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4717 ArgIterator(TL, TL.getNumArgs()),
4718 NewTemplateArgs))
4719 return QualType();
4720
4721 // FIXME: maybe don't rebuild if all the template arguments are the same.
4722
4723 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4724 QualType Result
4725 = getSema().Context.getDependentTemplateSpecializationType(
4726 TL.getTypePtr()->getKeyword(),
4727 DTN->getQualifier(),
4728 DTN->getIdentifier(),
4729 NewTemplateArgs);
4730
4731 DependentTemplateSpecializationTypeLoc NewTL
4732 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004733 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004734 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004735 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004736 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004737 NewTL.setLAngleLoc(TL.getLAngleLoc());
4738 NewTL.setRAngleLoc(TL.getRAngleLoc());
4739 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4740 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4741 return Result;
4742 }
4743
4744 QualType Result
4745 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004746 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004747 NewTemplateArgs);
4748
4749 if (!Result.isNull()) {
4750 /// FIXME: Wrap this in an elaborated-type-specifier?
4751 TemplateSpecializationTypeLoc NewTL
4752 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004753 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004754 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004755 NewTL.setLAngleLoc(TL.getLAngleLoc());
4756 NewTL.setRAngleLoc(TL.getRAngleLoc());
4757 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4758 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4759 }
4760
4761 return Result;
4762}
4763
Mike Stump1eb44332009-09-09 15:08:12 +00004764template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004765QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004766TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004767 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004768 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004769
Douglas Gregor9e876872011-03-01 18:12:44 +00004770 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004771 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004772 if (TL.getQualifierLoc()) {
4773 QualifierLoc
4774 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4775 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004776 return QualType();
4777 }
Mike Stump1eb44332009-09-09 15:08:12 +00004778
John McCall43fed0d2010-11-12 08:19:04 +00004779 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4780 if (NamedT.isNull())
4781 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004782
Richard Smith3e4c6c42011-05-05 21:57:07 +00004783 // C++0x [dcl.type.elab]p2:
4784 // If the identifier resolves to a typedef-name or the simple-template-id
4785 // resolves to an alias template specialization, the
4786 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004787 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4788 if (const TemplateSpecializationType *TST =
4789 NamedT->getAs<TemplateSpecializationType>()) {
4790 TemplateName Template = TST->getTemplateName();
4791 if (TypeAliasTemplateDecl *TAT =
4792 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4793 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4794 diag::err_tag_reference_non_tag) << 4;
4795 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4796 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004797 }
4798 }
4799
John McCalla2becad2009-10-21 00:40:46 +00004800 QualType Result = TL.getType();
4801 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004802 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004803 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004804 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004805 T->getKeyword(),
4806 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004807 if (Result.isNull())
4808 return QualType();
4809 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004810
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004811 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004812 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004813 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004814 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004815}
Mike Stump1eb44332009-09-09 15:08:12 +00004816
4817template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004818QualType TreeTransform<Derived>::TransformAttributedType(
4819 TypeLocBuilder &TLB,
4820 AttributedTypeLoc TL) {
4821 const AttributedType *oldType = TL.getTypePtr();
4822 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4823 if (modifiedType.isNull())
4824 return QualType();
4825
4826 QualType result = TL.getType();
4827
4828 // FIXME: dependent operand expressions?
4829 if (getDerived().AlwaysRebuild() ||
4830 modifiedType != oldType->getModifiedType()) {
4831 // TODO: this is really lame; we should really be rebuilding the
4832 // equivalent type from first principles.
4833 QualType equivalentType
4834 = getDerived().TransformType(oldType->getEquivalentType());
4835 if (equivalentType.isNull())
4836 return QualType();
4837 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4838 modifiedType,
4839 equivalentType);
4840 }
4841
4842 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4843 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4844 if (TL.hasAttrOperand())
4845 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4846 if (TL.hasAttrExprOperand())
4847 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4848 else if (TL.hasAttrEnumOperand())
4849 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4850
4851 return result;
4852}
4853
4854template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004855QualType
4856TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4857 ParenTypeLoc TL) {
4858 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4859 if (Inner.isNull())
4860 return QualType();
4861
4862 QualType Result = TL.getType();
4863 if (getDerived().AlwaysRebuild() ||
4864 Inner != TL.getInnerLoc().getType()) {
4865 Result = getDerived().RebuildParenType(Inner);
4866 if (Result.isNull())
4867 return QualType();
4868 }
4869
4870 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4871 NewTL.setLParenLoc(TL.getLParenLoc());
4872 NewTL.setRParenLoc(TL.getRParenLoc());
4873 return Result;
4874}
4875
4876template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004877QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004878 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004879 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004880
Douglas Gregor2494dd02011-03-01 01:34:45 +00004881 NestedNameSpecifierLoc QualifierLoc
4882 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4883 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004884 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004885
John McCall33500952010-06-11 00:33:02 +00004886 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004887 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004888 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004889 QualifierLoc,
4890 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004891 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004892 if (Result.isNull())
4893 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004894
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004895 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4896 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004897 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4898
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004899 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004900 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004901 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004902 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004903 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004904 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004905 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004906 NewTL.setNameLoc(TL.getNameLoc());
4907 }
John McCalla2becad2009-10-21 00:40:46 +00004908 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004909}
Mike Stump1eb44332009-09-09 15:08:12 +00004910
Douglas Gregor577f75a2009-08-04 16:50:30 +00004911template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004912QualType TreeTransform<Derived>::
4913 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004914 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004915 NestedNameSpecifierLoc QualifierLoc;
4916 if (TL.getQualifierLoc()) {
4917 QualifierLoc
4918 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4919 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004920 return QualType();
4921 }
4922
John McCall43fed0d2010-11-12 08:19:04 +00004923 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004924 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004925}
4926
4927template<typename Derived>
4928QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004929TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4930 DependentTemplateSpecializationTypeLoc TL,
4931 NestedNameSpecifierLoc QualifierLoc) {
4932 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4933
4934 TemplateArgumentListInfo NewTemplateArgs;
4935 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4936 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4937
4938 typedef TemplateArgumentLocContainerIterator<
4939 DependentTemplateSpecializationTypeLoc> ArgIterator;
4940 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4941 ArgIterator(TL, TL.getNumArgs()),
4942 NewTemplateArgs))
4943 return QualType();
4944
4945 QualType Result
4946 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4947 QualifierLoc,
4948 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004949 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004950 NewTemplateArgs);
4951 if (Result.isNull())
4952 return QualType();
4953
4954 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4955 QualType NamedT = ElabT->getNamedType();
4956
4957 // Copy information relevant to the template specialization.
4958 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004959 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004960 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004961 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004962 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4963 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004964 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004965 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004966
4967 // Copy information relevant to the elaborated type.
4968 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004969 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004970 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004971 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4972 DependentTemplateSpecializationTypeLoc SpecTL
4973 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004974 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004975 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004976 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004977 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004978 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4979 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004980 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004981 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004982 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004983 TemplateSpecializationTypeLoc SpecTL
4984 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004985 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004986 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004987 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4988 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004989 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004990 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004991 }
4992 return Result;
4993}
4994
4995template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004996QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4997 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004998 QualType Pattern
4999 = getDerived().TransformType(TLB, TL.getPatternLoc());
5000 if (Pattern.isNull())
5001 return QualType();
5002
5003 QualType Result = TL.getType();
5004 if (getDerived().AlwaysRebuild() ||
5005 Pattern != TL.getPatternLoc().getType()) {
5006 Result = getDerived().RebuildPackExpansionType(Pattern,
5007 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005008 TL.getEllipsisLoc(),
5009 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005010 if (Result.isNull())
5011 return QualType();
5012 }
5013
5014 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5015 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5016 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005017}
5018
5019template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005020QualType
5021TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005022 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005023 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005024 TLB.pushFullCopy(TL);
5025 return TL.getType();
5026}
5027
5028template<typename Derived>
5029QualType
5030TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005031 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005032 // ObjCObjectType is never dependent.
5033 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005034 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005035}
Mike Stump1eb44332009-09-09 15:08:12 +00005036
5037template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005038QualType
5039TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005040 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005041 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005042 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005043 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005044}
5045
Douglas Gregor577f75a2009-08-04 16:50:30 +00005046//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005047// Statement transformation
5048//===----------------------------------------------------------------------===//
5049template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005050StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005051TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005052 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005053}
5054
5055template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005056StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005057TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5058 return getDerived().TransformCompoundStmt(S, false);
5059}
5060
5061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005062StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005063TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005064 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005065 Sema::CompoundScopeRAII CompoundScope(getSema());
5066
John McCall7114cba2010-08-27 19:56:05 +00005067 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005068 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005069 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005070 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5071 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005072 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005073 if (Result.isInvalid()) {
5074 // Immediately fail if this was a DeclStmt, since it's very
5075 // likely that this will cause problems for future statements.
5076 if (isa<DeclStmt>(*B))
5077 return StmtError();
5078
5079 // Otherwise, just keep processing substatements and fail later.
5080 SubStmtInvalid = true;
5081 continue;
5082 }
Mike Stump1eb44332009-09-09 15:08:12 +00005083
Douglas Gregor43959a92009-08-20 07:17:43 +00005084 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5085 Statements.push_back(Result.takeAs<Stmt>());
5086 }
Mike Stump1eb44332009-09-09 15:08:12 +00005087
John McCall7114cba2010-08-27 19:56:05 +00005088 if (SubStmtInvalid)
5089 return StmtError();
5090
Douglas Gregor43959a92009-08-20 07:17:43 +00005091 if (!getDerived().AlwaysRebuild() &&
5092 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005093 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005094
5095 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5096 move_arg(Statements),
5097 S->getRBracLoc(),
5098 IsStmtExpr);
5099}
Mike Stump1eb44332009-09-09 15:08:12 +00005100
Douglas Gregor43959a92009-08-20 07:17:43 +00005101template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005102StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005103TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005104 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005105 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005106 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5107 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005108
Eli Friedman264c1f82009-11-19 03:14:00 +00005109 // Transform the left-hand case value.
5110 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005111 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005112 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005113 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005114
Eli Friedman264c1f82009-11-19 03:14:00 +00005115 // Transform the right-hand case value (for the GNU case-range extension).
5116 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005117 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005118 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005119 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005120 }
Mike Stump1eb44332009-09-09 15:08:12 +00005121
Douglas Gregor43959a92009-08-20 07:17:43 +00005122 // Build the case statement.
5123 // Case statements are always rebuilt so that they will attached to their
5124 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005125 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005126 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005127 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005128 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005129 S->getColonLoc());
5130 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005131 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005132
Douglas Gregor43959a92009-08-20 07:17:43 +00005133 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005134 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005135 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005136 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005137
Douglas Gregor43959a92009-08-20 07:17:43 +00005138 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005139 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005140}
5141
5142template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005143StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005144TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005145 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005146 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005147 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005148 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005149
Douglas Gregor43959a92009-08-20 07:17:43 +00005150 // Default statements are always rebuilt
5151 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005152 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005153}
Mike Stump1eb44332009-09-09 15:08:12 +00005154
Douglas Gregor43959a92009-08-20 07:17:43 +00005155template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005156StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005157TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005158 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005159 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005160 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005161
Chris Lattner57ad3782011-02-17 20:34:02 +00005162 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5163 S->getDecl());
5164 if (!LD)
5165 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005166
5167
Douglas Gregor43959a92009-08-20 07:17:43 +00005168 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005169 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005170 cast<LabelDecl>(LD), SourceLocation(),
5171 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005172}
Mike Stump1eb44332009-09-09 15:08:12 +00005173
Douglas Gregor43959a92009-08-20 07:17:43 +00005174template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005175StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005176TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5177 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5178 if (SubStmt.isInvalid())
5179 return StmtError();
5180
5181 // TODO: transform attributes
5182 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5183 return S;
5184
5185 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5186 S->getAttrs(),
5187 SubStmt.get());
5188}
5189
5190template<typename Derived>
5191StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005192TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005193 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005194 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005195 VarDecl *ConditionVar = 0;
5196 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005197 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005198 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005199 getDerived().TransformDefinition(
5200 S->getConditionVariable()->getLocation(),
5201 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005202 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005203 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005204 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005205 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005206
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005207 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005208 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005209
5210 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005211 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005212 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5213 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005214 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005215 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005216
John McCall9ae2f072010-08-23 23:25:46 +00005217 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005218 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005219 }
Sean Huntc3021132010-05-05 15:23:54 +00005220
John McCall9ae2f072010-08-23 23:25:46 +00005221 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5222 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005223 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005224
Douglas Gregor43959a92009-08-20 07:17:43 +00005225 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005226 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005227 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005228 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005229
Douglas Gregor43959a92009-08-20 07:17:43 +00005230 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005231 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005232 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005233 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005234
Douglas Gregor43959a92009-08-20 07:17:43 +00005235 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005236 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005237 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005238 Then.get() == S->getThen() &&
5239 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005240 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005241
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005242 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005243 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005244 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005245}
5246
5247template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005248StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005249TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005250 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005251 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005252 VarDecl *ConditionVar = 0;
5253 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005254 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005255 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005256 getDerived().TransformDefinition(
5257 S->getConditionVariable()->getLocation(),
5258 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005259 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005260 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005261 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005262 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005263
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005264 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005265 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005266 }
Mike Stump1eb44332009-09-09 15:08:12 +00005267
Douglas Gregor43959a92009-08-20 07:17:43 +00005268 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005269 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005270 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005271 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005272 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005273 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005274
Douglas Gregor43959a92009-08-20 07:17:43 +00005275 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005276 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005277 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005278 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005279
Douglas Gregor43959a92009-08-20 07:17:43 +00005280 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005281 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5282 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005283}
Mike Stump1eb44332009-09-09 15:08:12 +00005284
Douglas Gregor43959a92009-08-20 07:17:43 +00005285template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005286StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005287TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005288 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005289 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005290 VarDecl *ConditionVar = 0;
5291 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005292 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005293 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005294 getDerived().TransformDefinition(
5295 S->getConditionVariable()->getLocation(),
5296 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005297 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005298 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005299 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005300 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005301
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005302 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005303 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005304
5305 if (S->getCond()) {
5306 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005307 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5308 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005309 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005310 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005311 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005312 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005313 }
Mike Stump1eb44332009-09-09 15:08:12 +00005314
John McCall9ae2f072010-08-23 23:25:46 +00005315 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5316 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005317 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005318
Douglas Gregor43959a92009-08-20 07:17:43 +00005319 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005320 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005321 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005322 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005323
Douglas Gregor43959a92009-08-20 07:17:43 +00005324 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005325 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005326 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005327 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005328 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005329
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005330 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005331 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005332}
Mike Stump1eb44332009-09-09 15:08:12 +00005333
Douglas Gregor43959a92009-08-20 07:17:43 +00005334template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005335StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005336TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005337 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005338 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005339 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005340 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005341
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005342 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005343 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005344 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005345 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005346
Douglas Gregor43959a92009-08-20 07:17:43 +00005347 if (!getDerived().AlwaysRebuild() &&
5348 Cond.get() == S->getCond() &&
5349 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005350 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005351
John McCall9ae2f072010-08-23 23:25:46 +00005352 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5353 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005354 S->getRParenLoc());
5355}
Mike Stump1eb44332009-09-09 15:08:12 +00005356
Douglas Gregor43959a92009-08-20 07:17:43 +00005357template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005358StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005359TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005360 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005361 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005362 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005363 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005364
Douglas Gregor43959a92009-08-20 07:17:43 +00005365 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005366 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005367 VarDecl *ConditionVar = 0;
5368 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005369 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005370 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005371 getDerived().TransformDefinition(
5372 S->getConditionVariable()->getLocation(),
5373 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005374 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005375 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005376 } else {
5377 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005378
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005379 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005380 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005381
5382 if (S->getCond()) {
5383 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005384 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5385 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005386 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005387 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005388
John McCall9ae2f072010-08-23 23:25:46 +00005389 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005390 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005391 }
Mike Stump1eb44332009-09-09 15:08:12 +00005392
John McCall9ae2f072010-08-23 23:25:46 +00005393 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5394 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005395 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005396
Douglas Gregor43959a92009-08-20 07:17:43 +00005397 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005398 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005399 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005400 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005401
John McCall9ae2f072010-08-23 23:25:46 +00005402 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5403 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005404 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005405
Douglas Gregor43959a92009-08-20 07:17:43 +00005406 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005407 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005408 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005409 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005410
Douglas Gregor43959a92009-08-20 07:17:43 +00005411 if (!getDerived().AlwaysRebuild() &&
5412 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005413 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 Inc.get() == S->getInc() &&
5415 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005416 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005417
Douglas Gregor43959a92009-08-20 07:17:43 +00005418 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005419 Init.get(), FullCond, ConditionVar,
5420 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005421}
5422
5423template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005424StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005425TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005426 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5427 S->getLabel());
5428 if (!LD)
5429 return StmtError();
5430
Douglas Gregor43959a92009-08-20 07:17:43 +00005431 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005432 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005433 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005434}
5435
5436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005437StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005438TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005439 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005440 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005441 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005442 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005443
Douglas Gregor43959a92009-08-20 07:17:43 +00005444 if (!getDerived().AlwaysRebuild() &&
5445 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005446 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005447
5448 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005449 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005450}
5451
5452template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005453StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005454TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005455 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005456}
Mike Stump1eb44332009-09-09 15:08:12 +00005457
Douglas Gregor43959a92009-08-20 07:17:43 +00005458template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005459StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005460TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005461 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005462}
Mike Stump1eb44332009-09-09 15:08:12 +00005463
Douglas Gregor43959a92009-08-20 07:17:43 +00005464template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005465StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005466TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005467 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005468 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005469 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005470
Mike Stump1eb44332009-09-09 15:08:12 +00005471 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005472 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005473 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005474}
Mike Stump1eb44332009-09-09 15:08:12 +00005475
Douglas Gregor43959a92009-08-20 07:17:43 +00005476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005477StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005478TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005479 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005480 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005481 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5482 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005483 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5484 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005485 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005486 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005487
Douglas Gregor43959a92009-08-20 07:17:43 +00005488 if (Transformed != *D)
5489 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005490
Douglas Gregor43959a92009-08-20 07:17:43 +00005491 Decls.push_back(Transformed);
5492 }
Mike Stump1eb44332009-09-09 15:08:12 +00005493
Douglas Gregor43959a92009-08-20 07:17:43 +00005494 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005495 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005496
5497 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005498 S->getStartLoc(), S->getEndLoc());
5499}
Mike Stump1eb44332009-09-09 15:08:12 +00005500
Douglas Gregor43959a92009-08-20 07:17:43 +00005501template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005502StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005503TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005504
John McCallca0408f2010-08-23 06:44:23 +00005505 ASTOwningVector<Expr*> Constraints(getSema());
5506 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005507 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005508
John McCall60d7b3a2010-08-24 06:29:42 +00005509 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005510 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005511
5512 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005513
Anders Carlsson703e3942010-01-24 05:50:09 +00005514 // Go through the outputs.
5515 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005516 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005517
Anders Carlsson703e3942010-01-24 05:50:09 +00005518 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005519 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005520
Anders Carlsson703e3942010-01-24 05:50:09 +00005521 // Transform the output expr.
5522 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005523 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005524 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005525 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005526
Anders Carlsson703e3942010-01-24 05:50:09 +00005527 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005528
John McCall9ae2f072010-08-23 23:25:46 +00005529 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005530 }
Sean Huntc3021132010-05-05 15:23:54 +00005531
Anders Carlsson703e3942010-01-24 05:50:09 +00005532 // Go through the inputs.
5533 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005534 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005535
Anders Carlsson703e3942010-01-24 05:50:09 +00005536 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005537 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005538
Anders Carlsson703e3942010-01-24 05:50:09 +00005539 // Transform the input expr.
5540 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005541 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005542 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005543 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005544
Anders Carlsson703e3942010-01-24 05:50:09 +00005545 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005546
John McCall9ae2f072010-08-23 23:25:46 +00005547 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005548 }
Sean Huntc3021132010-05-05 15:23:54 +00005549
Anders Carlsson703e3942010-01-24 05:50:09 +00005550 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005551 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005552
5553 // Go through the clobbers.
5554 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005555 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005556
5557 // No need to transform the asm string literal.
5558 AsmString = SemaRef.Owned(S->getAsmString());
5559
5560 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5561 S->isSimple(),
5562 S->isVolatile(),
5563 S->getNumOutputs(),
5564 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005565 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005566 move_arg(Constraints),
5567 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005568 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005569 move_arg(Clobbers),
5570 S->getRParenLoc(),
5571 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005572}
5573
5574
5575template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005576StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005577TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005578 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005579 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005580 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005581 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005582
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005583 // Transform the @catch statements (if present).
5584 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005585 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005586 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005587 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005588 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005589 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005590 if (Catch.get() != S->getCatchStmt(I))
5591 AnyCatchChanged = true;
5592 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005593 }
Sean Huntc3021132010-05-05 15:23:54 +00005594
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005595 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005596 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005597 if (S->getFinallyStmt()) {
5598 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5599 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005600 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005601 }
5602
5603 // If nothing changed, just retain this statement.
5604 if (!getDerived().AlwaysRebuild() &&
5605 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005606 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005607 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005608 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005609
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005610 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005611 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5612 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005613}
Mike Stump1eb44332009-09-09 15:08:12 +00005614
Douglas Gregor43959a92009-08-20 07:17:43 +00005615template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005616StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005617TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005618 // Transform the @catch parameter, if there is one.
5619 VarDecl *Var = 0;
5620 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5621 TypeSourceInfo *TSInfo = 0;
5622 if (FromVar->getTypeSourceInfo()) {
5623 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5624 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005625 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005626 }
Sean Huntc3021132010-05-05 15:23:54 +00005627
Douglas Gregorbe270a02010-04-26 17:57:08 +00005628 QualType T;
5629 if (TSInfo)
5630 T = TSInfo->getType();
5631 else {
5632 T = getDerived().TransformType(FromVar->getType());
5633 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005634 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005635 }
Sean Huntc3021132010-05-05 15:23:54 +00005636
Douglas Gregorbe270a02010-04-26 17:57:08 +00005637 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5638 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005639 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005640 }
Sean Huntc3021132010-05-05 15:23:54 +00005641
John McCall60d7b3a2010-08-24 06:29:42 +00005642 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005643 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005644 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005645
5646 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005647 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005648 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005649}
Mike Stump1eb44332009-09-09 15:08:12 +00005650
Douglas Gregor43959a92009-08-20 07:17:43 +00005651template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005652StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005653TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005654 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005655 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005656 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005657 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005658
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005659 // If nothing changed, just retain this statement.
5660 if (!getDerived().AlwaysRebuild() &&
5661 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005662 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005663
5664 // Build a new statement.
5665 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005666 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005667}
Mike Stump1eb44332009-09-09 15:08:12 +00005668
Douglas Gregor43959a92009-08-20 07:17:43 +00005669template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005670StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005671TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005672 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005673 if (S->getThrowExpr()) {
5674 Operand = getDerived().TransformExpr(S->getThrowExpr());
5675 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005676 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005677 }
Sean Huntc3021132010-05-05 15:23:54 +00005678
Douglas Gregord1377b22010-04-22 21:44:01 +00005679 if (!getDerived().AlwaysRebuild() &&
5680 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005681 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005682
John McCall9ae2f072010-08-23 23:25:46 +00005683 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005684}
Mike Stump1eb44332009-09-09 15:08:12 +00005685
Douglas Gregor43959a92009-08-20 07:17:43 +00005686template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005687StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005688TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005689 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005690 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005691 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005692 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005693 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005694 Object =
5695 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5696 Object.get());
5697 if (Object.isInvalid())
5698 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005699
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005700 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005701 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005702 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005703 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005704
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005705 // If nothing change, just retain the current statement.
5706 if (!getDerived().AlwaysRebuild() &&
5707 Object.get() == S->getSynchExpr() &&
5708 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005709 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005710
5711 // Build a new statement.
5712 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005713 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005714}
5715
5716template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005717StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005718TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5719 ObjCAutoreleasePoolStmt *S) {
5720 // Transform the body.
5721 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5722 if (Body.isInvalid())
5723 return StmtError();
5724
5725 // If nothing changed, just retain this statement.
5726 if (!getDerived().AlwaysRebuild() &&
5727 Body.get() == S->getSubStmt())
5728 return SemaRef.Owned(S);
5729
5730 // Build a new statement.
5731 return getDerived().RebuildObjCAutoreleasePoolStmt(
5732 S->getAtLoc(), Body.get());
5733}
5734
5735template<typename Derived>
5736StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005737TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005738 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005739 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005740 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005741 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005742 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005743
Douglas Gregorc3203e72010-04-22 23:10:45 +00005744 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005745 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005746 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005747 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005748 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5749 Collection.take());
5750 if (Collection.isInvalid())
5751 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005752
Douglas Gregorc3203e72010-04-22 23:10:45 +00005753 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005754 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005755 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005756 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005757
Douglas Gregorc3203e72010-04-22 23:10:45 +00005758 // If nothing changed, just retain this statement.
5759 if (!getDerived().AlwaysRebuild() &&
5760 Element.get() == S->getElement() &&
5761 Collection.get() == S->getCollection() &&
5762 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005763 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005764
Douglas Gregorc3203e72010-04-22 23:10:45 +00005765 // Build a new statement.
5766 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5767 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005768 Element.get(),
5769 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005770 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005771 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005772}
5773
5774
5775template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005776StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005777TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5778 // Transform the exception declaration, if any.
5779 VarDecl *Var = 0;
5780 if (S->getExceptionDecl()) {
5781 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005782 TypeSourceInfo *T = getDerived().TransformType(
5783 ExceptionDecl->getTypeSourceInfo());
5784 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005785 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005786
Douglas Gregor83cb9422010-09-09 17:09:21 +00005787 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005788 ExceptionDecl->getInnerLocStart(),
5789 ExceptionDecl->getLocation(),
5790 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005791 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005792 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005793 }
Mike Stump1eb44332009-09-09 15:08:12 +00005794
Douglas Gregor43959a92009-08-20 07:17:43 +00005795 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005796 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005797 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005798 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005799
Douglas Gregor43959a92009-08-20 07:17:43 +00005800 if (!getDerived().AlwaysRebuild() &&
5801 !Var &&
5802 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005803 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005804
5805 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5806 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005807 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005808}
Mike Stump1eb44332009-09-09 15:08:12 +00005809
Douglas Gregor43959a92009-08-20 07:17:43 +00005810template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005811StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005812TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5813 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005814 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005815 = getDerived().TransformCompoundStmt(S->getTryBlock());
5816 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005817 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005818
Douglas Gregor43959a92009-08-20 07:17:43 +00005819 // Transform the handlers.
5820 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005821 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005822 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005823 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005824 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5825 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005826 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005827
Douglas Gregor43959a92009-08-20 07:17:43 +00005828 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5829 Handlers.push_back(Handler.takeAs<Stmt>());
5830 }
Mike Stump1eb44332009-09-09 15:08:12 +00005831
Douglas Gregor43959a92009-08-20 07:17:43 +00005832 if (!getDerived().AlwaysRebuild() &&
5833 TryBlock.get() == S->getTryBlock() &&
5834 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005835 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005836
John McCall9ae2f072010-08-23 23:25:46 +00005837 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005838 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005839}
Mike Stump1eb44332009-09-09 15:08:12 +00005840
Richard Smithad762fc2011-04-14 22:09:26 +00005841template<typename Derived>
5842StmtResult
5843TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5844 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5845 if (Range.isInvalid())
5846 return StmtError();
5847
5848 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5849 if (BeginEnd.isInvalid())
5850 return StmtError();
5851
5852 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5853 if (Cond.isInvalid())
5854 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005855 if (Cond.get())
5856 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5857 if (Cond.isInvalid())
5858 return StmtError();
5859 if (Cond.get())
5860 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005861
5862 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5863 if (Inc.isInvalid())
5864 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005865 if (Inc.get())
5866 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005867
5868 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5869 if (LoopVar.isInvalid())
5870 return StmtError();
5871
5872 StmtResult NewStmt = S;
5873 if (getDerived().AlwaysRebuild() ||
5874 Range.get() != S->getRangeStmt() ||
5875 BeginEnd.get() != S->getBeginEndStmt() ||
5876 Cond.get() != S->getCond() ||
5877 Inc.get() != S->getInc() ||
5878 LoopVar.get() != S->getLoopVarStmt())
5879 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5880 S->getColonLoc(), Range.get(),
5881 BeginEnd.get(), Cond.get(),
5882 Inc.get(), LoopVar.get(),
5883 S->getRParenLoc());
5884
5885 StmtResult Body = getDerived().TransformStmt(S->getBody());
5886 if (Body.isInvalid())
5887 return StmtError();
5888
5889 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5890 // it now so we have a new statement to attach the body to.
5891 if (Body.get() != S->getBody() && NewStmt.get() == S)
5892 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5893 S->getColonLoc(), Range.get(),
5894 BeginEnd.get(), Cond.get(),
5895 Inc.get(), LoopVar.get(),
5896 S->getRParenLoc());
5897
5898 if (NewStmt.get() == S)
5899 return SemaRef.Owned(S);
5900
5901 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5902}
5903
John Wiegley28bbe4b2011-04-28 01:08:34 +00005904template<typename Derived>
5905StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005906TreeTransform<Derived>::TransformMSDependentExistsStmt(
5907 MSDependentExistsStmt *S) {
5908 // Transform the nested-name-specifier, if any.
5909 NestedNameSpecifierLoc QualifierLoc;
5910 if (S->getQualifierLoc()) {
5911 QualifierLoc
5912 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5913 if (!QualifierLoc)
5914 return StmtError();
5915 }
5916
5917 // Transform the declaration name.
5918 DeclarationNameInfo NameInfo = S->getNameInfo();
5919 if (NameInfo.getName()) {
5920 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5921 if (!NameInfo.getName())
5922 return StmtError();
5923 }
5924
5925 // Check whether anything changed.
5926 if (!getDerived().AlwaysRebuild() &&
5927 QualifierLoc == S->getQualifierLoc() &&
5928 NameInfo.getName() == S->getNameInfo().getName())
5929 return S;
5930
5931 // Determine whether this name exists, if we can.
5932 CXXScopeSpec SS;
5933 SS.Adopt(QualifierLoc);
5934 bool Dependent = false;
5935 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5936 case Sema::IER_Exists:
5937 if (S->isIfExists())
5938 break;
5939
5940 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5941
5942 case Sema::IER_DoesNotExist:
5943 if (S->isIfNotExists())
5944 break;
5945
5946 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5947
5948 case Sema::IER_Dependent:
5949 Dependent = true;
5950 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005951
5952 case Sema::IER_Error:
5953 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005954 }
5955
5956 // We need to continue with the instantiation, so do so now.
5957 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5958 if (SubStmt.isInvalid())
5959 return StmtError();
5960
5961 // If we have resolved the name, just transform to the substatement.
5962 if (!Dependent)
5963 return SubStmt;
5964
5965 // The name is still dependent, so build a dependent expression again.
5966 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5967 S->isIfExists(),
5968 QualifierLoc,
5969 NameInfo,
5970 SubStmt.get());
5971}
5972
5973template<typename Derived>
5974StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005975TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5976 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5977 if(TryBlock.isInvalid()) return StmtError();
5978
5979 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5980 if(!getDerived().AlwaysRebuild() &&
5981 TryBlock.get() == S->getTryBlock() &&
5982 Handler.get() == S->getHandler())
5983 return SemaRef.Owned(S);
5984
5985 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5986 S->getTryLoc(),
5987 TryBlock.take(),
5988 Handler.take());
5989}
5990
5991template<typename Derived>
5992StmtResult
5993TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5994 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5995 if(Block.isInvalid()) return StmtError();
5996
5997 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5998 Block.take());
5999}
6000
6001template<typename Derived>
6002StmtResult
6003TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6004 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6005 if(FilterExpr.isInvalid()) return StmtError();
6006
6007 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6008 if(Block.isInvalid()) return StmtError();
6009
6010 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6011 FilterExpr.take(),
6012 Block.take());
6013}
6014
6015template<typename Derived>
6016StmtResult
6017TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6018 if(isa<SEHFinallyStmt>(Handler))
6019 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6020 else
6021 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6022}
6023
Douglas Gregor43959a92009-08-20 07:17:43 +00006024//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006025// Expression transformation
6026//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006027template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006028ExprResult
John McCall454feb92009-12-08 09:21:05 +00006029TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006030 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006031}
Mike Stump1eb44332009-09-09 15:08:12 +00006032
6033template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006034ExprResult
John McCall454feb92009-12-08 09:21:05 +00006035TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006036 NestedNameSpecifierLoc QualifierLoc;
6037 if (E->getQualifierLoc()) {
6038 QualifierLoc
6039 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6040 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006041 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006042 }
John McCalldbd872f2009-12-08 09:08:17 +00006043
6044 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006045 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6046 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006047 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006048 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006049
John McCallec8045d2010-08-17 21:27:17 +00006050 DeclarationNameInfo NameInfo = E->getNameInfo();
6051 if (NameInfo.getName()) {
6052 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6053 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006054 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006055 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006056
6057 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006058 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006059 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006060 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006061 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006062
6063 // Mark it referenced in the new context regardless.
6064 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006065 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006066
John McCall3fa5cae2010-10-26 07:05:15 +00006067 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006068 }
John McCalldbd872f2009-12-08 09:08:17 +00006069
6070 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006071 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006072 TemplateArgs = &TransArgs;
6073 TransArgs.setLAngleLoc(E->getLAngleLoc());
6074 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006075 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6076 E->getNumTemplateArgs(),
6077 TransArgs))
6078 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006079 }
6080
Douglas Gregor40d96a62011-02-28 21:54:11 +00006081 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6082 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006083}
Mike Stump1eb44332009-09-09 15:08:12 +00006084
Douglas Gregorb98b1992009-08-11 05:31:07 +00006085template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006086ExprResult
John McCall454feb92009-12-08 09:21:05 +00006087TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006088 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006089}
Mike Stump1eb44332009-09-09 15:08:12 +00006090
Douglas Gregorb98b1992009-08-11 05:31:07 +00006091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006092ExprResult
John McCall454feb92009-12-08 09:21:05 +00006093TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006094 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006095}
Mike Stump1eb44332009-09-09 15:08:12 +00006096
Douglas Gregorb98b1992009-08-11 05:31:07 +00006097template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006098ExprResult
John McCall454feb92009-12-08 09:21:05 +00006099TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006100 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006101}
Mike Stump1eb44332009-09-09 15:08:12 +00006102
Douglas Gregorb98b1992009-08-11 05:31:07 +00006103template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006104ExprResult
John McCall454feb92009-12-08 09:21:05 +00006105TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006106 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006107}
Mike Stump1eb44332009-09-09 15:08:12 +00006108
Douglas Gregorb98b1992009-08-11 05:31:07 +00006109template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006110ExprResult
John McCall454feb92009-12-08 09:21:05 +00006111TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006112 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006113}
6114
6115template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006116ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006117TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6118 return SemaRef.MaybeBindToTemporary(E);
6119}
6120
6121template<typename Derived>
6122ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006123TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6124 ExprResult ControllingExpr =
6125 getDerived().TransformExpr(E->getControllingExpr());
6126 if (ControllingExpr.isInvalid())
6127 return ExprError();
6128
Chris Lattner686775d2011-07-20 06:58:45 +00006129 SmallVector<Expr *, 4> AssocExprs;
6130 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006131 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6132 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6133 if (TS) {
6134 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6135 if (!AssocType)
6136 return ExprError();
6137 AssocTypes.push_back(AssocType);
6138 } else {
6139 AssocTypes.push_back(0);
6140 }
6141
6142 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6143 if (AssocExpr.isInvalid())
6144 return ExprError();
6145 AssocExprs.push_back(AssocExpr.release());
6146 }
6147
6148 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6149 E->getDefaultLoc(),
6150 E->getRParenLoc(),
6151 ControllingExpr.release(),
6152 AssocTypes.data(),
6153 AssocExprs.data(),
6154 E->getNumAssocs());
6155}
6156
6157template<typename Derived>
6158ExprResult
John McCall454feb92009-12-08 09:21:05 +00006159TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006160 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006161 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006162 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006163
Douglas Gregorb98b1992009-08-11 05:31:07 +00006164 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006165 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006166
John McCall9ae2f072010-08-23 23:25:46 +00006167 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006168 E->getRParen());
6169}
6170
Mike Stump1eb44332009-09-09 15:08:12 +00006171template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006172ExprResult
John McCall454feb92009-12-08 09:21:05 +00006173TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006174 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006175 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006176 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006177
Douglas Gregorb98b1992009-08-11 05:31:07 +00006178 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006179 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006180
Douglas Gregorb98b1992009-08-11 05:31:07 +00006181 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6182 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006183 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006184}
Mike Stump1eb44332009-09-09 15:08:12 +00006185
Douglas Gregorb98b1992009-08-11 05:31:07 +00006186template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006187ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006188TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6189 // Transform the type.
6190 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6191 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006192 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006193
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006194 // Transform all of the components into components similar to what the
6195 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006196 // FIXME: It would be slightly more efficient in the non-dependent case to
6197 // just map FieldDecls, rather than requiring the rebuilder to look for
6198 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006199 // template code that we don't care.
6200 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006201 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006202 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006203 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006204 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6205 const Node &ON = E->getComponent(I);
6206 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006207 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006208 Comp.LocStart = ON.getSourceRange().getBegin();
6209 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006210 switch (ON.getKind()) {
6211 case Node::Array: {
6212 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006213 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006214 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006215 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006216
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006217 ExprChanged = ExprChanged || Index.get() != FromIndex;
6218 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006219 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006220 break;
6221 }
Sean Huntc3021132010-05-05 15:23:54 +00006222
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006223 case Node::Field:
6224 case Node::Identifier:
6225 Comp.isBrackets = false;
6226 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006227 if (!Comp.U.IdentInfo)
6228 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006229
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006230 break;
Sean Huntc3021132010-05-05 15:23:54 +00006231
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006232 case Node::Base:
6233 // Will be recomputed during the rebuild.
6234 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006235 }
Sean Huntc3021132010-05-05 15:23:54 +00006236
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006237 Components.push_back(Comp);
6238 }
Sean Huntc3021132010-05-05 15:23:54 +00006239
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006240 // If nothing changed, retain the existing expression.
6241 if (!getDerived().AlwaysRebuild() &&
6242 Type == E->getTypeSourceInfo() &&
6243 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006244 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006245
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006246 // Build a new offsetof expression.
6247 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6248 Components.data(), Components.size(),
6249 E->getRParenLoc());
6250}
6251
6252template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006253ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006254TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6255 assert(getDerived().AlreadyTransformed(E->getType()) &&
6256 "opaque value expression requires transformation");
6257 return SemaRef.Owned(E);
6258}
6259
6260template<typename Derived>
6261ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006262TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006263 // Rebuild the syntactic form. The original syntactic form has
6264 // opaque-value expressions in it, so strip those away and rebuild
6265 // the result. This is a really awful way of doing this, but the
6266 // better solution (rebuilding the semantic expressions and
6267 // rebinding OVEs as necessary) doesn't work; we'd need
6268 // TreeTransform to not strip away implicit conversions.
6269 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6270 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006271 if (result.isInvalid()) return ExprError();
6272
6273 // If that gives us a pseudo-object result back, the pseudo-object
6274 // expression must have been an lvalue-to-rvalue conversion which we
6275 // should reapply.
6276 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6277 result = SemaRef.checkPseudoObjectRValue(result.take());
6278
6279 return result;
6280}
6281
6282template<typename Derived>
6283ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006284TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6285 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006286 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006287 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006288
John McCalla93c9342009-12-07 02:54:59 +00006289 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006290 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006291 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006292
John McCall5ab75172009-11-04 07:28:41 +00006293 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006294 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006295
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006296 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6297 E->getKind(),
6298 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006299 }
Mike Stump1eb44332009-09-09 15:08:12 +00006300
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006301 // C++0x [expr.sizeof]p1:
6302 // The operand is either an expression, which is an unevaluated operand
6303 // [...]
6304 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006305
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006306 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6307 if (SubExpr.isInvalid())
6308 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006309
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006310 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6311 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006312
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006313 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6314 E->getOperatorLoc(),
6315 E->getKind(),
6316 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006317}
Mike Stump1eb44332009-09-09 15:08:12 +00006318
Douglas Gregorb98b1992009-08-11 05:31:07 +00006319template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006320ExprResult
John McCall454feb92009-12-08 09:21:05 +00006321TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006322 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006323 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006324 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006325
John McCall60d7b3a2010-08-24 06:29:42 +00006326 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006327 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006328 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006329
6330
Douglas Gregorb98b1992009-08-11 05:31:07 +00006331 if (!getDerived().AlwaysRebuild() &&
6332 LHS.get() == E->getLHS() &&
6333 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006334 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006335
John McCall9ae2f072010-08-23 23:25:46 +00006336 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006337 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006338 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006339 E->getRBracketLoc());
6340}
Mike Stump1eb44332009-09-09 15:08:12 +00006341
6342template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006343ExprResult
John McCall454feb92009-12-08 09:21:05 +00006344TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006345 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006346 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006347 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006348 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006349
6350 // Transform arguments.
6351 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006352 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006353 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6354 &ArgChanged))
6355 return ExprError();
6356
Douglas Gregorb98b1992009-08-11 05:31:07 +00006357 if (!getDerived().AlwaysRebuild() &&
6358 Callee.get() == E->getCallee() &&
6359 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006360 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006361
Douglas Gregorb98b1992009-08-11 05:31:07 +00006362 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006363 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006364 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006365 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006366 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006367 E->getRParenLoc());
6368}
Mike Stump1eb44332009-09-09 15:08:12 +00006369
6370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006371ExprResult
John McCall454feb92009-12-08 09:21:05 +00006372TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006373 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006374 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006375 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006376
Douglas Gregor40d96a62011-02-28 21:54:11 +00006377 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006378 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006379 QualifierLoc
6380 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6381
6382 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006383 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006384 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006385 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006386
Eli Friedmanf595cc42009-12-04 06:40:45 +00006387 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006388 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6389 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006390 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006391 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006392
John McCall6bb80172010-03-30 21:47:33 +00006393 NamedDecl *FoundDecl = E->getFoundDecl();
6394 if (FoundDecl == E->getMemberDecl()) {
6395 FoundDecl = Member;
6396 } else {
6397 FoundDecl = cast_or_null<NamedDecl>(
6398 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6399 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006400 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006401 }
6402
Douglas Gregorb98b1992009-08-11 05:31:07 +00006403 if (!getDerived().AlwaysRebuild() &&
6404 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006405 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006406 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006407 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006408 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006409
Anders Carlsson1f240322009-12-22 05:24:09 +00006410 // Mark it referenced in the new context regardless.
6411 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006412 SemaRef.MarkMemberReferenced(E);
6413
John McCall3fa5cae2010-10-26 07:05:15 +00006414 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006415 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006416
John McCalld5532b62009-11-23 01:53:49 +00006417 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006418 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006419 TransArgs.setLAngleLoc(E->getLAngleLoc());
6420 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006421 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6422 E->getNumTemplateArgs(),
6423 TransArgs))
6424 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006425 }
Sean Huntc3021132010-05-05 15:23:54 +00006426
Douglas Gregorb98b1992009-08-11 05:31:07 +00006427 // FIXME: Bogus source location for the operator
6428 SourceLocation FakeOperatorLoc
6429 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6430
John McCallc2233c52010-01-15 08:34:02 +00006431 // FIXME: to do this check properly, we will need to preserve the
6432 // first-qualifier-in-scope here, just in case we had a dependent
6433 // base (and therefore couldn't do the check) and a
6434 // nested-name-qualifier (and therefore could do the lookup).
6435 NamedDecl *FirstQualifierInScope = 0;
6436
John McCall9ae2f072010-08-23 23:25:46 +00006437 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006439 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006440 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006441 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006442 Member,
John McCall6bb80172010-03-30 21:47:33 +00006443 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006444 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006445 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006446 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006447}
Mike Stump1eb44332009-09-09 15:08:12 +00006448
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006450ExprResult
John McCall454feb92009-12-08 09:21:05 +00006451TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006452 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006453 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006454 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006455
John McCall60d7b3a2010-08-24 06:29:42 +00006456 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006457 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006458 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006459
Douglas Gregorb98b1992009-08-11 05:31:07 +00006460 if (!getDerived().AlwaysRebuild() &&
6461 LHS.get() == E->getLHS() &&
6462 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006463 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006464
Douglas Gregorb98b1992009-08-11 05:31:07 +00006465 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006466 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006467}
6468
Mike Stump1eb44332009-09-09 15:08:12 +00006469template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006470ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006471TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006472 CompoundAssignOperator *E) {
6473 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006474}
Mike Stump1eb44332009-09-09 15:08:12 +00006475
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006477ExprResult TreeTransform<Derived>::
6478TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6479 // Just rebuild the common and RHS expressions and see whether we
6480 // get any changes.
6481
6482 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6483 if (commonExpr.isInvalid())
6484 return ExprError();
6485
6486 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6487 if (rhs.isInvalid())
6488 return ExprError();
6489
6490 if (!getDerived().AlwaysRebuild() &&
6491 commonExpr.get() == e->getCommon() &&
6492 rhs.get() == e->getFalseExpr())
6493 return SemaRef.Owned(e);
6494
6495 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6496 e->getQuestionLoc(),
6497 0,
6498 e->getColonLoc(),
6499 rhs.get());
6500}
6501
6502template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006503ExprResult
John McCall454feb92009-12-08 09:21:05 +00006504TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006505 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006507 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006508
John McCall60d7b3a2010-08-24 06:29:42 +00006509 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006510 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006511 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006512
John McCall60d7b3a2010-08-24 06:29:42 +00006513 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006514 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006515 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006516
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517 if (!getDerived().AlwaysRebuild() &&
6518 Cond.get() == E->getCond() &&
6519 LHS.get() == E->getLHS() &&
6520 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006521 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006522
John McCall9ae2f072010-08-23 23:25:46 +00006523 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006524 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006525 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006526 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006527 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006528}
Mike Stump1eb44332009-09-09 15:08:12 +00006529
6530template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006531ExprResult
John McCall454feb92009-12-08 09:21:05 +00006532TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006533 // Implicit casts are eliminated during transformation, since they
6534 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006535 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006536}
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>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006541 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6542 if (!Type)
6543 return ExprError();
6544
John McCall60d7b3a2010-08-24 06:29:42 +00006545 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006546 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006547 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006548 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006549
Douglas Gregorb98b1992009-08-11 05:31:07 +00006550 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006551 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006552 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006553 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006554
John McCall9d125032010-01-15 18:39:57 +00006555 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006556 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006557 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006558 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006559}
Mike Stump1eb44332009-09-09 15:08:12 +00006560
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006562ExprResult
John McCall454feb92009-12-08 09:21:05 +00006563TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006564 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6565 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6566 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006567 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006568
John McCall60d7b3a2010-08-24 06:29:42 +00006569 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006570 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006571 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006572
Douglas Gregorb98b1992009-08-11 05:31:07 +00006573 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006574 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006575 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006576 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006577
John McCall1d7d8d62010-01-19 22:33:45 +00006578 // Note: the expression type doesn't necessarily match the
6579 // type-as-written, but that's okay, because it should always be
6580 // derivable from the initializer.
6581
John McCall42f56b52010-01-18 19:35:47 +00006582 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006583 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006584 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006585}
Mike Stump1eb44332009-09-09 15:08:12 +00006586
Douglas Gregorb98b1992009-08-11 05:31:07 +00006587template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006588ExprResult
John McCall454feb92009-12-08 09:21:05 +00006589TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006590 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006592 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006593
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594 if (!getDerived().AlwaysRebuild() &&
6595 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006596 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006597
Douglas Gregorb98b1992009-08-11 05:31:07 +00006598 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006599 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006600 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006601 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006602 E->getAccessorLoc(),
6603 E->getAccessor());
6604}
Mike Stump1eb44332009-09-09 15:08:12 +00006605
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006607ExprResult
John McCall454feb92009-12-08 09:21:05 +00006608TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006609 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006610
John McCallca0408f2010-08-23 06:44:23 +00006611 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006612 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6613 Inits, &InitChanged))
6614 return ExprError();
6615
Douglas Gregorb98b1992009-08-11 05:31:07 +00006616 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006617 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006618
Douglas Gregorb98b1992009-08-11 05:31:07 +00006619 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006620 E->getRBraceLoc(), E->getType());
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
John McCall454feb92009-12-08 09:21:05 +00006625TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006627
Douglas Gregor43959a92009-08-20 07:17:43 +00006628 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006629 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006631 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006632
Douglas Gregor43959a92009-08-20 07:17:43 +00006633 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006634 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 bool ExprChanged = false;
6636 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6637 DEnd = E->designators_end();
6638 D != DEnd; ++D) {
6639 if (D->isFieldDesignator()) {
6640 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6641 D->getDotLoc(),
6642 D->getFieldLoc()));
6643 continue;
6644 }
Mike Stump1eb44332009-09-09 15:08:12 +00006645
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006647 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006648 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006649 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006650
6651 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006652 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006653
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6655 ArrayExprs.push_back(Index.release());
6656 continue;
6657 }
Mike Stump1eb44332009-09-09 15:08:12 +00006658
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006660 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6662 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006663 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006664
John McCall60d7b3a2010-08-24 06:29:42 +00006665 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006667 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006668
6669 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 End.get(),
6671 D->getLBracketLoc(),
6672 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006673
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6675 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006676
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677 ArrayExprs.push_back(Start.release());
6678 ArrayExprs.push_back(End.release());
6679 }
Mike Stump1eb44332009-09-09 15:08:12 +00006680
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681 if (!getDerived().AlwaysRebuild() &&
6682 Init.get() == E->getInit() &&
6683 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006684 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006685
Douglas Gregorb98b1992009-08-11 05:31:07 +00006686 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6687 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006688 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006689}
Mike Stump1eb44332009-09-09 15:08:12 +00006690
Douglas Gregorb98b1992009-08-11 05:31:07 +00006691template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006692ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006694 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006695 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006696
Douglas Gregor5557b252009-10-28 00:29:27 +00006697 // FIXME: Will we ever have proper type location here? Will we actually
6698 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699 QualType T = getDerived().TransformType(E->getType());
6700 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006701 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006702
Douglas Gregorb98b1992009-08-11 05:31:07 +00006703 if (!getDerived().AlwaysRebuild() &&
6704 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006705 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006706
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 return getDerived().RebuildImplicitValueInitExpr(T);
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>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006713 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6714 if (!TInfo)
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 SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006719 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006720
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006722 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006724 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006725
John McCall9ae2f072010-08-23 23:25:46 +00006726 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006727 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728}
6729
6730template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006731ExprResult
John McCall454feb92009-12-08 09:21:05 +00006732TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006734 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006735 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6736 &ArgumentChanged))
6737 return ExprError();
6738
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6740 move_arg(Inits),
6741 E->getRParenLoc());
6742}
Mike Stump1eb44332009-09-09 15:08:12 +00006743
Douglas Gregorb98b1992009-08-11 05:31:07 +00006744/// \brief Transform an address-of-label expression.
6745///
6746/// By default, the transformation of an address-of-label expression always
6747/// rebuilds the expression, so that the label identifier can be resolved to
6748/// the corresponding label statement by semantic analysis.
6749template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006750ExprResult
John McCall454feb92009-12-08 09:21:05 +00006751TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006752 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6753 E->getLabel());
6754 if (!LD)
6755 return ExprError();
6756
Douglas Gregorb98b1992009-08-11 05:31:07 +00006757 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006758 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006759}
Mike Stump1eb44332009-09-09 15:08:12 +00006760
6761template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006762ExprResult
John McCall454feb92009-12-08 09:21:05 +00006763TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006764 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006765 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006766 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006767 if (SubStmt.isInvalid()) {
6768 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006769 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006770 }
Mike Stump1eb44332009-09-09 15:08:12 +00006771
Douglas Gregorb98b1992009-08-11 05:31:07 +00006772 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006773 SubStmt.get() == E->getSubStmt()) {
6774 // Calling this an 'error' is unintuitive, but it does the right thing.
6775 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006776 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006777 }
Mike Stump1eb44332009-09-09 15:08:12 +00006778
6779 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006780 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006781 E->getRParenLoc());
6782}
Mike Stump1eb44332009-09-09 15:08:12 +00006783
Douglas Gregorb98b1992009-08-11 05:31:07 +00006784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006785ExprResult
John McCall454feb92009-12-08 09:21:05 +00006786TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006787 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006788 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006789 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006790
John McCall60d7b3a2010-08-24 06:29:42 +00006791 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006792 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006793 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006794
John McCall60d7b3a2010-08-24 06:29:42 +00006795 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006796 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006797 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006798
Douglas Gregorb98b1992009-08-11 05:31:07 +00006799 if (!getDerived().AlwaysRebuild() &&
6800 Cond.get() == E->getCond() &&
6801 LHS.get() == E->getLHS() &&
6802 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006803 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006804
Douglas Gregorb98b1992009-08-11 05:31:07 +00006805 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006806 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807 E->getRParenLoc());
6808}
Mike Stump1eb44332009-09-09 15:08:12 +00006809
Douglas Gregorb98b1992009-08-11 05:31:07 +00006810template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006811ExprResult
John McCall454feb92009-12-08 09:21:05 +00006812TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006813 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006814}
6815
6816template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006817ExprResult
John McCall454feb92009-12-08 09:21:05 +00006818TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006819 switch (E->getOperator()) {
6820 case OO_New:
6821 case OO_Delete:
6822 case OO_Array_New:
6823 case OO_Array_Delete:
6824 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Sean Huntc3021132010-05-05 15:23:54 +00006825
Douglas Gregor668d6d92009-12-13 20:44:55 +00006826 case OO_Call: {
6827 // This is a call to an object's operator().
6828 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6829
6830 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006831 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006832 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006833 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006834
6835 // FIXME: Poor location information
6836 SourceLocation FakeLParenLoc
6837 = SemaRef.PP.getLocForEndOfToken(
6838 static_cast<Expr *>(Object.get())->getLocEnd());
6839
6840 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006841 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006842 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6843 Args))
6844 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006845
John McCall9ae2f072010-08-23 23:25:46 +00006846 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006847 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006848 E->getLocEnd());
6849 }
6850
6851#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6852 case OO_##Name:
6853#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6854#include "clang/Basic/OperatorKinds.def"
6855 case OO_Subscript:
6856 // Handled below.
6857 break;
6858
6859 case OO_Conditional:
6860 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006861
6862 case OO_None:
6863 case NUM_OVERLOADED_OPERATORS:
6864 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006865 }
6866
John McCall60d7b3a2010-08-24 06:29:42 +00006867 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006868 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006869 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006870
John McCall60d7b3a2010-08-24 06:29:42 +00006871 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006872 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006873 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006874
John McCall60d7b3a2010-08-24 06:29:42 +00006875 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006876 if (E->getNumArgs() == 2) {
6877 Second = getDerived().TransformExpr(E->getArg(1));
6878 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006879 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006880 }
Mike Stump1eb44332009-09-09 15:08:12 +00006881
Douglas Gregorb98b1992009-08-11 05:31:07 +00006882 if (!getDerived().AlwaysRebuild() &&
6883 Callee.get() == E->getCallee() &&
6884 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006885 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006886 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006887
Douglas Gregorb98b1992009-08-11 05:31:07 +00006888 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6889 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006890 Callee.get(),
6891 First.get(),
6892 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006893}
Mike Stump1eb44332009-09-09 15:08:12 +00006894
Douglas Gregorb98b1992009-08-11 05:31:07 +00006895template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006896ExprResult
John McCall454feb92009-12-08 09:21:05 +00006897TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6898 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006899}
Mike Stump1eb44332009-09-09 15:08:12 +00006900
Douglas Gregorb98b1992009-08-11 05:31:07 +00006901template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006902ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006903TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6904 // Transform the callee.
6905 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6906 if (Callee.isInvalid())
6907 return ExprError();
6908
6909 // Transform exec config.
6910 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6911 if (EC.isInvalid())
6912 return ExprError();
6913
6914 // Transform arguments.
6915 bool ArgChanged = false;
6916 ASTOwningVector<Expr*> Args(SemaRef);
6917 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6918 &ArgChanged))
6919 return ExprError();
6920
6921 if (!getDerived().AlwaysRebuild() &&
6922 Callee.get() == E->getCallee() &&
6923 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006924 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006925
6926 // FIXME: Wrong source location information for the '('.
6927 SourceLocation FakeLParenLoc
6928 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6929 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6930 move_arg(Args),
6931 E->getRParenLoc(), EC.get());
6932}
6933
6934template<typename Derived>
6935ExprResult
John McCall454feb92009-12-08 09:21:05 +00006936TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006937 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6938 if (!Type)
6939 return ExprError();
6940
John McCall60d7b3a2010-08-24 06:29:42 +00006941 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006942 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006943 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006944 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006945
Douglas Gregorb98b1992009-08-11 05:31:07 +00006946 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006947 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006948 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006949 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006950
Douglas Gregorb98b1992009-08-11 05:31:07 +00006951 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006952 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006953 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6954 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6955 SourceLocation FakeRParenLoc
6956 = SemaRef.PP.getLocForEndOfToken(
6957 E->getSubExpr()->getSourceRange().getEnd());
6958 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006959 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006961 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006962 FakeRAngleLoc,
6963 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006964 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006965 FakeRParenLoc);
6966}
Mike Stump1eb44332009-09-09 15:08:12 +00006967
Douglas Gregorb98b1992009-08-11 05:31:07 +00006968template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006969ExprResult
John McCall454feb92009-12-08 09:21:05 +00006970TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6971 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972}
Mike Stump1eb44332009-09-09 15:08:12 +00006973
6974template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006975ExprResult
John McCall454feb92009-12-08 09:21:05 +00006976TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6977 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006978}
6979
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006981ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006982TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006983 CXXReinterpretCastExpr *E) {
6984 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985}
Mike Stump1eb44332009-09-09 15:08:12 +00006986
Douglas Gregorb98b1992009-08-11 05:31:07 +00006987template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006988ExprResult
John McCall454feb92009-12-08 09:21:05 +00006989TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6990 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006991}
Mike Stump1eb44332009-09-09 15:08:12 +00006992
Douglas Gregorb98b1992009-08-11 05:31:07 +00006993template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006994ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006996 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006997 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6998 if (!Type)
6999 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007000
John McCall60d7b3a2010-08-24 06:29:42 +00007001 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007002 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007003 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007004 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007005
Douglas Gregorb98b1992009-08-11 05:31:07 +00007006 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007007 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007009 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007010
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007011 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007012 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007013 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014 E->getRParenLoc());
7015}
Mike Stump1eb44332009-09-09 15:08:12 +00007016
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007018ExprResult
John McCall454feb92009-12-08 09:21:05 +00007019TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007020 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007021 TypeSourceInfo *TInfo
7022 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7023 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007024 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007025
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007027 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007028 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007029
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007030 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7031 E->getLocStart(),
7032 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033 E->getLocEnd());
7034 }
Mike Stump1eb44332009-09-09 15:08:12 +00007035
Eli Friedmanef331b72012-01-20 01:26:23 +00007036 // We don't know whether the subexpression is potentially evaluated until
7037 // after we perform semantic analysis. We speculatively assume it is
7038 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007039 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007040 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007041
John McCall60d7b3a2010-08-24 06:29:42 +00007042 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007043 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007044 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007045
Douglas Gregorb98b1992009-08-11 05:31:07 +00007046 if (!getDerived().AlwaysRebuild() &&
7047 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007048 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007049
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007050 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7051 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007052 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053 E->getLocEnd());
7054}
7055
7056template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007057ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007058TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7059 if (E->isTypeOperand()) {
7060 TypeSourceInfo *TInfo
7061 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7062 if (!TInfo)
7063 return ExprError();
7064
7065 if (!getDerived().AlwaysRebuild() &&
7066 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007067 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007068
Douglas Gregor3c52a212011-03-06 17:40:41 +00007069 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007070 E->getLocStart(),
7071 TInfo,
7072 E->getLocEnd());
7073 }
7074
Francois Pichet01b7c302010-09-08 12:20:18 +00007075 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7076
7077 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7078 if (SubExpr.isInvalid())
7079 return ExprError();
7080
7081 if (!getDerived().AlwaysRebuild() &&
7082 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007083 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007084
7085 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7086 E->getLocStart(),
7087 SubExpr.get(),
7088 E->getLocEnd());
7089}
7090
7091template<typename Derived>
7092ExprResult
John McCall454feb92009-12-08 09:21:05 +00007093TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007094 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007095}
Mike Stump1eb44332009-09-09 15:08:12 +00007096
Douglas Gregorb98b1992009-08-11 05:31:07 +00007097template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007098ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007099TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007100 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007101 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007102}
Mike Stump1eb44332009-09-09 15:08:12 +00007103
Douglas Gregorb98b1992009-08-11 05:31:07 +00007104template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007105ExprResult
John McCall454feb92009-12-08 09:21:05 +00007106TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007107 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007108 QualType T;
7109 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7110 T = MD->getThisType(getSema().Context);
7111 else
7112 T = getSema().Context.getPointerType(
7113 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007114
Douglas Gregorec79d872012-02-24 17:41:38 +00007115 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7116 // Make sure that we capture 'this'.
7117 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007118 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007119 }
7120
Douglas Gregor828a1972010-01-07 23:12:05 +00007121 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007122}
Mike Stump1eb44332009-09-09 15:08:12 +00007123
Douglas Gregorb98b1992009-08-11 05:31:07 +00007124template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007125ExprResult
John McCall454feb92009-12-08 09:21:05 +00007126TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007127 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007128 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007129 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007130
Douglas Gregorb98b1992009-08-11 05:31:07 +00007131 if (!getDerived().AlwaysRebuild() &&
7132 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007133 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007134
Douglas Gregorbca01b42011-07-06 22:04:06 +00007135 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7136 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007137}
Mike Stump1eb44332009-09-09 15:08:12 +00007138
Douglas Gregorb98b1992009-08-11 05:31:07 +00007139template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007140ExprResult
John McCall454feb92009-12-08 09:21:05 +00007141TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007142 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007143 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7144 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007145 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007146 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007147
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007148 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007149 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007150 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007151
Douglas Gregor036aed12009-12-23 23:03:06 +00007152 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007153}
Mike Stump1eb44332009-09-09 15:08:12 +00007154
Douglas Gregorb98b1992009-08-11 05:31:07 +00007155template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007156ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007157TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7158 CXXScalarValueInitExpr *E) {
7159 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7160 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007161 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007162
Douglas Gregorb98b1992009-08-11 05:31:07 +00007163 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007164 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007165 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007166
Douglas Gregorab6677e2010-09-08 00:15:04 +00007167 return getDerived().RebuildCXXScalarValueInitExpr(T,
7168 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007169 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007170}
Mike Stump1eb44332009-09-09 15:08:12 +00007171
Douglas Gregorb98b1992009-08-11 05:31:07 +00007172template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007173ExprResult
John McCall454feb92009-12-08 09:21:05 +00007174TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007175 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007176 TypeSourceInfo *AllocTypeInfo
7177 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7178 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007179 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007180
Douglas Gregorb98b1992009-08-11 05:31:07 +00007181 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007182 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007183 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007184 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007185
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186 // Transform the placement arguments (if any).
7187 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007188 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007189 if (getDerived().TransformExprs(E->getPlacementArgs(),
7190 E->getNumPlacementArgs(), true,
7191 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007192 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007193
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007194 // Transform the initializer (if any).
7195 Expr *OldInit = E->getInitializer();
7196 ExprResult NewInit;
7197 if (OldInit)
7198 NewInit = getDerived().TransformExpr(OldInit);
7199 if (NewInit.isInvalid())
7200 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007201
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007202 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007203 FunctionDecl *OperatorNew = 0;
7204 if (E->getOperatorNew()) {
7205 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007206 getDerived().TransformDecl(E->getLocStart(),
7207 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007208 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007209 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007210 }
7211
7212 FunctionDecl *OperatorDelete = 0;
7213 if (E->getOperatorDelete()) {
7214 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007215 getDerived().TransformDecl(E->getLocStart(),
7216 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007217 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007218 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007219 }
Sean Huntc3021132010-05-05 15:23:54 +00007220
Douglas Gregorb98b1992009-08-11 05:31:07 +00007221 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007222 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007223 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007224 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007225 OperatorNew == E->getOperatorNew() &&
7226 OperatorDelete == E->getOperatorDelete() &&
7227 !ArgumentChanged) {
7228 // Mark any declarations we need as referenced.
7229 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007230 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007231 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007232 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007233 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007234
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007235 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007236 QualType ElementType
7237 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7238 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7239 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7240 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007241 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007242 }
7243 }
7244 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007245
John McCall3fa5cae2010-10-26 07:05:15 +00007246 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007247 }
Mike Stump1eb44332009-09-09 15:08:12 +00007248
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007249 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007250 if (!ArraySize.get()) {
7251 // If no array size was specified, but the new expression was
7252 // instantiated with an array type (e.g., "new T" where T is
7253 // instantiated with "int[4]"), extract the outer bound from the
7254 // array type as our array size. We do this with constant and
7255 // dependently-sized array types.
7256 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7257 if (!ArrayT) {
7258 // Do nothing
7259 } else if (const ConstantArrayType *ConsArrayT
7260 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007261 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007262 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7263 ConsArrayT->getSize(),
7264 SemaRef.Context.getSizeType(),
7265 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007266 AllocType = ConsArrayT->getElementType();
7267 } else if (const DependentSizedArrayType *DepArrayT
7268 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7269 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007270 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007271 AllocType = DepArrayT->getElementType();
7272 }
7273 }
7274 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007275
Douglas Gregorb98b1992009-08-11 05:31:07 +00007276 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7277 E->isGlobalNew(),
7278 /*FIXME:*/E->getLocStart(),
7279 move_arg(PlacementArgs),
7280 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007281 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007282 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007283 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007284 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007285 E->getDirectInitRange(),
7286 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007287}
Mike Stump1eb44332009-09-09 15:08:12 +00007288
Douglas Gregorb98b1992009-08-11 05:31:07 +00007289template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007290ExprResult
John McCall454feb92009-12-08 09:21:05 +00007291TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007292 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007293 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007294 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007295
Douglas Gregor1af74512010-02-26 00:38:10 +00007296 // Transform the delete operator, if known.
7297 FunctionDecl *OperatorDelete = 0;
7298 if (E->getOperatorDelete()) {
7299 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007300 getDerived().TransformDecl(E->getLocStart(),
7301 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007302 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007303 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007304 }
Sean Huntc3021132010-05-05 15:23:54 +00007305
Douglas Gregorb98b1992009-08-11 05:31:07 +00007306 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007307 Operand.get() == E->getArgument() &&
7308 OperatorDelete == E->getOperatorDelete()) {
7309 // Mark any declarations we need as referenced.
7310 // FIXME: instantiation-specific.
7311 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007312 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007313
7314 if (!E->getArgument()->isTypeDependent()) {
7315 QualType Destroyed = SemaRef.Context.getBaseElementType(
7316 E->getDestroyedType());
7317 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7318 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007319 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7320 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007321 }
7322 }
7323
John McCall3fa5cae2010-10-26 07:05:15 +00007324 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007325 }
Mike Stump1eb44332009-09-09 15:08:12 +00007326
Douglas Gregorb98b1992009-08-11 05:31:07 +00007327 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7328 E->isGlobalDelete(),
7329 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007330 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007331}
Mike Stump1eb44332009-09-09 15:08:12 +00007332
Douglas Gregorb98b1992009-08-11 05:31:07 +00007333template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007334ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007335TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007336 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007337 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007338 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007339 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007340
John McCallb3d87482010-08-24 05:47:05 +00007341 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007342 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007343 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007344 E->getOperatorLoc(),
7345 E->isArrow()? tok::arrow : tok::period,
7346 ObjectTypePtr,
7347 MayBePseudoDestructor);
7348 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007349 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007350
John McCallb3d87482010-08-24 05:47:05 +00007351 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007352 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7353 if (QualifierLoc) {
7354 QualifierLoc
7355 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7356 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007357 return ExprError();
7358 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007359 CXXScopeSpec SS;
7360 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007361
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007362 PseudoDestructorTypeStorage Destroyed;
7363 if (E->getDestroyedTypeInfo()) {
7364 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007365 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007366 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007367 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007368 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007369 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007370 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007371 // We aren't likely to be able to resolve the identifier down to a type
7372 // now anyway, so just retain the identifier.
7373 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7374 E->getDestroyedTypeLoc());
7375 } else {
7376 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007377 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007378 *E->getDestroyedTypeIdentifier(),
7379 E->getDestroyedTypeLoc(),
7380 /*Scope=*/0,
7381 SS, ObjectTypePtr,
7382 false);
7383 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007384 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007385
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007386 Destroyed
7387 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7388 E->getDestroyedTypeLoc());
7389 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007390
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007391 TypeSourceInfo *ScopeTypeInfo = 0;
7392 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007393 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007394 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007395 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007396 }
Sean Huntc3021132010-05-05 15:23:54 +00007397
John McCall9ae2f072010-08-23 23:25:46 +00007398 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007399 E->getOperatorLoc(),
7400 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007401 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007402 ScopeTypeInfo,
7403 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007404 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007405 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007406}
Mike Stump1eb44332009-09-09 15:08:12 +00007407
Douglas Gregora71d8192009-09-04 17:36:40 +00007408template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007409ExprResult
John McCallba135432009-11-21 08:51:07 +00007410TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007411 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007412 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7413 Sema::LookupOrdinaryName);
7414
7415 // Transform all the decls.
7416 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7417 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007418 NamedDecl *InstD = static_cast<NamedDecl*>(
7419 getDerived().TransformDecl(Old->getNameLoc(),
7420 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007421 if (!InstD) {
7422 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7423 // This can happen because of dependent hiding.
7424 if (isa<UsingShadowDecl>(*I))
7425 continue;
7426 else
John McCallf312b1e2010-08-26 23:41:50 +00007427 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007428 }
John McCallf7a1a742009-11-24 19:00:30 +00007429
7430 // Expand using declarations.
7431 if (isa<UsingDecl>(InstD)) {
7432 UsingDecl *UD = cast<UsingDecl>(InstD);
7433 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7434 E = UD->shadow_end(); I != E; ++I)
7435 R.addDecl(*I);
7436 continue;
7437 }
7438
7439 R.addDecl(InstD);
7440 }
7441
7442 // Resolve a kind, but don't do any further analysis. If it's
7443 // ambiguous, the callee needs to deal with it.
7444 R.resolveKind();
7445
7446 // Rebuild the nested-name qualifier, if present.
7447 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007448 if (Old->getQualifierLoc()) {
7449 NestedNameSpecifierLoc QualifierLoc
7450 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7451 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007452 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007453
Douglas Gregor4c9be892011-02-28 20:01:57 +00007454 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007455 }
7456
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007457 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007458 CXXRecordDecl *NamingClass
7459 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7460 Old->getNameLoc(),
7461 Old->getNamingClass()));
7462 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007463 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007464
Douglas Gregor66c45152010-04-27 16:10:10 +00007465 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007466 }
7467
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007468 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7469
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007470 // If we have neither explicit template arguments, nor the template keyword,
7471 // it's a normal declaration name.
7472 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007473 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7474
7475 // If we have template arguments, rebuild them, then rebuild the
7476 // templateid expression.
7477 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007478 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7479 Old->getNumTemplateArgs(),
7480 TransArgs))
7481 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007482
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007483 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007484 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007485}
Mike Stump1eb44332009-09-09 15:08:12 +00007486
Douglas Gregorb98b1992009-08-11 05:31:07 +00007487template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007488ExprResult
John McCall454feb92009-12-08 09:21:05 +00007489TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007490 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7491 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007492 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007493
Douglas Gregorb98b1992009-08-11 05:31:07 +00007494 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007495 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007496 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007497
Mike Stump1eb44332009-09-09 15:08:12 +00007498 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007499 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007500 T,
7501 E->getLocEnd());
7502}
Mike Stump1eb44332009-09-09 15:08:12 +00007503
Douglas Gregorb98b1992009-08-11 05:31:07 +00007504template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007505ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007506TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7507 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7508 if (!LhsT)
7509 return ExprError();
7510
7511 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7512 if (!RhsT)
7513 return ExprError();
7514
7515 if (!getDerived().AlwaysRebuild() &&
7516 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7517 return SemaRef.Owned(E);
7518
7519 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7520 E->getLocStart(),
7521 LhsT, RhsT,
7522 E->getLocEnd());
7523}
7524
7525template<typename Derived>
7526ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007527TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7528 bool ArgChanged = false;
7529 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7530 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7531 TypeSourceInfo *From = E->getArg(I);
7532 TypeLoc FromTL = From->getTypeLoc();
7533 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7534 TypeLocBuilder TLB;
7535 TLB.reserve(FromTL.getFullDataSize());
7536 QualType To = getDerived().TransformType(TLB, FromTL);
7537 if (To.isNull())
7538 return ExprError();
7539
7540 if (To == From->getType())
7541 Args.push_back(From);
7542 else {
7543 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7544 ArgChanged = true;
7545 }
7546 continue;
7547 }
7548
7549 ArgChanged = true;
7550
7551 // We have a pack expansion. Instantiate it.
7552 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
7553 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7554 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7555 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7556
7557 // Determine whether the set of unexpanded parameter packs can and should
7558 // be expanded.
7559 bool Expand = true;
7560 bool RetainExpansion = false;
7561 llvm::Optional<unsigned> OrigNumExpansions
7562 = ExpansionTL.getTypePtr()->getNumExpansions();
7563 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7564 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7565 PatternTL.getSourceRange(),
7566 Unexpanded,
7567 Expand, RetainExpansion,
7568 NumExpansions))
7569 return ExprError();
7570
7571 if (!Expand) {
7572 // The transform has determined that we should perform a simple
7573 // transformation on the pack expansion, producing another pack
7574 // expansion.
7575 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7576
7577 TypeLocBuilder TLB;
7578 TLB.reserve(From->getTypeLoc().getFullDataSize());
7579
7580 QualType To = getDerived().TransformType(TLB, PatternTL);
7581 if (To.isNull())
7582 return ExprError();
7583
7584 To = getDerived().RebuildPackExpansionType(To,
7585 PatternTL.getSourceRange(),
7586 ExpansionTL.getEllipsisLoc(),
7587 NumExpansions);
7588 if (To.isNull())
7589 return ExprError();
7590
7591 PackExpansionTypeLoc ToExpansionTL
7592 = TLB.push<PackExpansionTypeLoc>(To);
7593 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7594 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7595 continue;
7596 }
7597
7598 // Expand the pack expansion by substituting for each argument in the
7599 // pack(s).
7600 for (unsigned I = 0; I != *NumExpansions; ++I) {
7601 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7602 TypeLocBuilder TLB;
7603 TLB.reserve(PatternTL.getFullDataSize());
7604 QualType To = getDerived().TransformType(TLB, PatternTL);
7605 if (To.isNull())
7606 return ExprError();
7607
7608 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7609 }
7610
7611 if (!RetainExpansion)
7612 continue;
7613
7614 // If we're supposed to retain a pack expansion, do so by temporarily
7615 // forgetting the partially-substituted parameter pack.
7616 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7617
7618 TypeLocBuilder TLB;
7619 TLB.reserve(From->getTypeLoc().getFullDataSize());
7620
7621 QualType To = getDerived().TransformType(TLB, PatternTL);
7622 if (To.isNull())
7623 return ExprError();
7624
7625 To = getDerived().RebuildPackExpansionType(To,
7626 PatternTL.getSourceRange(),
7627 ExpansionTL.getEllipsisLoc(),
7628 NumExpansions);
7629 if (To.isNull())
7630 return ExprError();
7631
7632 PackExpansionTypeLoc ToExpansionTL
7633 = TLB.push<PackExpansionTypeLoc>(To);
7634 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7635 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7636 }
7637
7638 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7639 return SemaRef.Owned(E);
7640
7641 return getDerived().RebuildTypeTrait(E->getTrait(),
7642 E->getLocStart(),
7643 Args,
7644 E->getLocEnd());
7645}
7646
7647template<typename Derived>
7648ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007649TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7650 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7651 if (!T)
7652 return ExprError();
7653
7654 if (!getDerived().AlwaysRebuild() &&
7655 T == E->getQueriedTypeSourceInfo())
7656 return SemaRef.Owned(E);
7657
7658 ExprResult SubExpr;
7659 {
7660 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7661 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7662 if (SubExpr.isInvalid())
7663 return ExprError();
7664
7665 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7666 return SemaRef.Owned(E);
7667 }
7668
7669 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7670 E->getLocStart(),
7671 T,
7672 SubExpr.get(),
7673 E->getLocEnd());
7674}
7675
7676template<typename Derived>
7677ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007678TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7679 ExprResult SubExpr;
7680 {
7681 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7682 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7683 if (SubExpr.isInvalid())
7684 return ExprError();
7685
7686 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7687 return SemaRef.Owned(E);
7688 }
7689
7690 return getDerived().RebuildExpressionTrait(
7691 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7692}
7693
7694template<typename Derived>
7695ExprResult
John McCall865d4472009-11-19 22:55:06 +00007696TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007697 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007698 NestedNameSpecifierLoc QualifierLoc
7699 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7700 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007701 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007702 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007703
John McCall43fed0d2010-11-12 08:19:04 +00007704 // TODO: If this is a conversion-function-id, verify that the
7705 // destination type name (if present) resolves the same way after
7706 // instantiation as it did in the local scope.
7707
Abramo Bagnara25777432010-08-11 22:01:17 +00007708 DeclarationNameInfo NameInfo
7709 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7710 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007711 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007712
John McCallf7a1a742009-11-24 19:00:30 +00007713 if (!E->hasExplicitTemplateArgs()) {
7714 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007715 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007716 // Note: it is sufficient to compare the Name component of NameInfo:
7717 // if name has not changed, DNLoc has not changed either.
7718 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007719 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007720
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007721 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007722 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007723 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007724 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007725 }
John McCalld5532b62009-11-23 01:53:49 +00007726
7727 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007728 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7729 E->getNumTemplateArgs(),
7730 TransArgs))
7731 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007732
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007733 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007734 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007735 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007736 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007737}
7738
7739template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007740ExprResult
John McCall454feb92009-12-08 09:21:05 +00007741TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007742 // CXXConstructExprs are always implicit, so when we have a
7743 // 1-argument construction we just transform that argument.
7744 if (E->getNumArgs() == 1 ||
7745 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7746 return getDerived().TransformExpr(E->getArg(0));
7747
Douglas Gregorb98b1992009-08-11 05:31:07 +00007748 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7749
7750 QualType T = getDerived().TransformType(E->getType());
7751 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007752 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007753
7754 CXXConstructorDecl *Constructor
7755 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007756 getDerived().TransformDecl(E->getLocStart(),
7757 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007758 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007759 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007760
Douglas Gregorb98b1992009-08-11 05:31:07 +00007761 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007762 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007763 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7764 &ArgumentChanged))
7765 return ExprError();
7766
Douglas Gregorb98b1992009-08-11 05:31:07 +00007767 if (!getDerived().AlwaysRebuild() &&
7768 T == E->getType() &&
7769 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007770 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007771 // Mark the constructor as referenced.
7772 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007773 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007774 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007775 }
Mike Stump1eb44332009-09-09 15:08:12 +00007776
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007777 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7778 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007779 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007780 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007781 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007782 E->getConstructionKind(),
7783 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007784}
Mike Stump1eb44332009-09-09 15:08:12 +00007785
Douglas Gregorb98b1992009-08-11 05:31:07 +00007786/// \brief Transform a C++ temporary-binding expression.
7787///
Douglas Gregor51326552009-12-24 18:51:59 +00007788/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7789/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007790template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007791ExprResult
John McCall454feb92009-12-08 09:21:05 +00007792TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007793 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007794}
Mike Stump1eb44332009-09-09 15:08:12 +00007795
John McCall4765fa02010-12-06 08:20:24 +00007796/// \brief Transform a C++ expression that contains cleanups that should
7797/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007798///
John McCall4765fa02010-12-06 08:20:24 +00007799/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007800/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007801template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007802ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007803TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007804 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007805}
Mike Stump1eb44332009-09-09 15:08:12 +00007806
Douglas Gregorb98b1992009-08-11 05:31:07 +00007807template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007808ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007809TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007810 CXXTemporaryObjectExpr *E) {
7811 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7812 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007813 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007814
Douglas Gregorb98b1992009-08-11 05:31:07 +00007815 CXXConstructorDecl *Constructor
7816 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007817 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007818 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007819 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007820 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007821
Douglas Gregorb98b1992009-08-11 05:31:07 +00007822 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007823 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007824 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007825 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7826 &ArgumentChanged))
7827 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007828
Douglas Gregorb98b1992009-08-11 05:31:07 +00007829 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007830 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007831 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007832 !ArgumentChanged) {
7833 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007834 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007835 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007836 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007837
7838 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7839 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007840 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007841 E->getLocEnd());
7842}
Mike Stump1eb44332009-09-09 15:08:12 +00007843
Douglas Gregorb98b1992009-08-11 05:31:07 +00007844template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007845ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007846TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007847 // Create the local class that will describe the lambda.
7848 CXXRecordDecl *Class
Douglas Gregorf54486a2012-04-04 17:40:10 +00007849 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7850 /*KnownDependent=*/false);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007851 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7852
7853 // Transform the type of the lambda parameters and start the definition of
7854 // the lambda itself.
7855 TypeSourceInfo *MethodTy
7856 = TransformType(E->getCallOperator()->getTypeSourceInfo());
7857 if (!MethodTy)
7858 return ExprError();
7859
Douglas Gregorc6889e72012-02-14 22:28:59 +00007860 // Transform lambda parameters.
7861 bool Invalid = false;
7862 llvm::SmallVector<QualType, 4> ParamTypes;
7863 llvm::SmallVector<ParmVarDecl *, 4> Params;
7864 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7865 E->getCallOperator()->param_begin(),
7866 E->getCallOperator()->param_size(),
7867 0, ParamTypes, &Params))
7868 Invalid = true;
7869
Douglas Gregordfca6f52012-02-13 22:00:16 +00007870 // Build the call operator.
Douglas Gregorf54486a2012-04-04 17:40:10 +00007871 // Note: Once a lambda mangling number and context declaration have been
7872 // assigned, they never change.
7873 unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber();
7874 Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl();
Douglas Gregordfca6f52012-02-13 22:00:16 +00007875 CXXMethodDecl *CallOperator
7876 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7877 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007878 E->getCallOperator()->getLocEnd(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00007879 Params, ManglingNumber, ContextDecl);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007880 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7881
Douglas Gregord5387e82012-02-14 00:00:48 +00007882 // FIXME: Instantiation-specific.
7883 CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(),
7884 TSK_ImplicitInstantiation);
7885
7886 // Introduce the context of the call operator.
7887 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7888
Douglas Gregordfca6f52012-02-13 22:00:16 +00007889 // Enter the scope of the lambda.
7890 sema::LambdaScopeInfo *LSI
7891 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7892 E->getCaptureDefault(),
7893 E->hasExplicitParameters(),
7894 E->hasExplicitResultType(),
7895 E->isMutable());
7896
7897 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00007898 bool FinishedExplicitCaptures = false;
7899 for (LambdaExpr::capture_iterator C = E->capture_begin(),
7900 CEnd = E->capture_end();
7901 C != CEnd; ++C) {
7902 // When we hit the first implicit capture, tell Sema that we've finished
7903 // the list of explicit captures.
7904 if (!FinishedExplicitCaptures && C->isImplicit()) {
7905 getSema().finishLambdaExplicitCaptures(LSI);
7906 FinishedExplicitCaptures = true;
7907 }
7908
7909 // Capturing 'this' is trivial.
7910 if (C->capturesThis()) {
7911 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7912 continue;
7913 }
7914
Douglas Gregora7365242012-02-14 19:27:52 +00007915 // Determine the capture kind for Sema.
7916 Sema::TryCaptureKind Kind
7917 = C->isImplicit()? Sema::TryCapture_Implicit
7918 : C->getCaptureKind() == LCK_ByCopy
7919 ? Sema::TryCapture_ExplicitByVal
7920 : Sema::TryCapture_ExplicitByRef;
7921 SourceLocation EllipsisLoc;
7922 if (C->isPackExpansion()) {
7923 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7924 bool ShouldExpand = false;
7925 bool RetainExpansion = false;
7926 llvm::Optional<unsigned> NumExpansions;
7927 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7928 C->getLocation(),
7929 Unexpanded,
7930 ShouldExpand, RetainExpansion,
7931 NumExpansions))
7932 return ExprError();
7933
7934 if (ShouldExpand) {
7935 // The transform has determined that we should perform an expansion;
7936 // transform and capture each of the arguments.
7937 // expansion of the pattern. Do so.
7938 VarDecl *Pack = C->getCapturedVar();
7939 for (unsigned I = 0; I != *NumExpansions; ++I) {
7940 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7941 VarDecl *CapturedVar
7942 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7943 Pack));
7944 if (!CapturedVar) {
7945 Invalid = true;
7946 continue;
7947 }
7948
7949 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007950 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregora7365242012-02-14 19:27:52 +00007951 }
7952 continue;
7953 }
7954
7955 EllipsisLoc = C->getEllipsisLoc();
7956 }
7957
Douglas Gregordfca6f52012-02-13 22:00:16 +00007958 // Transform the captured variable.
7959 VarDecl *CapturedVar
7960 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7961 C->getCapturedVar()));
7962 if (!CapturedVar) {
7963 Invalid = true;
7964 continue;
7965 }
Douglas Gregora7365242012-02-14 19:27:52 +00007966
Douglas Gregordfca6f52012-02-13 22:00:16 +00007967 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007968 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007969 }
7970 if (!FinishedExplicitCaptures)
7971 getSema().finishLambdaExplicitCaptures(LSI);
7972
Douglas Gregordfca6f52012-02-13 22:00:16 +00007973
7974 // Enter a new evaluation context to insulate the lambda from any
7975 // cleanups from the enclosing full-expression.
7976 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
7977
7978 if (Invalid) {
7979 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7980 /*IsInstantiation=*/true);
7981 return ExprError();
7982 }
7983
7984 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00007985 StmtResult Body = getDerived().TransformStmt(E->getBody());
7986 if (Body.isInvalid()) {
7987 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7988 /*IsInstantiation=*/true);
7989 return ExprError();
7990 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007991
Douglas Gregordfca6f52012-02-13 22:00:16 +00007992 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00007993 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00007994}
7995
7996template<typename Derived>
7997ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007998TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007999 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008000 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8001 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008002 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008003
Douglas Gregorb98b1992009-08-11 05:31:07 +00008004 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008005 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008006 Args.reserve(E->arg_size());
8007 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
8008 &ArgumentChanged))
8009 return ExprError();
8010
Douglas Gregorb98b1992009-08-11 05:31:07 +00008011 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008012 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008013 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008014 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008015
Douglas Gregorb98b1992009-08-11 05:31:07 +00008016 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008017 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008018 E->getLParenLoc(),
8019 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00008020 E->getRParenLoc());
8021}
Mike Stump1eb44332009-09-09 15:08:12 +00008022
Douglas Gregorb98b1992009-08-11 05:31:07 +00008023template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008024ExprResult
John McCall865d4472009-11-19 22:55:06 +00008025TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008026 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008027 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008028 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008029 Expr *OldBase;
8030 QualType BaseType;
8031 QualType ObjectType;
8032 if (!E->isImplicitAccess()) {
8033 OldBase = E->getBase();
8034 Base = getDerived().TransformExpr(OldBase);
8035 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008036 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008037
John McCallaa81e162009-12-01 22:10:20 +00008038 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008039 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008040 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008041 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008042 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008043 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008044 ObjectTy,
8045 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008046 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008047 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008048
John McCallb3d87482010-08-24 05:47:05 +00008049 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008050 BaseType = ((Expr*) Base.get())->getType();
8051 } else {
8052 OldBase = 0;
8053 BaseType = getDerived().TransformType(E->getBaseType());
8054 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8055 }
Mike Stump1eb44332009-09-09 15:08:12 +00008056
Douglas Gregor6cd21982009-10-20 05:58:46 +00008057 // Transform the first part of the nested-name-specifier that qualifies
8058 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008059 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008060 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008061 E->getFirstQualifierFoundInScope(),
8062 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008063
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008064 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008065 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008066 QualifierLoc
8067 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8068 ObjectType,
8069 FirstQualifierInScope);
8070 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008071 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008072 }
Mike Stump1eb44332009-09-09 15:08:12 +00008073
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008074 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8075
John McCall43fed0d2010-11-12 08:19:04 +00008076 // TODO: If this is a conversion-function-id, verify that the
8077 // destination type name (if present) resolves the same way after
8078 // instantiation as it did in the local scope.
8079
Abramo Bagnara25777432010-08-11 22:01:17 +00008080 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008081 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008082 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008083 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008084
John McCallaa81e162009-12-01 22:10:20 +00008085 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008086 // This is a reference to a member without an explicitly-specified
8087 // template argument list. Optimize for this common case.
8088 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008089 Base.get() == OldBase &&
8090 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008091 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008092 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008093 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008094 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008095
John McCall9ae2f072010-08-23 23:25:46 +00008096 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008097 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008098 E->isArrow(),
8099 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008100 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008101 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008102 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008103 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008104 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008105 }
8106
John McCalld5532b62009-11-23 01:53:49 +00008107 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008108 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8109 E->getNumTemplateArgs(),
8110 TransArgs))
8111 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008112
John McCall9ae2f072010-08-23 23:25:46 +00008113 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008114 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008115 E->isArrow(),
8116 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008117 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008118 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008119 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008120 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008121 &TransArgs);
8122}
8123
8124template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008125ExprResult
John McCall454feb92009-12-08 09:21:05 +00008126TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008127 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008128 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008129 QualType BaseType;
8130 if (!Old->isImplicitAccess()) {
8131 Base = getDerived().TransformExpr(Old->getBase());
8132 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008133 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008134 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8135 Old->isArrow());
8136 if (Base.isInvalid())
8137 return ExprError();
8138 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008139 } else {
8140 BaseType = getDerived().TransformType(Old->getBaseType());
8141 }
John McCall129e2df2009-11-30 22:42:35 +00008142
Douglas Gregor4c9be892011-02-28 20:01:57 +00008143 NestedNameSpecifierLoc QualifierLoc;
8144 if (Old->getQualifierLoc()) {
8145 QualifierLoc
8146 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8147 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008148 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008149 }
8150
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008151 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8152
Abramo Bagnara25777432010-08-11 22:01:17 +00008153 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008154 Sema::LookupOrdinaryName);
8155
8156 // Transform all the decls.
8157 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8158 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008159 NamedDecl *InstD = static_cast<NamedDecl*>(
8160 getDerived().TransformDecl(Old->getMemberLoc(),
8161 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008162 if (!InstD) {
8163 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8164 // This can happen because of dependent hiding.
8165 if (isa<UsingShadowDecl>(*I))
8166 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008167 else {
8168 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008169 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008170 }
John McCall9f54ad42009-12-10 09:41:52 +00008171 }
John McCall129e2df2009-11-30 22:42:35 +00008172
8173 // Expand using declarations.
8174 if (isa<UsingDecl>(InstD)) {
8175 UsingDecl *UD = cast<UsingDecl>(InstD);
8176 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8177 E = UD->shadow_end(); I != E; ++I)
8178 R.addDecl(*I);
8179 continue;
8180 }
8181
8182 R.addDecl(InstD);
8183 }
8184
8185 R.resolveKind();
8186
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008187 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008188 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00008189 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008190 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008191 Old->getMemberLoc(),
8192 Old->getNamingClass()));
8193 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008194 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008195
Douglas Gregor66c45152010-04-27 16:10:10 +00008196 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008197 }
Sean Huntc3021132010-05-05 15:23:54 +00008198
John McCall129e2df2009-11-30 22:42:35 +00008199 TemplateArgumentListInfo TransArgs;
8200 if (Old->hasExplicitTemplateArgs()) {
8201 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8202 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008203 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8204 Old->getNumTemplateArgs(),
8205 TransArgs))
8206 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008207 }
John McCallc2233c52010-01-15 08:34:02 +00008208
8209 // FIXME: to do this check properly, we will need to preserve the
8210 // first-qualifier-in-scope here, just in case we had a dependent
8211 // base (and therefore couldn't do the check) and a
8212 // nested-name-qualifier (and therefore could do the lookup).
8213 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00008214
John McCall9ae2f072010-08-23 23:25:46 +00008215 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008216 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008217 Old->getOperatorLoc(),
8218 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008219 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008220 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008221 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008222 R,
8223 (Old->hasExplicitTemplateArgs()
8224 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008225}
8226
8227template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008228ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008229TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008230 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008231 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8232 if (SubExpr.isInvalid())
8233 return ExprError();
8234
8235 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008236 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008237
8238 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8239}
8240
8241template<typename Derived>
8242ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008243TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008244 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8245 if (Pattern.isInvalid())
8246 return ExprError();
8247
8248 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8249 return SemaRef.Owned(E);
8250
Douglas Gregor67fd1252011-01-14 21:20:45 +00008251 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8252 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008253}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008254
8255template<typename Derived>
8256ExprResult
8257TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8258 // If E is not value-dependent, then nothing will change when we transform it.
8259 // Note: This is an instantiation-centric view.
8260 if (!E->isValueDependent())
8261 return SemaRef.Owned(E);
8262
8263 // Note: None of the implementations of TryExpandParameterPacks can ever
8264 // produce a diagnostic when given only a single unexpanded parameter pack,
8265 // so
8266 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8267 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008268 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008269 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00008270 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008271 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008272 ShouldExpand, RetainExpansion,
8273 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008274 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00008275
Douglas Gregor089e8932011-10-10 18:59:29 +00008276 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008277 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00008278
8279 NamedDecl *Pack = E->getPack();
8280 if (!ShouldExpand) {
8281 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8282 Pack));
8283 if (!Pack)
8284 return ExprError();
8285 }
8286
Douglas Gregoree8aff02011-01-04 17:33:58 +00008287
8288 // We now know the length of the parameter pack, so build a new expression
8289 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00008290 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00008291 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008292 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008293}
8294
Douglas Gregorbe230c32011-01-03 17:17:50 +00008295template<typename Derived>
8296ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008297TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8298 SubstNonTypeTemplateParmPackExpr *E) {
8299 // Default behavior is to do nothing with this transformation.
8300 return SemaRef.Owned(E);
8301}
8302
8303template<typename Derived>
8304ExprResult
John McCall91a57552011-07-15 05:09:51 +00008305TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8306 SubstNonTypeTemplateParmExpr *E) {
8307 // Default behavior is to do nothing with this transformation.
8308 return SemaRef.Owned(E);
8309}
8310
8311template<typename Derived>
8312ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008313TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8314 MaterializeTemporaryExpr *E) {
8315 return getDerived().TransformExpr(E->GetTemporaryExpr());
8316}
8317
8318template<typename Derived>
8319ExprResult
John McCall454feb92009-12-08 09:21:05 +00008320TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008321 return SemaRef.MaybeBindToTemporary(E);
8322}
8323
8324template<typename Derived>
8325ExprResult
8326TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008327 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008328}
8329
8330template<typename Derived>
8331ExprResult
8332TreeTransform<Derived>::TransformObjCNumericLiteral(ObjCNumericLiteral *E) {
8333 return SemaRef.MaybeBindToTemporary(E);
8334}
8335
8336template<typename Derived>
8337ExprResult
8338TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8339 // Transform each of the elements.
8340 llvm::SmallVector<Expr *, 8> Elements;
8341 bool ArgChanged = false;
8342 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
8343 /*IsCall=*/false, Elements, &ArgChanged))
8344 return ExprError();
8345
8346 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8347 return SemaRef.MaybeBindToTemporary(E);
8348
8349 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8350 Elements.data(),
8351 Elements.size());
8352}
8353
8354template<typename Derived>
8355ExprResult
8356TreeTransform<Derived>::TransformObjCDictionaryLiteral(
8357 ObjCDictionaryLiteral *E) {
8358 // Transform each of the elements.
8359 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8360 bool ArgChanged = false;
8361 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8362 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
8363
8364 if (OrigElement.isPackExpansion()) {
8365 // This key/value element is a pack expansion.
8366 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8367 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8368 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8369 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8370
8371 // Determine whether the set of unexpanded parameter packs can
8372 // and should be expanded.
8373 bool Expand = true;
8374 bool RetainExpansion = false;
8375 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8376 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8377 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8378 OrigElement.Value->getLocEnd());
8379 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8380 PatternRange,
8381 Unexpanded,
8382 Expand, RetainExpansion,
8383 NumExpansions))
8384 return ExprError();
8385
8386 if (!Expand) {
8387 // The transform has determined that we should perform a simple
8388 // transformation on the pack expansion, producing another pack
8389 // expansion.
8390 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8391 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8392 if (Key.isInvalid())
8393 return ExprError();
8394
8395 if (Key.get() != OrigElement.Key)
8396 ArgChanged = true;
8397
8398 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8399 if (Value.isInvalid())
8400 return ExprError();
8401
8402 if (Value.get() != OrigElement.Value)
8403 ArgChanged = true;
8404
8405 ObjCDictionaryElement Expansion = {
8406 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8407 };
8408 Elements.push_back(Expansion);
8409 continue;
8410 }
8411
8412 // Record right away that the argument was changed. This needs
8413 // to happen even if the array expands to nothing.
8414 ArgChanged = true;
8415
8416 // The transform has determined that we should perform an elementwise
8417 // expansion of the pattern. Do so.
8418 for (unsigned I = 0; I != *NumExpansions; ++I) {
8419 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8420 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8421 if (Key.isInvalid())
8422 return ExprError();
8423
8424 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8425 if (Value.isInvalid())
8426 return ExprError();
8427
8428 ObjCDictionaryElement Element = {
8429 Key.get(), Value.get(), SourceLocation(), NumExpansions
8430 };
8431
8432 // If any unexpanded parameter packs remain, we still have a
8433 // pack expansion.
8434 if (Key.get()->containsUnexpandedParameterPack() ||
8435 Value.get()->containsUnexpandedParameterPack())
8436 Element.EllipsisLoc = OrigElement.EllipsisLoc;
8437
8438 Elements.push_back(Element);
8439 }
8440
8441 // We've finished with this pack expansion.
8442 continue;
8443 }
8444
8445 // Transform and check key.
8446 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8447 if (Key.isInvalid())
8448 return ExprError();
8449
8450 if (Key.get() != OrigElement.Key)
8451 ArgChanged = true;
8452
8453 // Transform and check value.
8454 ExprResult Value
8455 = getDerived().TransformExpr(OrigElement.Value);
8456 if (Value.isInvalid())
8457 return ExprError();
8458
8459 if (Value.get() != OrigElement.Value)
8460 ArgChanged = true;
8461
8462 ObjCDictionaryElement Element = {
8463 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8464 };
8465 Elements.push_back(Element);
8466 }
8467
8468 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8469 return SemaRef.MaybeBindToTemporary(E);
8470
8471 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8472 Elements.data(),
8473 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008474}
8475
Mike Stump1eb44332009-09-09 15:08:12 +00008476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008477ExprResult
John McCall454feb92009-12-08 09:21:05 +00008478TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008479 TypeSourceInfo *EncodedTypeInfo
8480 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8481 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008482 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008483
Douglas Gregorb98b1992009-08-11 05:31:07 +00008484 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008485 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008486 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008487
8488 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008489 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008490 E->getRParenLoc());
8491}
Mike Stump1eb44332009-09-09 15:08:12 +00008492
Douglas Gregorb98b1992009-08-11 05:31:07 +00008493template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008494ExprResult TreeTransform<Derived>::
8495TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8496 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8497 if (result.isInvalid()) return ExprError();
8498 Expr *subExpr = result.take();
8499
8500 if (!getDerived().AlwaysRebuild() &&
8501 subExpr == E->getSubExpr())
8502 return SemaRef.Owned(E);
8503
8504 return SemaRef.Owned(new(SemaRef.Context)
8505 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8506}
8507
8508template<typename Derived>
8509ExprResult TreeTransform<Derived>::
8510TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
8511 TypeSourceInfo *TSInfo
8512 = getDerived().TransformType(E->getTypeInfoAsWritten());
8513 if (!TSInfo)
8514 return ExprError();
8515
8516 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
8517 if (Result.isInvalid())
8518 return ExprError();
8519
8520 if (!getDerived().AlwaysRebuild() &&
8521 TSInfo == E->getTypeInfoAsWritten() &&
8522 Result.get() == E->getSubExpr())
8523 return SemaRef.Owned(E);
8524
8525 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8526 E->getBridgeKeywordLoc(), TSInfo,
8527 Result.get());
8528}
8529
8530template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008531ExprResult
John McCall454feb92009-12-08 09:21:05 +00008532TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008533 // Transform arguments.
8534 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008535 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008536 Args.reserve(E->getNumArgs());
8537 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8538 &ArgChanged))
8539 return ExprError();
8540
Douglas Gregor92e986e2010-04-22 16:44:27 +00008541 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8542 // Class message: transform the receiver type.
8543 TypeSourceInfo *ReceiverTypeInfo
8544 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8545 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008546 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008547
Douglas Gregor92e986e2010-04-22 16:44:27 +00008548 // If nothing changed, just retain the existing message send.
8549 if (!getDerived().AlwaysRebuild() &&
8550 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008551 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008552
8553 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008554 SmallVector<SourceLocation, 16> SelLocs;
8555 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008556 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8557 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008558 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008559 E->getMethodDecl(),
8560 E->getLeftLoc(),
8561 move_arg(Args),
8562 E->getRightLoc());
8563 }
8564
8565 // Instance message: transform the receiver
8566 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8567 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008568 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008569 = getDerived().TransformExpr(E->getInstanceReceiver());
8570 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008571 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008572
8573 // If nothing changed, just retain the existing message send.
8574 if (!getDerived().AlwaysRebuild() &&
8575 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008576 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008577
Douglas Gregor92e986e2010-04-22 16:44:27 +00008578 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008579 SmallVector<SourceLocation, 16> SelLocs;
8580 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008581 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008582 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008583 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008584 E->getMethodDecl(),
8585 E->getLeftLoc(),
8586 move_arg(Args),
8587 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008588}
8589
Mike Stump1eb44332009-09-09 15:08:12 +00008590template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008591ExprResult
John McCall454feb92009-12-08 09:21:05 +00008592TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008593 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008594}
8595
Mike Stump1eb44332009-09-09 15:08:12 +00008596template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008597ExprResult
John McCall454feb92009-12-08 09:21:05 +00008598TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008599 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008600}
8601
Mike Stump1eb44332009-09-09 15:08:12 +00008602template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008603ExprResult
John McCall454feb92009-12-08 09:21:05 +00008604TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008605 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008606 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008607 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008608 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008609
8610 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008611
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008612 // If nothing changed, just retain the existing expression.
8613 if (!getDerived().AlwaysRebuild() &&
8614 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008615 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008616
John McCall9ae2f072010-08-23 23:25:46 +00008617 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008618 E->getLocation(),
8619 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008620}
8621
Mike Stump1eb44332009-09-09 15:08:12 +00008622template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008623ExprResult
John McCall454feb92009-12-08 09:21:05 +00008624TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008625 // 'super' and types never change. Property never changes. Just
8626 // retain the existing expression.
8627 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008628 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008629
Douglas Gregore3303542010-04-26 20:47:02 +00008630 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008631 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008632 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008633 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008634
Douglas Gregore3303542010-04-26 20:47:02 +00008635 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008636
Douglas Gregore3303542010-04-26 20:47:02 +00008637 // If nothing changed, just retain the existing expression.
8638 if (!getDerived().AlwaysRebuild() &&
8639 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008640 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008641
John McCall12f78a62010-12-02 01:19:52 +00008642 if (E->isExplicitProperty())
8643 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8644 E->getExplicitProperty(),
8645 E->getLocation());
8646
8647 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008648 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008649 E->getImplicitPropertyGetter(),
8650 E->getImplicitPropertySetter(),
8651 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008652}
8653
Mike Stump1eb44332009-09-09 15:08:12 +00008654template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008655ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008656TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8657 // Transform the base expression.
8658 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8659 if (Base.isInvalid())
8660 return ExprError();
8661
8662 // Transform the key expression.
8663 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8664 if (Key.isInvalid())
8665 return ExprError();
8666
8667 // If nothing changed, just retain the existing expression.
8668 if (!getDerived().AlwaysRebuild() &&
8669 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8670 return SemaRef.Owned(E);
8671
8672 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
8673 Base.get(), Key.get(),
8674 E->getAtIndexMethodDecl(),
8675 E->setAtIndexMethodDecl());
8676}
8677
8678template<typename Derived>
8679ExprResult
John McCall454feb92009-12-08 09:21:05 +00008680TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008681 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008682 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008683 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008684 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008685
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008686 // If nothing changed, just retain the existing expression.
8687 if (!getDerived().AlwaysRebuild() &&
8688 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008689 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008690
John McCall9ae2f072010-08-23 23:25:46 +00008691 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008692 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008693}
8694
Mike Stump1eb44332009-09-09 15:08:12 +00008695template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008696ExprResult
John McCall454feb92009-12-08 09:21:05 +00008697TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008698 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008699 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008700 SubExprs.reserve(E->getNumSubExprs());
8701 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8702 SubExprs, &ArgumentChanged))
8703 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008704
Douglas Gregorb98b1992009-08-11 05:31:07 +00008705 if (!getDerived().AlwaysRebuild() &&
8706 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008707 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008708
Douglas Gregorb98b1992009-08-11 05:31:07 +00008709 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8710 move_arg(SubExprs),
8711 E->getRParenLoc());
8712}
8713
Mike Stump1eb44332009-09-09 15:08:12 +00008714template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008715ExprResult
John McCall454feb92009-12-08 09:21:05 +00008716TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008717 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008718
John McCallc6ac9c32011-02-04 18:33:18 +00008719 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8720 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8721
8722 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008723 blockScope->TheDecl->setBlockMissingReturnType(
8724 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008725
Chris Lattner686775d2011-07-20 06:58:45 +00008726 SmallVector<ParmVarDecl*, 4> params;
8727 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008728
8729 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008730 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8731 oldBlock->param_begin(),
8732 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008733 0, paramTypes, &params)) {
8734 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008735 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008736 }
John McCallc6ac9c32011-02-04 18:33:18 +00008737
8738 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008739 QualType exprResultType =
8740 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008741
8742 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008743 if (exprResultType->isObjCObjectType()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008744 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008745 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008746 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008747 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008748 return ExprError();
8749 }
John McCall711c52b2011-01-05 12:14:39 +00008750
John McCallc6ac9c32011-02-04 18:33:18 +00008751 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008752 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008753 paramTypes.data(),
8754 paramTypes.size(),
8755 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008756 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008757 exprFunctionType->getExtInfo());
8758 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008759
8760 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008761 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008762 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008763
8764 if (!oldBlock->blockMissingReturnType()) {
8765 blockScope->HasImplicitReturnType = false;
8766 blockScope->ReturnType = exprResultType;
8767 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008768
John McCall711c52b2011-01-05 12:14:39 +00008769 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008770 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008771 if (body.isInvalid()) {
8772 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008773 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008774 }
John McCall711c52b2011-01-05 12:14:39 +00008775
John McCallc6ac9c32011-02-04 18:33:18 +00008776#ifndef NDEBUG
8777 // In builds with assertions, make sure that we captured everything we
8778 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008779 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8780 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8781 e = oldBlock->capture_end(); i != e; ++i) {
8782 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008783
Douglas Gregorfc921372011-05-20 15:32:55 +00008784 // Ignore parameter packs.
8785 if (isa<ParmVarDecl>(oldCapture) &&
8786 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8787 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008788
Douglas Gregorfc921372011-05-20 15:32:55 +00008789 VarDecl *newCapture =
8790 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8791 oldCapture));
8792 assert(blockScope->CaptureMap.count(newCapture));
8793 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008794 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008795 }
8796#endif
8797
8798 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8799 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008800}
8801
Mike Stump1eb44332009-09-09 15:08:12 +00008802template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008803ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008804TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008805 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008806}
Eli Friedman276b0612011-10-11 02:20:01 +00008807
8808template<typename Derived>
8809ExprResult
8810TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008811 QualType RetTy = getDerived().TransformType(E->getType());
8812 bool ArgumentChanged = false;
8813 ASTOwningVector<Expr*> SubExprs(SemaRef);
8814 SubExprs.reserve(E->getNumSubExprs());
8815 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8816 SubExprs, &ArgumentChanged))
8817 return ExprError();
8818
8819 if (!getDerived().AlwaysRebuild() &&
8820 !ArgumentChanged)
8821 return SemaRef.Owned(E);
8822
8823 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8824 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008825}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008826
Douglas Gregorb98b1992009-08-11 05:31:07 +00008827//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008828// Type reconstruction
8829//===----------------------------------------------------------------------===//
8830
Mike Stump1eb44332009-09-09 15:08:12 +00008831template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008832QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8833 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008834 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008835 getDerived().getBaseEntity());
8836}
8837
Mike Stump1eb44332009-09-09 15:08:12 +00008838template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008839QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8840 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008841 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008842 getDerived().getBaseEntity());
8843}
8844
Mike Stump1eb44332009-09-09 15:08:12 +00008845template<typename Derived>
8846QualType
John McCall85737a72009-10-30 00:06:24 +00008847TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8848 bool WrittenAsLValue,
8849 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008850 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008851 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008852}
8853
8854template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008855QualType
John McCall85737a72009-10-30 00:06:24 +00008856TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8857 QualType ClassType,
8858 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008859 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008860 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008861}
8862
8863template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008864QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008865TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8866 ArrayType::ArraySizeModifier SizeMod,
8867 const llvm::APInt *Size,
8868 Expr *SizeExpr,
8869 unsigned IndexTypeQuals,
8870 SourceRange BracketsRange) {
8871 if (SizeExpr || !Size)
8872 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8873 IndexTypeQuals, BracketsRange,
8874 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008875
8876 QualType Types[] = {
8877 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8878 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8879 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008880 };
8881 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8882 QualType SizeType;
8883 for (unsigned I = 0; I != NumTypes; ++I)
8884 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8885 SizeType = Types[I];
8886 break;
8887 }
Mike Stump1eb44332009-09-09 15:08:12 +00008888
Eli Friedman01f276d2012-01-25 23:20:27 +00008889 // Note that we can return a VariableArrayType here in the case where
8890 // the element type was a dependent VariableArrayType.
8891 IntegerLiteral *ArraySize
8892 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8893 /*FIXME*/BracketsRange.getBegin());
8894 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008895 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008896 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008897}
Mike Stump1eb44332009-09-09 15:08:12 +00008898
Douglas Gregor577f75a2009-08-04 16:50:30 +00008899template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008900QualType
8901TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008902 ArrayType::ArraySizeModifier SizeMod,
8903 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008904 unsigned IndexTypeQuals,
8905 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008906 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008907 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008908}
8909
8910template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008911QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008912TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008913 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008914 unsigned IndexTypeQuals,
8915 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008916 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008917 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008918}
Mike Stump1eb44332009-09-09 15:08:12 +00008919
Douglas Gregor577f75a2009-08-04 16:50:30 +00008920template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008921QualType
8922TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008923 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008924 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008925 unsigned IndexTypeQuals,
8926 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008927 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008928 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008929 IndexTypeQuals, BracketsRange);
8930}
8931
8932template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008933QualType
8934TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008935 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008936 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008937 unsigned IndexTypeQuals,
8938 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008939 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008940 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008941 IndexTypeQuals, BracketsRange);
8942}
8943
8944template<typename Derived>
8945QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008946 unsigned NumElements,
8947 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008948 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008949 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008950}
Mike Stump1eb44332009-09-09 15:08:12 +00008951
Douglas Gregor577f75a2009-08-04 16:50:30 +00008952template<typename Derived>
8953QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8954 unsigned NumElements,
8955 SourceLocation AttributeLoc) {
8956 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8957 NumElements, true);
8958 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008959 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8960 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008961 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008962}
Mike Stump1eb44332009-09-09 15:08:12 +00008963
Douglas Gregor577f75a2009-08-04 16:50:30 +00008964template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008965QualType
8966TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008967 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008968 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008969 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008970}
Mike Stump1eb44332009-09-09 15:08:12 +00008971
Douglas Gregor577f75a2009-08-04 16:50:30 +00008972template<typename Derived>
8973QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008974 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008975 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008976 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008977 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00008978 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008979 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008980 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008981 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008982 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008983 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008984 getDerived().getBaseEntity(),
8985 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008986}
Mike Stump1eb44332009-09-09 15:08:12 +00008987
Douglas Gregor577f75a2009-08-04 16:50:30 +00008988template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008989QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8990 return SemaRef.Context.getFunctionNoProtoType(T);
8991}
8992
8993template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008994QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8995 assert(D && "no decl found");
8996 if (D->isInvalidDecl()) return QualType();
8997
Douglas Gregor92e986e2010-04-22 16:44:27 +00008998 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008999 TypeDecl *Ty;
9000 if (isa<UsingDecl>(D)) {
9001 UsingDecl *Using = cast<UsingDecl>(D);
9002 assert(Using->isTypeName() &&
9003 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9004
9005 // A valid resolved using typename decl points to exactly one type decl.
9006 assert(++Using->shadow_begin() == Using->shadow_end());
9007 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00009008
John McCalled976492009-12-04 22:46:56 +00009009 } else {
9010 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9011 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9012 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9013 }
9014
9015 return SemaRef.Context.getTypeDeclType(Ty);
9016}
9017
9018template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009019QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9020 SourceLocation Loc) {
9021 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009022}
9023
9024template<typename Derived>
9025QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9026 return SemaRef.Context.getTypeOfType(Underlying);
9027}
9028
9029template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009030QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9031 SourceLocation Loc) {
9032 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009033}
9034
9035template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009036QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9037 UnaryTransformType::UTTKind UKind,
9038 SourceLocation Loc) {
9039 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9040}
9041
9042template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009043QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009044 TemplateName Template,
9045 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009046 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009047 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009048}
Mike Stump1eb44332009-09-09 15:08:12 +00009049
Douglas Gregordcee1a12009-08-06 05:28:30 +00009050template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009051QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9052 SourceLocation KWLoc) {
9053 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9054}
9055
9056template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009057TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009058TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009059 bool TemplateKW,
9060 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009061 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009062 Template);
9063}
9064
9065template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009066TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009067TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9068 const IdentifierInfo &Name,
9069 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009070 QualType ObjectType,
9071 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009072 UnqualifiedId TemplateName;
9073 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009074 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009075 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009076 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009077 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009078 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009079 /*EnteringContext=*/false,
9080 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009081 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009082}
Mike Stump1eb44332009-09-09 15:08:12 +00009083
Douglas Gregorb98b1992009-08-11 05:31:07 +00009084template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009085TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009086TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009087 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009088 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009089 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009090 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009091 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009092 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009093 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009094 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009095 Sema::TemplateTy Template;
9096 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009097 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009098 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009099 /*EnteringContext=*/false,
9100 Template);
9101 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009102}
Sean Huntc3021132010-05-05 15:23:54 +00009103
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009104template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009105ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009106TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9107 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009108 Expr *OrigCallee,
9109 Expr *First,
9110 Expr *Second) {
9111 Expr *Callee = OrigCallee->IgnoreParenCasts();
9112 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009113
Douglas Gregorb98b1992009-08-11 05:31:07 +00009114 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009115 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009116 if (!First->getType()->isOverloadableType() &&
9117 !Second->getType()->isOverloadableType())
9118 return getSema().CreateBuiltinArraySubscriptExpr(First,
9119 Callee->getLocStart(),
9120 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009121 } else if (Op == OO_Arrow) {
9122 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009123 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9124 } else if (Second == 0 || isPostIncDec) {
9125 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009126 // The argument is not of overloadable type, so try to create a
9127 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009128 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009129 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009130
John McCall9ae2f072010-08-23 23:25:46 +00009131 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009132 }
9133 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009134 if (!First->getType()->isOverloadableType() &&
9135 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009136 // Neither of the arguments is an overloadable type, so try to
9137 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009138 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009139 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009140 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009141 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009142 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009143
Douglas Gregorb98b1992009-08-11 05:31:07 +00009144 return move(Result);
9145 }
9146 }
Mike Stump1eb44332009-09-09 15:08:12 +00009147
9148 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009149 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009150 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009151
John McCall9ae2f072010-08-23 23:25:46 +00009152 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009153 assert(ULE->requiresADL());
9154
9155 // FIXME: Do we have to check
9156 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009157 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009158 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009159 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009160 }
Mike Stump1eb44332009-09-09 15:08:12 +00009161
Douglas Gregorb98b1992009-08-11 05:31:07 +00009162 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009163 Expr *Args[2] = { First, Second };
9164 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009165
Douglas Gregorb98b1992009-08-11 05:31:07 +00009166 // Create the overloaded operator invocation for unary operators.
9167 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009168 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009169 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009170 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009171 }
Mike Stump1eb44332009-09-09 15:08:12 +00009172
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009173 if (Op == OO_Subscript) {
9174 SourceLocation LBrace;
9175 SourceLocation RBrace;
9176
9177 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9178 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9179 LBrace = SourceLocation::getFromRawEncoding(
9180 NameLoc.CXXOperatorName.BeginOpNameLoc);
9181 RBrace = SourceLocation::getFromRawEncoding(
9182 NameLoc.CXXOperatorName.EndOpNameLoc);
9183 } else {
9184 LBrace = Callee->getLocStart();
9185 RBrace = OpLoc;
9186 }
9187
9188 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9189 First, Second);
9190 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009191
Douglas Gregorb98b1992009-08-11 05:31:07 +00009192 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009193 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009194 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009195 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9196 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009197 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009198
Mike Stump1eb44332009-09-09 15:08:12 +00009199 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009200}
Mike Stump1eb44332009-09-09 15:08:12 +00009201
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009202template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009203ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009204TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009205 SourceLocation OperatorLoc,
9206 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009207 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009208 TypeSourceInfo *ScopeType,
9209 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009210 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009211 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009212 QualType BaseType = Base->getType();
9213 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009214 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00009215 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009216 !BaseType->getAs<PointerType>()->getPointeeType()
9217 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009218 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009219 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009220 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009221 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009222 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009223 /*FIXME?*/true);
9224 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009225
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009226 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009227 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9228 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9229 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9230 NameInfo.setNamedTypeInfo(DestroyedType);
9231
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009232 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00009233
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009234 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009235 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009236 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009237 SS, TemplateKWLoc,
9238 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009239 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009240 /*TemplateArgs*/ 0);
9241}
9242
Douglas Gregor577f75a2009-08-04 16:50:30 +00009243} // end namespace clang
9244
9245#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H