blob: 0a0f5c7c3284e194f07f4af76f0b940b2267e8fe [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall2d887082010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000036#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCall781472f2010-08-25 08:40:02 +000040using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000041
Douglas Gregor577f75a2009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump1eb44332009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump1eb44332009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
101
102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
106
107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000114
Douglas Gregordfca6f52012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
119
Mike Stump1eb44332009-09-09 15:08:12 +0000120public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000123
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 }
131
John McCall60d7b3a2010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000134
Douglas Gregor577f75a2009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000138
Douglas Gregor577f75a2009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
144 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Douglas Gregor577f75a2009-08-04 16:50:30 +0000146 /// \brief Returns the location of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
148 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000149 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000150 /// provide an alternative implementation that provides better location
151 /// information.
152 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000153
Douglas Gregor577f75a2009-08-04 16:50:30 +0000154 /// \brief Returns the name of the entity being transformed, if that
155 /// information was not available elsewhere in the AST.
156 ///
157 /// By default, returns an empty name. Subclasses can provide an alternative
158 /// implementation with a more precise name.
159 DeclarationName getBaseEntity() { return DeclarationName(); }
160
Douglas Gregorb98b1992009-08-11 05:31:07 +0000161 /// \brief Sets the "base" location and entity when that
162 /// information is known based on another transformation.
163 ///
164 /// By default, the source location and entity are ignored. Subclasses can
165 /// override this function to provide a customized implementation.
166 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000167
Douglas Gregorb98b1992009-08-11 05:31:07 +0000168 /// \brief RAII object that temporarily sets the base location and entity
169 /// used for reporting diagnostics in types.
170 class TemporaryBase {
171 TreeTransform &Self;
172 SourceLocation OldLocation;
173 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000174
Douglas Gregorb98b1992009-08-11 05:31:07 +0000175 public:
176 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000177 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 OldLocation = Self.getDerived().getBaseLocation();
179 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregorae201f72011-01-25 17:51:48 +0000180
181 if (Location.isValid())
182 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000183 }
Mike Stump1eb44332009-09-09 15:08:12 +0000184
Douglas Gregorb98b1992009-08-11 05:31:07 +0000185 ~TemporaryBase() {
186 Self.getDerived().setBase(OldLocation, OldEntity);
187 }
188 };
Mike Stump1eb44332009-09-09 15:08:12 +0000189
190 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000191 /// transformed.
192 ///
193 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000194 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000195 /// not change. For example, template instantiation need not traverse
196 /// non-dependent types.
197 bool AlreadyTransformed(QualType T) {
198 return T.isNull();
199 }
200
Douglas Gregor6eef5192009-12-14 19:27:10 +0000201 /// \brief Determine whether the given call argument should be dropped, e.g.,
202 /// because it is a default argument.
203 ///
204 /// Subclasses can provide an alternative implementation of this routine to
205 /// determine which kinds of call arguments get dropped. By default,
206 /// CXXDefaultArgument nodes are dropped (prior to transformation).
207 bool DropCallArgument(Expr *E) {
208 return E->isDefaultArgument();
209 }
Sean Huntc3021132010-05-05 15:23:54 +0000210
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000211 /// \brief Determine whether we should expand a pack expansion with the
212 /// given set of parameter packs into separate arguments by repeatedly
213 /// transforming the pattern.
214 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000215 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000216 /// Subclasses can override this routine to provide different behavior.
217 ///
218 /// \param EllipsisLoc The location of the ellipsis that identifies the
219 /// pack expansion.
220 ///
221 /// \param PatternRange The source range that covers the entire pattern of
222 /// the pack expansion.
223 ///
224 /// \param Unexpanded The set of unexpanded parameter packs within the
225 /// pattern.
226 ///
227 /// \param NumUnexpanded The number of unexpanded parameter packs in
228 /// \p Unexpanded.
229 ///
230 /// \param ShouldExpand Will be set to \c true if the transformer should
231 /// expand the corresponding pack expansions into separate arguments. When
232 /// set, \c NumExpansions must also be set.
233 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000234 /// \param RetainExpansion Whether the caller should add an unexpanded
235 /// pack expansion after all of the expanded arguments. This is used
236 /// when extending explicitly-specified template argument packs per
237 /// C++0x [temp.arg.explicit]p9.
238 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000239 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000240 /// the expanded form of the corresponding pack expansion. This is both an
241 /// input and an output parameter, which can be set by the caller if the
242 /// number of expansions is known a priori (e.g., due to a prior substitution)
243 /// and will be set by the callee when the number of expansions is known.
244 /// The callee must set this value when \c ShouldExpand is \c true; it may
245 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000246 ///
247 /// \returns true if an error occurred (e.g., because the parameter packs
248 /// are to be instantiated with arguments of different lengths), false
249 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
250 /// must be set.
251 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
252 SourceRange PatternRange,
David Blaikiea71f9d02011-09-22 02:34:54 +0000253 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000254 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000255 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000256 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000257 ShouldExpand = false;
258 return false;
259 }
260
Douglas Gregord3731192011-01-10 07:32:04 +0000261 /// \brief "Forget" about the partially-substituted pack template argument,
262 /// when performing an instantiation that must preserve the parameter pack
263 /// use.
264 ///
265 /// This routine is meant to be overridden by the template instantiator.
266 TemplateArgument ForgetPartiallySubstitutedPack() {
267 return TemplateArgument();
268 }
269
270 /// \brief "Remember" the partially-substituted pack template argument
271 /// after performing an instantiation that must preserve the parameter pack
272 /// use.
273 ///
274 /// This routine is meant to be overridden by the template instantiator.
275 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
276
Douglas Gregor12c9c002011-01-07 16:43:16 +0000277 /// \brief Note to the derived class when a function parameter pack is
278 /// being expanded.
279 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
280
Douglas Gregor577f75a2009-08-04 16:50:30 +0000281 /// \brief Transforms the given type into another type.
282 ///
John McCalla2becad2009-10-21 00:40:46 +0000283 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000284 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000285 /// function. This is expensive, but we don't mind, because
286 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000287 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000288 ///
289 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000290 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000291
John McCalla2becad2009-10-21 00:40:46 +0000292 /// \brief Transforms the given type-with-location into a new
293 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000294 ///
John McCalla2becad2009-10-21 00:40:46 +0000295 /// By default, this routine transforms a type by delegating to the
296 /// appropriate TransformXXXType to build a new type. Subclasses
297 /// may override this function (to take over all type
298 /// transformations) or some set of the TransformXXXType functions
299 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000300 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000301
302 /// \brief Transform the given type-with-location into a new
303 /// type, collecting location information in the given builder
304 /// as necessary.
305 ///
John McCall43fed0d2010-11-12 08:19:04 +0000306 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000307
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000308 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000309 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000310 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000311 /// appropriate TransformXXXStmt function to transform a specific kind of
312 /// statement or the TransformExpr() function to transform an expression.
313 /// Subclasses may override this function to transform statements using some
314 /// other mechanism.
315 ///
316 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000317 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000318
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000319 /// \brief Transform the given expression.
320 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000321 /// By default, this routine transforms an expression by delegating to the
322 /// appropriate TransformXXXExpr function to build a new expression.
323 /// Subclasses may override this function to transform expressions using some
324 /// other mechanism.
325 ///
326 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000327 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000328
Douglas Gregoraa165f82011-01-03 19:04:46 +0000329 /// \brief Transform the given list of expressions.
330 ///
331 /// This routine transforms a list of expressions by invoking
332 /// \c TransformExpr() for each subexpression. However, it also provides
333 /// support for variadic templates by expanding any pack expansions (if the
334 /// derived class permits such expansion) along the way. When pack expansions
335 /// are present, the number of outputs may not equal the number of inputs.
336 ///
337 /// \param Inputs The set of expressions to be transformed.
338 ///
339 /// \param NumInputs The number of expressions in \c Inputs.
340 ///
341 /// \param IsCall If \c true, then this transform is being performed on
342 /// function-call arguments, and any arguments that should be dropped, will
343 /// be.
344 ///
345 /// \param Outputs The transformed input expressions will be added to this
346 /// vector.
347 ///
348 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
349 /// due to transformation.
350 ///
351 /// \returns true if an error occurred, false otherwise.
352 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000353 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000354 bool *ArgChanged = 0);
355
Douglas Gregor577f75a2009-08-04 16:50:30 +0000356 /// \brief Transform the given declaration, which is referenced from a type
357 /// or expression.
358 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000359 /// By default, acts as the identity function on declarations, unless the
360 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000361 /// may override this function to provide alternate behavior.
Douglas Gregordfca6f52012-02-13 22:00:16 +0000362 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
363 llvm::DenseMap<Decl *, Decl *>::iterator Known
364 = TransformedLocalDecls.find(D);
365 if (Known != TransformedLocalDecls.end())
366 return Known->second;
367
368 return D;
369 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000370
Douglas Gregordfca6f52012-02-13 22:00:16 +0000371 /// \brief Transform the attributes associated with the given declaration and
372 /// place them on the new declaration.
373 ///
374 /// By default, this operation does nothing. Subclasses may override this
375 /// behavior to transform attributes.
376 void transformAttrs(Decl *Old, Decl *New) { }
377
378 /// \brief Note that a local declaration has been transformed by this
379 /// transformer.
380 ///
381 /// Local declarations are typically transformed via a call to
382 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
383 /// the transformer itself has to transform the declarations. This routine
384 /// can be overridden by a subclass that keeps track of such mappings.
385 void transformedLocalDecl(Decl *Old, Decl *New) {
386 TransformedLocalDecls[Old] = New;
387 }
388
Douglas Gregor43959a92009-08-20 07:17:43 +0000389 /// \brief Transform the definition of the given declaration.
390 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000391 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000392 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000393 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
394 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000395 }
Mike Stump1eb44332009-09-09 15:08:12 +0000396
Douglas Gregor6cd21982009-10-20 05:58:46 +0000397 /// \brief Transform the given declaration, which was the first part of a
398 /// nested-name-specifier in a member access expression.
399 ///
Sean Huntc3021132010-05-05 15:23:54 +0000400 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000401 /// identifier in a nested-name-specifier of a member access expression, e.g.,
402 /// the \c T in \c x->T::member
403 ///
404 /// By default, invokes TransformDecl() to transform the declaration.
405 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000406 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
407 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000408 }
Sean Huntc3021132010-05-05 15:23:54 +0000409
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000410 /// \brief Transform the given nested-name-specifier with source-location
411 /// information.
412 ///
413 /// By default, transforms all of the types and declarations within the
414 /// nested-name-specifier. Subclasses may override this function to provide
415 /// alternate behavior.
416 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
417 NestedNameSpecifierLoc NNS,
418 QualType ObjectType = QualType(),
419 NamedDecl *FirstQualifierInScope = 0);
420
Douglas Gregor81499bb2009-09-03 22:13:48 +0000421 /// \brief Transform the given declaration name.
422 ///
423 /// By default, transforms the types of conversion function, constructor,
424 /// and destructor names and then (if needed) rebuilds the declaration name.
425 /// Identifiers and selectors are returned unmodified. Sublcasses may
426 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000427 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000428 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000429
Douglas Gregor577f75a2009-08-04 16:50:30 +0000430 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000431 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000432 /// \param SS The nested-name-specifier that qualifies the template
433 /// name. This nested-name-specifier must already have been transformed.
434 ///
435 /// \param Name The template name to transform.
436 ///
437 /// \param NameLoc The source location of the template name.
438 ///
439 /// \param ObjectType If we're translating a template name within a member
440 /// access expression, this is the type of the object whose member template
441 /// is being referenced.
442 ///
443 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
444 /// also refers to a name within the current (lexical) scope, this is the
445 /// declaration it refers to.
446 ///
447 /// By default, transforms the template name by transforming the declarations
448 /// and nested-name-specifiers that occur within the template name.
449 /// Subclasses may override this function to provide alternate behavior.
450 TemplateName TransformTemplateName(CXXScopeSpec &SS,
451 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000452 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000453 QualType ObjectType = QualType(),
454 NamedDecl *FirstQualifierInScope = 0);
455
Douglas Gregor577f75a2009-08-04 16:50:30 +0000456 /// \brief Transform the given template argument.
457 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000458 /// By default, this operation transforms the type, expression, or
459 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000460 /// new template argument from the transformed result. Subclasses may
461 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000462 ///
463 /// Returns true if there was an error.
464 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
465 TemplateArgumentLoc &Output);
466
Douglas Gregorfcc12532010-12-20 17:31:10 +0000467 /// \brief Transform the given set of template arguments.
468 ///
469 /// By default, this operation transforms all of the template arguments
470 /// in the input set using \c TransformTemplateArgument(), and appends
471 /// the transformed arguments to the output list.
472 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000473 /// Note that this overload of \c TransformTemplateArguments() is merely
474 /// a convenience function. Subclasses that wish to override this behavior
475 /// should override the iterator-based member template version.
476 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000477 /// \param Inputs The set of template arguments to be transformed.
478 ///
479 /// \param NumInputs The number of template arguments in \p Inputs.
480 ///
481 /// \param Outputs The set of transformed template arguments output by this
482 /// routine.
483 ///
484 /// Returns true if an error occurred.
485 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
486 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000487 TemplateArgumentListInfo &Outputs) {
488 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
489 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000490
491 /// \brief Transform the given set of template arguments.
492 ///
493 /// By default, this operation transforms all of the template arguments
494 /// in the input set using \c TransformTemplateArgument(), and appends
495 /// the transformed arguments to the output list.
496 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000497 /// \param First An iterator to the first template argument.
498 ///
499 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000500 ///
501 /// \param Outputs The set of transformed template arguments output by this
502 /// routine.
503 ///
504 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000505 template<typename InputIterator>
506 bool TransformTemplateArguments(InputIterator First,
507 InputIterator Last,
508 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000509
John McCall833ca992009-10-29 08:12:44 +0000510 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
511 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
512 TemplateArgumentLoc &ArgLoc);
513
John McCalla93c9342009-12-07 02:54:59 +0000514 /// \brief Fakes up a TypeSourceInfo for a type.
515 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
516 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000517 getDerived().getBaseLocation());
518 }
Mike Stump1eb44332009-09-09 15:08:12 +0000519
John McCalla2becad2009-10-21 00:40:46 +0000520#define ABSTRACT_TYPELOC(CLASS, PARENT)
521#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000522 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000523#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000524
John Wiegley28bbe4b2011-04-28 01:08:34 +0000525 StmtResult
526 TransformSEHHandler(Stmt *Handler);
527
John McCall43fed0d2010-11-12 08:19:04 +0000528 QualType
529 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
530 TemplateSpecializationTypeLoc TL,
531 TemplateName Template);
532
533 QualType
534 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
535 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000536 TemplateName Template,
537 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000538
539 QualType
540 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000541 DependentTemplateSpecializationTypeLoc TL,
542 NestedNameSpecifierLoc QualifierLoc);
543
John McCall21ef0fa2010-03-11 09:03:00 +0000544 /// \brief Transforms the parameters of a function type into the
545 /// given vectors.
546 ///
547 /// The result vectors should be kept in sync; null entries in the
548 /// variables vector are acceptable.
549 ///
550 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000551 bool TransformFunctionTypeParams(SourceLocation Loc,
552 ParmVarDecl **Params, unsigned NumParams,
553 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000554 SmallVectorImpl<QualType> &PTypes,
555 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000556
557 /// \brief Transforms a single function-type parameter. Return null
558 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000559 ///
560 /// \param indexAdjustment - A number to add to the parameter's
561 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000562 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000563 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000564 llvm::Optional<unsigned> NumExpansions,
565 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000566
John McCall43fed0d2010-11-12 08:19:04 +0000567 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000568
John McCall60d7b3a2010-08-24 06:29:42 +0000569 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
570 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000571
Douglas Gregor43959a92009-08-20 07:17:43 +0000572#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000573 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000574#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000575 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000576#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000577#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000578
Douglas Gregor577f75a2009-08-04 16:50:30 +0000579 /// \brief Build a new pointer type given its pointee type.
580 ///
581 /// By default, performs semantic analysis when building the pointer type.
582 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000583 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000584
585 /// \brief Build a new block pointer type given its pointee type.
586 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000587 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000588 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000589 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000590
John McCall85737a72009-10-30 00:06:24 +0000591 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000592 ///
John McCall85737a72009-10-30 00:06:24 +0000593 /// By default, performs semantic analysis when building the
594 /// reference type. Subclasses may override this routine to provide
595 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000596 ///
John McCall85737a72009-10-30 00:06:24 +0000597 /// \param LValue whether the type was written with an lvalue sigil
598 /// or an rvalue sigil.
599 QualType RebuildReferenceType(QualType ReferentType,
600 bool LValue,
601 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000602
Douglas Gregor577f75a2009-08-04 16:50:30 +0000603 /// \brief Build a new member pointer type given the pointee type and the
604 /// class type it refers into.
605 ///
606 /// By default, performs semantic analysis when building the member pointer
607 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000608 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
609 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000610
Douglas Gregor577f75a2009-08-04 16:50:30 +0000611 /// \brief Build a new array type given the element type, size
612 /// modifier, size of the array (if known), size expression, and index type
613 /// qualifiers.
614 ///
615 /// By default, performs semantic analysis when building the array type.
616 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000617 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000618 QualType RebuildArrayType(QualType ElementType,
619 ArrayType::ArraySizeModifier SizeMod,
620 const llvm::APInt *Size,
621 Expr *SizeExpr,
622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000624
Douglas Gregor577f75a2009-08-04 16:50:30 +0000625 /// \brief Build a new constant array type given the element type, size
626 /// modifier, (known) size of the array, and index type qualifiers.
627 ///
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000630 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
632 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000635
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 /// \brief Build a new incomplete array type given the element type, size
637 /// modifier, and index type qualifiers.
638 ///
639 /// By default, performs semantic analysis when building the array type.
640 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000641 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000642 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000643 unsigned IndexTypeQuals,
644 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000645
Mike Stump1eb44332009-09-09 15:08:12 +0000646 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000647 /// size modifier, size expression, and index type qualifiers.
648 ///
649 /// By default, performs semantic analysis when building the array type.
650 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000651 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000652 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000653 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 unsigned IndexTypeQuals,
655 SourceRange BracketsRange);
656
Mike Stump1eb44332009-09-09 15:08:12 +0000657 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000658 /// size modifier, size expression, and index type qualifiers.
659 ///
660 /// By default, performs semantic analysis when building the array type.
661 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000662 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000664 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000665 unsigned IndexTypeQuals,
666 SourceRange BracketsRange);
667
668 /// \brief Build a new vector type given the element type and
669 /// number of elements.
670 ///
671 /// By default, performs semantic analysis when building the vector type.
672 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000673 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000674 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000675
Douglas Gregor577f75a2009-08-04 16:50:30 +0000676 /// \brief Build a new extended vector type given the element type and
677 /// number of elements.
678 ///
679 /// By default, performs semantic analysis when building the vector type.
680 /// Subclasses may override this routine to provide different behavior.
681 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
682 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000683
684 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000685 /// given the element type and number of elements.
686 ///
687 /// By default, performs semantic analysis when building the vector type.
688 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000689 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000690 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000691 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000692
Douglas Gregor577f75a2009-08-04 16:50:30 +0000693 /// \brief Build a new function type.
694 ///
695 /// By default, performs semantic analysis when building the function type.
696 /// Subclasses may override this routine to provide different behavior.
697 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000698 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000699 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000700 bool Variadic, bool HasTrailingReturn,
701 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000702 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000703 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000704
John McCalla2becad2009-10-21 00:40:46 +0000705 /// \brief Build a new unprototyped function type.
706 QualType RebuildFunctionNoProtoType(QualType ResultType);
707
John McCalled976492009-12-04 22:46:56 +0000708 /// \brief Rebuild an unresolved typename type, given the decl that
709 /// the UnresolvedUsingTypenameDecl was transformed to.
710 QualType RebuildUnresolvedUsingType(Decl *D);
711
Douglas Gregor577f75a2009-08-04 16:50:30 +0000712 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000713 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000714 return SemaRef.Context.getTypeDeclType(Typedef);
715 }
716
717 /// \brief Build a new class/struct/union type.
718 QualType RebuildRecordType(RecordDecl *Record) {
719 return SemaRef.Context.getTypeDeclType(Record);
720 }
721
722 /// \brief Build a new Enum type.
723 QualType RebuildEnumType(EnumDecl *Enum) {
724 return SemaRef.Context.getTypeDeclType(Enum);
725 }
John McCall7da24312009-09-05 00:15:47 +0000726
Mike Stump1eb44332009-09-09 15:08:12 +0000727 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000728 ///
729 /// By default, performs semantic analysis when building the typeof type.
730 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000731 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000732
Mike Stump1eb44332009-09-09 15:08:12 +0000733 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000734 ///
735 /// By default, builds a new TypeOfType with the given underlying type.
736 QualType RebuildTypeOfType(QualType Underlying);
737
Sean Huntca63c202011-05-24 22:41:36 +0000738 /// \brief Build a new unary transform type.
739 QualType RebuildUnaryTransformType(QualType BaseType,
740 UnaryTransformType::UTTKind UKind,
741 SourceLocation Loc);
742
Mike Stump1eb44332009-09-09 15:08:12 +0000743 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000744 ///
745 /// By default, performs semantic analysis when building the decltype type.
746 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000747 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000748
Richard Smith34b41d92011-02-20 03:19:35 +0000749 /// \brief Build a new C++0x auto type.
750 ///
751 /// By default, builds a new AutoType with the given deduced type.
752 QualType RebuildAutoType(QualType Deduced) {
753 return SemaRef.Context.getAutoType(Deduced);
754 }
755
Douglas Gregor577f75a2009-08-04 16:50:30 +0000756 /// \brief Build a new template specialization type.
757 ///
758 /// By default, performs semantic analysis when building the template
759 /// specialization type. Subclasses may override this routine to provide
760 /// different behavior.
761 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000762 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000763 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000764
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000765 /// \brief Build a new parenthesized type.
766 ///
767 /// By default, builds a new ParenType type from the inner type.
768 /// Subclasses may override this routine to provide different behavior.
769 QualType RebuildParenType(QualType InnerType) {
770 return SemaRef.Context.getParenType(InnerType);
771 }
772
Douglas Gregor577f75a2009-08-04 16:50:30 +0000773 /// \brief Build a new qualified name type.
774 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000775 /// By default, builds a new ElaboratedType type from the keyword,
776 /// the nested-name-specifier and the named type.
777 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000778 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
779 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000780 NestedNameSpecifierLoc QualifierLoc,
781 QualType Named) {
782 return SemaRef.Context.getElaboratedType(Keyword,
783 QualifierLoc.getNestedNameSpecifier(),
784 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000785 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000786
787 /// \brief Build a new typename type that refers to a template-id.
788 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000789 /// By default, builds a new DependentNameType type from the
790 /// nested-name-specifier and the given type. Subclasses may override
791 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000792 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000793 ElaboratedTypeKeyword Keyword,
794 NestedNameSpecifierLoc QualifierLoc,
795 const IdentifierInfo *Name,
796 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000797 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000798 // Rebuild the template name.
799 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000800 CXXScopeSpec SS;
801 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000802 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000803 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000804
805 if (InstName.isNull())
806 return QualType();
807
808 // If it's still dependent, make a dependent specialization.
809 if (InstName.getAsDependentTemplateName())
810 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
811 QualifierLoc.getNestedNameSpecifier(),
812 Name,
813 Args);
814
815 // Otherwise, make an elaborated type wrapping a non-dependent
816 // specialization.
817 QualType T =
818 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
819 if (T.isNull()) return QualType();
820
821 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
822 return T;
823
824 return SemaRef.Context.getElaboratedType(Keyword,
825 QualifierLoc.getNestedNameSpecifier(),
826 T);
827 }
828
Douglas Gregor577f75a2009-08-04 16:50:30 +0000829 /// \brief Build a new typename type that refers to an identifier.
830 ///
831 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000832 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000833 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000834 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000835 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000836 NestedNameSpecifierLoc QualifierLoc,
837 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000838 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000839 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000840 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000841
Douglas Gregor2494dd02011-03-01 01:34:45 +0000842 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000843 // If the name is still dependent, just build a new dependent name type.
844 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000845 return SemaRef.Context.getDependentNameType(Keyword,
846 QualifierLoc.getNestedNameSpecifier(),
847 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000848 }
849
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000850 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000851 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000852 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000853
854 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
855
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000856 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000857 // into a non-dependent elaborated-type-specifier. Find the tag we're
858 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000859 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000860 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
861 if (!DC)
862 return QualType();
863
John McCall56138762010-05-27 06:40:31 +0000864 if (SemaRef.RequireCompleteDeclContext(SS, DC))
865 return QualType();
866
Douglas Gregor40336422010-03-31 22:19:08 +0000867 TagDecl *Tag = 0;
868 SemaRef.LookupQualifiedName(Result, DC);
869 switch (Result.getResultKind()) {
870 case LookupResult::NotFound:
871 case LookupResult::NotFoundInCurrentInstantiation:
872 break;
Sean Huntc3021132010-05-05 15:23:54 +0000873
Douglas Gregor40336422010-03-31 22:19:08 +0000874 case LookupResult::Found:
875 Tag = Result.getAsSingle<TagDecl>();
876 break;
Sean Huntc3021132010-05-05 15:23:54 +0000877
Douglas Gregor40336422010-03-31 22:19:08 +0000878 case LookupResult::FoundOverloaded:
879 case LookupResult::FoundUnresolvedValue:
880 llvm_unreachable("Tag lookup cannot find non-tags");
Sean Huntc3021132010-05-05 15:23:54 +0000881
Douglas Gregor40336422010-03-31 22:19:08 +0000882 case LookupResult::Ambiguous:
883 // Let the LookupResult structure handle ambiguities.
884 return QualType();
885 }
886
887 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000888 // Check where the name exists but isn't a tag type and use that to emit
889 // better diagnostics.
890 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
891 SemaRef.LookupQualifiedName(Result, DC);
892 switch (Result.getResultKind()) {
893 case LookupResult::Found:
894 case LookupResult::FoundOverloaded:
895 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000896 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000897 unsigned Kind = 0;
898 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000899 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
900 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000901 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
902 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
903 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000904 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000905 default:
906 // FIXME: Would be nice to highlight just the source range.
907 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
908 << Kind << Id << DC;
909 break;
910 }
Douglas Gregor40336422010-03-31 22:19:08 +0000911 return QualType();
912 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000913
Richard Trieubbf34c02011-06-10 03:11:26 +0000914 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
915 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000916 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000917 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
918 return QualType();
919 }
920
921 // Build the elaborated-type-specifier type.
922 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000923 return SemaRef.Context.getElaboratedType(Keyword,
924 QualifierLoc.getNestedNameSpecifier(),
925 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000926 }
Mike Stump1eb44332009-09-09 15:08:12 +0000927
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000928 /// \brief Build a new pack expansion type.
929 ///
930 /// By default, builds a new PackExpansionType type from the given pattern.
931 /// Subclasses may override this routine to provide different behavior.
932 QualType RebuildPackExpansionType(QualType Pattern,
933 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000934 SourceLocation EllipsisLoc,
935 llvm::Optional<unsigned> NumExpansions) {
936 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
937 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000938 }
939
Eli Friedmanb001de72011-10-06 23:00:33 +0000940 /// \brief Build a new atomic type given its value type.
941 ///
942 /// By default, performs semantic analysis when building the atomic type.
943 /// Subclasses may override this routine to provide different behavior.
944 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
945
Douglas Gregord1067e52009-08-06 06:41:21 +0000946 /// \brief Build a new template name given a nested name specifier, a flag
947 /// indicating whether the "template" keyword was provided, and the template
948 /// that the template name refers to.
949 ///
950 /// By default, builds the new template name directly. Subclasses may override
951 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000952 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000953 bool TemplateKW,
954 TemplateDecl *Template);
955
Douglas Gregord1067e52009-08-06 06:41:21 +0000956 /// \brief Build a new template name given a nested name specifier and the
957 /// name that is referred to as a template.
958 ///
959 /// By default, performs semantic analysis to determine whether the name can
960 /// be resolved to a specific template, then builds the appropriate kind of
961 /// template name. Subclasses may override this routine to provide different
962 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000963 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
964 const IdentifierInfo &Name,
965 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000966 QualType ObjectType,
967 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000968
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000969 /// \brief Build a new template name given a nested name specifier and the
970 /// overloaded operator name that is referred to as a template.
971 ///
972 /// By default, performs semantic analysis to determine whether the name can
973 /// be resolved to a specific template, then builds the appropriate kind of
974 /// template name. Subclasses may override this routine to provide different
975 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000976 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000977 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000978 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000979 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000980
981 /// \brief Build a new template name given a template template parameter pack
982 /// and the
983 ///
984 /// By default, performs semantic analysis to determine whether the name can
985 /// be resolved to a specific template, then builds the appropriate kind of
986 /// template name. Subclasses may override this routine to provide different
987 /// behavior.
988 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
989 const TemplateArgument &ArgPack) {
990 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
991 }
992
Douglas Gregor43959a92009-08-20 07:17:43 +0000993 /// \brief Build a new compound statement.
994 ///
995 /// By default, performs semantic analysis to build the new statement.
996 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000997 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000998 MultiStmtArg Statements,
999 SourceLocation RBraceLoc,
1000 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001001 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001002 IsStmtExpr);
1003 }
1004
1005 /// \brief Build a new case statement.
1006 ///
1007 /// By default, performs semantic analysis to build the new statement.
1008 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001009 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001010 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001011 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001012 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001013 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001014 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 ColonLoc);
1016 }
Mike Stump1eb44332009-09-09 15:08:12 +00001017
Douglas Gregor43959a92009-08-20 07:17:43 +00001018 /// \brief Attach the body to a new case statement.
1019 ///
1020 /// By default, performs semantic analysis to build the new statement.
1021 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001022 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001023 getSema().ActOnCaseStmtBody(S, Body);
1024 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001025 }
Mike Stump1eb44332009-09-09 15:08:12 +00001026
Douglas Gregor43959a92009-08-20 07:17:43 +00001027 /// \brief Build a new default statement.
1028 ///
1029 /// By default, performs semantic analysis to build the new statement.
1030 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001031 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001033 Stmt *SubStmt) {
1034 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 /*CurScope=*/0);
1036 }
Mike Stump1eb44332009-09-09 15:08:12 +00001037
Douglas Gregor43959a92009-08-20 07:17:43 +00001038 /// \brief Build a new label statement.
1039 ///
1040 /// By default, performs semantic analysis to build the new statement.
1041 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001042 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1043 SourceLocation ColonLoc, Stmt *SubStmt) {
1044 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001045 }
Mike Stump1eb44332009-09-09 15:08:12 +00001046
Douglas Gregor43959a92009-08-20 07:17:43 +00001047 /// \brief Build a new "if" statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001051 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001052 VarDecl *CondVar, Stmt *Then,
1053 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001054 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 }
Mike Stump1eb44332009-09-09 15:08:12 +00001056
Douglas Gregor43959a92009-08-20 07:17:43 +00001057 /// \brief Start building a new switch statement.
1058 ///
1059 /// By default, performs semantic analysis to build the new statement.
1060 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001061 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001062 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001063 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001064 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001065 }
Mike Stump1eb44332009-09-09 15:08:12 +00001066
Douglas Gregor43959a92009-08-20 07:17:43 +00001067 /// \brief Attach the body to the switch statement.
1068 ///
1069 /// By default, performs semantic analysis to build the new statement.
1070 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001071 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001072 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001073 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001074 }
1075
1076 /// \brief Build a new while statement.
1077 ///
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001080 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1081 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001082 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001083 }
Mike Stump1eb44332009-09-09 15:08:12 +00001084
Douglas Gregor43959a92009-08-20 07:17:43 +00001085 /// \brief Build a new do-while statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001089 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001090 SourceLocation WhileLoc, SourceLocation LParenLoc,
1091 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001092 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1093 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 }
1095
1096 /// \brief Build a new for statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001100 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1101 Stmt *Init, Sema::FullExprArg Cond,
1102 VarDecl *CondVar, Sema::FullExprArg Inc,
1103 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001104 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001105 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001106 }
Mike Stump1eb44332009-09-09 15:08:12 +00001107
Douglas Gregor43959a92009-08-20 07:17:43 +00001108 /// \brief Build a new goto statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001112 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1113 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001114 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001115 }
1116
1117 /// \brief Build a new indirect goto statement.
1118 ///
1119 /// By default, performs semantic analysis to build the new statement.
1120 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001121 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001122 SourceLocation StarLoc,
1123 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001124 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001125 }
Mike Stump1eb44332009-09-09 15:08:12 +00001126
Douglas Gregor43959a92009-08-20 07:17:43 +00001127 /// \brief Build a new return statement.
1128 ///
1129 /// By default, performs semantic analysis to build the new statement.
1130 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001131 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001132 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001133 }
Mike Stump1eb44332009-09-09 15:08:12 +00001134
Douglas Gregor43959a92009-08-20 07:17:43 +00001135 /// \brief Build a new declaration statement.
1136 ///
1137 /// By default, performs semantic analysis to build the new statement.
1138 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001139 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001140 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001141 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001142 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1143 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001144 }
Mike Stump1eb44332009-09-09 15:08:12 +00001145
Anders Carlsson703e3942010-01-24 05:50:09 +00001146 /// \brief Build a new inline asm statement.
1147 ///
1148 /// By default, performs semantic analysis to build the new statement.
1149 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001150 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001151 bool IsSimple,
1152 bool IsVolatile,
1153 unsigned NumOutputs,
1154 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001155 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001156 MultiExprArg Constraints,
1157 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001158 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001159 MultiExprArg Clobbers,
1160 SourceLocation RParenLoc,
1161 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001162 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001163 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001164 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001165 RParenLoc, MSAsm);
1166 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001167
1168 /// \brief Build a new Objective-C @try statement.
1169 ///
1170 /// By default, performs semantic analysis to build the new statement.
1171 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001172 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001173 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001174 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001175 Stmt *Finally) {
1176 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1177 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001178 }
1179
Douglas Gregorbe270a02010-04-26 17:57:08 +00001180 /// \brief Rebuild an Objective-C exception declaration.
1181 ///
1182 /// By default, performs semantic analysis to build the new declaration.
1183 /// Subclasses may override this routine to provide different behavior.
1184 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1185 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001186 return getSema().BuildObjCExceptionDecl(TInfo, T,
1187 ExceptionDecl->getInnerLocStart(),
1188 ExceptionDecl->getLocation(),
1189 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001190 }
Sean Huntc3021132010-05-05 15:23:54 +00001191
Douglas Gregorbe270a02010-04-26 17:57:08 +00001192 /// \brief Build a new Objective-C @catch statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001196 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001197 SourceLocation RParenLoc,
1198 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001199 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001200 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001201 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001202 }
Sean Huntc3021132010-05-05 15:23:54 +00001203
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001204 /// \brief Build a new Objective-C @finally statement.
1205 ///
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001208 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001209 Stmt *Body) {
1210 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001211 }
Sean Huntc3021132010-05-05 15:23:54 +00001212
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001213 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001214 ///
1215 /// By default, performs semantic analysis to build the new statement.
1216 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001217 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001218 Expr *Operand) {
1219 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001220 }
Sean Huntc3021132010-05-05 15:23:54 +00001221
John McCall07524032011-07-27 21:50:02 +00001222 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
1226 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1227 Expr *object) {
1228 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1229 }
1230
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001231 /// \brief Build a new Objective-C @synchronized statement.
1232 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001233 /// By default, performs semantic analysis to build the new statement.
1234 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001235 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001236 Expr *Object, Stmt *Body) {
1237 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001238 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001239
John McCallf85e1932011-06-15 23:02:42 +00001240 /// \brief Build a new Objective-C @autoreleasepool statement.
1241 ///
1242 /// By default, performs semantic analysis to build the new statement.
1243 /// Subclasses may override this routine to provide different behavior.
1244 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1245 Stmt *Body) {
1246 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1247 }
John McCall990567c2011-07-27 01:07:15 +00001248
1249 /// \brief Build the collection operand to a new Objective-C fast
1250 /// enumeration statement.
1251 ///
1252 /// By default, performs semantic analysis to build the new statement.
1253 /// Subclasses may override this routine to provide different behavior.
1254 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1255 Expr *collection) {
1256 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1257 }
John McCallf85e1932011-06-15 23:02:42 +00001258
Douglas Gregorc3203e72010-04-22 23:10:45 +00001259 /// \brief Build a new Objective-C fast enumeration statement.
1260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001263 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001264 SourceLocation LParenLoc,
1265 Stmt *Element,
1266 Expr *Collection,
1267 SourceLocation RParenLoc,
1268 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001269 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001270 Element,
1271 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001272 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001273 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001274 }
Sean Huntc3021132010-05-05 15:23:54 +00001275
Douglas Gregor43959a92009-08-20 07:17:43 +00001276 /// \brief Build a new C++ exception declaration.
1277 ///
1278 /// By default, performs semantic analysis to build the new decaration.
1279 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001280 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001281 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001282 SourceLocation StartLoc,
1283 SourceLocation IdLoc,
1284 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001285 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1286 StartLoc, IdLoc, Id);
1287 if (Var)
1288 getSema().CurContext->addDecl(Var);
1289 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001290 }
1291
1292 /// \brief Build a new C++ catch statement.
1293 ///
1294 /// By default, performs semantic analysis to build the new statement.
1295 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001296 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001297 VarDecl *ExceptionDecl,
1298 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001299 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1300 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001301 }
Mike Stump1eb44332009-09-09 15:08:12 +00001302
Douglas Gregor43959a92009-08-20 07:17:43 +00001303 /// \brief Build a new C++ try statement.
1304 ///
1305 /// By default, performs semantic analysis to build the new statement.
1306 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001307 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001308 Stmt *TryBlock,
1309 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001310 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001311 }
Mike Stump1eb44332009-09-09 15:08:12 +00001312
Richard Smithad762fc2011-04-14 22:09:26 +00001313 /// \brief Build a new C++0x range-based for statement.
1314 ///
1315 /// By default, performs semantic analysis to build the new statement.
1316 /// Subclasses may override this routine to provide different behavior.
1317 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1318 SourceLocation ColonLoc,
1319 Stmt *Range, Stmt *BeginEnd,
1320 Expr *Cond, Expr *Inc,
1321 Stmt *LoopVar,
1322 SourceLocation RParenLoc) {
1323 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1324 Cond, Inc, LoopVar, RParenLoc);
1325 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001326
1327 /// \brief Build a new C++0x range-based for statement.
1328 ///
1329 /// By default, performs semantic analysis to build the new statement.
1330 /// Subclasses may override this routine to provide different behavior.
1331 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1332 bool IsIfExists,
1333 NestedNameSpecifierLoc QualifierLoc,
1334 DeclarationNameInfo NameInfo,
1335 Stmt *Nested) {
1336 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1337 QualifierLoc, NameInfo, Nested);
1338 }
1339
Richard Smithad762fc2011-04-14 22:09:26 +00001340 /// \brief Attach body to a C++0x range-based for statement.
1341 ///
1342 /// By default, performs semantic analysis to finish the new statement.
1343 /// Subclasses may override this routine to provide different behavior.
1344 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1345 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1346 }
1347
John Wiegley28bbe4b2011-04-28 01:08:34 +00001348 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1349 SourceLocation TryLoc,
1350 Stmt *TryBlock,
1351 Stmt *Handler) {
1352 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1353 }
1354
1355 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1356 Expr *FilterExpr,
1357 Stmt *Block) {
1358 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1359 }
1360
1361 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1362 Stmt *Block) {
1363 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1364 }
1365
Douglas Gregorb98b1992009-08-11 05:31:07 +00001366 /// \brief Build a new expression that references a declaration.
1367 ///
1368 /// By default, performs semantic analysis to build the new expression.
1369 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001370 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001371 LookupResult &R,
1372 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001373 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1374 }
1375
1376
1377 /// \brief Build a new expression that references a declaration.
1378 ///
1379 /// By default, performs semantic analysis to build the new expression.
1380 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001381 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001382 ValueDecl *VD,
1383 const DeclarationNameInfo &NameInfo,
1384 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001385 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001386 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001387
1388 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001389
1390 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001391 }
Mike Stump1eb44332009-09-09 15:08:12 +00001392
Douglas Gregorb98b1992009-08-11 05:31:07 +00001393 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001394 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001395 /// By default, performs semantic analysis to build the new expression.
1396 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001397 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001398 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001399 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 }
1401
Douglas Gregora71d8192009-09-04 17:36:40 +00001402 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001403 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001406 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001407 SourceLocation OperatorLoc,
1408 bool isArrow,
1409 CXXScopeSpec &SS,
1410 TypeSourceInfo *ScopeType,
1411 SourceLocation CCLoc,
1412 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001413 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001414
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001416 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 /// By default, performs semantic analysis to build the new expression.
1418 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001419 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001420 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001421 Expr *SubExpr) {
1422 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001423 }
Mike Stump1eb44332009-09-09 15:08:12 +00001424
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001425 /// \brief Build a new builtin offsetof expression.
1426 ///
1427 /// By default, performs semantic analysis to build the new expression.
1428 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001429 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001430 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001431 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001432 unsigned NumComponents,
1433 SourceLocation RParenLoc) {
1434 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1435 NumComponents, RParenLoc);
1436 }
Sean Huntc3021132010-05-05 15:23:54 +00001437
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001438 /// \brief Build a new sizeof, alignof or vec_step expression with a
1439 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001440 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001441 /// By default, performs semantic analysis to build the new expression.
1442 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001443 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1444 SourceLocation OpLoc,
1445 UnaryExprOrTypeTrait ExprKind,
1446 SourceRange R) {
1447 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001448 }
1449
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001450 /// \brief Build a new sizeof, alignof or vec step expression with an
1451 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001452 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001453 /// By default, performs semantic analysis to build the new expression.
1454 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001455 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1456 UnaryExprOrTypeTrait ExprKind,
1457 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001458 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001459 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001460 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001461 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001462
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 return move(Result);
1464 }
Mike Stump1eb44332009-09-09 15:08:12 +00001465
Douglas Gregorb98b1992009-08-11 05:31:07 +00001466 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001467 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001468 /// By default, performs semantic analysis to build the new expression.
1469 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001470 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001472 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001474 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1475 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001476 RBracketLoc);
1477 }
1478
1479 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001480 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 /// By default, performs semantic analysis to build the new expression.
1482 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001483 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001485 SourceLocation RParenLoc,
1486 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001487 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001488 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 }
1490
1491 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001492 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001495 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001496 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001497 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001498 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001499 const DeclarationNameInfo &MemberNameInfo,
1500 ValueDecl *Member,
1501 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001502 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001503 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001504 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1505 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001506 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001507 // We have a reference to an unnamed field. This is always the
1508 // base of an anonymous struct/union member access, i.e. the
1509 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001510 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001511 assert(Member->getType()->isRecordType() &&
1512 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001513
Richard Smith9138b4e2011-10-26 19:06:56 +00001514 BaseResult =
1515 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001516 QualifierLoc.getNestedNameSpecifier(),
1517 FoundDecl, Member);
1518 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001519 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001520 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001521 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001522 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001523 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001524 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001525 cast<FieldDecl>(Member)->getType(),
1526 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001527 return getSema().Owned(ME);
1528 }
Mike Stump1eb44332009-09-09 15:08:12 +00001529
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001530 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001531 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001532
John Wiegley429bb272011-04-08 18:41:53 +00001533 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001534 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001535
John McCall6bb80172010-03-30 21:47:33 +00001536 // FIXME: this involves duplicating earlier analysis in a lot of
1537 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001538 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001539 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001540 R.resolveKind();
1541
John McCall9ae2f072010-08-23 23:25:46 +00001542 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001543 SS, TemplateKWLoc,
1544 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001545 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001546 }
Mike Stump1eb44332009-09-09 15:08:12 +00001547
Douglas Gregorb98b1992009-08-11 05:31:07 +00001548 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001549 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001550 /// By default, performs semantic analysis to build the new expression.
1551 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001552 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001553 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001554 Expr *LHS, Expr *RHS) {
1555 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001556 }
1557
1558 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001559 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001562 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001563 SourceLocation QuestionLoc,
1564 Expr *LHS,
1565 SourceLocation ColonLoc,
1566 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001567 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1568 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 }
1570
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001572 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001575 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001576 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001578 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001579 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001580 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 }
Mike Stump1eb44332009-09-09 15:08:12 +00001582
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001584 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 /// By default, performs semantic analysis to build the new expression.
1586 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001587 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001588 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001590 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001591 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001592 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 }
Mike Stump1eb44332009-09-09 15:08:12 +00001594
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001596 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001599 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 SourceLocation OpLoc,
1601 SourceLocation AccessorLoc,
1602 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001603
John McCall129e2df2009-11-30 22:42:35 +00001604 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001605 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001606 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001607 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001608 SS, SourceLocation(),
1609 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001610 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001611 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 }
Mike Stump1eb44332009-09-09 15:08:12 +00001613
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001615 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 /// By default, performs semantic analysis to build the new expression.
1617 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001618 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001619 MultiExprArg Inits,
1620 SourceLocation RBraceLoc,
1621 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001622 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001623 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1624 if (Result.isInvalid() || ResultTy->isDependentType())
1625 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001626
Douglas Gregore48319a2009-11-09 17:16:50 +00001627 // Patch in the result type we were given, which may have been computed
1628 // when the initial InitListExpr was built.
1629 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1630 ILE->setType(ResultTy);
1631 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 }
Mike Stump1eb44332009-09-09 15:08:12 +00001633
Douglas Gregorb98b1992009-08-11 05:31:07 +00001634 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001635 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 /// By default, performs semantic analysis to build the new expression.
1637 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001638 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 MultiExprArg ArrayExprs,
1640 SourceLocation EqualOrColonLoc,
1641 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001642 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001643 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001645 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001647 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001648
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 ArrayExprs.release();
1650 return move(Result);
1651 }
Mike Stump1eb44332009-09-09 15:08:12 +00001652
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001654 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 /// By default, builds the implicit value initialization without performing
1656 /// any semantic analysis. Subclasses may override this routine to provide
1657 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001658 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1660 }
Mike Stump1eb44332009-09-09 15:08:12 +00001661
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001663 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 /// By default, performs semantic analysis to build the new expression.
1665 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001666 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001667 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001668 SourceLocation RParenLoc) {
1669 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001670 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001671 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 }
1673
1674 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001675 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 /// By default, performs semantic analysis to build the new expression.
1677 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001678 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001679 MultiExprArg SubExprs,
1680 SourceLocation RParenLoc) {
1681 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001682 }
Mike Stump1eb44332009-09-09 15:08:12 +00001683
Douglas Gregorb98b1992009-08-11 05:31:07 +00001684 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001685 ///
1686 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 /// rather than attempting to map the label statement itself.
1688 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001689 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001690 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001691 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001692 }
Mike Stump1eb44332009-09-09 15:08:12 +00001693
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001695 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 /// By default, performs semantic analysis to build the new expression.
1697 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001698 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001699 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001701 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001702 }
Mike Stump1eb44332009-09-09 15:08:12 +00001703
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 /// \brief Build a new __builtin_choose_expr expression.
1705 ///
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001708 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001709 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 SourceLocation RParenLoc) {
1711 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001712 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 RParenLoc);
1714 }
Mike Stump1eb44332009-09-09 15:08:12 +00001715
Peter Collingbournef111d932011-04-15 00:35:48 +00001716 /// \brief Build a new generic selection expression.
1717 ///
1718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
1720 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1721 SourceLocation DefaultLoc,
1722 SourceLocation RParenLoc,
1723 Expr *ControllingExpr,
1724 TypeSourceInfo **Types,
1725 Expr **Exprs,
1726 unsigned NumAssocs) {
1727 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1728 ControllingExpr, Types, Exprs,
1729 NumAssocs);
1730 }
1731
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 /// \brief Build a new overloaded operator call expression.
1733 ///
1734 /// By default, performs semantic analysis to build the new expression.
1735 /// The semantic analysis provides the behavior of template instantiation,
1736 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001737 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 /// argument-dependent lookup, etc. Subclasses may override this routine to
1739 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001740 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001742 Expr *Callee,
1743 Expr *First,
1744 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001745
1746 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001747 /// reinterpret_cast.
1748 ///
1749 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001750 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001751 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001752 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 Stmt::StmtClass Class,
1754 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001755 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 SourceLocation RAngleLoc,
1757 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001758 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 SourceLocation RParenLoc) {
1760 switch (Class) {
1761 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001762 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001763 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001764 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765
1766 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001767 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001768 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001769 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001770
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001772 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001773 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001774 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001776
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001778 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001779 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001780 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001781
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001783 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 }
Mike Stump1eb44332009-09-09 15:08:12 +00001786
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 /// \brief Build a new C++ static_cast expression.
1788 ///
1789 /// By default, performs semantic analysis to build the new expression.
1790 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001791 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001793 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 SourceLocation RAngleLoc,
1795 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001796 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001798 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001799 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001800 SourceRange(LAngleLoc, RAngleLoc),
1801 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001802 }
1803
1804 /// \brief Build a new C++ dynamic_cast expression.
1805 ///
1806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001808 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001810 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 SourceLocation RAngleLoc,
1812 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001813 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001815 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001816 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001817 SourceRange(LAngleLoc, RAngleLoc),
1818 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 }
1820
1821 /// \brief Build a new C++ reinterpret_cast expression.
1822 ///
1823 /// By default, performs semantic analysis to build the new expression.
1824 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001825 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001827 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 SourceLocation RAngleLoc,
1829 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001830 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001832 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001833 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001834 SourceRange(LAngleLoc, RAngleLoc),
1835 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 }
1837
1838 /// \brief Build a new C++ const_cast expression.
1839 ///
1840 /// By default, performs semantic analysis to build the new expression.
1841 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001842 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001843 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001844 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 SourceLocation RAngleLoc,
1846 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001847 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001848 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001849 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001850 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001851 SourceRange(LAngleLoc, RAngleLoc),
1852 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 }
Mike Stump1eb44332009-09-09 15:08:12 +00001854
Douglas Gregorb98b1992009-08-11 05:31:07 +00001855 /// \brief Build a new C++ functional-style cast expression.
1856 ///
1857 /// By default, performs semantic analysis to build the new expression.
1858 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001859 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1860 SourceLocation LParenLoc,
1861 Expr *Sub,
1862 SourceLocation RParenLoc) {
1863 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001864 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001865 RParenLoc);
1866 }
Mike Stump1eb44332009-09-09 15:08:12 +00001867
Douglas Gregorb98b1992009-08-11 05:31:07 +00001868 /// \brief Build a new C++ typeid(type) expression.
1869 ///
1870 /// By default, performs semantic analysis to build the new expression.
1871 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001872 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001873 SourceLocation TypeidLoc,
1874 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001875 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001876 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001877 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001878 }
Mike Stump1eb44332009-09-09 15:08:12 +00001879
Francois Pichet01b7c302010-09-08 12:20:18 +00001880
Douglas Gregorb98b1992009-08-11 05:31:07 +00001881 /// \brief Build a new C++ typeid(expr) expression.
1882 ///
1883 /// By default, performs semantic analysis to build the new expression.
1884 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001885 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001886 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001887 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001888 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001889 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001890 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001891 }
1892
Francois Pichet01b7c302010-09-08 12:20:18 +00001893 /// \brief Build a new C++ __uuidof(type) expression.
1894 ///
1895 /// By default, performs semantic analysis to build the new expression.
1896 /// Subclasses may override this routine to provide different behavior.
1897 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1898 SourceLocation TypeidLoc,
1899 TypeSourceInfo *Operand,
1900 SourceLocation RParenLoc) {
1901 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1902 RParenLoc);
1903 }
1904
1905 /// \brief Build a new C++ __uuidof(expr) expression.
1906 ///
1907 /// By default, performs semantic analysis to build the new expression.
1908 /// Subclasses may override this routine to provide different behavior.
1909 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1910 SourceLocation TypeidLoc,
1911 Expr *Operand,
1912 SourceLocation RParenLoc) {
1913 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1914 RParenLoc);
1915 }
1916
Douglas Gregorb98b1992009-08-11 05:31:07 +00001917 /// \brief Build a new C++ "this" expression.
1918 ///
1919 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001920 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001921 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001922 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001923 QualType ThisType,
1924 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001925 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001926 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001927 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1928 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001929 }
1930
1931 /// \brief Build a new C++ throw expression.
1932 ///
1933 /// By default, performs semantic analysis to build the new expression.
1934 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001935 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1936 bool IsThrownVariableInScope) {
1937 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 }
1939
1940 /// \brief Build a new C++ default-argument expression.
1941 ///
1942 /// By default, builds a new default-argument expression, which does not
1943 /// require any semantic analysis. Subclasses may override this routine to
1944 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001945 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001946 ParmVarDecl *Param) {
1947 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1948 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001949 }
1950
1951 /// \brief Build a new C++ zero-initialization expression.
1952 ///
1953 /// By default, performs semantic analysis to build the new expression.
1954 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001955 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1956 SourceLocation LParenLoc,
1957 SourceLocation RParenLoc) {
1958 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001959 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001960 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001961 }
Mike Stump1eb44332009-09-09 15:08:12 +00001962
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 /// \brief Build a new C++ "new" expression.
1964 ///
1965 /// By default, performs semantic analysis to build the new expression.
1966 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001967 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001968 bool UseGlobal,
1969 SourceLocation PlacementLParen,
1970 MultiExprArg PlacementArgs,
1971 SourceLocation PlacementRParen,
1972 SourceRange TypeIdParens,
1973 QualType AllocatedType,
1974 TypeSourceInfo *AllocatedTypeInfo,
1975 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001976 SourceRange DirectInitRange,
1977 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001978 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001979 PlacementLParen,
1980 move(PlacementArgs),
1981 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001982 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001983 AllocatedType,
1984 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001985 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001986 DirectInitRange,
1987 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001988 }
Mike Stump1eb44332009-09-09 15:08:12 +00001989
Douglas Gregorb98b1992009-08-11 05:31:07 +00001990 /// \brief Build a new C++ "delete" expression.
1991 ///
1992 /// By default, performs semantic analysis to build the new expression.
1993 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001994 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001995 bool IsGlobalDelete,
1996 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001997 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001998 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001999 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002000 }
Mike Stump1eb44332009-09-09 15:08:12 +00002001
Douglas Gregorb98b1992009-08-11 05:31:07 +00002002 /// \brief Build a new unary type trait expression.
2003 ///
2004 /// By default, performs semantic analysis to build the new expression.
2005 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002006 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002007 SourceLocation StartLoc,
2008 TypeSourceInfo *T,
2009 SourceLocation RParenLoc) {
2010 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002011 }
2012
Francois Pichet6ad6f282010-12-07 00:08:36 +00002013 /// \brief Build a new binary type trait expression.
2014 ///
2015 /// By default, performs semantic analysis to build the new expression.
2016 /// Subclasses may override this routine to provide different behavior.
2017 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2018 SourceLocation StartLoc,
2019 TypeSourceInfo *LhsT,
2020 TypeSourceInfo *RhsT,
2021 SourceLocation RParenLoc) {
2022 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2023 }
2024
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002025 /// \brief Build a new type trait expression.
2026 ///
2027 /// By default, performs semantic analysis to build the new expression.
2028 /// Subclasses may override this routine to provide different behavior.
2029 ExprResult RebuildTypeTrait(TypeTrait Trait,
2030 SourceLocation StartLoc,
2031 ArrayRef<TypeSourceInfo *> Args,
2032 SourceLocation RParenLoc) {
2033 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2034 }
2035
John Wiegley21ff2e52011-04-28 00:16:57 +00002036 /// \brief Build a new array type trait expression.
2037 ///
2038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
2040 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2041 SourceLocation StartLoc,
2042 TypeSourceInfo *TSInfo,
2043 Expr *DimExpr,
2044 SourceLocation RParenLoc) {
2045 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2046 }
2047
John Wiegley55262202011-04-25 06:54:41 +00002048 /// \brief Build a new expression trait expression.
2049 ///
2050 /// By default, performs semantic analysis to build the new expression.
2051 /// Subclasses may override this routine to provide different behavior.
2052 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2053 SourceLocation StartLoc,
2054 Expr *Queried,
2055 SourceLocation RParenLoc) {
2056 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2057 }
2058
Mike Stump1eb44332009-09-09 15:08:12 +00002059 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002060 /// expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002064 ExprResult RebuildDependentScopeDeclRefExpr(
2065 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002066 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002067 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002068 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002069 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002070 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002071
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002072 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002073 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002074 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002075
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002076 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002077 }
2078
2079 /// \brief Build a new template-id expression.
2080 ///
2081 /// By default, performs semantic analysis to build the new expression.
2082 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002083 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002084 SourceLocation TemplateKWLoc,
2085 LookupResult &R,
2086 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002087 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002088 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2089 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002090 }
2091
2092 /// \brief Build a new object-construction expression.
2093 ///
2094 /// By default, performs semantic analysis to build the new expression.
2095 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002096 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002097 SourceLocation Loc,
2098 CXXConstructorDecl *Constructor,
2099 bool IsElidable,
2100 MultiExprArg Args,
2101 bool HadMultipleCandidates,
2102 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002103 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002104 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002105 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002106 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002107 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002108 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002109
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002110 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002111 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002112 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002113 RequiresZeroInit, ConstructKind,
2114 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002115 }
2116
2117 /// \brief Build a new object-construction expression.
2118 ///
2119 /// By default, performs semantic analysis to build the new expression.
2120 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002121 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2122 SourceLocation LParenLoc,
2123 MultiExprArg Args,
2124 SourceLocation RParenLoc) {
2125 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002126 LParenLoc,
2127 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002128 RParenLoc);
2129 }
2130
2131 /// \brief Build a new object-construction expression.
2132 ///
2133 /// By default, performs semantic analysis to build the new expression.
2134 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002135 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2136 SourceLocation LParenLoc,
2137 MultiExprArg Args,
2138 SourceLocation RParenLoc) {
2139 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002140 LParenLoc,
2141 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002142 RParenLoc);
2143 }
Mike Stump1eb44332009-09-09 15:08:12 +00002144
Douglas Gregorb98b1992009-08-11 05:31:07 +00002145 /// \brief Build a new member reference expression.
2146 ///
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002149 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002150 QualType BaseType,
2151 bool IsArrow,
2152 SourceLocation OperatorLoc,
2153 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002154 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002155 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002156 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002157 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002158 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002159 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002160
John McCall9ae2f072010-08-23 23:25:46 +00002161 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002162 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002163 SS, TemplateKWLoc,
2164 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002165 MemberNameInfo,
2166 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002167 }
2168
John McCall129e2df2009-11-30 22:42:35 +00002169 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002170 ///
2171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002173 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2174 SourceLocation OperatorLoc,
2175 bool IsArrow,
2176 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002177 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002178 NamedDecl *FirstQualifierInScope,
2179 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002180 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002181 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002182 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002183
John McCall9ae2f072010-08-23 23:25:46 +00002184 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002185 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002186 SS, TemplateKWLoc,
2187 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002188 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002189 }
Mike Stump1eb44332009-09-09 15:08:12 +00002190
Sebastian Redl2e156222010-09-10 20:55:43 +00002191 /// \brief Build a new noexcept expression.
2192 ///
2193 /// By default, performs semantic analysis to build the new expression.
2194 /// Subclasses may override this routine to provide different behavior.
2195 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2196 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2197 }
2198
Douglas Gregoree8aff02011-01-04 17:33:58 +00002199 /// \brief Build a new expression to compute the length of a parameter pack.
2200 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2201 SourceLocation PackLoc,
2202 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002203 llvm::Optional<unsigned> Length) {
2204 if (Length)
2205 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2206 OperatorLoc, Pack, PackLoc,
2207 RParenLoc, *Length);
2208
Douglas Gregoree8aff02011-01-04 17:33:58 +00002209 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2210 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002211 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002212 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002213
2214 /// \brief Build a new Objective-C array literal.
2215 ///
2216 /// By default, performs semantic analysis to build the new expression.
2217 /// Subclasses may override this routine to provide different behavior.
2218 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2219 Expr **Elements, unsigned NumElements) {
2220 return getSema().BuildObjCArrayLiteral(Range,
2221 MultiExprArg(Elements, NumElements));
2222 }
2223
2224 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2225 Expr *Base, Expr *Key,
2226 ObjCMethodDecl *getterMethod,
2227 ObjCMethodDecl *setterMethod) {
2228 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2229 getterMethod, setterMethod);
2230 }
2231
2232 /// \brief Build a new Objective-C dictionary literal.
2233 ///
2234 /// By default, performs semantic analysis to build the new expression.
2235 /// Subclasses may override this routine to provide different behavior.
2236 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2237 ObjCDictionaryElement *Elements,
2238 unsigned NumElements) {
2239 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2240 }
2241
Douglas Gregorb98b1992009-08-11 05:31:07 +00002242 /// \brief Build a new Objective-C @encode expression.
2243 ///
2244 /// By default, performs semantic analysis to build the new expression.
2245 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002246 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002247 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002248 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002249 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002250 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002251 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002252
Douglas Gregor92e986e2010-04-22 16:44:27 +00002253 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002254 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002255 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002256 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002257 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002258 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002259 MultiExprArg Args,
2260 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002261 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2262 ReceiverTypeInfo->getType(),
2263 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002264 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002265 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002266 }
2267
2268 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002269 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002270 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002271 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002272 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002273 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002274 MultiExprArg Args,
2275 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002276 return SemaRef.BuildInstanceMessage(Receiver,
2277 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002278 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002279 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002280 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002281 }
2282
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002283 /// \brief Build a new Objective-C ivar reference expression.
2284 ///
2285 /// By default, performs semantic analysis to build the new expression.
2286 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002287 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002288 SourceLocation IvarLoc,
2289 bool IsArrow, bool IsFreeIvar) {
2290 // FIXME: We lose track of the IsFreeIvar bit.
2291 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002292 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002293 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2294 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002295 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002296 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002297 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002298 false);
John Wiegley429bb272011-04-08 18:41:53 +00002299 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002300 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002301
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002302 if (Result.get())
2303 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002304
John Wiegley429bb272011-04-08 18:41:53 +00002305 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002306 /*FIXME:*/IvarLoc, IsArrow,
2307 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002308 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002309 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002310 /*TemplateArgs=*/0);
2311 }
Douglas Gregore3303542010-04-26 20:47:02 +00002312
2313 /// \brief Build a new Objective-C property reference expression.
2314 ///
2315 /// By default, performs semantic analysis to build the new expression.
2316 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002317 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002318 ObjCPropertyDecl *Property,
2319 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002320 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002321 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002322 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2323 Sema::LookupMemberName);
2324 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002325 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002326 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002327 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002328 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002329 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002330
Douglas Gregore3303542010-04-26 20:47:02 +00002331 if (Result.get())
2332 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002333
John Wiegley429bb272011-04-08 18:41:53 +00002334 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002335 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002336 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002337 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002338 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002339 /*TemplateArgs=*/0);
2340 }
Sean Huntc3021132010-05-05 15:23:54 +00002341
John McCall12f78a62010-12-02 01:19:52 +00002342 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002343 ///
2344 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002345 /// Subclasses may override this routine to provide different behavior.
2346 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2347 ObjCMethodDecl *Getter,
2348 ObjCMethodDecl *Setter,
2349 SourceLocation PropertyLoc) {
2350 // Since these expressions can only be value-dependent, we do not
2351 // need to perform semantic analysis again.
2352 return Owned(
2353 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2354 VK_LValue, OK_ObjCProperty,
2355 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002356 }
2357
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002358 /// \brief Build a new Objective-C "isa" expression.
2359 ///
2360 /// By default, performs semantic analysis to build the new expression.
2361 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002362 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002363 bool IsArrow) {
2364 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002365 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002366 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2367 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002368 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002369 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002370 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002371 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002372 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002373
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002374 if (Result.get())
2375 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002376
John Wiegley429bb272011-04-08 18:41:53 +00002377 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002378 /*FIXME:*/IsaLoc, IsArrow,
2379 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002380 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002381 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002382 /*TemplateArgs=*/0);
2383 }
Sean Huntc3021132010-05-05 15:23:54 +00002384
Douglas Gregorb98b1992009-08-11 05:31:07 +00002385 /// \brief Build a new shuffle vector expression.
2386 ///
2387 /// By default, performs semantic analysis to build the new expression.
2388 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002389 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002390 MultiExprArg SubExprs,
2391 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002392 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002393 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002394 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2395 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2396 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2397 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002398
Douglas Gregorb98b1992009-08-11 05:31:07 +00002399 // Build a reference to the __builtin_shufflevector builtin
2400 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002401 ExprResult Callee
2402 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2403 VK_LValue, BuiltinLoc));
2404 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2405 if (Callee.isInvalid())
2406 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002407
2408 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002409 unsigned NumSubExprs = SubExprs.size();
2410 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002411 ExprResult TheCall = SemaRef.Owned(
2412 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002413 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002414 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002415 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002416 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002417
Douglas Gregorb98b1992009-08-11 05:31:07 +00002418 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002419 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002420 }
John McCall43fed0d2010-11-12 08:19:04 +00002421
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002422 /// \brief Build a new template argument pack expansion.
2423 ///
2424 /// By default, performs semantic analysis to build a new pack expansion
2425 /// for a template argument. Subclasses may override this routine to provide
2426 /// different behavior.
2427 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002428 SourceLocation EllipsisLoc,
2429 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002430 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002431 case TemplateArgument::Expression: {
2432 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002433 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2434 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002435 if (Result.isInvalid())
2436 return TemplateArgumentLoc();
2437
2438 return TemplateArgumentLoc(Result.get(), Result.get());
2439 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002440
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002441 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002442 return TemplateArgumentLoc(TemplateArgument(
2443 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002444 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002445 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002446 Pattern.getTemplateNameLoc(),
2447 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002448
2449 case TemplateArgument::Null:
2450 case TemplateArgument::Integral:
2451 case TemplateArgument::Declaration:
2452 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002453 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002454 llvm_unreachable("Pack expansion pattern has no parameter packs");
2455
2456 case TemplateArgument::Type:
2457 if (TypeSourceInfo *Expansion
2458 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002459 EllipsisLoc,
2460 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002461 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2462 Expansion);
2463 break;
2464 }
2465
2466 return TemplateArgumentLoc();
2467 }
2468
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002469 /// \brief Build a new expression pack expansion.
2470 ///
2471 /// By default, performs semantic analysis to build a new pack expansion
2472 /// for an expression. Subclasses may override this routine to provide
2473 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002474 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2475 llvm::Optional<unsigned> NumExpansions) {
2476 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002477 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002478
2479 /// \brief Build a new atomic operation expression.
2480 ///
2481 /// By default, performs semantic analysis to build the new expression.
2482 /// Subclasses may override this routine to provide different behavior.
2483 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2484 MultiExprArg SubExprs,
2485 QualType RetTy,
2486 AtomicExpr::AtomicOp Op,
2487 SourceLocation RParenLoc) {
2488 // Just create the expression; there is not any interesting semantic
2489 // analysis here because we can't actually build an AtomicExpr until
2490 // we are sure it is semantically sound.
2491 unsigned NumSubExprs = SubExprs.size();
2492 Expr **Subs = (Expr **)SubExprs.release();
2493 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2494 NumSubExprs, RetTy, Op,
2495 RParenLoc);
2496 }
2497
John McCall43fed0d2010-11-12 08:19:04 +00002498private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002499 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2500 QualType ObjectType,
2501 NamedDecl *FirstQualifierInScope,
2502 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002503
2504 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2505 QualType ObjectType,
2506 NamedDecl *FirstQualifierInScope,
2507 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002508};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002509
Douglas Gregor43959a92009-08-20 07:17:43 +00002510template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002511StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002512 if (!S)
2513 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002514
Douglas Gregor43959a92009-08-20 07:17:43 +00002515 switch (S->getStmtClass()) {
2516 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002517
Douglas Gregor43959a92009-08-20 07:17:43 +00002518 // Transform individual statement nodes
2519#define STMT(Node, Parent) \
2520 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002521#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002522#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002523#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002524
Douglas Gregor43959a92009-08-20 07:17:43 +00002525 // Transform expressions by calling TransformExpr.
2526#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002527#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002528#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002529#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002530 {
John McCall60d7b3a2010-08-24 06:29:42 +00002531 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002532 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002533 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002534
John McCall9ae2f072010-08-23 23:25:46 +00002535 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002536 }
Mike Stump1eb44332009-09-09 15:08:12 +00002537 }
2538
John McCall3fa5cae2010-10-26 07:05:15 +00002539 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002540}
Mike Stump1eb44332009-09-09 15:08:12 +00002541
2542
Douglas Gregor670444e2009-08-04 22:27:00 +00002543template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002544ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002545 if (!E)
2546 return SemaRef.Owned(E);
2547
2548 switch (E->getStmtClass()) {
2549 case Stmt::NoStmtClass: break;
2550#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002551#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002552#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002553 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002554#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002555 }
2556
John McCall3fa5cae2010-10-26 07:05:15 +00002557 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002558}
2559
2560template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002561bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2562 unsigned NumInputs,
2563 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002564 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002565 bool *ArgChanged) {
2566 for (unsigned I = 0; I != NumInputs; ++I) {
2567 // If requested, drop call arguments that need to be dropped.
2568 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2569 if (ArgChanged)
2570 *ArgChanged = true;
2571
2572 break;
2573 }
2574
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002575 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2576 Expr *Pattern = Expansion->getPattern();
2577
Chris Lattner686775d2011-07-20 06:58:45 +00002578 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002579 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2580 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2581
2582 // Determine whether the set of unexpanded parameter packs can and should
2583 // be expanded.
2584 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002585 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002586 llvm::Optional<unsigned> OrigNumExpansions
2587 = Expansion->getNumExpansions();
2588 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002589 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2590 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002591 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002592 Expand, RetainExpansion,
2593 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002594 return true;
2595
2596 if (!Expand) {
2597 // The transform has determined that we should perform a simple
2598 // transformation on the pack expansion, producing another pack
2599 // expansion.
2600 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2601 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2602 if (OutPattern.isInvalid())
2603 return true;
2604
2605 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002606 Expansion->getEllipsisLoc(),
2607 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002608 if (Out.isInvalid())
2609 return true;
2610
2611 if (ArgChanged)
2612 *ArgChanged = true;
2613 Outputs.push_back(Out.get());
2614 continue;
2615 }
John McCallc8fc90a2011-07-06 07:30:07 +00002616
2617 // Record right away that the argument was changed. This needs
2618 // to happen even if the array expands to nothing.
2619 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002620
2621 // The transform has determined that we should perform an elementwise
2622 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002623 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002624 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2625 ExprResult Out = getDerived().TransformExpr(Pattern);
2626 if (Out.isInvalid())
2627 return true;
2628
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002629 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002630 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2631 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002632 if (Out.isInvalid())
2633 return true;
2634 }
2635
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002636 Outputs.push_back(Out.get());
2637 }
2638
2639 continue;
2640 }
2641
Douglas Gregoraa165f82011-01-03 19:04:46 +00002642 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2643 if (Result.isInvalid())
2644 return true;
2645
2646 if (Result.get() != Inputs[I] && ArgChanged)
2647 *ArgChanged = true;
2648
2649 Outputs.push_back(Result.get());
2650 }
2651
2652 return false;
2653}
2654
2655template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002656NestedNameSpecifierLoc
2657TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2658 NestedNameSpecifierLoc NNS,
2659 QualType ObjectType,
2660 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002661 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002662 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2663 Qualifier = Qualifier.getPrefix())
2664 Qualifiers.push_back(Qualifier);
2665
2666 CXXScopeSpec SS;
2667 while (!Qualifiers.empty()) {
2668 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2669 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2670
2671 switch (QNNS->getKind()) {
2672 case NestedNameSpecifier::Identifier:
2673 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2674 *QNNS->getAsIdentifier(),
2675 Q.getLocalBeginLoc(),
2676 Q.getLocalEndLoc(),
2677 ObjectType, false, SS,
2678 FirstQualifierInScope, false))
2679 return NestedNameSpecifierLoc();
2680
2681 break;
2682
2683 case NestedNameSpecifier::Namespace: {
2684 NamespaceDecl *NS
2685 = cast_or_null<NamespaceDecl>(
2686 getDerived().TransformDecl(
2687 Q.getLocalBeginLoc(),
2688 QNNS->getAsNamespace()));
2689 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2690 break;
2691 }
2692
2693 case NestedNameSpecifier::NamespaceAlias: {
2694 NamespaceAliasDecl *Alias
2695 = cast_or_null<NamespaceAliasDecl>(
2696 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2697 QNNS->getAsNamespaceAlias()));
2698 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2699 Q.getLocalEndLoc());
2700 break;
2701 }
2702
2703 case NestedNameSpecifier::Global:
2704 // There is no meaningful transformation that one could perform on the
2705 // global scope.
2706 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2707 break;
2708
2709 case NestedNameSpecifier::TypeSpecWithTemplate:
2710 case NestedNameSpecifier::TypeSpec: {
2711 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2712 FirstQualifierInScope, SS);
2713
2714 if (!TL)
2715 return NestedNameSpecifierLoc();
2716
2717 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2718 (SemaRef.getLangOptions().CPlusPlus0x &&
2719 TL.getType()->isEnumeralType())) {
2720 assert(!TL.getType().hasLocalQualifiers() &&
2721 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002722 if (TL.getType()->isEnumeralType())
2723 SemaRef.Diag(TL.getBeginLoc(),
2724 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002725 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2726 Q.getLocalEndLoc());
2727 break;
2728 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002729 // If the nested-name-specifier is an invalid type def, don't emit an
2730 // error because a previous error should have already been emitted.
2731 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2732 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2733 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2734 << TL.getType() << SS.getRange();
2735 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002736 return NestedNameSpecifierLoc();
2737 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002738 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002739
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002740 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002741 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002742 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002743 }
2744
2745 // Don't rebuild the nested-name-specifier if we don't have to.
2746 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2747 !getDerived().AlwaysRebuild())
2748 return NNS;
2749
2750 // If we can re-use the source-location data from the original
2751 // nested-name-specifier, do so.
2752 if (SS.location_size() == NNS.getDataLength() &&
2753 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2754 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2755
2756 // Allocate new nested-name-specifier location information.
2757 return SS.getWithLocInContext(SemaRef.Context);
2758}
2759
2760template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002761DeclarationNameInfo
2762TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002763::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002764 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002765 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002766 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002767
2768 switch (Name.getNameKind()) {
2769 case DeclarationName::Identifier:
2770 case DeclarationName::ObjCZeroArgSelector:
2771 case DeclarationName::ObjCOneArgSelector:
2772 case DeclarationName::ObjCMultiArgSelector:
2773 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002774 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002775 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002776 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002777
Douglas Gregor81499bb2009-09-03 22:13:48 +00002778 case DeclarationName::CXXConstructorName:
2779 case DeclarationName::CXXDestructorName:
2780 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002781 TypeSourceInfo *NewTInfo;
2782 CanQualType NewCanTy;
2783 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002784 NewTInfo = getDerived().TransformType(OldTInfo);
2785 if (!NewTInfo)
2786 return DeclarationNameInfo();
2787 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002788 }
2789 else {
2790 NewTInfo = 0;
2791 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002792 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002793 if (NewT.isNull())
2794 return DeclarationNameInfo();
2795 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2796 }
Mike Stump1eb44332009-09-09 15:08:12 +00002797
Abramo Bagnara25777432010-08-11 22:01:17 +00002798 DeclarationName NewName
2799 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2800 NewCanTy);
2801 DeclarationNameInfo NewNameInfo(NameInfo);
2802 NewNameInfo.setName(NewName);
2803 NewNameInfo.setNamedTypeInfo(NewTInfo);
2804 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002805 }
Mike Stump1eb44332009-09-09 15:08:12 +00002806 }
2807
David Blaikieb219cfc2011-09-23 05:06:16 +00002808 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002809}
2810
2811template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002812TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002813TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2814 TemplateName Name,
2815 SourceLocation NameLoc,
2816 QualType ObjectType,
2817 NamedDecl *FirstQualifierInScope) {
2818 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2819 TemplateDecl *Template = QTN->getTemplateDecl();
2820 assert(Template && "qualified template name must refer to a template");
2821
2822 TemplateDecl *TransTemplate
2823 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2824 Template));
2825 if (!TransTemplate)
2826 return TemplateName();
2827
2828 if (!getDerived().AlwaysRebuild() &&
2829 SS.getScopeRep() == QTN->getQualifier() &&
2830 TransTemplate == Template)
2831 return Name;
2832
2833 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2834 TransTemplate);
2835 }
2836
2837 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2838 if (SS.getScopeRep()) {
2839 // These apply to the scope specifier, not the template.
2840 ObjectType = QualType();
2841 FirstQualifierInScope = 0;
2842 }
2843
2844 if (!getDerived().AlwaysRebuild() &&
2845 SS.getScopeRep() == DTN->getQualifier() &&
2846 ObjectType.isNull())
2847 return Name;
2848
2849 if (DTN->isIdentifier()) {
2850 return getDerived().RebuildTemplateName(SS,
2851 *DTN->getIdentifier(),
2852 NameLoc,
2853 ObjectType,
2854 FirstQualifierInScope);
2855 }
2856
2857 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2858 ObjectType);
2859 }
2860
2861 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2862 TemplateDecl *TransTemplate
2863 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2864 Template));
2865 if (!TransTemplate)
2866 return TemplateName();
2867
2868 if (!getDerived().AlwaysRebuild() &&
2869 TransTemplate == Template)
2870 return Name;
2871
2872 return TemplateName(TransTemplate);
2873 }
2874
2875 if (SubstTemplateTemplateParmPackStorage *SubstPack
2876 = Name.getAsSubstTemplateTemplateParmPack()) {
2877 TemplateTemplateParmDecl *TransParam
2878 = cast_or_null<TemplateTemplateParmDecl>(
2879 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2880 if (!TransParam)
2881 return TemplateName();
2882
2883 if (!getDerived().AlwaysRebuild() &&
2884 TransParam == SubstPack->getParameterPack())
2885 return Name;
2886
2887 return getDerived().RebuildTemplateName(TransParam,
2888 SubstPack->getArgumentPack());
2889 }
2890
2891 // These should be getting filtered out before they reach the AST.
2892 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002893}
2894
2895template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002896void TreeTransform<Derived>::InventTemplateArgumentLoc(
2897 const TemplateArgument &Arg,
2898 TemplateArgumentLoc &Output) {
2899 SourceLocation Loc = getDerived().getBaseLocation();
2900 switch (Arg.getKind()) {
2901 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002902 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002903 break;
2904
2905 case TemplateArgument::Type:
2906 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002907 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002908
John McCall833ca992009-10-29 08:12:44 +00002909 break;
2910
Douglas Gregor788cd062009-11-11 01:00:40 +00002911 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002912 case TemplateArgument::TemplateExpansion: {
2913 NestedNameSpecifierLocBuilder Builder;
2914 TemplateName Template = Arg.getAsTemplate();
2915 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2916 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2917 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2918 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2919
2920 if (Arg.getKind() == TemplateArgument::Template)
2921 Output = TemplateArgumentLoc(Arg,
2922 Builder.getWithLocInContext(SemaRef.Context),
2923 Loc);
2924 else
2925 Output = TemplateArgumentLoc(Arg,
2926 Builder.getWithLocInContext(SemaRef.Context),
2927 Loc, Loc);
2928
Douglas Gregor788cd062009-11-11 01:00:40 +00002929 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002930 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002931
John McCall833ca992009-10-29 08:12:44 +00002932 case TemplateArgument::Expression:
2933 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2934 break;
2935
2936 case TemplateArgument::Declaration:
2937 case TemplateArgument::Integral:
2938 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002939 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002940 break;
2941 }
2942}
2943
2944template<typename Derived>
2945bool TreeTransform<Derived>::TransformTemplateArgument(
2946 const TemplateArgumentLoc &Input,
2947 TemplateArgumentLoc &Output) {
2948 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002949 switch (Arg.getKind()) {
2950 case TemplateArgument::Null:
2951 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002952 Output = Input;
2953 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002954
Douglas Gregor670444e2009-08-04 22:27:00 +00002955 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002956 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002957 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002958 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002959
2960 DI = getDerived().TransformType(DI);
2961 if (!DI) return true;
2962
2963 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2964 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002965 }
Mike Stump1eb44332009-09-09 15:08:12 +00002966
Douglas Gregor670444e2009-08-04 22:27:00 +00002967 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002968 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002969 DeclarationName Name;
2970 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2971 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002972 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002973 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002974 if (!D) return true;
2975
John McCall828bff22009-10-29 18:45:58 +00002976 Expr *SourceExpr = Input.getSourceDeclExpression();
2977 if (SourceExpr) {
2978 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002979 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002980 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00002981 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00002982 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002983 }
2984
2985 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002986 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002987 }
Mike Stump1eb44332009-09-09 15:08:12 +00002988
Douglas Gregor788cd062009-11-11 01:00:40 +00002989 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002990 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2991 if (QualifierLoc) {
2992 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2993 if (!QualifierLoc)
2994 return true;
2995 }
2996
Douglas Gregor1d752d72011-03-02 18:46:51 +00002997 CXXScopeSpec SS;
2998 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002999 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003000 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3001 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003002 if (Template.isNull())
3003 return true;
Sean Huntc3021132010-05-05 15:23:54 +00003004
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003005 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003006 Input.getTemplateNameLoc());
3007 return false;
3008 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003009
3010 case TemplateArgument::TemplateExpansion:
3011 llvm_unreachable("Caller should expand pack expansions");
3012
Douglas Gregor670444e2009-08-04 22:27:00 +00003013 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003014 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003015 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003016 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003017
John McCall833ca992009-10-29 08:12:44 +00003018 Expr *InputExpr = Input.getSourceExpression();
3019 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3020
Chris Lattner223de242011-04-25 20:37:58 +00003021 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003022 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003023 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003024 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003025 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003026 }
Mike Stump1eb44332009-09-09 15:08:12 +00003027
Douglas Gregor670444e2009-08-04 22:27:00 +00003028 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003029 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003030 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003031 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003032 AEnd = Arg.pack_end();
3033 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003034
John McCall833ca992009-10-29 08:12:44 +00003035 // FIXME: preserve source information here when we start
3036 // caring about parameter packs.
3037
John McCall828bff22009-10-29 18:45:58 +00003038 TemplateArgumentLoc InputArg;
3039 TemplateArgumentLoc OutputArg;
3040 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3041 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003042 return true;
3043
John McCall828bff22009-10-29 18:45:58 +00003044 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003045 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003046
3047 TemplateArgument *TransformedArgsPtr
3048 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3049 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3050 TransformedArgsPtr);
3051 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3052 TransformedArgs.size()),
3053 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003054 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003055 }
3056 }
Mike Stump1eb44332009-09-09 15:08:12 +00003057
Douglas Gregor670444e2009-08-04 22:27:00 +00003058 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003059 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003060}
3061
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003062/// \brief Iterator adaptor that invents template argument location information
3063/// for each of the template arguments in its underlying iterator.
3064template<typename Derived, typename InputIterator>
3065class TemplateArgumentLocInventIterator {
3066 TreeTransform<Derived> &Self;
3067 InputIterator Iter;
3068
3069public:
3070 typedef TemplateArgumentLoc value_type;
3071 typedef TemplateArgumentLoc reference;
3072 typedef typename std::iterator_traits<InputIterator>::difference_type
3073 difference_type;
3074 typedef std::input_iterator_tag iterator_category;
3075
3076 class pointer {
3077 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003078
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003079 public:
3080 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3081
3082 const TemplateArgumentLoc *operator->() const { return &Arg; }
3083 };
3084
3085 TemplateArgumentLocInventIterator() { }
3086
3087 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3088 InputIterator Iter)
3089 : Self(Self), Iter(Iter) { }
3090
3091 TemplateArgumentLocInventIterator &operator++() {
3092 ++Iter;
3093 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003094 }
3095
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003096 TemplateArgumentLocInventIterator operator++(int) {
3097 TemplateArgumentLocInventIterator Old(*this);
3098 ++(*this);
3099 return Old;
3100 }
3101
3102 reference operator*() const {
3103 TemplateArgumentLoc Result;
3104 Self.InventTemplateArgumentLoc(*Iter, Result);
3105 return Result;
3106 }
3107
3108 pointer operator->() const { return pointer(**this); }
3109
3110 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3111 const TemplateArgumentLocInventIterator &Y) {
3112 return X.Iter == Y.Iter;
3113 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003114
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003115 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3116 const TemplateArgumentLocInventIterator &Y) {
3117 return X.Iter != Y.Iter;
3118 }
3119};
3120
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003121template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003122template<typename InputIterator>
3123bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3124 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003125 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003126 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003127 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003128 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003129
3130 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3131 // Unpack argument packs, which we translate them into separate
3132 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003133 // FIXME: We could do much better if we could guarantee that the
3134 // TemplateArgumentLocInfo for the pack expansion would be usable for
3135 // all of the template arguments in the argument pack.
3136 typedef TemplateArgumentLocInventIterator<Derived,
3137 TemplateArgument::pack_iterator>
3138 PackLocIterator;
3139 if (TransformTemplateArguments(PackLocIterator(*this,
3140 In.getArgument().pack_begin()),
3141 PackLocIterator(*this,
3142 In.getArgument().pack_end()),
3143 Outputs))
3144 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003145
3146 continue;
3147 }
3148
3149 if (In.getArgument().isPackExpansion()) {
3150 // We have a pack expansion, for which we will be substituting into
3151 // the pattern.
3152 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003153 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003154 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003155 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3156 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003157
Chris Lattner686775d2011-07-20 06:58:45 +00003158 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003159 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3160 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3161
3162 // Determine whether the set of unexpanded parameter packs can and should
3163 // be expanded.
3164 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003165 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003166 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003167 if (getDerived().TryExpandParameterPacks(Ellipsis,
3168 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003169 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003170 Expand,
3171 RetainExpansion,
3172 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003173 return true;
3174
3175 if (!Expand) {
3176 // The transform has determined that we should perform a simple
3177 // transformation on the pack expansion, producing another pack
3178 // expansion.
3179 TemplateArgumentLoc OutPattern;
3180 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3181 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3182 return true;
3183
Douglas Gregorcded4f62011-01-14 17:04:44 +00003184 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3185 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003186 if (Out.getArgument().isNull())
3187 return true;
3188
3189 Outputs.addArgument(Out);
3190 continue;
3191 }
3192
3193 // The transform has determined that we should perform an elementwise
3194 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003195 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003196 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3197
3198 if (getDerived().TransformTemplateArgument(Pattern, Out))
3199 return true;
3200
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003201 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003202 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3203 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003204 if (Out.getArgument().isNull())
3205 return true;
3206 }
3207
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003208 Outputs.addArgument(Out);
3209 }
3210
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003211 // If we're supposed to retain a pack expansion, do so by temporarily
3212 // forgetting the partially-substituted parameter pack.
3213 if (RetainExpansion) {
3214 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3215
3216 if (getDerived().TransformTemplateArgument(Pattern, Out))
3217 return true;
3218
Douglas Gregorcded4f62011-01-14 17:04:44 +00003219 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3220 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003221 if (Out.getArgument().isNull())
3222 return true;
3223
3224 Outputs.addArgument(Out);
3225 }
Douglas Gregord3731192011-01-10 07:32:04 +00003226
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003227 continue;
3228 }
3229
3230 // The simple case:
3231 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003232 return true;
3233
3234 Outputs.addArgument(Out);
3235 }
3236
3237 return false;
3238
3239}
3240
Douglas Gregor577f75a2009-08-04 16:50:30 +00003241//===----------------------------------------------------------------------===//
3242// Type transformation
3243//===----------------------------------------------------------------------===//
3244
3245template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003246QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003247 if (getDerived().AlreadyTransformed(T))
3248 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003249
John McCalla2becad2009-10-21 00:40:46 +00003250 // Temporary workaround. All of these transformations should
3251 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003252 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3253 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003254
John McCall43fed0d2010-11-12 08:19:04 +00003255 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003256
John McCalla2becad2009-10-21 00:40:46 +00003257 if (!NewDI)
3258 return QualType();
3259
3260 return NewDI->getType();
3261}
3262
3263template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003264TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003265 // Refine the base location to the type's location.
3266 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3267 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003268 if (getDerived().AlreadyTransformed(DI->getType()))
3269 return DI;
3270
3271 TypeLocBuilder TLB;
3272
3273 TypeLoc TL = DI->getTypeLoc();
3274 TLB.reserve(TL.getFullDataSize());
3275
John McCall43fed0d2010-11-12 08:19:04 +00003276 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003277 if (Result.isNull())
3278 return 0;
3279
John McCalla93c9342009-12-07 02:54:59 +00003280 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003281}
3282
3283template<typename Derived>
3284QualType
John McCall43fed0d2010-11-12 08:19:04 +00003285TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003286 switch (T.getTypeLocClass()) {
3287#define ABSTRACT_TYPELOC(CLASS, PARENT)
3288#define TYPELOC(CLASS, PARENT) \
3289 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003290 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003291#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003292 }
Mike Stump1eb44332009-09-09 15:08:12 +00003293
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003294 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003295}
3296
3297/// FIXME: By default, this routine adds type qualifiers only to types
3298/// that can have qualifiers, and silently suppresses those qualifiers
3299/// that are not permitted (e.g., qualifiers on reference or function
3300/// types). This is the right thing for template instantiation, but
3301/// probably not for other clients.
3302template<typename Derived>
3303QualType
3304TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003305 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003306 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003307
John McCall43fed0d2010-11-12 08:19:04 +00003308 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003309 if (Result.isNull())
3310 return QualType();
3311
3312 // Silently suppress qualifiers if the result type can't be qualified.
3313 // FIXME: this is the right thing for template instantiation, but
3314 // probably not for other clients.
3315 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003316 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003317
John McCallf85e1932011-06-15 23:02:42 +00003318 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003319 // resulting type.
3320 if (Quals.hasObjCLifetime()) {
3321 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3322 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003323 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003324 // Objective-C ARC:
3325 // A lifetime qualifier applied to a substituted template parameter
3326 // overrides the lifetime qualifier from the template argument.
3327 if (const SubstTemplateTypeParmType *SubstTypeParam
3328 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3329 QualType Replacement = SubstTypeParam->getReplacementType();
3330 Qualifiers Qs = Replacement.getQualifiers();
3331 Qs.removeObjCLifetime();
3332 Replacement
3333 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3334 Qs);
3335 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3336 SubstTypeParam->getReplacedParameter(),
3337 Replacement);
3338 TLB.TypeWasModifiedSafely(Result);
3339 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003340 // Otherwise, complain about the addition of a qualifier to an
3341 // already-qualified type.
3342 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003343 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003344 << Result << R;
3345
Douglas Gregore559ca12011-06-17 22:11:49 +00003346 Quals.removeObjCLifetime();
3347 }
3348 }
3349 }
John McCall28654742010-06-05 06:41:15 +00003350 if (!Quals.empty()) {
3351 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3352 TLB.push<QualifiedTypeLoc>(Result);
3353 // No location information to preserve.
3354 }
John McCalla2becad2009-10-21 00:40:46 +00003355
3356 return Result;
3357}
3358
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003359template<typename Derived>
3360TypeLoc
3361TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3362 QualType ObjectType,
3363 NamedDecl *UnqualLookup,
3364 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003365 QualType T = TL.getType();
3366 if (getDerived().AlreadyTransformed(T))
3367 return TL;
3368
3369 TypeLocBuilder TLB;
3370 QualType Result;
3371
3372 if (isa<TemplateSpecializationType>(T)) {
3373 TemplateSpecializationTypeLoc SpecTL
3374 = cast<TemplateSpecializationTypeLoc>(TL);
3375
3376 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003377 getDerived().TransformTemplateName(SS,
3378 SpecTL.getTypePtr()->getTemplateName(),
3379 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003380 ObjectType, UnqualLookup);
3381 if (Template.isNull())
3382 return TypeLoc();
3383
3384 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3385 Template);
3386 } else if (isa<DependentTemplateSpecializationType>(T)) {
3387 DependentTemplateSpecializationTypeLoc SpecTL
3388 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3389
Douglas Gregora88f09f2011-02-28 17:23:35 +00003390 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003391 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003392 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003393 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003394 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003395 if (Template.isNull())
3396 return TypeLoc();
3397
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003398 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003399 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003400 Template,
3401 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003402 } else {
3403 // Nothing special needs to be done for these.
3404 Result = getDerived().TransformType(TLB, TL);
3405 }
3406
3407 if (Result.isNull())
3408 return TypeLoc();
3409
3410 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3411}
3412
Douglas Gregorb71d8212011-03-02 18:32:08 +00003413template<typename Derived>
3414TypeSourceInfo *
3415TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3416 QualType ObjectType,
3417 NamedDecl *UnqualLookup,
3418 CXXScopeSpec &SS) {
3419 // FIXME: Painfully copy-paste from the above!
3420
3421 QualType T = TSInfo->getType();
3422 if (getDerived().AlreadyTransformed(T))
3423 return TSInfo;
3424
3425 TypeLocBuilder TLB;
3426 QualType Result;
3427
3428 TypeLoc TL = TSInfo->getTypeLoc();
3429 if (isa<TemplateSpecializationType>(T)) {
3430 TemplateSpecializationTypeLoc SpecTL
3431 = cast<TemplateSpecializationTypeLoc>(TL);
3432
3433 TemplateName Template
3434 = getDerived().TransformTemplateName(SS,
3435 SpecTL.getTypePtr()->getTemplateName(),
3436 SpecTL.getTemplateNameLoc(),
3437 ObjectType, UnqualLookup);
3438 if (Template.isNull())
3439 return 0;
3440
3441 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3442 Template);
3443 } else if (isa<DependentTemplateSpecializationType>(T)) {
3444 DependentTemplateSpecializationTypeLoc SpecTL
3445 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3446
3447 TemplateName Template
3448 = getDerived().RebuildTemplateName(SS,
3449 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003450 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003451 ObjectType, UnqualLookup);
3452 if (Template.isNull())
3453 return 0;
3454
3455 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3456 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003457 Template,
3458 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003459 } else {
3460 // Nothing special needs to be done for these.
3461 Result = getDerived().TransformType(TLB, TL);
3462 }
3463
3464 if (Result.isNull())
3465 return 0;
3466
3467 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3468}
3469
John McCalla2becad2009-10-21 00:40:46 +00003470template <class TyLoc> static inline
3471QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3472 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3473 NewT.setNameLoc(T.getNameLoc());
3474 return T.getType();
3475}
3476
John McCalla2becad2009-10-21 00:40:46 +00003477template<typename Derived>
3478QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003479 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003480 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3481 NewT.setBuiltinLoc(T.getBuiltinLoc());
3482 if (T.needsExtraLocalData())
3483 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3484 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003485}
Mike Stump1eb44332009-09-09 15:08:12 +00003486
Douglas Gregor577f75a2009-08-04 16:50:30 +00003487template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003488QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003489 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003490 // FIXME: recurse?
3491 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003492}
Mike Stump1eb44332009-09-09 15:08:12 +00003493
Douglas Gregor577f75a2009-08-04 16:50:30 +00003494template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003495QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003496 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003497 QualType PointeeType
3498 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003499 if (PointeeType.isNull())
3500 return QualType();
3501
3502 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003503 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003504 // A dependent pointer type 'T *' has is being transformed such
3505 // that an Objective-C class type is being replaced for 'T'. The
3506 // resulting pointer type is an ObjCObjectPointerType, not a
3507 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003508 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003509
John McCallc12c5bb2010-05-15 11:32:37 +00003510 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3511 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003512 return Result;
3513 }
John McCall43fed0d2010-11-12 08:19:04 +00003514
Douglas Gregor92e986e2010-04-22 16:44:27 +00003515 if (getDerived().AlwaysRebuild() ||
3516 PointeeType != TL.getPointeeLoc().getType()) {
3517 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3518 if (Result.isNull())
3519 return QualType();
3520 }
John McCallf85e1932011-06-15 23:02:42 +00003521
3522 // Objective-C ARC can add lifetime qualifiers to the type that we're
3523 // pointing to.
3524 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3525
Douglas Gregor92e986e2010-04-22 16:44:27 +00003526 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3527 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003528 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003529}
Mike Stump1eb44332009-09-09 15:08:12 +00003530
3531template<typename Derived>
3532QualType
John McCalla2becad2009-10-21 00:40:46 +00003533TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003534 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003535 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003536 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3537 if (PointeeType.isNull())
3538 return QualType();
3539
3540 QualType Result = TL.getType();
3541 if (getDerived().AlwaysRebuild() ||
3542 PointeeType != TL.getPointeeLoc().getType()) {
3543 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003544 TL.getSigilLoc());
3545 if (Result.isNull())
3546 return QualType();
3547 }
3548
Douglas Gregor39968ad2010-04-22 16:50:51 +00003549 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003550 NewT.setSigilLoc(TL.getSigilLoc());
3551 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003552}
3553
John McCall85737a72009-10-30 00:06:24 +00003554/// Transforms a reference type. Note that somewhat paradoxically we
3555/// don't care whether the type itself is an l-value type or an r-value
3556/// type; we only care if the type was *written* as an l-value type
3557/// or an r-value type.
3558template<typename Derived>
3559QualType
3560TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003561 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003562 const ReferenceType *T = TL.getTypePtr();
3563
3564 // Note that this works with the pointee-as-written.
3565 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3566 if (PointeeType.isNull())
3567 return QualType();
3568
3569 QualType Result = TL.getType();
3570 if (getDerived().AlwaysRebuild() ||
3571 PointeeType != T->getPointeeTypeAsWritten()) {
3572 Result = getDerived().RebuildReferenceType(PointeeType,
3573 T->isSpelledAsLValue(),
3574 TL.getSigilLoc());
3575 if (Result.isNull())
3576 return QualType();
3577 }
3578
John McCallf85e1932011-06-15 23:02:42 +00003579 // Objective-C ARC can add lifetime qualifiers to the type that we're
3580 // referring to.
3581 TLB.TypeWasModifiedSafely(
3582 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3583
John McCall85737a72009-10-30 00:06:24 +00003584 // r-value references can be rebuilt as l-value references.
3585 ReferenceTypeLoc NewTL;
3586 if (isa<LValueReferenceType>(Result))
3587 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3588 else
3589 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3590 NewTL.setSigilLoc(TL.getSigilLoc());
3591
3592 return Result;
3593}
3594
Mike Stump1eb44332009-09-09 15:08:12 +00003595template<typename Derived>
3596QualType
John McCalla2becad2009-10-21 00:40:46 +00003597TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003598 LValueReferenceTypeLoc TL) {
3599 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003600}
3601
Mike Stump1eb44332009-09-09 15:08:12 +00003602template<typename Derived>
3603QualType
John McCalla2becad2009-10-21 00:40:46 +00003604TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003605 RValueReferenceTypeLoc TL) {
3606 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003607}
Mike Stump1eb44332009-09-09 15:08:12 +00003608
Douglas Gregor577f75a2009-08-04 16:50:30 +00003609template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003610QualType
John McCalla2becad2009-10-21 00:40:46 +00003611TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003612 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003613 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003614 if (PointeeType.isNull())
3615 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003616
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003617 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3618 TypeSourceInfo* NewClsTInfo = 0;
3619 if (OldClsTInfo) {
3620 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3621 if (!NewClsTInfo)
3622 return QualType();
3623 }
3624
3625 const MemberPointerType *T = TL.getTypePtr();
3626 QualType OldClsType = QualType(T->getClass(), 0);
3627 QualType NewClsType;
3628 if (NewClsTInfo)
3629 NewClsType = NewClsTInfo->getType();
3630 else {
3631 NewClsType = getDerived().TransformType(OldClsType);
3632 if (NewClsType.isNull())
3633 return QualType();
3634 }
Mike Stump1eb44332009-09-09 15:08:12 +00003635
John McCalla2becad2009-10-21 00:40:46 +00003636 QualType Result = TL.getType();
3637 if (getDerived().AlwaysRebuild() ||
3638 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003639 NewClsType != OldClsType) {
3640 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003641 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003642 if (Result.isNull())
3643 return QualType();
3644 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003645
John McCalla2becad2009-10-21 00:40:46 +00003646 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3647 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003648 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003649
3650 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003651}
3652
Mike Stump1eb44332009-09-09 15:08:12 +00003653template<typename Derived>
3654QualType
John McCalla2becad2009-10-21 00:40:46 +00003655TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003656 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003657 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003658 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003659 if (ElementType.isNull())
3660 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003661
John McCalla2becad2009-10-21 00:40:46 +00003662 QualType Result = TL.getType();
3663 if (getDerived().AlwaysRebuild() ||
3664 ElementType != T->getElementType()) {
3665 Result = getDerived().RebuildConstantArrayType(ElementType,
3666 T->getSizeModifier(),
3667 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003668 T->getIndexTypeCVRQualifiers(),
3669 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003670 if (Result.isNull())
3671 return QualType();
3672 }
Eli Friedman457a3772012-01-25 22:19:07 +00003673
3674 // We might have either a ConstantArrayType or a VariableArrayType now:
3675 // a ConstantArrayType is allowed to have an element type which is a
3676 // VariableArrayType if the type is dependent. Fortunately, all array
3677 // types have the same location layout.
3678 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003679 NewTL.setLBracketLoc(TL.getLBracketLoc());
3680 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003681
John McCalla2becad2009-10-21 00:40:46 +00003682 Expr *Size = TL.getSizeExpr();
3683 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003684 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3685 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003686 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003687 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003688 }
3689 NewTL.setSizeExpr(Size);
3690
3691 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003692}
Mike Stump1eb44332009-09-09 15:08:12 +00003693
Douglas Gregor577f75a2009-08-04 16:50:30 +00003694template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003695QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003696 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003697 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003698 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003699 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003700 if (ElementType.isNull())
3701 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003702
John McCalla2becad2009-10-21 00:40:46 +00003703 QualType Result = TL.getType();
3704 if (getDerived().AlwaysRebuild() ||
3705 ElementType != T->getElementType()) {
3706 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003707 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003708 T->getIndexTypeCVRQualifiers(),
3709 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003710 if (Result.isNull())
3711 return QualType();
3712 }
Sean Huntc3021132010-05-05 15:23:54 +00003713
John McCalla2becad2009-10-21 00:40:46 +00003714 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3715 NewTL.setLBracketLoc(TL.getLBracketLoc());
3716 NewTL.setRBracketLoc(TL.getRBracketLoc());
3717 NewTL.setSizeExpr(0);
3718
3719 return Result;
3720}
3721
3722template<typename Derived>
3723QualType
3724TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003725 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003726 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003727 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3728 if (ElementType.isNull())
3729 return QualType();
3730
John McCall60d7b3a2010-08-24 06:29:42 +00003731 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003732 = getDerived().TransformExpr(T->getSizeExpr());
3733 if (SizeResult.isInvalid())
3734 return QualType();
3735
John McCall9ae2f072010-08-23 23:25:46 +00003736 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003737
3738 QualType Result = TL.getType();
3739 if (getDerived().AlwaysRebuild() ||
3740 ElementType != T->getElementType() ||
3741 Size != T->getSizeExpr()) {
3742 Result = getDerived().RebuildVariableArrayType(ElementType,
3743 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003744 Size,
John McCalla2becad2009-10-21 00:40:46 +00003745 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003746 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003747 if (Result.isNull())
3748 return QualType();
3749 }
Sean Huntc3021132010-05-05 15:23:54 +00003750
John McCalla2becad2009-10-21 00:40:46 +00003751 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3752 NewTL.setLBracketLoc(TL.getLBracketLoc());
3753 NewTL.setRBracketLoc(TL.getRBracketLoc());
3754 NewTL.setSizeExpr(Size);
3755
3756 return Result;
3757}
3758
3759template<typename Derived>
3760QualType
3761TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003762 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003763 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003764 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3765 if (ElementType.isNull())
3766 return QualType();
3767
Richard Smithf6702a32011-12-20 02:08:33 +00003768 // Array bounds are constant expressions.
3769 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3770 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003771
John McCall3b657512011-01-19 10:06:00 +00003772 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3773 Expr *origSize = TL.getSizeExpr();
3774 if (!origSize) origSize = T->getSizeExpr();
3775
3776 ExprResult sizeResult
3777 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003778 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003779 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003780 return QualType();
3781
John McCall3b657512011-01-19 10:06:00 +00003782 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003783
3784 QualType Result = TL.getType();
3785 if (getDerived().AlwaysRebuild() ||
3786 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003787 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003788 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3789 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003790 size,
John McCalla2becad2009-10-21 00:40:46 +00003791 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003792 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003793 if (Result.isNull())
3794 return QualType();
3795 }
John McCalla2becad2009-10-21 00:40:46 +00003796
3797 // We might have any sort of array type now, but fortunately they
3798 // all have the same location layout.
3799 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3800 NewTL.setLBracketLoc(TL.getLBracketLoc());
3801 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003802 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003803
3804 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003805}
Mike Stump1eb44332009-09-09 15:08:12 +00003806
3807template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003808QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003809 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003810 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003811 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003812
3813 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003814 QualType ElementType = getDerived().TransformType(T->getElementType());
3815 if (ElementType.isNull())
3816 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003817
Richard Smithf6702a32011-12-20 02:08:33 +00003818 // Vector sizes are constant expressions.
3819 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3820 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003821
John McCall60d7b3a2010-08-24 06:29:42 +00003822 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003823 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003824 if (Size.isInvalid())
3825 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003826
John McCalla2becad2009-10-21 00:40:46 +00003827 QualType Result = TL.getType();
3828 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003829 ElementType != T->getElementType() ||
3830 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003831 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003832 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003833 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003834 if (Result.isNull())
3835 return QualType();
3836 }
John McCalla2becad2009-10-21 00:40:46 +00003837
3838 // Result might be dependent or not.
3839 if (isa<DependentSizedExtVectorType>(Result)) {
3840 DependentSizedExtVectorTypeLoc NewTL
3841 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3842 NewTL.setNameLoc(TL.getNameLoc());
3843 } else {
3844 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3845 NewTL.setNameLoc(TL.getNameLoc());
3846 }
3847
3848 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003849}
Mike Stump1eb44332009-09-09 15:08:12 +00003850
3851template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003852QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003853 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003854 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003855 QualType ElementType = getDerived().TransformType(T->getElementType());
3856 if (ElementType.isNull())
3857 return QualType();
3858
John McCalla2becad2009-10-21 00:40:46 +00003859 QualType Result = TL.getType();
3860 if (getDerived().AlwaysRebuild() ||
3861 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003862 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003863 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003864 if (Result.isNull())
3865 return QualType();
3866 }
Sean Huntc3021132010-05-05 15:23:54 +00003867
John McCalla2becad2009-10-21 00:40:46 +00003868 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3869 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003870
John McCalla2becad2009-10-21 00:40:46 +00003871 return Result;
3872}
3873
3874template<typename Derived>
3875QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003876 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003877 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003878 QualType ElementType = getDerived().TransformType(T->getElementType());
3879 if (ElementType.isNull())
3880 return QualType();
3881
3882 QualType Result = TL.getType();
3883 if (getDerived().AlwaysRebuild() ||
3884 ElementType != T->getElementType()) {
3885 Result = getDerived().RebuildExtVectorType(ElementType,
3886 T->getNumElements(),
3887 /*FIXME*/ SourceLocation());
3888 if (Result.isNull())
3889 return QualType();
3890 }
Sean Huntc3021132010-05-05 15:23:54 +00003891
John McCalla2becad2009-10-21 00:40:46 +00003892 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3893 NewTL.setNameLoc(TL.getNameLoc());
3894
3895 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003896}
Mike Stump1eb44332009-09-09 15:08:12 +00003897
3898template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003899ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003900TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003901 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003902 llvm::Optional<unsigned> NumExpansions,
3903 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003904 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003905 TypeSourceInfo *NewDI = 0;
3906
3907 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3908 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003909 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003910 TypeLoc OldTL = OldDI->getTypeLoc();
3911 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3912
3913 TypeLocBuilder TLB;
3914 TypeLoc NewTL = OldDI->getTypeLoc();
3915 TLB.reserve(NewTL.getFullDataSize());
3916
3917 QualType Result = getDerived().TransformType(TLB,
3918 OldExpansionTL.getPatternLoc());
3919 if (Result.isNull())
3920 return 0;
3921
3922 Result = RebuildPackExpansionType(Result,
3923 OldExpansionTL.getPatternLoc().getSourceRange(),
3924 OldExpansionTL.getEllipsisLoc(),
3925 NumExpansions);
3926 if (Result.isNull())
3927 return 0;
3928
3929 PackExpansionTypeLoc NewExpansionTL
3930 = TLB.push<PackExpansionTypeLoc>(Result);
3931 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3932 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3933 } else
3934 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003935 if (!NewDI)
3936 return 0;
3937
John McCallfb44de92011-05-01 22:35:37 +00003938 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003939 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003940
3941 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3942 OldParm->getDeclContext(),
3943 OldParm->getInnerLocStart(),
3944 OldParm->getLocation(),
3945 OldParm->getIdentifier(),
3946 NewDI->getType(),
3947 NewDI,
3948 OldParm->getStorageClass(),
3949 OldParm->getStorageClassAsWritten(),
3950 /* DefArg */ NULL);
3951 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3952 OldParm->getFunctionScopeIndex() + indexAdjustment);
3953 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003954}
3955
3956template<typename Derived>
3957bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003958 TransformFunctionTypeParams(SourceLocation Loc,
3959 ParmVarDecl **Params, unsigned NumParams,
3960 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003961 SmallVectorImpl<QualType> &OutParamTypes,
3962 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003963 int indexAdjustment = 0;
3964
Douglas Gregora009b592011-01-07 00:20:55 +00003965 for (unsigned i = 0; i != NumParams; ++i) {
3966 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003967 assert(OldParm->getFunctionScopeIndex() == i);
3968
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003969 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003970 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003971 if (OldParm->isParameterPack()) {
3972 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003973 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003974
Douglas Gregor603cfb42011-01-05 23:12:31 +00003975 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003976 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3977 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3978 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3979 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003980 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3981
Douglas Gregor603cfb42011-01-05 23:12:31 +00003982 // Determine whether we should expand the parameter packs.
3983 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003984 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003985 llvm::Optional<unsigned> OrigNumExpansions
3986 = ExpansionTL.getTypePtr()->getNumExpansions();
3987 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003988 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3989 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003990 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003991 ShouldExpand,
3992 RetainExpansion,
3993 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003994 return true;
3995 }
3996
3997 if (ShouldExpand) {
3998 // Expand the function parameter pack into multiple, separate
3999 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004000 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004001 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004002 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4003 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004004 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004005 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004006 OrigNumExpansions,
4007 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004008 if (!NewParm)
4009 return true;
4010
Douglas Gregora009b592011-01-07 00:20:55 +00004011 OutParamTypes.push_back(NewParm->getType());
4012 if (PVars)
4013 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004014 }
Douglas Gregord3731192011-01-10 07:32:04 +00004015
4016 // If we're supposed to retain a pack expansion, do so by temporarily
4017 // forgetting the partially-substituted parameter pack.
4018 if (RetainExpansion) {
4019 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4020 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004021 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004022 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004023 OrigNumExpansions,
4024 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004025 if (!NewParm)
4026 return true;
4027
4028 OutParamTypes.push_back(NewParm->getType());
4029 if (PVars)
4030 PVars->push_back(NewParm);
4031 }
4032
John McCallfb44de92011-05-01 22:35:37 +00004033 // The next parameter should have the same adjustment as the
4034 // last thing we pushed, but we post-incremented indexAdjustment
4035 // on every push. Also, if we push nothing, the adjustment should
4036 // go down by one.
4037 indexAdjustment--;
4038
Douglas Gregor603cfb42011-01-05 23:12:31 +00004039 // We're done with the pack expansion.
4040 continue;
4041 }
4042
4043 // We'll substitute the parameter now without expanding the pack
4044 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004045 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4046 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004047 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004048 NumExpansions,
4049 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004050 } else {
4051 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004052 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004053 llvm::Optional<unsigned>(),
4054 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004055 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004056
John McCall21ef0fa2010-03-11 09:03:00 +00004057 if (!NewParm)
4058 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004059
Douglas Gregora009b592011-01-07 00:20:55 +00004060 OutParamTypes.push_back(NewParm->getType());
4061 if (PVars)
4062 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004063 continue;
4064 }
John McCall21ef0fa2010-03-11 09:03:00 +00004065
4066 // Deal with the possibility that we don't have a parameter
4067 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004068 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004069 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004070 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004071 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004072 if (const PackExpansionType *Expansion
4073 = dyn_cast<PackExpansionType>(OldType)) {
4074 // We have a function parameter pack that may need to be expanded.
4075 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004076 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004077 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4078
4079 // Determine whether we should expand the parameter packs.
4080 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004081 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004082 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004083 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004084 ShouldExpand,
4085 RetainExpansion,
4086 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004087 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004088 }
4089
4090 if (ShouldExpand) {
4091 // Expand the function parameter pack into multiple, separate
4092 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004093 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004094 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4095 QualType NewType = getDerived().TransformType(Pattern);
4096 if (NewType.isNull())
4097 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004098
Douglas Gregora009b592011-01-07 00:20:55 +00004099 OutParamTypes.push_back(NewType);
4100 if (PVars)
4101 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004102 }
4103
4104 // We're done with the pack expansion.
4105 continue;
4106 }
4107
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004108 // If we're supposed to retain a pack expansion, do so by temporarily
4109 // forgetting the partially-substituted parameter pack.
4110 if (RetainExpansion) {
4111 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4112 QualType NewType = getDerived().TransformType(Pattern);
4113 if (NewType.isNull())
4114 return true;
4115
4116 OutParamTypes.push_back(NewType);
4117 if (PVars)
4118 PVars->push_back(0);
4119 }
Douglas Gregord3731192011-01-10 07:32:04 +00004120
Douglas Gregor603cfb42011-01-05 23:12:31 +00004121 // We'll substitute the parameter now without expanding the pack
4122 // expansion.
4123 OldType = Expansion->getPattern();
4124 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004125 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4126 NewType = getDerived().TransformType(OldType);
4127 } else {
4128 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004129 }
4130
Douglas Gregor603cfb42011-01-05 23:12:31 +00004131 if (NewType.isNull())
4132 return true;
4133
4134 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004135 NewType = getSema().Context.getPackExpansionType(NewType,
4136 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004137
Douglas Gregora009b592011-01-07 00:20:55 +00004138 OutParamTypes.push_back(NewType);
4139 if (PVars)
4140 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004141 }
4142
John McCallfb44de92011-05-01 22:35:37 +00004143#ifndef NDEBUG
4144 if (PVars) {
4145 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4146 if (ParmVarDecl *parm = (*PVars)[i])
4147 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004148 }
John McCallfb44de92011-05-01 22:35:37 +00004149#endif
4150
4151 return false;
4152}
John McCall21ef0fa2010-03-11 09:03:00 +00004153
4154template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004155QualType
John McCalla2becad2009-10-21 00:40:46 +00004156TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004157 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004158 // Transform the parameters and return type.
4159 //
4160 // We instantiate in source order, with the return type first followed by
4161 // the parameters, because users tend to expect this (even if they shouldn't
4162 // rely on it!).
4163 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004164 // When the function has a trailing return type, we instantiate the
4165 // parameters before the return type, since the return type can then refer
4166 // to the parameters themselves (via decltype, sizeof, etc.).
4167 //
Chris Lattner686775d2011-07-20 06:58:45 +00004168 SmallVector<QualType, 4> ParamTypes;
4169 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004170 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004171
Douglas Gregordab60ad2010-10-01 18:44:50 +00004172 QualType ResultType;
4173
4174 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004175 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4176 TL.getParmArray(),
4177 TL.getNumArgs(),
4178 TL.getTypePtr()->arg_type_begin(),
4179 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004180 return QualType();
4181
4182 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4183 if (ResultType.isNull())
4184 return QualType();
4185 }
4186 else {
4187 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4188 if (ResultType.isNull())
4189 return QualType();
4190
Douglas Gregora009b592011-01-07 00:20:55 +00004191 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4192 TL.getParmArray(),
4193 TL.getNumArgs(),
4194 TL.getTypePtr()->arg_type_begin(),
4195 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004196 return QualType();
4197 }
4198
John McCalla2becad2009-10-21 00:40:46 +00004199 QualType Result = TL.getType();
4200 if (getDerived().AlwaysRebuild() ||
4201 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004202 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004203 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4204 Result = getDerived().RebuildFunctionProtoType(ResultType,
4205 ParamTypes.data(),
4206 ParamTypes.size(),
4207 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004208 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004209 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004210 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004211 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004212 if (Result.isNull())
4213 return QualType();
4214 }
Mike Stump1eb44332009-09-09 15:08:12 +00004215
John McCalla2becad2009-10-21 00:40:46 +00004216 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004217 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4218 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004219 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004220 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4221 NewTL.setArg(i, ParamDecls[i]);
4222
4223 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004224}
Mike Stump1eb44332009-09-09 15:08:12 +00004225
Douglas Gregor577f75a2009-08-04 16:50:30 +00004226template<typename Derived>
4227QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004228 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004229 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004230 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004231 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4232 if (ResultType.isNull())
4233 return QualType();
4234
4235 QualType Result = TL.getType();
4236 if (getDerived().AlwaysRebuild() ||
4237 ResultType != T->getResultType())
4238 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4239
4240 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004241 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4242 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004243 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004244
4245 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004246}
Mike Stump1eb44332009-09-09 15:08:12 +00004247
John McCalled976492009-12-04 22:46:56 +00004248template<typename Derived> QualType
4249TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004250 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004251 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004252 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004253 if (!D)
4254 return QualType();
4255
4256 QualType Result = TL.getType();
4257 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4258 Result = getDerived().RebuildUnresolvedUsingType(D);
4259 if (Result.isNull())
4260 return QualType();
4261 }
4262
4263 // We might get an arbitrary type spec type back. We should at
4264 // least always get a type spec type, though.
4265 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4266 NewTL.setNameLoc(TL.getNameLoc());
4267
4268 return Result;
4269}
4270
Douglas Gregor577f75a2009-08-04 16:50:30 +00004271template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004272QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004273 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004274 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004275 TypedefNameDecl *Typedef
4276 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4277 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004278 if (!Typedef)
4279 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004280
John McCalla2becad2009-10-21 00:40:46 +00004281 QualType Result = TL.getType();
4282 if (getDerived().AlwaysRebuild() ||
4283 Typedef != T->getDecl()) {
4284 Result = getDerived().RebuildTypedefType(Typedef);
4285 if (Result.isNull())
4286 return QualType();
4287 }
Mike Stump1eb44332009-09-09 15:08:12 +00004288
John McCalla2becad2009-10-21 00:40:46 +00004289 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4290 NewTL.setNameLoc(TL.getNameLoc());
4291
4292 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004293}
Mike Stump1eb44332009-09-09 15:08:12 +00004294
Douglas Gregor577f75a2009-08-04 16:50:30 +00004295template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004296QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004297 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004298 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004299 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004300
John McCall60d7b3a2010-08-24 06:29:42 +00004301 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004302 if (E.isInvalid())
4303 return QualType();
4304
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004305 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4306 if (E.isInvalid())
4307 return QualType();
4308
John McCalla2becad2009-10-21 00:40:46 +00004309 QualType Result = TL.getType();
4310 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004311 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004312 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004313 if (Result.isNull())
4314 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004315 }
John McCalla2becad2009-10-21 00:40:46 +00004316 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004317
John McCalla2becad2009-10-21 00:40:46 +00004318 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004319 NewTL.setTypeofLoc(TL.getTypeofLoc());
4320 NewTL.setLParenLoc(TL.getLParenLoc());
4321 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004322
4323 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004324}
Mike Stump1eb44332009-09-09 15:08:12 +00004325
4326template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004327QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004328 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004329 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4330 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4331 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004332 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004333
John McCalla2becad2009-10-21 00:40:46 +00004334 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004335 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4336 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004337 if (Result.isNull())
4338 return QualType();
4339 }
Mike Stump1eb44332009-09-09 15:08:12 +00004340
John McCalla2becad2009-10-21 00:40:46 +00004341 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004342 NewTL.setTypeofLoc(TL.getTypeofLoc());
4343 NewTL.setLParenLoc(TL.getLParenLoc());
4344 NewTL.setRParenLoc(TL.getRParenLoc());
4345 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004346
4347 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004348}
Mike Stump1eb44332009-09-09 15:08:12 +00004349
4350template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004351QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004352 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004353 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004354
Douglas Gregor670444e2009-08-04 22:27:00 +00004355 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004356 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4357 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004358
John McCall60d7b3a2010-08-24 06:29:42 +00004359 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004360 if (E.isInvalid())
4361 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004362
Richard Smith76f3f692012-02-22 02:04:18 +00004363 E = getSema().ActOnDecltypeExpression(E.take());
4364 if (E.isInvalid())
4365 return QualType();
4366
John McCalla2becad2009-10-21 00:40:46 +00004367 QualType Result = TL.getType();
4368 if (getDerived().AlwaysRebuild() ||
4369 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004370 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004371 if (Result.isNull())
4372 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004373 }
John McCalla2becad2009-10-21 00:40:46 +00004374 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004375
John McCalla2becad2009-10-21 00:40:46 +00004376 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4377 NewTL.setNameLoc(TL.getNameLoc());
4378
4379 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004380}
4381
4382template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004383QualType TreeTransform<Derived>::TransformUnaryTransformType(
4384 TypeLocBuilder &TLB,
4385 UnaryTransformTypeLoc TL) {
4386 QualType Result = TL.getType();
4387 if (Result->isDependentType()) {
4388 const UnaryTransformType *T = TL.getTypePtr();
4389 QualType NewBase =
4390 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4391 Result = getDerived().RebuildUnaryTransformType(NewBase,
4392 T->getUTTKind(),
4393 TL.getKWLoc());
4394 if (Result.isNull())
4395 return QualType();
4396 }
4397
4398 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4399 NewTL.setKWLoc(TL.getKWLoc());
4400 NewTL.setParensRange(TL.getParensRange());
4401 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4402 return Result;
4403}
4404
4405template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004406QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4407 AutoTypeLoc TL) {
4408 const AutoType *T = TL.getTypePtr();
4409 QualType OldDeduced = T->getDeducedType();
4410 QualType NewDeduced;
4411 if (!OldDeduced.isNull()) {
4412 NewDeduced = getDerived().TransformType(OldDeduced);
4413 if (NewDeduced.isNull())
4414 return QualType();
4415 }
4416
4417 QualType Result = TL.getType();
4418 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4419 Result = getDerived().RebuildAutoType(NewDeduced);
4420 if (Result.isNull())
4421 return QualType();
4422 }
4423
4424 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4425 NewTL.setNameLoc(TL.getNameLoc());
4426
4427 return Result;
4428}
4429
4430template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004431QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004432 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004433 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004434 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004435 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4436 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004437 if (!Record)
4438 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004439
John McCalla2becad2009-10-21 00:40:46 +00004440 QualType Result = TL.getType();
4441 if (getDerived().AlwaysRebuild() ||
4442 Record != T->getDecl()) {
4443 Result = getDerived().RebuildRecordType(Record);
4444 if (Result.isNull())
4445 return QualType();
4446 }
Mike Stump1eb44332009-09-09 15:08:12 +00004447
John McCalla2becad2009-10-21 00:40:46 +00004448 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4449 NewTL.setNameLoc(TL.getNameLoc());
4450
4451 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004452}
Mike Stump1eb44332009-09-09 15:08:12 +00004453
4454template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004455QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004456 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004457 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004458 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004459 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4460 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004461 if (!Enum)
4462 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004463
John McCalla2becad2009-10-21 00:40:46 +00004464 QualType Result = TL.getType();
4465 if (getDerived().AlwaysRebuild() ||
4466 Enum != T->getDecl()) {
4467 Result = getDerived().RebuildEnumType(Enum);
4468 if (Result.isNull())
4469 return QualType();
4470 }
Mike Stump1eb44332009-09-09 15:08:12 +00004471
John McCalla2becad2009-10-21 00:40:46 +00004472 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4473 NewTL.setNameLoc(TL.getNameLoc());
4474
4475 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004476}
John McCall7da24312009-09-05 00:15:47 +00004477
John McCall3cb0ebd2010-03-10 03:28:59 +00004478template<typename Derived>
4479QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4480 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004481 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004482 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4483 TL.getTypePtr()->getDecl());
4484 if (!D) return QualType();
4485
4486 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4487 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4488 return T;
4489}
4490
Douglas Gregor577f75a2009-08-04 16:50:30 +00004491template<typename Derived>
4492QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004493 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004494 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004495 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004496}
4497
Mike Stump1eb44332009-09-09 15:08:12 +00004498template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004499QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004500 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004501 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004502 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4503
4504 // Substitute into the replacement type, which itself might involve something
4505 // that needs to be transformed. This only tends to occur with default
4506 // template arguments of template template parameters.
4507 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4508 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4509 if (Replacement.isNull())
4510 return QualType();
4511
4512 // Always canonicalize the replacement type.
4513 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4514 QualType Result
4515 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4516 Replacement);
4517
4518 // Propagate type-source information.
4519 SubstTemplateTypeParmTypeLoc NewTL
4520 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4521 NewTL.setNameLoc(TL.getNameLoc());
4522 return Result;
4523
John McCall49a832b2009-10-18 09:09:24 +00004524}
4525
4526template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004527QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4528 TypeLocBuilder &TLB,
4529 SubstTemplateTypeParmPackTypeLoc TL) {
4530 return TransformTypeSpecType(TLB, TL);
4531}
4532
4533template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004534QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004535 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004536 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004537 const TemplateSpecializationType *T = TL.getTypePtr();
4538
Douglas Gregor1d752d72011-03-02 18:46:51 +00004539 // The nested-name-specifier never matters in a TemplateSpecializationType,
4540 // because we can't have a dependent nested-name-specifier anyway.
4541 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004542 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004543 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4544 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004545 if (Template.isNull())
4546 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004547
John McCall43fed0d2010-11-12 08:19:04 +00004548 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4549}
4550
Eli Friedmanb001de72011-10-06 23:00:33 +00004551template<typename Derived>
4552QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4553 AtomicTypeLoc TL) {
4554 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4555 if (ValueType.isNull())
4556 return QualType();
4557
4558 QualType Result = TL.getType();
4559 if (getDerived().AlwaysRebuild() ||
4560 ValueType != TL.getValueLoc().getType()) {
4561 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4562 if (Result.isNull())
4563 return QualType();
4564 }
4565
4566 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4567 NewTL.setKWLoc(TL.getKWLoc());
4568 NewTL.setLParenLoc(TL.getLParenLoc());
4569 NewTL.setRParenLoc(TL.getRParenLoc());
4570
4571 return Result;
4572}
4573
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004574namespace {
4575 /// \brief Simple iterator that traverses the template arguments in a
4576 /// container that provides a \c getArgLoc() member function.
4577 ///
4578 /// This iterator is intended to be used with the iterator form of
4579 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4580 template<typename ArgLocContainer>
4581 class TemplateArgumentLocContainerIterator {
4582 ArgLocContainer *Container;
4583 unsigned Index;
4584
4585 public:
4586 typedef TemplateArgumentLoc value_type;
4587 typedef TemplateArgumentLoc reference;
4588 typedef int difference_type;
4589 typedef std::input_iterator_tag iterator_category;
4590
4591 class pointer {
4592 TemplateArgumentLoc Arg;
4593
4594 public:
4595 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4596
4597 const TemplateArgumentLoc *operator->() const {
4598 return &Arg;
4599 }
4600 };
4601
4602
4603 TemplateArgumentLocContainerIterator() {}
4604
4605 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4606 unsigned Index)
4607 : Container(&Container), Index(Index) { }
4608
4609 TemplateArgumentLocContainerIterator &operator++() {
4610 ++Index;
4611 return *this;
4612 }
4613
4614 TemplateArgumentLocContainerIterator operator++(int) {
4615 TemplateArgumentLocContainerIterator Old(*this);
4616 ++(*this);
4617 return Old;
4618 }
4619
4620 TemplateArgumentLoc operator*() const {
4621 return Container->getArgLoc(Index);
4622 }
4623
4624 pointer operator->() const {
4625 return pointer(Container->getArgLoc(Index));
4626 }
4627
4628 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004629 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004630 return X.Container == Y.Container && X.Index == Y.Index;
4631 }
4632
4633 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004634 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004635 return !(X == Y);
4636 }
4637 };
4638}
4639
4640
John McCall43fed0d2010-11-12 08:19:04 +00004641template <typename Derived>
4642QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4643 TypeLocBuilder &TLB,
4644 TemplateSpecializationTypeLoc TL,
4645 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004646 TemplateArgumentListInfo NewTemplateArgs;
4647 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4648 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004649 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4650 ArgIterator;
4651 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4652 ArgIterator(TL, TL.getNumArgs()),
4653 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004654 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004655
John McCall833ca992009-10-29 08:12:44 +00004656 // FIXME: maybe don't rebuild if all the template arguments are the same.
4657
4658 QualType Result =
4659 getDerived().RebuildTemplateSpecializationType(Template,
4660 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004661 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004662
4663 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004664 // Specializations of template template parameters are represented as
4665 // TemplateSpecializationTypes, and substitution of type alias templates
4666 // within a dependent context can transform them into
4667 // DependentTemplateSpecializationTypes.
4668 if (isa<DependentTemplateSpecializationType>(Result)) {
4669 DependentTemplateSpecializationTypeLoc NewTL
4670 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004671 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004672 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004673 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004674 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004675 NewTL.setLAngleLoc(TL.getLAngleLoc());
4676 NewTL.setRAngleLoc(TL.getRAngleLoc());
4677 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4678 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4679 return Result;
4680 }
4681
John McCall833ca992009-10-29 08:12:44 +00004682 TemplateSpecializationTypeLoc NewTL
4683 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004684 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004685 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4686 NewTL.setLAngleLoc(TL.getLAngleLoc());
4687 NewTL.setRAngleLoc(TL.getRAngleLoc());
4688 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4689 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004690 }
Mike Stump1eb44332009-09-09 15:08:12 +00004691
John McCall833ca992009-10-29 08:12:44 +00004692 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004693}
Mike Stump1eb44332009-09-09 15:08:12 +00004694
Douglas Gregora88f09f2011-02-28 17:23:35 +00004695template <typename Derived>
4696QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4697 TypeLocBuilder &TLB,
4698 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004699 TemplateName Template,
4700 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004701 TemplateArgumentListInfo NewTemplateArgs;
4702 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4703 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4704 typedef TemplateArgumentLocContainerIterator<
4705 DependentTemplateSpecializationTypeLoc> ArgIterator;
4706 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4707 ArgIterator(TL, TL.getNumArgs()),
4708 NewTemplateArgs))
4709 return QualType();
4710
4711 // FIXME: maybe don't rebuild if all the template arguments are the same.
4712
4713 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4714 QualType Result
4715 = getSema().Context.getDependentTemplateSpecializationType(
4716 TL.getTypePtr()->getKeyword(),
4717 DTN->getQualifier(),
4718 DTN->getIdentifier(),
4719 NewTemplateArgs);
4720
4721 DependentTemplateSpecializationTypeLoc NewTL
4722 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004723 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004724 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004725 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004726 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004727 NewTL.setLAngleLoc(TL.getLAngleLoc());
4728 NewTL.setRAngleLoc(TL.getRAngleLoc());
4729 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4730 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4731 return Result;
4732 }
4733
4734 QualType Result
4735 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004736 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004737 NewTemplateArgs);
4738
4739 if (!Result.isNull()) {
4740 /// FIXME: Wrap this in an elaborated-type-specifier?
4741 TemplateSpecializationTypeLoc NewTL
4742 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004743 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004744 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004745 NewTL.setLAngleLoc(TL.getLAngleLoc());
4746 NewTL.setRAngleLoc(TL.getRAngleLoc());
4747 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4748 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4749 }
4750
4751 return Result;
4752}
4753
Mike Stump1eb44332009-09-09 15:08:12 +00004754template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004755QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004756TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004757 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004758 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004759
Douglas Gregor9e876872011-03-01 18:12:44 +00004760 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004761 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004762 if (TL.getQualifierLoc()) {
4763 QualifierLoc
4764 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4765 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004766 return QualType();
4767 }
Mike Stump1eb44332009-09-09 15:08:12 +00004768
John McCall43fed0d2010-11-12 08:19:04 +00004769 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4770 if (NamedT.isNull())
4771 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004772
Richard Smith3e4c6c42011-05-05 21:57:07 +00004773 // C++0x [dcl.type.elab]p2:
4774 // If the identifier resolves to a typedef-name or the simple-template-id
4775 // resolves to an alias template specialization, the
4776 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004777 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4778 if (const TemplateSpecializationType *TST =
4779 NamedT->getAs<TemplateSpecializationType>()) {
4780 TemplateName Template = TST->getTemplateName();
4781 if (TypeAliasTemplateDecl *TAT =
4782 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4783 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4784 diag::err_tag_reference_non_tag) << 4;
4785 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4786 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004787 }
4788 }
4789
John McCalla2becad2009-10-21 00:40:46 +00004790 QualType Result = TL.getType();
4791 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004792 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004793 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004794 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004795 T->getKeyword(),
4796 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004797 if (Result.isNull())
4798 return QualType();
4799 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004800
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004801 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004802 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004803 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004804 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004805}
Mike Stump1eb44332009-09-09 15:08:12 +00004806
4807template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004808QualType TreeTransform<Derived>::TransformAttributedType(
4809 TypeLocBuilder &TLB,
4810 AttributedTypeLoc TL) {
4811 const AttributedType *oldType = TL.getTypePtr();
4812 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4813 if (modifiedType.isNull())
4814 return QualType();
4815
4816 QualType result = TL.getType();
4817
4818 // FIXME: dependent operand expressions?
4819 if (getDerived().AlwaysRebuild() ||
4820 modifiedType != oldType->getModifiedType()) {
4821 // TODO: this is really lame; we should really be rebuilding the
4822 // equivalent type from first principles.
4823 QualType equivalentType
4824 = getDerived().TransformType(oldType->getEquivalentType());
4825 if (equivalentType.isNull())
4826 return QualType();
4827 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4828 modifiedType,
4829 equivalentType);
4830 }
4831
4832 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4833 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4834 if (TL.hasAttrOperand())
4835 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4836 if (TL.hasAttrExprOperand())
4837 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4838 else if (TL.hasAttrEnumOperand())
4839 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4840
4841 return result;
4842}
4843
4844template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004845QualType
4846TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4847 ParenTypeLoc TL) {
4848 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4849 if (Inner.isNull())
4850 return QualType();
4851
4852 QualType Result = TL.getType();
4853 if (getDerived().AlwaysRebuild() ||
4854 Inner != TL.getInnerLoc().getType()) {
4855 Result = getDerived().RebuildParenType(Inner);
4856 if (Result.isNull())
4857 return QualType();
4858 }
4859
4860 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4861 NewTL.setLParenLoc(TL.getLParenLoc());
4862 NewTL.setRParenLoc(TL.getRParenLoc());
4863 return Result;
4864}
4865
4866template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004867QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004868 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004869 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004870
Douglas Gregor2494dd02011-03-01 01:34:45 +00004871 NestedNameSpecifierLoc QualifierLoc
4872 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4873 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004874 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004875
John McCall33500952010-06-11 00:33:02 +00004876 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004877 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004878 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004879 QualifierLoc,
4880 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004881 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004882 if (Result.isNull())
4883 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004884
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004885 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4886 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004887 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4888
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004889 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004890 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004891 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004892 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004893 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004894 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004895 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004896 NewTL.setNameLoc(TL.getNameLoc());
4897 }
John McCalla2becad2009-10-21 00:40:46 +00004898 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004899}
Mike Stump1eb44332009-09-09 15:08:12 +00004900
Douglas Gregor577f75a2009-08-04 16:50:30 +00004901template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004902QualType TreeTransform<Derived>::
4903 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004904 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004905 NestedNameSpecifierLoc QualifierLoc;
4906 if (TL.getQualifierLoc()) {
4907 QualifierLoc
4908 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4909 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004910 return QualType();
4911 }
4912
John McCall43fed0d2010-11-12 08:19:04 +00004913 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004914 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004915}
4916
4917template<typename Derived>
4918QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004919TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4920 DependentTemplateSpecializationTypeLoc TL,
4921 NestedNameSpecifierLoc QualifierLoc) {
4922 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4923
4924 TemplateArgumentListInfo NewTemplateArgs;
4925 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4926 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4927
4928 typedef TemplateArgumentLocContainerIterator<
4929 DependentTemplateSpecializationTypeLoc> ArgIterator;
4930 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4931 ArgIterator(TL, TL.getNumArgs()),
4932 NewTemplateArgs))
4933 return QualType();
4934
4935 QualType Result
4936 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4937 QualifierLoc,
4938 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004939 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004940 NewTemplateArgs);
4941 if (Result.isNull())
4942 return QualType();
4943
4944 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4945 QualType NamedT = ElabT->getNamedType();
4946
4947 // Copy information relevant to the template specialization.
4948 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004949 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004950 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004951 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004952 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4953 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004954 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004955 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004956
4957 // Copy information relevant to the elaborated type.
4958 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004959 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004960 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004961 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4962 DependentTemplateSpecializationTypeLoc SpecTL
4963 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004964 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004965 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004966 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004967 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004968 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4969 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004970 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004971 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004972 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004973 TemplateSpecializationTypeLoc SpecTL
4974 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004975 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004976 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004977 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4978 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004979 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004980 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004981 }
4982 return Result;
4983}
4984
4985template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004986QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4987 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004988 QualType Pattern
4989 = getDerived().TransformType(TLB, TL.getPatternLoc());
4990 if (Pattern.isNull())
4991 return QualType();
4992
4993 QualType Result = TL.getType();
4994 if (getDerived().AlwaysRebuild() ||
4995 Pattern != TL.getPatternLoc().getType()) {
4996 Result = getDerived().RebuildPackExpansionType(Pattern,
4997 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004998 TL.getEllipsisLoc(),
4999 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005000 if (Result.isNull())
5001 return QualType();
5002 }
5003
5004 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5005 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5006 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005007}
5008
5009template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005010QualType
5011TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005012 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005013 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005014 TLB.pushFullCopy(TL);
5015 return TL.getType();
5016}
5017
5018template<typename Derived>
5019QualType
5020TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005021 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005022 // ObjCObjectType is never dependent.
5023 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005024 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005025}
Mike Stump1eb44332009-09-09 15:08:12 +00005026
5027template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005028QualType
5029TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005030 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005031 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005032 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005033 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005034}
5035
Douglas Gregor577f75a2009-08-04 16:50:30 +00005036//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005037// Statement transformation
5038//===----------------------------------------------------------------------===//
5039template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005040StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005041TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005042 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005043}
5044
5045template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005046StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005047TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5048 return getDerived().TransformCompoundStmt(S, false);
5049}
5050
5051template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005052StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005053TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005054 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005055 Sema::CompoundScopeRAII CompoundScope(getSema());
5056
John McCall7114cba2010-08-27 19:56:05 +00005057 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005058 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005059 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005060 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5061 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005062 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005063 if (Result.isInvalid()) {
5064 // Immediately fail if this was a DeclStmt, since it's very
5065 // likely that this will cause problems for future statements.
5066 if (isa<DeclStmt>(*B))
5067 return StmtError();
5068
5069 // Otherwise, just keep processing substatements and fail later.
5070 SubStmtInvalid = true;
5071 continue;
5072 }
Mike Stump1eb44332009-09-09 15:08:12 +00005073
Douglas Gregor43959a92009-08-20 07:17:43 +00005074 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5075 Statements.push_back(Result.takeAs<Stmt>());
5076 }
Mike Stump1eb44332009-09-09 15:08:12 +00005077
John McCall7114cba2010-08-27 19:56:05 +00005078 if (SubStmtInvalid)
5079 return StmtError();
5080
Douglas Gregor43959a92009-08-20 07:17:43 +00005081 if (!getDerived().AlwaysRebuild() &&
5082 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005083 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005084
5085 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5086 move_arg(Statements),
5087 S->getRBracLoc(),
5088 IsStmtExpr);
5089}
Mike Stump1eb44332009-09-09 15:08:12 +00005090
Douglas Gregor43959a92009-08-20 07:17:43 +00005091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005092StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005093TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005094 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005095 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005096 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5097 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005098
Eli Friedman264c1f82009-11-19 03:14:00 +00005099 // Transform the left-hand case value.
5100 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005101 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005102 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005103 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005104
Eli Friedman264c1f82009-11-19 03:14:00 +00005105 // Transform the right-hand case value (for the GNU case-range extension).
5106 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005107 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005108 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005109 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005110 }
Mike Stump1eb44332009-09-09 15:08:12 +00005111
Douglas Gregor43959a92009-08-20 07:17:43 +00005112 // Build the case statement.
5113 // Case statements are always rebuilt so that they will attached to their
5114 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005115 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005116 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005117 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005118 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005119 S->getColonLoc());
5120 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005121 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005122
Douglas Gregor43959a92009-08-20 07:17:43 +00005123 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005124 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005125 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005126 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005127
Douglas Gregor43959a92009-08-20 07:17:43 +00005128 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005129 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005130}
5131
5132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005133StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005134TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005135 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005136 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005137 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005138 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005139
Douglas Gregor43959a92009-08-20 07:17:43 +00005140 // Default statements are always rebuilt
5141 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005142 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005143}
Mike Stump1eb44332009-09-09 15:08:12 +00005144
Douglas Gregor43959a92009-08-20 07:17:43 +00005145template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005146StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005147TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005148 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005149 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005150 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005151
Chris Lattner57ad3782011-02-17 20:34:02 +00005152 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5153 S->getDecl());
5154 if (!LD)
5155 return StmtError();
5156
5157
Douglas Gregor43959a92009-08-20 07:17:43 +00005158 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005159 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005160 cast<LabelDecl>(LD), SourceLocation(),
5161 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005162}
Mike Stump1eb44332009-09-09 15:08:12 +00005163
Douglas Gregor43959a92009-08-20 07:17:43 +00005164template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005165StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005166TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005167 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005168 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005169 VarDecl *ConditionVar = 0;
5170 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005171 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005172 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005173 getDerived().TransformDefinition(
5174 S->getConditionVariable()->getLocation(),
5175 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005176 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005177 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005178 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005179 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005180
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005181 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005182 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005183
5184 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005185 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005186 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5187 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005188 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005189 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005190
John McCall9ae2f072010-08-23 23:25:46 +00005191 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005192 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005193 }
Sean Huntc3021132010-05-05 15:23:54 +00005194
John McCall9ae2f072010-08-23 23:25:46 +00005195 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5196 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005197 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005198
Douglas Gregor43959a92009-08-20 07:17:43 +00005199 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005200 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005201 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005202 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005203
Douglas Gregor43959a92009-08-20 07:17:43 +00005204 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005205 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005206 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005207 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005208
Douglas Gregor43959a92009-08-20 07:17:43 +00005209 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005210 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005211 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005212 Then.get() == S->getThen() &&
5213 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005214 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005215
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005216 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005217 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005218 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005219}
5220
5221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005222StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005223TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005224 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005225 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005226 VarDecl *ConditionVar = 0;
5227 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005228 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005229 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005230 getDerived().TransformDefinition(
5231 S->getConditionVariable()->getLocation(),
5232 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005233 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005234 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005235 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005236 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005237
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005238 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005239 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005240 }
Mike Stump1eb44332009-09-09 15:08:12 +00005241
Douglas Gregor43959a92009-08-20 07:17:43 +00005242 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005243 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005244 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005245 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005246 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005247 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005248
Douglas Gregor43959a92009-08-20 07:17:43 +00005249 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005250 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005251 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005252 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005253
Douglas Gregor43959a92009-08-20 07:17:43 +00005254 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005255 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5256 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005257}
Mike Stump1eb44332009-09-09 15:08:12 +00005258
Douglas Gregor43959a92009-08-20 07:17:43 +00005259template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005260StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005261TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005262 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005263 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005264 VarDecl *ConditionVar = 0;
5265 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005266 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005267 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005268 getDerived().TransformDefinition(
5269 S->getConditionVariable()->getLocation(),
5270 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005271 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005272 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005273 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005274 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005275
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005276 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005277 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005278
5279 if (S->getCond()) {
5280 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005281 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5282 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005283 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005284 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005285 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005286 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005287 }
Mike Stump1eb44332009-09-09 15:08:12 +00005288
John McCall9ae2f072010-08-23 23:25:46 +00005289 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5290 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005291 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005292
Douglas Gregor43959a92009-08-20 07:17:43 +00005293 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005294 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005295 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005296 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005297
Douglas Gregor43959a92009-08-20 07:17:43 +00005298 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005299 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005300 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005301 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005302 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005303
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005304 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005305 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005306}
Mike Stump1eb44332009-09-09 15:08:12 +00005307
Douglas Gregor43959a92009-08-20 07:17:43 +00005308template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005309StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005310TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005311 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005312 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005313 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005314 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005315
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005316 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005317 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005318 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005319 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005320
Douglas Gregor43959a92009-08-20 07:17:43 +00005321 if (!getDerived().AlwaysRebuild() &&
5322 Cond.get() == S->getCond() &&
5323 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005324 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005325
John McCall9ae2f072010-08-23 23:25:46 +00005326 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5327 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005328 S->getRParenLoc());
5329}
Mike Stump1eb44332009-09-09 15:08:12 +00005330
Douglas Gregor43959a92009-08-20 07:17:43 +00005331template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005332StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005333TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005334 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005335 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005336 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005337 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005338
Douglas Gregor43959a92009-08-20 07:17:43 +00005339 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005340 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005341 VarDecl *ConditionVar = 0;
5342 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005343 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005344 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005345 getDerived().TransformDefinition(
5346 S->getConditionVariable()->getLocation(),
5347 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005348 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005349 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005350 } else {
5351 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005352
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005353 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005354 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005355
5356 if (S->getCond()) {
5357 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005358 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5359 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005360 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005361 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005362
John McCall9ae2f072010-08-23 23:25:46 +00005363 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005364 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005365 }
Mike Stump1eb44332009-09-09 15:08:12 +00005366
John McCall9ae2f072010-08-23 23:25:46 +00005367 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5368 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005369 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005370
Douglas Gregor43959a92009-08-20 07:17:43 +00005371 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005372 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005373 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005374 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005375
John McCall9ae2f072010-08-23 23:25:46 +00005376 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5377 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005378 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005379
Douglas Gregor43959a92009-08-20 07:17:43 +00005380 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005381 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005382 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005383 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005384
Douglas Gregor43959a92009-08-20 07:17:43 +00005385 if (!getDerived().AlwaysRebuild() &&
5386 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005387 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005388 Inc.get() == S->getInc() &&
5389 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005390 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005391
Douglas Gregor43959a92009-08-20 07:17:43 +00005392 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005393 Init.get(), FullCond, ConditionVar,
5394 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005395}
5396
5397template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005398StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005399TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005400 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5401 S->getLabel());
5402 if (!LD)
5403 return StmtError();
5404
Douglas Gregor43959a92009-08-20 07:17:43 +00005405 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005406 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005407 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005408}
5409
5410template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005411StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005412TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005413 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005415 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005416 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005417
Douglas Gregor43959a92009-08-20 07:17:43 +00005418 if (!getDerived().AlwaysRebuild() &&
5419 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005420 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005421
5422 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005423 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005424}
5425
5426template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005427StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005428TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005429 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005430}
Mike Stump1eb44332009-09-09 15:08:12 +00005431
Douglas Gregor43959a92009-08-20 07:17:43 +00005432template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005433StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005434TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005435 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005436}
Mike Stump1eb44332009-09-09 15:08:12 +00005437
Douglas Gregor43959a92009-08-20 07:17:43 +00005438template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005439StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005440TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005441 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005442 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005443 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005444
Mike Stump1eb44332009-09-09 15:08:12 +00005445 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005446 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005447 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005448}
Mike Stump1eb44332009-09-09 15:08:12 +00005449
Douglas Gregor43959a92009-08-20 07:17:43 +00005450template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005451StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005452TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005453 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005454 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005455 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5456 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005457 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5458 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005459 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005460 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005461
Douglas Gregor43959a92009-08-20 07:17:43 +00005462 if (Transformed != *D)
5463 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005464
Douglas Gregor43959a92009-08-20 07:17:43 +00005465 Decls.push_back(Transformed);
5466 }
Mike Stump1eb44332009-09-09 15:08:12 +00005467
Douglas Gregor43959a92009-08-20 07:17:43 +00005468 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005469 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005470
5471 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005472 S->getStartLoc(), S->getEndLoc());
5473}
Mike Stump1eb44332009-09-09 15:08:12 +00005474
Douglas Gregor43959a92009-08-20 07:17:43 +00005475template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005476StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005477TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005478
John McCallca0408f2010-08-23 06:44:23 +00005479 ASTOwningVector<Expr*> Constraints(getSema());
5480 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005481 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005482
John McCall60d7b3a2010-08-24 06:29:42 +00005483 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005484 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005485
5486 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005487
Anders Carlsson703e3942010-01-24 05:50:09 +00005488 // Go through the outputs.
5489 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005490 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005491
Anders Carlsson703e3942010-01-24 05:50:09 +00005492 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005493 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005494
Anders Carlsson703e3942010-01-24 05:50:09 +00005495 // Transform the output expr.
5496 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005497 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005498 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005499 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005500
Anders Carlsson703e3942010-01-24 05:50:09 +00005501 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005502
John McCall9ae2f072010-08-23 23:25:46 +00005503 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005504 }
Sean Huntc3021132010-05-05 15:23:54 +00005505
Anders Carlsson703e3942010-01-24 05:50:09 +00005506 // Go through the inputs.
5507 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005508 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005509
Anders Carlsson703e3942010-01-24 05:50:09 +00005510 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005511 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005512
Anders Carlsson703e3942010-01-24 05:50:09 +00005513 // Transform the input expr.
5514 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005515 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005516 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005517 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005518
Anders Carlsson703e3942010-01-24 05:50:09 +00005519 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005520
John McCall9ae2f072010-08-23 23:25:46 +00005521 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005522 }
Sean Huntc3021132010-05-05 15:23:54 +00005523
Anders Carlsson703e3942010-01-24 05:50:09 +00005524 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005525 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005526
5527 // Go through the clobbers.
5528 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005529 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005530
5531 // No need to transform the asm string literal.
5532 AsmString = SemaRef.Owned(S->getAsmString());
5533
5534 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5535 S->isSimple(),
5536 S->isVolatile(),
5537 S->getNumOutputs(),
5538 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005539 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005540 move_arg(Constraints),
5541 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005542 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005543 move_arg(Clobbers),
5544 S->getRParenLoc(),
5545 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005546}
5547
5548
5549template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005550StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005551TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005552 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005553 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005554 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005555 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005556
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005557 // Transform the @catch statements (if present).
5558 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005559 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005560 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005561 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005562 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005563 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005564 if (Catch.get() != S->getCatchStmt(I))
5565 AnyCatchChanged = true;
5566 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005567 }
Sean Huntc3021132010-05-05 15:23:54 +00005568
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005569 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005570 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005571 if (S->getFinallyStmt()) {
5572 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5573 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005574 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005575 }
5576
5577 // If nothing changed, just retain this statement.
5578 if (!getDerived().AlwaysRebuild() &&
5579 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005580 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005581 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005582 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005583
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005584 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005585 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5586 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005587}
Mike Stump1eb44332009-09-09 15:08:12 +00005588
Douglas Gregor43959a92009-08-20 07:17:43 +00005589template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005590StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005591TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005592 // Transform the @catch parameter, if there is one.
5593 VarDecl *Var = 0;
5594 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5595 TypeSourceInfo *TSInfo = 0;
5596 if (FromVar->getTypeSourceInfo()) {
5597 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5598 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005599 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005600 }
Sean Huntc3021132010-05-05 15:23:54 +00005601
Douglas Gregorbe270a02010-04-26 17:57:08 +00005602 QualType T;
5603 if (TSInfo)
5604 T = TSInfo->getType();
5605 else {
5606 T = getDerived().TransformType(FromVar->getType());
5607 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005608 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005609 }
Sean Huntc3021132010-05-05 15:23:54 +00005610
Douglas Gregorbe270a02010-04-26 17:57:08 +00005611 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5612 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005613 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005614 }
Sean Huntc3021132010-05-05 15:23:54 +00005615
John McCall60d7b3a2010-08-24 06:29:42 +00005616 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005617 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005618 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005619
5620 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005621 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005622 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005623}
Mike Stump1eb44332009-09-09 15:08:12 +00005624
Douglas Gregor43959a92009-08-20 07:17:43 +00005625template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005626StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005627TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005628 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005629 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005630 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005631 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005632
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005633 // If nothing changed, just retain this statement.
5634 if (!getDerived().AlwaysRebuild() &&
5635 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005636 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005637
5638 // Build a new statement.
5639 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005640 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005641}
Mike Stump1eb44332009-09-09 15:08:12 +00005642
Douglas Gregor43959a92009-08-20 07:17:43 +00005643template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005644StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005645TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005646 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005647 if (S->getThrowExpr()) {
5648 Operand = getDerived().TransformExpr(S->getThrowExpr());
5649 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005650 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005651 }
Sean Huntc3021132010-05-05 15:23:54 +00005652
Douglas Gregord1377b22010-04-22 21:44:01 +00005653 if (!getDerived().AlwaysRebuild() &&
5654 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005655 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005656
John McCall9ae2f072010-08-23 23:25:46 +00005657 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005658}
Mike Stump1eb44332009-09-09 15:08:12 +00005659
Douglas Gregor43959a92009-08-20 07:17:43 +00005660template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005661StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005662TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005663 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005664 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005665 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005666 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005667 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005668 Object =
5669 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5670 Object.get());
5671 if (Object.isInvalid())
5672 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005673
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005674 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005675 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005676 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005677 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005678
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005679 // If nothing change, just retain the current statement.
5680 if (!getDerived().AlwaysRebuild() &&
5681 Object.get() == S->getSynchExpr() &&
5682 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005683 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005684
5685 // Build a new statement.
5686 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005687 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005688}
5689
5690template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005691StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005692TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5693 ObjCAutoreleasePoolStmt *S) {
5694 // Transform the body.
5695 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5696 if (Body.isInvalid())
5697 return StmtError();
5698
5699 // If nothing changed, just retain this statement.
5700 if (!getDerived().AlwaysRebuild() &&
5701 Body.get() == S->getSubStmt())
5702 return SemaRef.Owned(S);
5703
5704 // Build a new statement.
5705 return getDerived().RebuildObjCAutoreleasePoolStmt(
5706 S->getAtLoc(), Body.get());
5707}
5708
5709template<typename Derived>
5710StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005711TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005712 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005713 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005714 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005715 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005716 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005717
Douglas Gregorc3203e72010-04-22 23:10:45 +00005718 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005719 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005720 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005721 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005722 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5723 Collection.take());
5724 if (Collection.isInvalid())
5725 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005726
Douglas Gregorc3203e72010-04-22 23:10:45 +00005727 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005728 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005729 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005730 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005731
Douglas Gregorc3203e72010-04-22 23:10:45 +00005732 // If nothing changed, just retain this statement.
5733 if (!getDerived().AlwaysRebuild() &&
5734 Element.get() == S->getElement() &&
5735 Collection.get() == S->getCollection() &&
5736 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005737 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005738
Douglas Gregorc3203e72010-04-22 23:10:45 +00005739 // Build a new statement.
5740 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5741 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005742 Element.get(),
5743 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005744 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005745 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005746}
5747
5748
5749template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005750StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005751TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5752 // Transform the exception declaration, if any.
5753 VarDecl *Var = 0;
5754 if (S->getExceptionDecl()) {
5755 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005756 TypeSourceInfo *T = getDerived().TransformType(
5757 ExceptionDecl->getTypeSourceInfo());
5758 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005759 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005760
Douglas Gregor83cb9422010-09-09 17:09:21 +00005761 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005762 ExceptionDecl->getInnerLocStart(),
5763 ExceptionDecl->getLocation(),
5764 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005765 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005766 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005767 }
Mike Stump1eb44332009-09-09 15:08:12 +00005768
Douglas Gregor43959a92009-08-20 07:17:43 +00005769 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005770 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005771 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005772 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005773
Douglas Gregor43959a92009-08-20 07:17:43 +00005774 if (!getDerived().AlwaysRebuild() &&
5775 !Var &&
5776 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005777 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005778
5779 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5780 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005781 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005782}
Mike Stump1eb44332009-09-09 15:08:12 +00005783
Douglas Gregor43959a92009-08-20 07:17:43 +00005784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005785StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005786TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5787 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005788 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005789 = getDerived().TransformCompoundStmt(S->getTryBlock());
5790 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005791 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005792
Douglas Gregor43959a92009-08-20 07:17:43 +00005793 // Transform the handlers.
5794 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005795 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005796 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005797 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005798 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5799 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005800 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005801
Douglas Gregor43959a92009-08-20 07:17:43 +00005802 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5803 Handlers.push_back(Handler.takeAs<Stmt>());
5804 }
Mike Stump1eb44332009-09-09 15:08:12 +00005805
Douglas Gregor43959a92009-08-20 07:17:43 +00005806 if (!getDerived().AlwaysRebuild() &&
5807 TryBlock.get() == S->getTryBlock() &&
5808 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005809 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005810
John McCall9ae2f072010-08-23 23:25:46 +00005811 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005812 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005813}
Mike Stump1eb44332009-09-09 15:08:12 +00005814
Richard Smithad762fc2011-04-14 22:09:26 +00005815template<typename Derived>
5816StmtResult
5817TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5818 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5819 if (Range.isInvalid())
5820 return StmtError();
5821
5822 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5823 if (BeginEnd.isInvalid())
5824 return StmtError();
5825
5826 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5827 if (Cond.isInvalid())
5828 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005829 if (Cond.get())
5830 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5831 if (Cond.isInvalid())
5832 return StmtError();
5833 if (Cond.get())
5834 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005835
5836 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5837 if (Inc.isInvalid())
5838 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005839 if (Inc.get())
5840 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005841
5842 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5843 if (LoopVar.isInvalid())
5844 return StmtError();
5845
5846 StmtResult NewStmt = S;
5847 if (getDerived().AlwaysRebuild() ||
5848 Range.get() != S->getRangeStmt() ||
5849 BeginEnd.get() != S->getBeginEndStmt() ||
5850 Cond.get() != S->getCond() ||
5851 Inc.get() != S->getInc() ||
5852 LoopVar.get() != S->getLoopVarStmt())
5853 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5854 S->getColonLoc(), Range.get(),
5855 BeginEnd.get(), Cond.get(),
5856 Inc.get(), LoopVar.get(),
5857 S->getRParenLoc());
5858
5859 StmtResult Body = getDerived().TransformStmt(S->getBody());
5860 if (Body.isInvalid())
5861 return StmtError();
5862
5863 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5864 // it now so we have a new statement to attach the body to.
5865 if (Body.get() != S->getBody() && NewStmt.get() == S)
5866 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5867 S->getColonLoc(), Range.get(),
5868 BeginEnd.get(), Cond.get(),
5869 Inc.get(), LoopVar.get(),
5870 S->getRParenLoc());
5871
5872 if (NewStmt.get() == S)
5873 return SemaRef.Owned(S);
5874
5875 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5876}
5877
John Wiegley28bbe4b2011-04-28 01:08:34 +00005878template<typename Derived>
5879StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005880TreeTransform<Derived>::TransformMSDependentExistsStmt(
5881 MSDependentExistsStmt *S) {
5882 // Transform the nested-name-specifier, if any.
5883 NestedNameSpecifierLoc QualifierLoc;
5884 if (S->getQualifierLoc()) {
5885 QualifierLoc
5886 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5887 if (!QualifierLoc)
5888 return StmtError();
5889 }
5890
5891 // Transform the declaration name.
5892 DeclarationNameInfo NameInfo = S->getNameInfo();
5893 if (NameInfo.getName()) {
5894 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5895 if (!NameInfo.getName())
5896 return StmtError();
5897 }
5898
5899 // Check whether anything changed.
5900 if (!getDerived().AlwaysRebuild() &&
5901 QualifierLoc == S->getQualifierLoc() &&
5902 NameInfo.getName() == S->getNameInfo().getName())
5903 return S;
5904
5905 // Determine whether this name exists, if we can.
5906 CXXScopeSpec SS;
5907 SS.Adopt(QualifierLoc);
5908 bool Dependent = false;
5909 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5910 case Sema::IER_Exists:
5911 if (S->isIfExists())
5912 break;
5913
5914 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5915
5916 case Sema::IER_DoesNotExist:
5917 if (S->isIfNotExists())
5918 break;
5919
5920 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5921
5922 case Sema::IER_Dependent:
5923 Dependent = true;
5924 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005925
5926 case Sema::IER_Error:
5927 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005928 }
5929
5930 // We need to continue with the instantiation, so do so now.
5931 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5932 if (SubStmt.isInvalid())
5933 return StmtError();
5934
5935 // If we have resolved the name, just transform to the substatement.
5936 if (!Dependent)
5937 return SubStmt;
5938
5939 // The name is still dependent, so build a dependent expression again.
5940 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5941 S->isIfExists(),
5942 QualifierLoc,
5943 NameInfo,
5944 SubStmt.get());
5945}
5946
5947template<typename Derived>
5948StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005949TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5950 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5951 if(TryBlock.isInvalid()) return StmtError();
5952
5953 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5954 if(!getDerived().AlwaysRebuild() &&
5955 TryBlock.get() == S->getTryBlock() &&
5956 Handler.get() == S->getHandler())
5957 return SemaRef.Owned(S);
5958
5959 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5960 S->getTryLoc(),
5961 TryBlock.take(),
5962 Handler.take());
5963}
5964
5965template<typename Derived>
5966StmtResult
5967TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5968 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5969 if(Block.isInvalid()) return StmtError();
5970
5971 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5972 Block.take());
5973}
5974
5975template<typename Derived>
5976StmtResult
5977TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5978 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5979 if(FilterExpr.isInvalid()) return StmtError();
5980
5981 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5982 if(Block.isInvalid()) return StmtError();
5983
5984 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5985 FilterExpr.take(),
5986 Block.take());
5987}
5988
5989template<typename Derived>
5990StmtResult
5991TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5992 if(isa<SEHFinallyStmt>(Handler))
5993 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5994 else
5995 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5996}
5997
Douglas Gregor43959a92009-08-20 07:17:43 +00005998//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005999// Expression transformation
6000//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006001template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006002ExprResult
John McCall454feb92009-12-08 09:21:05 +00006003TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006004 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006005}
Mike Stump1eb44332009-09-09 15:08:12 +00006006
6007template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006008ExprResult
John McCall454feb92009-12-08 09:21:05 +00006009TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006010 NestedNameSpecifierLoc QualifierLoc;
6011 if (E->getQualifierLoc()) {
6012 QualifierLoc
6013 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6014 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006015 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006016 }
John McCalldbd872f2009-12-08 09:08:17 +00006017
6018 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006019 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6020 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006021 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006022 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006023
John McCallec8045d2010-08-17 21:27:17 +00006024 DeclarationNameInfo NameInfo = E->getNameInfo();
6025 if (NameInfo.getName()) {
6026 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6027 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006028 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006029 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006030
6031 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006032 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006033 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006034 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006035 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006036
6037 // Mark it referenced in the new context regardless.
6038 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006039 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006040
John McCall3fa5cae2010-10-26 07:05:15 +00006041 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006042 }
John McCalldbd872f2009-12-08 09:08:17 +00006043
6044 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006045 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006046 TemplateArgs = &TransArgs;
6047 TransArgs.setLAngleLoc(E->getLAngleLoc());
6048 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006049 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6050 E->getNumTemplateArgs(),
6051 TransArgs))
6052 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006053 }
6054
Douglas Gregor40d96a62011-02-28 21:54:11 +00006055 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6056 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006057}
Mike Stump1eb44332009-09-09 15:08:12 +00006058
Douglas Gregorb98b1992009-08-11 05:31:07 +00006059template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006060ExprResult
John McCall454feb92009-12-08 09:21:05 +00006061TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006062 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006063}
Mike Stump1eb44332009-09-09 15:08:12 +00006064
Douglas Gregorb98b1992009-08-11 05:31:07 +00006065template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006066ExprResult
John McCall454feb92009-12-08 09:21:05 +00006067TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006068 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006069}
Mike Stump1eb44332009-09-09 15:08:12 +00006070
Douglas Gregorb98b1992009-08-11 05:31:07 +00006071template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006072ExprResult
John McCall454feb92009-12-08 09:21:05 +00006073TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006074 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006075}
Mike Stump1eb44332009-09-09 15:08:12 +00006076
Douglas Gregorb98b1992009-08-11 05:31:07 +00006077template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006078ExprResult
John McCall454feb92009-12-08 09:21:05 +00006079TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006080 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006081}
Mike Stump1eb44332009-09-09 15:08:12 +00006082
Douglas Gregorb98b1992009-08-11 05:31:07 +00006083template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006084ExprResult
John McCall454feb92009-12-08 09:21:05 +00006085TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006086 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006087}
6088
6089template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006090ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006091TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6092 ExprResult ControllingExpr =
6093 getDerived().TransformExpr(E->getControllingExpr());
6094 if (ControllingExpr.isInvalid())
6095 return ExprError();
6096
Chris Lattner686775d2011-07-20 06:58:45 +00006097 SmallVector<Expr *, 4> AssocExprs;
6098 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006099 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6100 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6101 if (TS) {
6102 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6103 if (!AssocType)
6104 return ExprError();
6105 AssocTypes.push_back(AssocType);
6106 } else {
6107 AssocTypes.push_back(0);
6108 }
6109
6110 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6111 if (AssocExpr.isInvalid())
6112 return ExprError();
6113 AssocExprs.push_back(AssocExpr.release());
6114 }
6115
6116 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6117 E->getDefaultLoc(),
6118 E->getRParenLoc(),
6119 ControllingExpr.release(),
6120 AssocTypes.data(),
6121 AssocExprs.data(),
6122 E->getNumAssocs());
6123}
6124
6125template<typename Derived>
6126ExprResult
John McCall454feb92009-12-08 09:21:05 +00006127TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006128 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006129 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006130 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006131
Douglas Gregorb98b1992009-08-11 05:31:07 +00006132 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006133 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006134
John McCall9ae2f072010-08-23 23:25:46 +00006135 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006136 E->getRParen());
6137}
6138
Mike Stump1eb44332009-09-09 15:08:12 +00006139template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006140ExprResult
John McCall454feb92009-12-08 09:21:05 +00006141TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006142 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006143 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006144 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006145
Douglas Gregorb98b1992009-08-11 05:31:07 +00006146 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006147 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006148
Douglas Gregorb98b1992009-08-11 05:31:07 +00006149 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6150 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006151 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006152}
Mike Stump1eb44332009-09-09 15:08:12 +00006153
Douglas Gregorb98b1992009-08-11 05:31:07 +00006154template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006155ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006156TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6157 // Transform the type.
6158 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6159 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006160 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006161
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006162 // Transform all of the components into components similar to what the
6163 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006164 // FIXME: It would be slightly more efficient in the non-dependent case to
6165 // just map FieldDecls, rather than requiring the rebuilder to look for
6166 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006167 // template code that we don't care.
6168 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006169 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006170 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006171 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006172 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6173 const Node &ON = E->getComponent(I);
6174 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006175 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006176 Comp.LocStart = ON.getSourceRange().getBegin();
6177 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006178 switch (ON.getKind()) {
6179 case Node::Array: {
6180 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006181 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006182 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006183 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006184
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006185 ExprChanged = ExprChanged || Index.get() != FromIndex;
6186 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006187 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006188 break;
6189 }
Sean Huntc3021132010-05-05 15:23:54 +00006190
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006191 case Node::Field:
6192 case Node::Identifier:
6193 Comp.isBrackets = false;
6194 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006195 if (!Comp.U.IdentInfo)
6196 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006197
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006198 break;
Sean Huntc3021132010-05-05 15:23:54 +00006199
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006200 case Node::Base:
6201 // Will be recomputed during the rebuild.
6202 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006203 }
Sean Huntc3021132010-05-05 15:23:54 +00006204
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006205 Components.push_back(Comp);
6206 }
Sean Huntc3021132010-05-05 15:23:54 +00006207
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006208 // If nothing changed, retain the existing expression.
6209 if (!getDerived().AlwaysRebuild() &&
6210 Type == E->getTypeSourceInfo() &&
6211 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006212 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006213
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006214 // Build a new offsetof expression.
6215 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6216 Components.data(), Components.size(),
6217 E->getRParenLoc());
6218}
6219
6220template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006221ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006222TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6223 assert(getDerived().AlreadyTransformed(E->getType()) &&
6224 "opaque value expression requires transformation");
6225 return SemaRef.Owned(E);
6226}
6227
6228template<typename Derived>
6229ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006230TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006231 // Rebuild the syntactic form. The original syntactic form has
6232 // opaque-value expressions in it, so strip those away and rebuild
6233 // the result. This is a really awful way of doing this, but the
6234 // better solution (rebuilding the semantic expressions and
6235 // rebinding OVEs as necessary) doesn't work; we'd need
6236 // TreeTransform to not strip away implicit conversions.
6237 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6238 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006239 if (result.isInvalid()) return ExprError();
6240
6241 // If that gives us a pseudo-object result back, the pseudo-object
6242 // expression must have been an lvalue-to-rvalue conversion which we
6243 // should reapply.
6244 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6245 result = SemaRef.checkPseudoObjectRValue(result.take());
6246
6247 return result;
6248}
6249
6250template<typename Derived>
6251ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006252TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6253 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006254 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006255 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006256
John McCalla93c9342009-12-07 02:54:59 +00006257 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006258 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006259 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006260
John McCall5ab75172009-11-04 07:28:41 +00006261 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006262 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006263
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006264 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6265 E->getKind(),
6266 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006267 }
Mike Stump1eb44332009-09-09 15:08:12 +00006268
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006269 // C++0x [expr.sizeof]p1:
6270 // The operand is either an expression, which is an unevaluated operand
6271 // [...]
6272 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006273
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006274 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6275 if (SubExpr.isInvalid())
6276 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006277
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006278 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6279 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006280
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006281 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6282 E->getOperatorLoc(),
6283 E->getKind(),
6284 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006285}
Mike Stump1eb44332009-09-09 15:08:12 +00006286
Douglas Gregorb98b1992009-08-11 05:31:07 +00006287template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006288ExprResult
John McCall454feb92009-12-08 09:21:05 +00006289TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006290 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006291 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006292 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006293
John McCall60d7b3a2010-08-24 06:29:42 +00006294 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006295 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006296 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006297
6298
Douglas Gregorb98b1992009-08-11 05:31:07 +00006299 if (!getDerived().AlwaysRebuild() &&
6300 LHS.get() == E->getLHS() &&
6301 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006302 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006303
John McCall9ae2f072010-08-23 23:25:46 +00006304 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006305 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006306 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006307 E->getRBracketLoc());
6308}
Mike Stump1eb44332009-09-09 15:08:12 +00006309
6310template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006311ExprResult
John McCall454feb92009-12-08 09:21:05 +00006312TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006313 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006314 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006315 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006316 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006317
6318 // Transform arguments.
6319 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006320 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006321 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6322 &ArgChanged))
6323 return ExprError();
6324
Douglas Gregorb98b1992009-08-11 05:31:07 +00006325 if (!getDerived().AlwaysRebuild() &&
6326 Callee.get() == E->getCallee() &&
6327 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006328 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006329
Douglas Gregorb98b1992009-08-11 05:31:07 +00006330 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006331 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006332 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006333 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006334 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006335 E->getRParenLoc());
6336}
Mike Stump1eb44332009-09-09 15:08:12 +00006337
6338template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006339ExprResult
John McCall454feb92009-12-08 09:21:05 +00006340TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006341 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006342 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006343 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006344
Douglas Gregor40d96a62011-02-28 21:54:11 +00006345 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006346 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006347 QualifierLoc
6348 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6349
6350 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006351 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006352 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006353 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006354
Eli Friedmanf595cc42009-12-04 06:40:45 +00006355 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006356 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6357 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006358 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006359 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006360
John McCall6bb80172010-03-30 21:47:33 +00006361 NamedDecl *FoundDecl = E->getFoundDecl();
6362 if (FoundDecl == E->getMemberDecl()) {
6363 FoundDecl = Member;
6364 } else {
6365 FoundDecl = cast_or_null<NamedDecl>(
6366 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6367 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006368 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006369 }
6370
Douglas Gregorb98b1992009-08-11 05:31:07 +00006371 if (!getDerived().AlwaysRebuild() &&
6372 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006373 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006374 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006375 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006376 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006377
Anders Carlsson1f240322009-12-22 05:24:09 +00006378 // Mark it referenced in the new context regardless.
6379 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006380 SemaRef.MarkMemberReferenced(E);
6381
John McCall3fa5cae2010-10-26 07:05:15 +00006382 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006383 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006384
John McCalld5532b62009-11-23 01:53:49 +00006385 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006386 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006387 TransArgs.setLAngleLoc(E->getLAngleLoc());
6388 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006389 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6390 E->getNumTemplateArgs(),
6391 TransArgs))
6392 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006393 }
Sean Huntc3021132010-05-05 15:23:54 +00006394
Douglas Gregorb98b1992009-08-11 05:31:07 +00006395 // FIXME: Bogus source location for the operator
6396 SourceLocation FakeOperatorLoc
6397 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6398
John McCallc2233c52010-01-15 08:34:02 +00006399 // FIXME: to do this check properly, we will need to preserve the
6400 // first-qualifier-in-scope here, just in case we had a dependent
6401 // base (and therefore couldn't do the check) and a
6402 // nested-name-qualifier (and therefore could do the lookup).
6403 NamedDecl *FirstQualifierInScope = 0;
6404
John McCall9ae2f072010-08-23 23:25:46 +00006405 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006406 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006407 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006408 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006409 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006410 Member,
John McCall6bb80172010-03-30 21:47:33 +00006411 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006412 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006413 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006414 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006415}
Mike Stump1eb44332009-09-09 15:08:12 +00006416
Douglas Gregorb98b1992009-08-11 05:31:07 +00006417template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006418ExprResult
John McCall454feb92009-12-08 09:21:05 +00006419TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006420 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006421 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006422 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006423
John McCall60d7b3a2010-08-24 06:29:42 +00006424 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006425 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006426 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006427
Douglas Gregorb98b1992009-08-11 05:31:07 +00006428 if (!getDerived().AlwaysRebuild() &&
6429 LHS.get() == E->getLHS() &&
6430 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006431 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006432
Douglas Gregorb98b1992009-08-11 05:31:07 +00006433 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006434 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006435}
6436
Mike Stump1eb44332009-09-09 15:08:12 +00006437template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006438ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006439TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006440 CompoundAssignOperator *E) {
6441 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006442}
Mike Stump1eb44332009-09-09 15:08:12 +00006443
Douglas Gregorb98b1992009-08-11 05:31:07 +00006444template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006445ExprResult TreeTransform<Derived>::
6446TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6447 // Just rebuild the common and RHS expressions and see whether we
6448 // get any changes.
6449
6450 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6451 if (commonExpr.isInvalid())
6452 return ExprError();
6453
6454 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6455 if (rhs.isInvalid())
6456 return ExprError();
6457
6458 if (!getDerived().AlwaysRebuild() &&
6459 commonExpr.get() == e->getCommon() &&
6460 rhs.get() == e->getFalseExpr())
6461 return SemaRef.Owned(e);
6462
6463 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6464 e->getQuestionLoc(),
6465 0,
6466 e->getColonLoc(),
6467 rhs.get());
6468}
6469
6470template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006471ExprResult
John McCall454feb92009-12-08 09:21:05 +00006472TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006473 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006474 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006475 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006476
John McCall60d7b3a2010-08-24 06:29:42 +00006477 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006478 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006479 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006480
John McCall60d7b3a2010-08-24 06:29:42 +00006481 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006483 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006484
Douglas Gregorb98b1992009-08-11 05:31:07 +00006485 if (!getDerived().AlwaysRebuild() &&
6486 Cond.get() == E->getCond() &&
6487 LHS.get() == E->getLHS() &&
6488 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006489 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006490
John McCall9ae2f072010-08-23 23:25:46 +00006491 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006492 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006493 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006494 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006495 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006496}
Mike Stump1eb44332009-09-09 15:08:12 +00006497
6498template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006499ExprResult
John McCall454feb92009-12-08 09:21:05 +00006500TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006501 // Implicit casts are eliminated during transformation, since they
6502 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006503 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504}
Mike Stump1eb44332009-09-09 15:08:12 +00006505
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006507ExprResult
John McCall454feb92009-12-08 09:21:05 +00006508TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006509 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6510 if (!Type)
6511 return ExprError();
6512
John McCall60d7b3a2010-08-24 06:29:42 +00006513 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006514 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006515 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006516 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006517
Douglas Gregorb98b1992009-08-11 05:31:07 +00006518 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006519 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006520 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006521 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006522
John McCall9d125032010-01-15 18:39:57 +00006523 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006524 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006525 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006526 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006527}
Mike Stump1eb44332009-09-09 15:08:12 +00006528
Douglas Gregorb98b1992009-08-11 05:31:07 +00006529template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006530ExprResult
John McCall454feb92009-12-08 09:21:05 +00006531TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006532 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6533 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6534 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006535 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006536
John McCall60d7b3a2010-08-24 06:29:42 +00006537 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006538 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006539 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006540
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006542 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006543 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006544 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006545
John McCall1d7d8d62010-01-19 22:33:45 +00006546 // Note: the expression type doesn't necessarily match the
6547 // type-as-written, but that's okay, because it should always be
6548 // derivable from the initializer.
6549
John McCall42f56b52010-01-18 19:35:47 +00006550 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006552 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006553}
Mike Stump1eb44332009-09-09 15:08:12 +00006554
Douglas Gregorb98b1992009-08-11 05:31:07 +00006555template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006556ExprResult
John McCall454feb92009-12-08 09:21:05 +00006557TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006558 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006559 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006560 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006561
Douglas Gregorb98b1992009-08-11 05:31:07 +00006562 if (!getDerived().AlwaysRebuild() &&
6563 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006564 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006565
Douglas Gregorb98b1992009-08-11 05:31:07 +00006566 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006567 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006568 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006569 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006570 E->getAccessorLoc(),
6571 E->getAccessor());
6572}
Mike Stump1eb44332009-09-09 15:08:12 +00006573
Douglas Gregorb98b1992009-08-11 05:31:07 +00006574template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006575ExprResult
John McCall454feb92009-12-08 09:21:05 +00006576TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006577 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006578
John McCallca0408f2010-08-23 06:44:23 +00006579 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006580 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6581 Inits, &InitChanged))
6582 return ExprError();
6583
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006585 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006586
Douglas Gregorb98b1992009-08-11 05:31:07 +00006587 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006588 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006589}
Mike Stump1eb44332009-09-09 15:08:12 +00006590
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006592ExprResult
John McCall454feb92009-12-08 09:21:05 +00006593TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006595
Douglas Gregor43959a92009-08-20 07:17:43 +00006596 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006597 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006598 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006599 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006600
Douglas Gregor43959a92009-08-20 07:17:43 +00006601 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006602 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006603 bool ExprChanged = false;
6604 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6605 DEnd = E->designators_end();
6606 D != DEnd; ++D) {
6607 if (D->isFieldDesignator()) {
6608 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6609 D->getDotLoc(),
6610 D->getFieldLoc()));
6611 continue;
6612 }
Mike Stump1eb44332009-09-09 15:08:12 +00006613
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006615 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006616 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006617 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006618
6619 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006621
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6623 ArrayExprs.push_back(Index.release());
6624 continue;
6625 }
Mike Stump1eb44332009-09-09 15:08:12 +00006626
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006628 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6630 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006631 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006632
John McCall60d7b3a2010-08-24 06:29:42 +00006633 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006635 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006636
6637 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006638 End.get(),
6639 D->getLBracketLoc(),
6640 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006641
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6643 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006644
Douglas Gregorb98b1992009-08-11 05:31:07 +00006645 ArrayExprs.push_back(Start.release());
6646 ArrayExprs.push_back(End.release());
6647 }
Mike Stump1eb44332009-09-09 15:08:12 +00006648
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649 if (!getDerived().AlwaysRebuild() &&
6650 Init.get() == E->getInit() &&
6651 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006652 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006653
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6655 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006656 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006657}
Mike Stump1eb44332009-09-09 15:08:12 +00006658
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006660ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006662 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006663 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006664
Douglas Gregor5557b252009-10-28 00:29:27 +00006665 // FIXME: Will we ever have proper type location here? Will we actually
6666 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667 QualType T = getDerived().TransformType(E->getType());
6668 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006669 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006670
Douglas Gregorb98b1992009-08-11 05:31:07 +00006671 if (!getDerived().AlwaysRebuild() &&
6672 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006673 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006674
Douglas Gregorb98b1992009-08-11 05:31:07 +00006675 return getDerived().RebuildImplicitValueInitExpr(T);
6676}
Mike Stump1eb44332009-09-09 15:08:12 +00006677
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006679ExprResult
John McCall454feb92009-12-08 09:21:05 +00006680TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006681 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6682 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006683 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006684
John McCall60d7b3a2010-08-24 06:29:42 +00006685 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006686 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006687 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006688
Douglas Gregorb98b1992009-08-11 05:31:07 +00006689 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006690 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006691 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006692 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006693
John McCall9ae2f072010-08-23 23:25:46 +00006694 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006695 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696}
6697
6698template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006699ExprResult
John McCall454feb92009-12-08 09:21:05 +00006700TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006702 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006703 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6704 &ArgumentChanged))
6705 return ExprError();
6706
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6708 move_arg(Inits),
6709 E->getRParenLoc());
6710}
Mike Stump1eb44332009-09-09 15:08:12 +00006711
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712/// \brief Transform an address-of-label expression.
6713///
6714/// By default, the transformation of an address-of-label expression always
6715/// rebuilds the expression, so that the label identifier can be resolved to
6716/// the corresponding label statement by semantic analysis.
6717template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006718ExprResult
John McCall454feb92009-12-08 09:21:05 +00006719TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006720 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6721 E->getLabel());
6722 if (!LD)
6723 return ExprError();
6724
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006726 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006727}
Mike Stump1eb44332009-09-09 15:08:12 +00006728
6729template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006730ExprResult
John McCall454feb92009-12-08 09:21:05 +00006731TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006732 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6734 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006735 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006736
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737 if (!getDerived().AlwaysRebuild() &&
6738 SubStmt.get() == E->getSubStmt())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006739 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006740
6741 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006742 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743 E->getRParenLoc());
6744}
Mike Stump1eb44332009-09-09 15:08:12 +00006745
Douglas Gregorb98b1992009-08-11 05:31:07 +00006746template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006747ExprResult
John McCall454feb92009-12-08 09:21:05 +00006748TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006749 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006750 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006751 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006752
John McCall60d7b3a2010-08-24 06:29:42 +00006753 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006754 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006755 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006756
John McCall60d7b3a2010-08-24 06:29:42 +00006757 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006759 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006760
Douglas Gregorb98b1992009-08-11 05:31:07 +00006761 if (!getDerived().AlwaysRebuild() &&
6762 Cond.get() == E->getCond() &&
6763 LHS.get() == E->getLHS() &&
6764 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006765 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006766
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006768 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 E->getRParenLoc());
6770}
Mike Stump1eb44332009-09-09 15:08:12 +00006771
Douglas Gregorb98b1992009-08-11 05:31:07 +00006772template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006773ExprResult
John McCall454feb92009-12-08 09:21:05 +00006774TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006775 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006776}
6777
6778template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006779ExprResult
John McCall454feb92009-12-08 09:21:05 +00006780TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006781 switch (E->getOperator()) {
6782 case OO_New:
6783 case OO_Delete:
6784 case OO_Array_New:
6785 case OO_Array_Delete:
6786 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Sean Huntc3021132010-05-05 15:23:54 +00006787
Douglas Gregor668d6d92009-12-13 20:44:55 +00006788 case OO_Call: {
6789 // This is a call to an object's operator().
6790 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6791
6792 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006793 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006794 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006795 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006796
6797 // FIXME: Poor location information
6798 SourceLocation FakeLParenLoc
6799 = SemaRef.PP.getLocForEndOfToken(
6800 static_cast<Expr *>(Object.get())->getLocEnd());
6801
6802 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006803 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006804 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6805 Args))
6806 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006807
John McCall9ae2f072010-08-23 23:25:46 +00006808 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006809 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006810 E->getLocEnd());
6811 }
6812
6813#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6814 case OO_##Name:
6815#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6816#include "clang/Basic/OperatorKinds.def"
6817 case OO_Subscript:
6818 // Handled below.
6819 break;
6820
6821 case OO_Conditional:
6822 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006823
6824 case OO_None:
6825 case NUM_OVERLOADED_OPERATORS:
6826 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006827 }
6828
John McCall60d7b3a2010-08-24 06:29:42 +00006829 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006831 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006832
John McCall60d7b3a2010-08-24 06:29:42 +00006833 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006835 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836
John McCall60d7b3a2010-08-24 06:29:42 +00006837 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006838 if (E->getNumArgs() == 2) {
6839 Second = getDerived().TransformExpr(E->getArg(1));
6840 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006841 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006842 }
Mike Stump1eb44332009-09-09 15:08:12 +00006843
Douglas Gregorb98b1992009-08-11 05:31:07 +00006844 if (!getDerived().AlwaysRebuild() &&
6845 Callee.get() == E->getCallee() &&
6846 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006847 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006848 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006849
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6851 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006852 Callee.get(),
6853 First.get(),
6854 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006855}
Mike Stump1eb44332009-09-09 15:08:12 +00006856
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006858ExprResult
John McCall454feb92009-12-08 09:21:05 +00006859TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6860 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006861}
Mike Stump1eb44332009-09-09 15:08:12 +00006862
Douglas Gregorb98b1992009-08-11 05:31:07 +00006863template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006864ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006865TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6866 // Transform the callee.
6867 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6868 if (Callee.isInvalid())
6869 return ExprError();
6870
6871 // Transform exec config.
6872 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6873 if (EC.isInvalid())
6874 return ExprError();
6875
6876 // Transform arguments.
6877 bool ArgChanged = false;
6878 ASTOwningVector<Expr*> Args(SemaRef);
6879 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6880 &ArgChanged))
6881 return ExprError();
6882
6883 if (!getDerived().AlwaysRebuild() &&
6884 Callee.get() == E->getCallee() &&
6885 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006886 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006887
6888 // FIXME: Wrong source location information for the '('.
6889 SourceLocation FakeLParenLoc
6890 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6891 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6892 move_arg(Args),
6893 E->getRParenLoc(), EC.get());
6894}
6895
6896template<typename Derived>
6897ExprResult
John McCall454feb92009-12-08 09:21:05 +00006898TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006899 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6900 if (!Type)
6901 return ExprError();
6902
John McCall60d7b3a2010-08-24 06:29:42 +00006903 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006904 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006905 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006906 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006907
Douglas Gregorb98b1992009-08-11 05:31:07 +00006908 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006909 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006910 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006911 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006912
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006914 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006915 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6916 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6917 SourceLocation FakeRParenLoc
6918 = SemaRef.PP.getLocForEndOfToken(
6919 E->getSubExpr()->getSourceRange().getEnd());
6920 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006921 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006922 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006923 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006924 FakeRAngleLoc,
6925 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006926 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006927 FakeRParenLoc);
6928}
Mike Stump1eb44332009-09-09 15:08:12 +00006929
Douglas Gregorb98b1992009-08-11 05:31:07 +00006930template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006931ExprResult
John McCall454feb92009-12-08 09:21:05 +00006932TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6933 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006934}
Mike Stump1eb44332009-09-09 15:08:12 +00006935
6936template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006937ExprResult
John McCall454feb92009-12-08 09:21:05 +00006938TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6939 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006940}
6941
Douglas Gregorb98b1992009-08-11 05:31:07 +00006942template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006943ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006944TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006945 CXXReinterpretCastExpr *E) {
6946 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006947}
Mike Stump1eb44332009-09-09 15:08:12 +00006948
Douglas Gregorb98b1992009-08-11 05:31:07 +00006949template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006950ExprResult
John McCall454feb92009-12-08 09:21:05 +00006951TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6952 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006953}
Mike Stump1eb44332009-09-09 15:08:12 +00006954
Douglas Gregorb98b1992009-08-11 05:31:07 +00006955template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006956ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006957TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006958 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006959 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6960 if (!Type)
6961 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006962
John McCall60d7b3a2010-08-24 06:29:42 +00006963 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006964 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006965 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006966 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006967
Douglas Gregorb98b1992009-08-11 05:31:07 +00006968 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006969 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006970 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006971 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006972
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006973 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006975 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976 E->getRParenLoc());
6977}
Mike Stump1eb44332009-09-09 15:08:12 +00006978
Douglas Gregorb98b1992009-08-11 05:31:07 +00006979template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006980ExprResult
John McCall454feb92009-12-08 09:21:05 +00006981TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006982 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006983 TypeSourceInfo *TInfo
6984 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6985 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006986 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006987
Douglas Gregorb98b1992009-08-11 05:31:07 +00006988 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006989 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006990 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006991
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006992 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6993 E->getLocStart(),
6994 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995 E->getLocEnd());
6996 }
Mike Stump1eb44332009-09-09 15:08:12 +00006997
Eli Friedmanef331b72012-01-20 01:26:23 +00006998 // We don't know whether the subexpression is potentially evaluated until
6999 // after we perform semantic analysis. We speculatively assume it is
7000 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007001 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007002 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007003
John McCall60d7b3a2010-08-24 06:29:42 +00007004 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007005 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007006 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007007
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008 if (!getDerived().AlwaysRebuild() &&
7009 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007010 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007011
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007012 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7013 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007014 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015 E->getLocEnd());
7016}
7017
7018template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007019ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007020TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7021 if (E->isTypeOperand()) {
7022 TypeSourceInfo *TInfo
7023 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7024 if (!TInfo)
7025 return ExprError();
7026
7027 if (!getDerived().AlwaysRebuild() &&
7028 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007029 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007030
Douglas Gregor3c52a212011-03-06 17:40:41 +00007031 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007032 E->getLocStart(),
7033 TInfo,
7034 E->getLocEnd());
7035 }
7036
Francois Pichet01b7c302010-09-08 12:20:18 +00007037 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7038
7039 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7040 if (SubExpr.isInvalid())
7041 return ExprError();
7042
7043 if (!getDerived().AlwaysRebuild() &&
7044 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007045 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007046
7047 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7048 E->getLocStart(),
7049 SubExpr.get(),
7050 E->getLocEnd());
7051}
7052
7053template<typename Derived>
7054ExprResult
John McCall454feb92009-12-08 09:21:05 +00007055TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007056 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007057}
Mike Stump1eb44332009-09-09 15:08:12 +00007058
Douglas Gregorb98b1992009-08-11 05:31:07 +00007059template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007060ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007062 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007063 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064}
Mike Stump1eb44332009-09-09 15:08:12 +00007065
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007067ExprResult
John McCall454feb92009-12-08 09:21:05 +00007068TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007069 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007070 QualType T;
7071 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7072 T = MD->getThisType(getSema().Context);
7073 else
7074 T = getSema().Context.getPointerType(
7075 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007076
Douglas Gregorec79d872012-02-24 17:41:38 +00007077 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7078 // Make sure that we capture 'this'.
7079 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007080 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007081 }
7082
Douglas Gregor828a1972010-01-07 23:12:05 +00007083 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007084}
Mike Stump1eb44332009-09-09 15:08:12 +00007085
Douglas Gregorb98b1992009-08-11 05:31:07 +00007086template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007087ExprResult
John McCall454feb92009-12-08 09:21:05 +00007088TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007089 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007090 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007091 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007092
Douglas Gregorb98b1992009-08-11 05:31:07 +00007093 if (!getDerived().AlwaysRebuild() &&
7094 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007095 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007096
Douglas Gregorbca01b42011-07-06 22:04:06 +00007097 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7098 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007099}
Mike Stump1eb44332009-09-09 15:08:12 +00007100
Douglas Gregorb98b1992009-08-11 05:31:07 +00007101template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007102ExprResult
John McCall454feb92009-12-08 09:21:05 +00007103TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007104 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007105 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7106 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007107 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007108 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007109
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007110 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007111 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007112 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007113
Douglas Gregor036aed12009-12-23 23:03:06 +00007114 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007115}
Mike Stump1eb44332009-09-09 15:08:12 +00007116
Douglas Gregorb98b1992009-08-11 05:31:07 +00007117template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007118ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007119TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7120 CXXScalarValueInitExpr *E) {
7121 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7122 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007123 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007124
Douglas Gregorb98b1992009-08-11 05:31:07 +00007125 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007126 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007127 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007128
Douglas Gregorab6677e2010-09-08 00:15:04 +00007129 return getDerived().RebuildCXXScalarValueInitExpr(T,
7130 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007131 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007132}
Mike Stump1eb44332009-09-09 15:08:12 +00007133
Douglas Gregorb98b1992009-08-11 05:31:07 +00007134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007135ExprResult
John McCall454feb92009-12-08 09:21:05 +00007136TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007137 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007138 TypeSourceInfo *AllocTypeInfo
7139 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7140 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007141 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007142
Douglas Gregorb98b1992009-08-11 05:31:07 +00007143 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007144 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007145 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007146 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007147
Douglas Gregorb98b1992009-08-11 05:31:07 +00007148 // Transform the placement arguments (if any).
7149 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007150 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007151 if (getDerived().TransformExprs(E->getPlacementArgs(),
7152 E->getNumPlacementArgs(), true,
7153 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007154 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007155
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007156 // Transform the initializer (if any).
7157 Expr *OldInit = E->getInitializer();
7158 ExprResult NewInit;
7159 if (OldInit)
7160 NewInit = getDerived().TransformExpr(OldInit);
7161 if (NewInit.isInvalid())
7162 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007163
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007164 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007165 FunctionDecl *OperatorNew = 0;
7166 if (E->getOperatorNew()) {
7167 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007168 getDerived().TransformDecl(E->getLocStart(),
7169 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007170 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007171 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007172 }
7173
7174 FunctionDecl *OperatorDelete = 0;
7175 if (E->getOperatorDelete()) {
7176 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007177 getDerived().TransformDecl(E->getLocStart(),
7178 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007179 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007180 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007181 }
Sean Huntc3021132010-05-05 15:23:54 +00007182
Douglas Gregorb98b1992009-08-11 05:31:07 +00007183 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007184 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007185 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007186 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007187 OperatorNew == E->getOperatorNew() &&
7188 OperatorDelete == E->getOperatorDelete() &&
7189 !ArgumentChanged) {
7190 // Mark any declarations we need as referenced.
7191 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007192 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007193 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007194 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007195 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007196
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007197 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007198 QualType ElementType
7199 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7200 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7201 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7202 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007203 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007204 }
7205 }
7206 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007207
John McCall3fa5cae2010-10-26 07:05:15 +00007208 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007209 }
Mike Stump1eb44332009-09-09 15:08:12 +00007210
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007211 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007212 if (!ArraySize.get()) {
7213 // If no array size was specified, but the new expression was
7214 // instantiated with an array type (e.g., "new T" where T is
7215 // instantiated with "int[4]"), extract the outer bound from the
7216 // array type as our array size. We do this with constant and
7217 // dependently-sized array types.
7218 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7219 if (!ArrayT) {
7220 // Do nothing
7221 } else if (const ConstantArrayType *ConsArrayT
7222 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007223 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007224 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7225 ConsArrayT->getSize(),
7226 SemaRef.Context.getSizeType(),
7227 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007228 AllocType = ConsArrayT->getElementType();
7229 } else if (const DependentSizedArrayType *DepArrayT
7230 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7231 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007232 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007233 AllocType = DepArrayT->getElementType();
7234 }
7235 }
7236 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007237
Douglas Gregorb98b1992009-08-11 05:31:07 +00007238 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7239 E->isGlobalNew(),
7240 /*FIXME:*/E->getLocStart(),
7241 move_arg(PlacementArgs),
7242 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007243 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007244 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007245 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007246 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007247 E->getDirectInitRange(),
7248 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007249}
Mike Stump1eb44332009-09-09 15:08:12 +00007250
Douglas Gregorb98b1992009-08-11 05:31:07 +00007251template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007252ExprResult
John McCall454feb92009-12-08 09:21:05 +00007253TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007254 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007255 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007256 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007257
Douglas Gregor1af74512010-02-26 00:38:10 +00007258 // Transform the delete operator, if known.
7259 FunctionDecl *OperatorDelete = 0;
7260 if (E->getOperatorDelete()) {
7261 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007262 getDerived().TransformDecl(E->getLocStart(),
7263 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007264 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007265 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007266 }
Sean Huntc3021132010-05-05 15:23:54 +00007267
Douglas Gregorb98b1992009-08-11 05:31:07 +00007268 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007269 Operand.get() == E->getArgument() &&
7270 OperatorDelete == E->getOperatorDelete()) {
7271 // Mark any declarations we need as referenced.
7272 // FIXME: instantiation-specific.
7273 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007274 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007275
7276 if (!E->getArgument()->isTypeDependent()) {
7277 QualType Destroyed = SemaRef.Context.getBaseElementType(
7278 E->getDestroyedType());
7279 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7280 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007281 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7282 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007283 }
7284 }
7285
John McCall3fa5cae2010-10-26 07:05:15 +00007286 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007287 }
Mike Stump1eb44332009-09-09 15:08:12 +00007288
Douglas Gregorb98b1992009-08-11 05:31:07 +00007289 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7290 E->isGlobalDelete(),
7291 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007292 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007293}
Mike Stump1eb44332009-09-09 15:08:12 +00007294
Douglas Gregorb98b1992009-08-11 05:31:07 +00007295template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007296ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007297TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007298 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007299 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007300 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007301 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007302
John McCallb3d87482010-08-24 05:47:05 +00007303 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007304 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007305 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007306 E->getOperatorLoc(),
7307 E->isArrow()? tok::arrow : tok::period,
7308 ObjectTypePtr,
7309 MayBePseudoDestructor);
7310 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007311 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007312
John McCallb3d87482010-08-24 05:47:05 +00007313 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007314 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7315 if (QualifierLoc) {
7316 QualifierLoc
7317 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7318 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007319 return ExprError();
7320 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007321 CXXScopeSpec SS;
7322 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007323
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007324 PseudoDestructorTypeStorage Destroyed;
7325 if (E->getDestroyedTypeInfo()) {
7326 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007327 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007328 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007329 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007330 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007331 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007332 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007333 // We aren't likely to be able to resolve the identifier down to a type
7334 // now anyway, so just retain the identifier.
7335 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7336 E->getDestroyedTypeLoc());
7337 } else {
7338 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007339 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007340 *E->getDestroyedTypeIdentifier(),
7341 E->getDestroyedTypeLoc(),
7342 /*Scope=*/0,
7343 SS, ObjectTypePtr,
7344 false);
7345 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007346 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007347
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007348 Destroyed
7349 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7350 E->getDestroyedTypeLoc());
7351 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007352
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007353 TypeSourceInfo *ScopeTypeInfo = 0;
7354 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007355 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007356 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007357 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007358 }
Sean Huntc3021132010-05-05 15:23:54 +00007359
John McCall9ae2f072010-08-23 23:25:46 +00007360 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007361 E->getOperatorLoc(),
7362 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007363 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007364 ScopeTypeInfo,
7365 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007366 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007367 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007368}
Mike Stump1eb44332009-09-09 15:08:12 +00007369
Douglas Gregora71d8192009-09-04 17:36:40 +00007370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007371ExprResult
John McCallba135432009-11-21 08:51:07 +00007372TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007373 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007374 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7375 Sema::LookupOrdinaryName);
7376
7377 // Transform all the decls.
7378 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7379 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007380 NamedDecl *InstD = static_cast<NamedDecl*>(
7381 getDerived().TransformDecl(Old->getNameLoc(),
7382 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007383 if (!InstD) {
7384 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7385 // This can happen because of dependent hiding.
7386 if (isa<UsingShadowDecl>(*I))
7387 continue;
7388 else
John McCallf312b1e2010-08-26 23:41:50 +00007389 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007390 }
John McCallf7a1a742009-11-24 19:00:30 +00007391
7392 // Expand using declarations.
7393 if (isa<UsingDecl>(InstD)) {
7394 UsingDecl *UD = cast<UsingDecl>(InstD);
7395 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7396 E = UD->shadow_end(); I != E; ++I)
7397 R.addDecl(*I);
7398 continue;
7399 }
7400
7401 R.addDecl(InstD);
7402 }
7403
7404 // Resolve a kind, but don't do any further analysis. If it's
7405 // ambiguous, the callee needs to deal with it.
7406 R.resolveKind();
7407
7408 // Rebuild the nested-name qualifier, if present.
7409 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007410 if (Old->getQualifierLoc()) {
7411 NestedNameSpecifierLoc QualifierLoc
7412 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7413 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007414 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007415
Douglas Gregor4c9be892011-02-28 20:01:57 +00007416 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007417 }
7418
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007419 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007420 CXXRecordDecl *NamingClass
7421 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7422 Old->getNameLoc(),
7423 Old->getNamingClass()));
7424 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007425 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007426
Douglas Gregor66c45152010-04-27 16:10:10 +00007427 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007428 }
7429
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007430 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7431
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007432 // If we have neither explicit template arguments, nor the template keyword,
7433 // it's a normal declaration name.
7434 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007435 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7436
7437 // If we have template arguments, rebuild them, then rebuild the
7438 // templateid expression.
7439 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007440 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7441 Old->getNumTemplateArgs(),
7442 TransArgs))
7443 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007444
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007445 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007446 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007447}
Mike Stump1eb44332009-09-09 15:08:12 +00007448
Douglas Gregorb98b1992009-08-11 05:31:07 +00007449template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007450ExprResult
John McCall454feb92009-12-08 09:21:05 +00007451TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007452 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7453 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007454 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007455
Douglas Gregorb98b1992009-08-11 05:31:07 +00007456 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007457 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007458 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007459
Mike Stump1eb44332009-09-09 15:08:12 +00007460 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007461 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007462 T,
7463 E->getLocEnd());
7464}
Mike Stump1eb44332009-09-09 15:08:12 +00007465
Douglas Gregorb98b1992009-08-11 05:31:07 +00007466template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007467ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007468TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7469 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7470 if (!LhsT)
7471 return ExprError();
7472
7473 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7474 if (!RhsT)
7475 return ExprError();
7476
7477 if (!getDerived().AlwaysRebuild() &&
7478 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7479 return SemaRef.Owned(E);
7480
7481 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7482 E->getLocStart(),
7483 LhsT, RhsT,
7484 E->getLocEnd());
7485}
7486
7487template<typename Derived>
7488ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007489TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7490 bool ArgChanged = false;
7491 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7492 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7493 TypeSourceInfo *From = E->getArg(I);
7494 TypeLoc FromTL = From->getTypeLoc();
7495 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7496 TypeLocBuilder TLB;
7497 TLB.reserve(FromTL.getFullDataSize());
7498 QualType To = getDerived().TransformType(TLB, FromTL);
7499 if (To.isNull())
7500 return ExprError();
7501
7502 if (To == From->getType())
7503 Args.push_back(From);
7504 else {
7505 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7506 ArgChanged = true;
7507 }
7508 continue;
7509 }
7510
7511 ArgChanged = true;
7512
7513 // We have a pack expansion. Instantiate it.
7514 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
7515 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7516 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7517 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7518
7519 // Determine whether the set of unexpanded parameter packs can and should
7520 // be expanded.
7521 bool Expand = true;
7522 bool RetainExpansion = false;
7523 llvm::Optional<unsigned> OrigNumExpansions
7524 = ExpansionTL.getTypePtr()->getNumExpansions();
7525 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7526 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7527 PatternTL.getSourceRange(),
7528 Unexpanded,
7529 Expand, RetainExpansion,
7530 NumExpansions))
7531 return ExprError();
7532
7533 if (!Expand) {
7534 // The transform has determined that we should perform a simple
7535 // transformation on the pack expansion, producing another pack
7536 // expansion.
7537 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7538
7539 TypeLocBuilder TLB;
7540 TLB.reserve(From->getTypeLoc().getFullDataSize());
7541
7542 QualType To = getDerived().TransformType(TLB, PatternTL);
7543 if (To.isNull())
7544 return ExprError();
7545
7546 To = getDerived().RebuildPackExpansionType(To,
7547 PatternTL.getSourceRange(),
7548 ExpansionTL.getEllipsisLoc(),
7549 NumExpansions);
7550 if (To.isNull())
7551 return ExprError();
7552
7553 PackExpansionTypeLoc ToExpansionTL
7554 = TLB.push<PackExpansionTypeLoc>(To);
7555 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7556 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7557 continue;
7558 }
7559
7560 // Expand the pack expansion by substituting for each argument in the
7561 // pack(s).
7562 for (unsigned I = 0; I != *NumExpansions; ++I) {
7563 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7564 TypeLocBuilder TLB;
7565 TLB.reserve(PatternTL.getFullDataSize());
7566 QualType To = getDerived().TransformType(TLB, PatternTL);
7567 if (To.isNull())
7568 return ExprError();
7569
7570 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7571 }
7572
7573 if (!RetainExpansion)
7574 continue;
7575
7576 // If we're supposed to retain a pack expansion, do so by temporarily
7577 // forgetting the partially-substituted parameter pack.
7578 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7579
7580 TypeLocBuilder TLB;
7581 TLB.reserve(From->getTypeLoc().getFullDataSize());
7582
7583 QualType To = getDerived().TransformType(TLB, PatternTL);
7584 if (To.isNull())
7585 return ExprError();
7586
7587 To = getDerived().RebuildPackExpansionType(To,
7588 PatternTL.getSourceRange(),
7589 ExpansionTL.getEllipsisLoc(),
7590 NumExpansions);
7591 if (To.isNull())
7592 return ExprError();
7593
7594 PackExpansionTypeLoc ToExpansionTL
7595 = TLB.push<PackExpansionTypeLoc>(To);
7596 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7597 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7598 }
7599
7600 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7601 return SemaRef.Owned(E);
7602
7603 return getDerived().RebuildTypeTrait(E->getTrait(),
7604 E->getLocStart(),
7605 Args,
7606 E->getLocEnd());
7607}
7608
7609template<typename Derived>
7610ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007611TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7612 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7613 if (!T)
7614 return ExprError();
7615
7616 if (!getDerived().AlwaysRebuild() &&
7617 T == E->getQueriedTypeSourceInfo())
7618 return SemaRef.Owned(E);
7619
7620 ExprResult SubExpr;
7621 {
7622 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7623 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7624 if (SubExpr.isInvalid())
7625 return ExprError();
7626
7627 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7628 return SemaRef.Owned(E);
7629 }
7630
7631 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7632 E->getLocStart(),
7633 T,
7634 SubExpr.get(),
7635 E->getLocEnd());
7636}
7637
7638template<typename Derived>
7639ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007640TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7641 ExprResult SubExpr;
7642 {
7643 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7644 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7645 if (SubExpr.isInvalid())
7646 return ExprError();
7647
7648 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7649 return SemaRef.Owned(E);
7650 }
7651
7652 return getDerived().RebuildExpressionTrait(
7653 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7654}
7655
7656template<typename Derived>
7657ExprResult
John McCall865d4472009-11-19 22:55:06 +00007658TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007659 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007660 NestedNameSpecifierLoc QualifierLoc
7661 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7662 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007663 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007664 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007665
John McCall43fed0d2010-11-12 08:19:04 +00007666 // TODO: If this is a conversion-function-id, verify that the
7667 // destination type name (if present) resolves the same way after
7668 // instantiation as it did in the local scope.
7669
Abramo Bagnara25777432010-08-11 22:01:17 +00007670 DeclarationNameInfo NameInfo
7671 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7672 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007673 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007674
John McCallf7a1a742009-11-24 19:00:30 +00007675 if (!E->hasExplicitTemplateArgs()) {
7676 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007677 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007678 // Note: it is sufficient to compare the Name component of NameInfo:
7679 // if name has not changed, DNLoc has not changed either.
7680 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007681 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007682
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007683 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007684 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007685 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007686 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007687 }
John McCalld5532b62009-11-23 01:53:49 +00007688
7689 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007690 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7691 E->getNumTemplateArgs(),
7692 TransArgs))
7693 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007694
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007695 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007696 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007697 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007698 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007699}
7700
7701template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007702ExprResult
John McCall454feb92009-12-08 09:21:05 +00007703TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007704 // CXXConstructExprs are always implicit, so when we have a
7705 // 1-argument construction we just transform that argument.
7706 if (E->getNumArgs() == 1 ||
7707 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7708 return getDerived().TransformExpr(E->getArg(0));
7709
Douglas Gregorb98b1992009-08-11 05:31:07 +00007710 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7711
7712 QualType T = getDerived().TransformType(E->getType());
7713 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007714 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007715
7716 CXXConstructorDecl *Constructor
7717 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007718 getDerived().TransformDecl(E->getLocStart(),
7719 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007720 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007721 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007722
Douglas Gregorb98b1992009-08-11 05:31:07 +00007723 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007724 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007725 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7726 &ArgumentChanged))
7727 return ExprError();
7728
Douglas Gregorb98b1992009-08-11 05:31:07 +00007729 if (!getDerived().AlwaysRebuild() &&
7730 T == E->getType() &&
7731 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007732 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007733 // Mark the constructor as referenced.
7734 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007735 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007736 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007737 }
Mike Stump1eb44332009-09-09 15:08:12 +00007738
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007739 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7740 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007741 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007742 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007743 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007744 E->getConstructionKind(),
7745 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007746}
Mike Stump1eb44332009-09-09 15:08:12 +00007747
Douglas Gregorb98b1992009-08-11 05:31:07 +00007748/// \brief Transform a C++ temporary-binding expression.
7749///
Douglas Gregor51326552009-12-24 18:51:59 +00007750/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7751/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007752template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007753ExprResult
John McCall454feb92009-12-08 09:21:05 +00007754TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007755 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007756}
Mike Stump1eb44332009-09-09 15:08:12 +00007757
John McCall4765fa02010-12-06 08:20:24 +00007758/// \brief Transform a C++ expression that contains cleanups that should
7759/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007760///
John McCall4765fa02010-12-06 08:20:24 +00007761/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007762/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007763template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007764ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007765TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007766 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007767}
Mike Stump1eb44332009-09-09 15:08:12 +00007768
Douglas Gregorb98b1992009-08-11 05:31:07 +00007769template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007770ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007771TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007772 CXXTemporaryObjectExpr *E) {
7773 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7774 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007775 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007776
Douglas Gregorb98b1992009-08-11 05:31:07 +00007777 CXXConstructorDecl *Constructor
7778 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007779 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007780 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007781 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007782 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007783
Douglas Gregorb98b1992009-08-11 05:31:07 +00007784 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007785 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007786 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007787 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7788 &ArgumentChanged))
7789 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007790
Douglas Gregorb98b1992009-08-11 05:31:07 +00007791 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007792 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007793 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007794 !ArgumentChanged) {
7795 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007796 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007797 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007798 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007799
7800 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7801 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007802 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007803 E->getLocEnd());
7804}
Mike Stump1eb44332009-09-09 15:08:12 +00007805
Douglas Gregorb98b1992009-08-11 05:31:07 +00007806template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007807ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007808TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007809 // Create the local class that will describe the lambda.
7810 CXXRecordDecl *Class
7811 = getSema().createLambdaClosureType(E->getIntroducerRange());
7812 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7813
7814 // Transform the type of the lambda parameters and start the definition of
7815 // the lambda itself.
7816 TypeSourceInfo *MethodTy
7817 = TransformType(E->getCallOperator()->getTypeSourceInfo());
7818 if (!MethodTy)
7819 return ExprError();
7820
Douglas Gregorc6889e72012-02-14 22:28:59 +00007821 // Transform lambda parameters.
7822 bool Invalid = false;
7823 llvm::SmallVector<QualType, 4> ParamTypes;
7824 llvm::SmallVector<ParmVarDecl *, 4> Params;
7825 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7826 E->getCallOperator()->param_begin(),
7827 E->getCallOperator()->param_size(),
7828 0, ParamTypes, &Params))
7829 Invalid = true;
7830
Douglas Gregordfca6f52012-02-13 22:00:16 +00007831 // Build the call operator.
7832 CXXMethodDecl *CallOperator
7833 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7834 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007835 E->getCallOperator()->getLocEnd(),
7836 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007837 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7838
Douglas Gregord5387e82012-02-14 00:00:48 +00007839 // FIXME: Instantiation-specific.
7840 CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(),
7841 TSK_ImplicitInstantiation);
7842
7843 // Introduce the context of the call operator.
7844 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7845
Douglas Gregordfca6f52012-02-13 22:00:16 +00007846 // Enter the scope of the lambda.
7847 sema::LambdaScopeInfo *LSI
7848 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7849 E->getCaptureDefault(),
7850 E->hasExplicitParameters(),
7851 E->hasExplicitResultType(),
7852 E->isMutable());
7853
7854 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00007855 bool FinishedExplicitCaptures = false;
7856 for (LambdaExpr::capture_iterator C = E->capture_begin(),
7857 CEnd = E->capture_end();
7858 C != CEnd; ++C) {
7859 // When we hit the first implicit capture, tell Sema that we've finished
7860 // the list of explicit captures.
7861 if (!FinishedExplicitCaptures && C->isImplicit()) {
7862 getSema().finishLambdaExplicitCaptures(LSI);
7863 FinishedExplicitCaptures = true;
7864 }
7865
7866 // Capturing 'this' is trivial.
7867 if (C->capturesThis()) {
7868 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7869 continue;
7870 }
7871
Douglas Gregora7365242012-02-14 19:27:52 +00007872 // Determine the capture kind for Sema.
7873 Sema::TryCaptureKind Kind
7874 = C->isImplicit()? Sema::TryCapture_Implicit
7875 : C->getCaptureKind() == LCK_ByCopy
7876 ? Sema::TryCapture_ExplicitByVal
7877 : Sema::TryCapture_ExplicitByRef;
7878 SourceLocation EllipsisLoc;
7879 if (C->isPackExpansion()) {
7880 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7881 bool ShouldExpand = false;
7882 bool RetainExpansion = false;
7883 llvm::Optional<unsigned> NumExpansions;
7884 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7885 C->getLocation(),
7886 Unexpanded,
7887 ShouldExpand, RetainExpansion,
7888 NumExpansions))
7889 return ExprError();
7890
7891 if (ShouldExpand) {
7892 // The transform has determined that we should perform an expansion;
7893 // transform and capture each of the arguments.
7894 // expansion of the pattern. Do so.
7895 VarDecl *Pack = C->getCapturedVar();
7896 for (unsigned I = 0; I != *NumExpansions; ++I) {
7897 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7898 VarDecl *CapturedVar
7899 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7900 Pack));
7901 if (!CapturedVar) {
7902 Invalid = true;
7903 continue;
7904 }
7905
7906 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007907 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregora7365242012-02-14 19:27:52 +00007908 }
7909 continue;
7910 }
7911
7912 EllipsisLoc = C->getEllipsisLoc();
7913 }
7914
Douglas Gregordfca6f52012-02-13 22:00:16 +00007915 // Transform the captured variable.
7916 VarDecl *CapturedVar
7917 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7918 C->getCapturedVar()));
7919 if (!CapturedVar) {
7920 Invalid = true;
7921 continue;
7922 }
Douglas Gregora7365242012-02-14 19:27:52 +00007923
Douglas Gregordfca6f52012-02-13 22:00:16 +00007924 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007925 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007926 }
7927 if (!FinishedExplicitCaptures)
7928 getSema().finishLambdaExplicitCaptures(LSI);
7929
Douglas Gregordfca6f52012-02-13 22:00:16 +00007930
7931 // Enter a new evaluation context to insulate the lambda from any
7932 // cleanups from the enclosing full-expression.
7933 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
7934
7935 if (Invalid) {
7936 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7937 /*IsInstantiation=*/true);
7938 return ExprError();
7939 }
7940
7941 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00007942 StmtResult Body = getDerived().TransformStmt(E->getBody());
7943 if (Body.isInvalid()) {
7944 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7945 /*IsInstantiation=*/true);
7946 return ExprError();
7947 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007948
7949 // Note: Once a lambda mangling number and context declaration have been
7950 // assigned, they never change.
Douglas Gregor9e8c92a2012-02-20 19:44:39 +00007951 unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber();
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007952 Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl();
Douglas Gregordfca6f52012-02-13 22:00:16 +00007953 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregor9e8c92a2012-02-20 19:44:39 +00007954 /*CurScope=*/0, ManglingNumber,
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007955 ContextDecl,
Douglas Gregordfca6f52012-02-13 22:00:16 +00007956 /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00007957}
7958
7959template<typename Derived>
7960ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007961TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007962 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007963 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7964 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007965 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007966
Douglas Gregorb98b1992009-08-11 05:31:07 +00007967 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007968 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007969 Args.reserve(E->arg_size());
7970 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7971 &ArgumentChanged))
7972 return ExprError();
7973
Douglas Gregorb98b1992009-08-11 05:31:07 +00007974 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007975 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007976 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007977 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007978
Douglas Gregorb98b1992009-08-11 05:31:07 +00007979 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007980 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007981 E->getLParenLoc(),
7982 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007983 E->getRParenLoc());
7984}
Mike Stump1eb44332009-09-09 15:08:12 +00007985
Douglas Gregorb98b1992009-08-11 05:31:07 +00007986template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007987ExprResult
John McCall865d4472009-11-19 22:55:06 +00007988TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007989 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007990 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007991 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007992 Expr *OldBase;
7993 QualType BaseType;
7994 QualType ObjectType;
7995 if (!E->isImplicitAccess()) {
7996 OldBase = E->getBase();
7997 Base = getDerived().TransformExpr(OldBase);
7998 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007999 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008000
John McCallaa81e162009-12-01 22:10:20 +00008001 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008002 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008003 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008004 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008005 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008006 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008007 ObjectTy,
8008 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008009 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008010 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008011
John McCallb3d87482010-08-24 05:47:05 +00008012 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008013 BaseType = ((Expr*) Base.get())->getType();
8014 } else {
8015 OldBase = 0;
8016 BaseType = getDerived().TransformType(E->getBaseType());
8017 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8018 }
Mike Stump1eb44332009-09-09 15:08:12 +00008019
Douglas Gregor6cd21982009-10-20 05:58:46 +00008020 // Transform the first part of the nested-name-specifier that qualifies
8021 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008022 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008023 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008024 E->getFirstQualifierFoundInScope(),
8025 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008026
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008027 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008028 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008029 QualifierLoc
8030 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8031 ObjectType,
8032 FirstQualifierInScope);
8033 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008034 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008035 }
Mike Stump1eb44332009-09-09 15:08:12 +00008036
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008037 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8038
John McCall43fed0d2010-11-12 08:19:04 +00008039 // TODO: If this is a conversion-function-id, verify that the
8040 // destination type name (if present) resolves the same way after
8041 // instantiation as it did in the local scope.
8042
Abramo Bagnara25777432010-08-11 22:01:17 +00008043 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008044 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008045 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008046 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008047
John McCallaa81e162009-12-01 22:10:20 +00008048 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008049 // This is a reference to a member without an explicitly-specified
8050 // template argument list. Optimize for this common case.
8051 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008052 Base.get() == OldBase &&
8053 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008054 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008055 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008056 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008057 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008058
John McCall9ae2f072010-08-23 23:25:46 +00008059 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008060 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008061 E->isArrow(),
8062 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008063 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008064 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008065 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008066 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008067 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008068 }
8069
John McCalld5532b62009-11-23 01:53:49 +00008070 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008071 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8072 E->getNumTemplateArgs(),
8073 TransArgs))
8074 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008075
John McCall9ae2f072010-08-23 23:25:46 +00008076 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008077 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008078 E->isArrow(),
8079 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008080 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008081 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008082 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008083 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008084 &TransArgs);
8085}
8086
8087template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008088ExprResult
John McCall454feb92009-12-08 09:21:05 +00008089TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008090 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008091 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008092 QualType BaseType;
8093 if (!Old->isImplicitAccess()) {
8094 Base = getDerived().TransformExpr(Old->getBase());
8095 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008096 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008097 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8098 Old->isArrow());
8099 if (Base.isInvalid())
8100 return ExprError();
8101 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008102 } else {
8103 BaseType = getDerived().TransformType(Old->getBaseType());
8104 }
John McCall129e2df2009-11-30 22:42:35 +00008105
Douglas Gregor4c9be892011-02-28 20:01:57 +00008106 NestedNameSpecifierLoc QualifierLoc;
8107 if (Old->getQualifierLoc()) {
8108 QualifierLoc
8109 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8110 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008111 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008112 }
8113
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008114 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8115
Abramo Bagnara25777432010-08-11 22:01:17 +00008116 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008117 Sema::LookupOrdinaryName);
8118
8119 // Transform all the decls.
8120 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8121 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008122 NamedDecl *InstD = static_cast<NamedDecl*>(
8123 getDerived().TransformDecl(Old->getMemberLoc(),
8124 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008125 if (!InstD) {
8126 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8127 // This can happen because of dependent hiding.
8128 if (isa<UsingShadowDecl>(*I))
8129 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008130 else {
8131 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008132 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008133 }
John McCall9f54ad42009-12-10 09:41:52 +00008134 }
John McCall129e2df2009-11-30 22:42:35 +00008135
8136 // Expand using declarations.
8137 if (isa<UsingDecl>(InstD)) {
8138 UsingDecl *UD = cast<UsingDecl>(InstD);
8139 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8140 E = UD->shadow_end(); I != E; ++I)
8141 R.addDecl(*I);
8142 continue;
8143 }
8144
8145 R.addDecl(InstD);
8146 }
8147
8148 R.resolveKind();
8149
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008150 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008151 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00008152 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008153 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008154 Old->getMemberLoc(),
8155 Old->getNamingClass()));
8156 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008157 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008158
Douglas Gregor66c45152010-04-27 16:10:10 +00008159 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008160 }
Sean Huntc3021132010-05-05 15:23:54 +00008161
John McCall129e2df2009-11-30 22:42:35 +00008162 TemplateArgumentListInfo TransArgs;
8163 if (Old->hasExplicitTemplateArgs()) {
8164 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8165 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008166 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8167 Old->getNumTemplateArgs(),
8168 TransArgs))
8169 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008170 }
John McCallc2233c52010-01-15 08:34:02 +00008171
8172 // FIXME: to do this check properly, we will need to preserve the
8173 // first-qualifier-in-scope here, just in case we had a dependent
8174 // base (and therefore couldn't do the check) and a
8175 // nested-name-qualifier (and therefore could do the lookup).
8176 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00008177
John McCall9ae2f072010-08-23 23:25:46 +00008178 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008179 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008180 Old->getOperatorLoc(),
8181 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008182 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008183 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008184 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008185 R,
8186 (Old->hasExplicitTemplateArgs()
8187 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008188}
8189
8190template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008191ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008192TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008193 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008194 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8195 if (SubExpr.isInvalid())
8196 return ExprError();
8197
8198 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008199 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008200
8201 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8202}
8203
8204template<typename Derived>
8205ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008206TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008207 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8208 if (Pattern.isInvalid())
8209 return ExprError();
8210
8211 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8212 return SemaRef.Owned(E);
8213
Douglas Gregor67fd1252011-01-14 21:20:45 +00008214 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8215 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008216}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008217
8218template<typename Derived>
8219ExprResult
8220TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8221 // If E is not value-dependent, then nothing will change when we transform it.
8222 // Note: This is an instantiation-centric view.
8223 if (!E->isValueDependent())
8224 return SemaRef.Owned(E);
8225
8226 // Note: None of the implementations of TryExpandParameterPacks can ever
8227 // produce a diagnostic when given only a single unexpanded parameter pack,
8228 // so
8229 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8230 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008231 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008232 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00008233 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008234 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008235 ShouldExpand, RetainExpansion,
8236 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008237 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00008238
Douglas Gregor089e8932011-10-10 18:59:29 +00008239 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008240 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00008241
8242 NamedDecl *Pack = E->getPack();
8243 if (!ShouldExpand) {
8244 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8245 Pack));
8246 if (!Pack)
8247 return ExprError();
8248 }
8249
Douglas Gregoree8aff02011-01-04 17:33:58 +00008250
8251 // We now know the length of the parameter pack, so build a new expression
8252 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00008253 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00008254 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008255 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008256}
8257
Douglas Gregorbe230c32011-01-03 17:17:50 +00008258template<typename Derived>
8259ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008260TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8261 SubstNonTypeTemplateParmPackExpr *E) {
8262 // Default behavior is to do nothing with this transformation.
8263 return SemaRef.Owned(E);
8264}
8265
8266template<typename Derived>
8267ExprResult
John McCall91a57552011-07-15 05:09:51 +00008268TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8269 SubstNonTypeTemplateParmExpr *E) {
8270 // Default behavior is to do nothing with this transformation.
8271 return SemaRef.Owned(E);
8272}
8273
8274template<typename Derived>
8275ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008276TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8277 MaterializeTemporaryExpr *E) {
8278 return getDerived().TransformExpr(E->GetTemporaryExpr());
8279}
8280
8281template<typename Derived>
8282ExprResult
John McCall454feb92009-12-08 09:21:05 +00008283TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008284 return SemaRef.MaybeBindToTemporary(E);
8285}
8286
8287template<typename Derived>
8288ExprResult
8289TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
8290 return SemaRef.MaybeBindToTemporary(E);
8291}
8292
8293template<typename Derived>
8294ExprResult
8295TreeTransform<Derived>::TransformObjCNumericLiteral(ObjCNumericLiteral *E) {
8296 return SemaRef.MaybeBindToTemporary(E);
8297}
8298
8299template<typename Derived>
8300ExprResult
8301TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8302 // Transform each of the elements.
8303 llvm::SmallVector<Expr *, 8> Elements;
8304 bool ArgChanged = false;
8305 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
8306 /*IsCall=*/false, Elements, &ArgChanged))
8307 return ExprError();
8308
8309 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8310 return SemaRef.MaybeBindToTemporary(E);
8311
8312 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8313 Elements.data(),
8314 Elements.size());
8315}
8316
8317template<typename Derived>
8318ExprResult
8319TreeTransform<Derived>::TransformObjCDictionaryLiteral(
8320 ObjCDictionaryLiteral *E) {
8321 // Transform each of the elements.
8322 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8323 bool ArgChanged = false;
8324 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8325 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
8326
8327 if (OrigElement.isPackExpansion()) {
8328 // This key/value element is a pack expansion.
8329 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8330 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8331 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8332 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8333
8334 // Determine whether the set of unexpanded parameter packs can
8335 // and should be expanded.
8336 bool Expand = true;
8337 bool RetainExpansion = false;
8338 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8339 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8340 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8341 OrigElement.Value->getLocEnd());
8342 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8343 PatternRange,
8344 Unexpanded,
8345 Expand, RetainExpansion,
8346 NumExpansions))
8347 return ExprError();
8348
8349 if (!Expand) {
8350 // The transform has determined that we should perform a simple
8351 // transformation on the pack expansion, producing another pack
8352 // expansion.
8353 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8354 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8355 if (Key.isInvalid())
8356 return ExprError();
8357
8358 if (Key.get() != OrigElement.Key)
8359 ArgChanged = true;
8360
8361 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8362 if (Value.isInvalid())
8363 return ExprError();
8364
8365 if (Value.get() != OrigElement.Value)
8366 ArgChanged = true;
8367
8368 ObjCDictionaryElement Expansion = {
8369 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8370 };
8371 Elements.push_back(Expansion);
8372 continue;
8373 }
8374
8375 // Record right away that the argument was changed. This needs
8376 // to happen even if the array expands to nothing.
8377 ArgChanged = true;
8378
8379 // The transform has determined that we should perform an elementwise
8380 // expansion of the pattern. Do so.
8381 for (unsigned I = 0; I != *NumExpansions; ++I) {
8382 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8383 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8384 if (Key.isInvalid())
8385 return ExprError();
8386
8387 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8388 if (Value.isInvalid())
8389 return ExprError();
8390
8391 ObjCDictionaryElement Element = {
8392 Key.get(), Value.get(), SourceLocation(), NumExpansions
8393 };
8394
8395 // If any unexpanded parameter packs remain, we still have a
8396 // pack expansion.
8397 if (Key.get()->containsUnexpandedParameterPack() ||
8398 Value.get()->containsUnexpandedParameterPack())
8399 Element.EllipsisLoc = OrigElement.EllipsisLoc;
8400
8401 Elements.push_back(Element);
8402 }
8403
8404 // We've finished with this pack expansion.
8405 continue;
8406 }
8407
8408 // Transform and check key.
8409 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8410 if (Key.isInvalid())
8411 return ExprError();
8412
8413 if (Key.get() != OrigElement.Key)
8414 ArgChanged = true;
8415
8416 // Transform and check value.
8417 ExprResult Value
8418 = getDerived().TransformExpr(OrigElement.Value);
8419 if (Value.isInvalid())
8420 return ExprError();
8421
8422 if (Value.get() != OrigElement.Value)
8423 ArgChanged = true;
8424
8425 ObjCDictionaryElement Element = {
8426 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8427 };
8428 Elements.push_back(Element);
8429 }
8430
8431 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8432 return SemaRef.MaybeBindToTemporary(E);
8433
8434 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8435 Elements.data(),
8436 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008437}
8438
Mike Stump1eb44332009-09-09 15:08:12 +00008439template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008440ExprResult
John McCall454feb92009-12-08 09:21:05 +00008441TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008442 TypeSourceInfo *EncodedTypeInfo
8443 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8444 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008445 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008446
Douglas Gregorb98b1992009-08-11 05:31:07 +00008447 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008448 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008449 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008450
8451 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008452 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008453 E->getRParenLoc());
8454}
Mike Stump1eb44332009-09-09 15:08:12 +00008455
Douglas Gregorb98b1992009-08-11 05:31:07 +00008456template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008457ExprResult TreeTransform<Derived>::
8458TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8459 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8460 if (result.isInvalid()) return ExprError();
8461 Expr *subExpr = result.take();
8462
8463 if (!getDerived().AlwaysRebuild() &&
8464 subExpr == E->getSubExpr())
8465 return SemaRef.Owned(E);
8466
8467 return SemaRef.Owned(new(SemaRef.Context)
8468 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8469}
8470
8471template<typename Derived>
8472ExprResult TreeTransform<Derived>::
8473TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
8474 TypeSourceInfo *TSInfo
8475 = getDerived().TransformType(E->getTypeInfoAsWritten());
8476 if (!TSInfo)
8477 return ExprError();
8478
8479 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
8480 if (Result.isInvalid())
8481 return ExprError();
8482
8483 if (!getDerived().AlwaysRebuild() &&
8484 TSInfo == E->getTypeInfoAsWritten() &&
8485 Result.get() == E->getSubExpr())
8486 return SemaRef.Owned(E);
8487
8488 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8489 E->getBridgeKeywordLoc(), TSInfo,
8490 Result.get());
8491}
8492
8493template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008494ExprResult
John McCall454feb92009-12-08 09:21:05 +00008495TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008496 // Transform arguments.
8497 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008498 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008499 Args.reserve(E->getNumArgs());
8500 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8501 &ArgChanged))
8502 return ExprError();
8503
Douglas Gregor92e986e2010-04-22 16:44:27 +00008504 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8505 // Class message: transform the receiver type.
8506 TypeSourceInfo *ReceiverTypeInfo
8507 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8508 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008509 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008510
Douglas Gregor92e986e2010-04-22 16:44:27 +00008511 // If nothing changed, just retain the existing message send.
8512 if (!getDerived().AlwaysRebuild() &&
8513 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008514 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008515
8516 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008517 SmallVector<SourceLocation, 16> SelLocs;
8518 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008519 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8520 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008521 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008522 E->getMethodDecl(),
8523 E->getLeftLoc(),
8524 move_arg(Args),
8525 E->getRightLoc());
8526 }
8527
8528 // Instance message: transform the receiver
8529 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8530 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008531 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008532 = getDerived().TransformExpr(E->getInstanceReceiver());
8533 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008534 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008535
8536 // If nothing changed, just retain the existing message send.
8537 if (!getDerived().AlwaysRebuild() &&
8538 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008539 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008540
Douglas Gregor92e986e2010-04-22 16:44:27 +00008541 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008542 SmallVector<SourceLocation, 16> SelLocs;
8543 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008544 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008545 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008546 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008547 E->getMethodDecl(),
8548 E->getLeftLoc(),
8549 move_arg(Args),
8550 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008551}
8552
Mike Stump1eb44332009-09-09 15:08:12 +00008553template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008554ExprResult
John McCall454feb92009-12-08 09:21:05 +00008555TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008556 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008557}
8558
Mike Stump1eb44332009-09-09 15:08:12 +00008559template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008560ExprResult
John McCall454feb92009-12-08 09:21:05 +00008561TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008562 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008563}
8564
Mike Stump1eb44332009-09-09 15:08:12 +00008565template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008566ExprResult
John McCall454feb92009-12-08 09:21:05 +00008567TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008568 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008569 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008570 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008571 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008572
8573 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008574
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008575 // If nothing changed, just retain the existing expression.
8576 if (!getDerived().AlwaysRebuild() &&
8577 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008578 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008579
John McCall9ae2f072010-08-23 23:25:46 +00008580 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008581 E->getLocation(),
8582 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008583}
8584
Mike Stump1eb44332009-09-09 15:08:12 +00008585template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008586ExprResult
John McCall454feb92009-12-08 09:21:05 +00008587TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008588 // 'super' and types never change. Property never changes. Just
8589 // retain the existing expression.
8590 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008591 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008592
Douglas Gregore3303542010-04-26 20:47:02 +00008593 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008594 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008595 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008596 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008597
Douglas Gregore3303542010-04-26 20:47:02 +00008598 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008599
Douglas Gregore3303542010-04-26 20:47:02 +00008600 // If nothing changed, just retain the existing expression.
8601 if (!getDerived().AlwaysRebuild() &&
8602 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008603 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008604
John McCall12f78a62010-12-02 01:19:52 +00008605 if (E->isExplicitProperty())
8606 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8607 E->getExplicitProperty(),
8608 E->getLocation());
8609
8610 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008611 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008612 E->getImplicitPropertyGetter(),
8613 E->getImplicitPropertySetter(),
8614 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008615}
8616
Mike Stump1eb44332009-09-09 15:08:12 +00008617template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008618ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008619TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8620 // Transform the base expression.
8621 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8622 if (Base.isInvalid())
8623 return ExprError();
8624
8625 // Transform the key expression.
8626 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8627 if (Key.isInvalid())
8628 return ExprError();
8629
8630 // If nothing changed, just retain the existing expression.
8631 if (!getDerived().AlwaysRebuild() &&
8632 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8633 return SemaRef.Owned(E);
8634
8635 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
8636 Base.get(), Key.get(),
8637 E->getAtIndexMethodDecl(),
8638 E->setAtIndexMethodDecl());
8639}
8640
8641template<typename Derived>
8642ExprResult
John McCall454feb92009-12-08 09:21:05 +00008643TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008644 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008645 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008646 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008647 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008648
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008649 // If nothing changed, just retain the existing expression.
8650 if (!getDerived().AlwaysRebuild() &&
8651 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008652 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008653
John McCall9ae2f072010-08-23 23:25:46 +00008654 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008655 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008656}
8657
Mike Stump1eb44332009-09-09 15:08:12 +00008658template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008659ExprResult
John McCall454feb92009-12-08 09:21:05 +00008660TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008661 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008662 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008663 SubExprs.reserve(E->getNumSubExprs());
8664 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8665 SubExprs, &ArgumentChanged))
8666 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008667
Douglas Gregorb98b1992009-08-11 05:31:07 +00008668 if (!getDerived().AlwaysRebuild() &&
8669 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008670 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008671
Douglas Gregorb98b1992009-08-11 05:31:07 +00008672 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8673 move_arg(SubExprs),
8674 E->getRParenLoc());
8675}
8676
Mike Stump1eb44332009-09-09 15:08:12 +00008677template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008678ExprResult
John McCall454feb92009-12-08 09:21:05 +00008679TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008680 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008681
John McCallc6ac9c32011-02-04 18:33:18 +00008682 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8683 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8684
8685 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008686 blockScope->TheDecl->setBlockMissingReturnType(
8687 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008688
Chris Lattner686775d2011-07-20 06:58:45 +00008689 SmallVector<ParmVarDecl*, 4> params;
8690 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008691
8692 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008693 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8694 oldBlock->param_begin(),
8695 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008696 0, paramTypes, &params)) {
8697 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008698 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008699 }
John McCallc6ac9c32011-02-04 18:33:18 +00008700
8701 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008702 QualType exprResultType =
8703 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008704
8705 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008706 if (exprResultType->isObjCObjectType()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008707 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008708 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008709 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008710 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008711 return ExprError();
8712 }
John McCall711c52b2011-01-05 12:14:39 +00008713
John McCallc6ac9c32011-02-04 18:33:18 +00008714 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008715 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008716 paramTypes.data(),
8717 paramTypes.size(),
8718 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008719 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008720 exprFunctionType->getExtInfo());
8721 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008722
8723 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008724 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008725 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008726
8727 if (!oldBlock->blockMissingReturnType()) {
8728 blockScope->HasImplicitReturnType = false;
8729 blockScope->ReturnType = exprResultType;
8730 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008731
John McCall711c52b2011-01-05 12:14:39 +00008732 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008733 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008734 if (body.isInvalid()) {
8735 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008736 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008737 }
John McCall711c52b2011-01-05 12:14:39 +00008738
John McCallc6ac9c32011-02-04 18:33:18 +00008739#ifndef NDEBUG
8740 // In builds with assertions, make sure that we captured everything we
8741 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008742 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8743 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8744 e = oldBlock->capture_end(); i != e; ++i) {
8745 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008746
Douglas Gregorfc921372011-05-20 15:32:55 +00008747 // Ignore parameter packs.
8748 if (isa<ParmVarDecl>(oldCapture) &&
8749 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8750 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008751
Douglas Gregorfc921372011-05-20 15:32:55 +00008752 VarDecl *newCapture =
8753 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8754 oldCapture));
8755 assert(blockScope->CaptureMap.count(newCapture));
8756 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008757 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008758 }
8759#endif
8760
8761 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8762 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008763}
8764
Mike Stump1eb44332009-09-09 15:08:12 +00008765template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008766ExprResult
John McCall454feb92009-12-08 09:21:05 +00008767TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008768 ValueDecl *ND
8769 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8770 E->getDecl()));
8771 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00008772 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00008773
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008774 if (!getDerived().AlwaysRebuild() &&
8775 ND == E->getDecl()) {
8776 // Mark it referenced in the new context regardless.
8777 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00008778 SemaRef.MarkBlockDeclRefReferenced(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008779
John McCall3fa5cae2010-10-26 07:05:15 +00008780 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008781 }
8782
Abramo Bagnara25777432010-08-11 22:01:17 +00008783 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00008784 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00008785 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008786}
Mike Stump1eb44332009-09-09 15:08:12 +00008787
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008788template<typename Derived>
8789ExprResult
8790TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008791 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008792}
Eli Friedman276b0612011-10-11 02:20:01 +00008793
8794template<typename Derived>
8795ExprResult
8796TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008797 QualType RetTy = getDerived().TransformType(E->getType());
8798 bool ArgumentChanged = false;
8799 ASTOwningVector<Expr*> SubExprs(SemaRef);
8800 SubExprs.reserve(E->getNumSubExprs());
8801 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8802 SubExprs, &ArgumentChanged))
8803 return ExprError();
8804
8805 if (!getDerived().AlwaysRebuild() &&
8806 !ArgumentChanged)
8807 return SemaRef.Owned(E);
8808
8809 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8810 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008811}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008812
Douglas Gregorb98b1992009-08-11 05:31:07 +00008813//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008814// Type reconstruction
8815//===----------------------------------------------------------------------===//
8816
Mike Stump1eb44332009-09-09 15:08:12 +00008817template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008818QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8819 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008820 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008821 getDerived().getBaseEntity());
8822}
8823
Mike Stump1eb44332009-09-09 15:08:12 +00008824template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008825QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8826 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008827 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008828 getDerived().getBaseEntity());
8829}
8830
Mike Stump1eb44332009-09-09 15:08:12 +00008831template<typename Derived>
8832QualType
John McCall85737a72009-10-30 00:06:24 +00008833TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8834 bool WrittenAsLValue,
8835 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008836 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008837 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008838}
8839
8840template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008841QualType
John McCall85737a72009-10-30 00:06:24 +00008842TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8843 QualType ClassType,
8844 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008845 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008846 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008847}
8848
8849template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008850QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008851TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8852 ArrayType::ArraySizeModifier SizeMod,
8853 const llvm::APInt *Size,
8854 Expr *SizeExpr,
8855 unsigned IndexTypeQuals,
8856 SourceRange BracketsRange) {
8857 if (SizeExpr || !Size)
8858 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8859 IndexTypeQuals, BracketsRange,
8860 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008861
8862 QualType Types[] = {
8863 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8864 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8865 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008866 };
8867 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8868 QualType SizeType;
8869 for (unsigned I = 0; I != NumTypes; ++I)
8870 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8871 SizeType = Types[I];
8872 break;
8873 }
Mike Stump1eb44332009-09-09 15:08:12 +00008874
Eli Friedman01f276d2012-01-25 23:20:27 +00008875 // Note that we can return a VariableArrayType here in the case where
8876 // the element type was a dependent VariableArrayType.
8877 IntegerLiteral *ArraySize
8878 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8879 /*FIXME*/BracketsRange.getBegin());
8880 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008881 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008882 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008883}
Mike Stump1eb44332009-09-09 15:08:12 +00008884
Douglas Gregor577f75a2009-08-04 16:50:30 +00008885template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008886QualType
8887TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008888 ArrayType::ArraySizeModifier SizeMod,
8889 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008890 unsigned IndexTypeQuals,
8891 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008892 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008893 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008894}
8895
8896template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008897QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008898TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008899 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008900 unsigned IndexTypeQuals,
8901 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008902 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008903 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008904}
Mike Stump1eb44332009-09-09 15:08:12 +00008905
Douglas Gregor577f75a2009-08-04 16:50:30 +00008906template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008907QualType
8908TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008909 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008910 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008911 unsigned IndexTypeQuals,
8912 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008913 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008914 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008915 IndexTypeQuals, BracketsRange);
8916}
8917
8918template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008919QualType
8920TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008921 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008922 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008923 unsigned IndexTypeQuals,
8924 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008925 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008926 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008927 IndexTypeQuals, BracketsRange);
8928}
8929
8930template<typename Derived>
8931QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008932 unsigned NumElements,
8933 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008934 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008935 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008936}
Mike Stump1eb44332009-09-09 15:08:12 +00008937
Douglas Gregor577f75a2009-08-04 16:50:30 +00008938template<typename Derived>
8939QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8940 unsigned NumElements,
8941 SourceLocation AttributeLoc) {
8942 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8943 NumElements, true);
8944 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008945 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8946 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008947 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008948}
Mike Stump1eb44332009-09-09 15:08:12 +00008949
Douglas Gregor577f75a2009-08-04 16:50:30 +00008950template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008951QualType
8952TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008953 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008954 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008955 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008956}
Mike Stump1eb44332009-09-09 15:08:12 +00008957
Douglas Gregor577f75a2009-08-04 16:50:30 +00008958template<typename Derived>
8959QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008960 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008961 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008962 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008963 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00008964 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008965 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008966 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008967 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008968 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008969 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008970 getDerived().getBaseEntity(),
8971 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008972}
Mike Stump1eb44332009-09-09 15:08:12 +00008973
Douglas Gregor577f75a2009-08-04 16:50:30 +00008974template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008975QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8976 return SemaRef.Context.getFunctionNoProtoType(T);
8977}
8978
8979template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008980QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8981 assert(D && "no decl found");
8982 if (D->isInvalidDecl()) return QualType();
8983
Douglas Gregor92e986e2010-04-22 16:44:27 +00008984 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008985 TypeDecl *Ty;
8986 if (isa<UsingDecl>(D)) {
8987 UsingDecl *Using = cast<UsingDecl>(D);
8988 assert(Using->isTypeName() &&
8989 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8990
8991 // A valid resolved using typename decl points to exactly one type decl.
8992 assert(++Using->shadow_begin() == Using->shadow_end());
8993 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008994
John McCalled976492009-12-04 22:46:56 +00008995 } else {
8996 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8997 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8998 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8999 }
9000
9001 return SemaRef.Context.getTypeDeclType(Ty);
9002}
9003
9004template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009005QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9006 SourceLocation Loc) {
9007 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009008}
9009
9010template<typename Derived>
9011QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9012 return SemaRef.Context.getTypeOfType(Underlying);
9013}
9014
9015template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009016QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9017 SourceLocation Loc) {
9018 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009019}
9020
9021template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009022QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9023 UnaryTransformType::UTTKind UKind,
9024 SourceLocation Loc) {
9025 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9026}
9027
9028template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009029QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009030 TemplateName Template,
9031 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009032 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009033 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009034}
Mike Stump1eb44332009-09-09 15:08:12 +00009035
Douglas Gregordcee1a12009-08-06 05:28:30 +00009036template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009037QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9038 SourceLocation KWLoc) {
9039 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9040}
9041
9042template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009043TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009044TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009045 bool TemplateKW,
9046 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009047 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009048 Template);
9049}
9050
9051template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009052TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009053TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9054 const IdentifierInfo &Name,
9055 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009056 QualType ObjectType,
9057 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009058 UnqualifiedId TemplateName;
9059 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009060 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009061 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009062 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009063 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009064 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009065 /*EnteringContext=*/false,
9066 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009067 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009068}
Mike Stump1eb44332009-09-09 15:08:12 +00009069
Douglas Gregorb98b1992009-08-11 05:31:07 +00009070template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009071TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009072TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009073 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009074 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009075 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009076 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009077 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009078 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009079 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009080 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009081 Sema::TemplateTy Template;
9082 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009083 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009084 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009085 /*EnteringContext=*/false,
9086 Template);
9087 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009088}
Sean Huntc3021132010-05-05 15:23:54 +00009089
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009090template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009091ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009092TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9093 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009094 Expr *OrigCallee,
9095 Expr *First,
9096 Expr *Second) {
9097 Expr *Callee = OrigCallee->IgnoreParenCasts();
9098 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009099
Douglas Gregorb98b1992009-08-11 05:31:07 +00009100 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009101 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009102 if (!First->getType()->isOverloadableType() &&
9103 !Second->getType()->isOverloadableType())
9104 return getSema().CreateBuiltinArraySubscriptExpr(First,
9105 Callee->getLocStart(),
9106 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009107 } else if (Op == OO_Arrow) {
9108 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009109 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9110 } else if (Second == 0 || isPostIncDec) {
9111 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009112 // The argument is not of overloadable type, so try to create a
9113 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009114 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009115 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009116
John McCall9ae2f072010-08-23 23:25:46 +00009117 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009118 }
9119 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009120 if (!First->getType()->isOverloadableType() &&
9121 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009122 // Neither of the arguments is an overloadable type, so try to
9123 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009124 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009125 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009126 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009127 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009128 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009129
Douglas Gregorb98b1992009-08-11 05:31:07 +00009130 return move(Result);
9131 }
9132 }
Mike Stump1eb44332009-09-09 15:08:12 +00009133
9134 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009135 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009136 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009137
John McCall9ae2f072010-08-23 23:25:46 +00009138 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009139 assert(ULE->requiresADL());
9140
9141 // FIXME: Do we have to check
9142 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009143 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009144 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009145 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009146 }
Mike Stump1eb44332009-09-09 15:08:12 +00009147
Douglas Gregorb98b1992009-08-11 05:31:07 +00009148 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009149 Expr *Args[2] = { First, Second };
9150 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009151
Douglas Gregorb98b1992009-08-11 05:31:07 +00009152 // Create the overloaded operator invocation for unary operators.
9153 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009154 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009155 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009156 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009157 }
Mike Stump1eb44332009-09-09 15:08:12 +00009158
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009159 if (Op == OO_Subscript) {
9160 SourceLocation LBrace;
9161 SourceLocation RBrace;
9162
9163 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9164 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9165 LBrace = SourceLocation::getFromRawEncoding(
9166 NameLoc.CXXOperatorName.BeginOpNameLoc);
9167 RBrace = SourceLocation::getFromRawEncoding(
9168 NameLoc.CXXOperatorName.EndOpNameLoc);
9169 } else {
9170 LBrace = Callee->getLocStart();
9171 RBrace = OpLoc;
9172 }
9173
9174 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9175 First, Second);
9176 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009177
Douglas Gregorb98b1992009-08-11 05:31:07 +00009178 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009179 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009180 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009181 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9182 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009183 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009184
Mike Stump1eb44332009-09-09 15:08:12 +00009185 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009186}
Mike Stump1eb44332009-09-09 15:08:12 +00009187
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009188template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009189ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009190TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009191 SourceLocation OperatorLoc,
9192 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009193 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009194 TypeSourceInfo *ScopeType,
9195 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009196 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009197 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009198 QualType BaseType = Base->getType();
9199 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009200 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00009201 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009202 !BaseType->getAs<PointerType>()->getPointeeType()
9203 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009204 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009205 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009206 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009207 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009208 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009209 /*FIXME?*/true);
9210 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009211
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009212 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009213 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9214 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9215 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9216 NameInfo.setNamedTypeInfo(DestroyedType);
9217
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009218 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00009219
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009220 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009221 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009222 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009223 SS, TemplateKWLoc,
9224 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009225 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009226 /*TemplateArgs*/ 0);
9227}
9228
Douglas Gregor577f75a2009-08-04 16:50:30 +00009229} // end namespace clang
9230
9231#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H